- added Bit Packer

git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@423 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2019-02-10 15:55:43 +00:00
parent e7e3babb50
commit 28681c4973
4 changed files with 295 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
<?xml version="1.0"?>
<block>
<name>Bit Packer</name>
<key>jay_bit_packer</key>
<category>[JAY]</category>
<import>import jay</import>
<make>jay.bit_packer($numBitsIn, $numBitsOut, $endianess)</make>
<!-- Make one 'param' node for every Parameter you want settable from the GUI.
Sub-nodes:
* name
* key (makes the value accessible as $keyname, e.g. in the make node)
* type -->
<param>
<name>Number of input bits</name>
<key>numBitsIn</key>
<type>int</type>
</param>
<param>
<name>Number of output bits</name>
<key>numBitsOut,</key>
<type>int</type>
</param>
<param>
<name>Endianess</name>
<key>endianess</key>
<type>int</type>
</param>
<!-- Make one 'sink' node per input. Sub-nodes:
* name (an identifier for the GUI)
* type
* vlen
* optional (set to 1 for optional inputs) -->
<sink>
<name>in</name>
<type>int</type>
</sink>
<!-- Make one 'source' node per output. Sub-nodes:
* name (an identifier for the GUI)
* type
* vlen
* optional (set to 1 for optional inputs) -->
<source>
<name>out</name>
<type>int</type>
</source>
</block>
+56
View File
@@ -0,0 +1,56 @@
/* -*- c++ -*- */
/*
* Copyright 2019 Jay Arrowfield.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef INCLUDED_JAY_BIT_PACKER_H
#define INCLUDED_JAY_BIT_PACKER_H
#include <jay/api.h>
#include <gnuradio/block.h>
namespace gr {
namespace jay {
/*!
* \brief <+description of block+>
* \ingroup jay
*
*/
class JAY_API bit_packer : virtual public gr::block
{
public:
typedef boost::shared_ptr<bit_packer> sptr;
/*!
* \brief Return a shared_ptr to a new instance of jay::bit_packer.
*
* To avoid accidental use of raw pointers, jay::bit_packer's
* constructor is in a private implementation
* class. jay::bit_packer::make is the public interface for
* creating new instances.
*/
static sptr make(int numBitsIn, int numBitsOut, int endianess);
};
} // namespace jay
} // namespace gr
#endif /* INCLUDED_JAY_BIT_PACKER_H */
+134
View File
@@ -0,0 +1,134 @@
/* -*- c++ -*- */
/*
* Copyright 2019 Jay Arrowfield.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "bit_packer_impl.h"
namespace gr {
namespace jay {
bit_packer::sptr
bit_packer::make(int numBitsIn, int numBitsOut, int endianess)
{
return gnuradio::get_initial_sptr
(new bit_packer_impl(numBitsIn, numBitsOut, endianess));
}
/*
* The private constructor
*/
bit_packer_impl::bit_packer_impl(int numBitsIn, int numBitsOut, int endianess)
: gr::block("bit_packer"
, gr::io_signature::make(1, 1, sizeof(int))
, gr::io_signature::make(1, 1, sizeof(int)))
, m_inputCounter(0)
, m_outputCounter(0)
, m_numBitsIn(numBitsIn)
, m_numBitsOut(numBitsOut)
, m_endianess(endianess)
{}
/*
* Our virtual destructor.
*/
bit_packer_impl::~bit_packer_impl()
{
}
void
bit_packer_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
{
/* <+forecast+> e.g. ninput_items_required[0] = noutput_items */
ninput_items_required[0] = m_numBitsIn*noutput_items;
}
int
bit_packer_impl::general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const int *in = (const int *) input_items[0];
int *out = (int *) output_items[0];
// Do <+signal processing+>
size_t i = 0;
size_t j = 0;
for (i=0; i < ninput_items[0]; i++)
{
if (in[i] == 0xFF)
{
m_inputCounter = 0;
m_outputCounter = 0;
}
else
{
if (m_endianess == 0)
{
if(m_inputCounter == m_numBitsIn)
{
m_output <<= (m_numBitsOut - m_outputCounter);
out[j++] = m_output;
m_output = 0;
m_inputCounter = 0;
m_outputCounter = 0;
}
m_output <<= 1;
if (in[i] != 0)
{
m_output |= 1;
}
}
else
{
if(m_inputCounter == m_numBitsIn)
{
m_output >>= (m_numBitsOut - m_outputCounter);
out[j++] = m_output;
m_output = 0;
m_inputCounter = 0;
m_outputCounter = 0;
}
m_output >>= 1;
if (in[i] != 0)
{
m_output |= 1 << (m_numBitsOut-1);
}
}
m_inputCounter++;
m_outputCounter++;
}
}
// Tell runtime system how many input items we consumed on
// each input stream.
consume_each (i);
// Tell runtime system how many output items we produced.
return j;
}
} /* namespace jay */
} /* namespace gr */
+57
View File
@@ -0,0 +1,57 @@
/* -*- c++ -*- */
/*
* Copyright 2019 Jay Arrowfield.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef INCLUDED_JAY_BIT_PACKER_IMPL_H
#define INCLUDED_JAY_BIT_PACKER_IMPL_H
#include <jay/bit_packer.h>
namespace gr {
namespace jay {
class bit_packer_impl : public bit_packer
{
private:
// Nothing to declare in this block.
int m_inputCounter;
int m_outputCounter;
int m_numBitsIn;
int m_numBitsOut;
int m_endianess;
int m_output;
public:
bit_packer_impl(int numBitsIn, int numBitsOut, int endianess);
~bit_packer_impl();
// Where all the action really happens
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
int general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
} // namespace jay
} // namespace gr
#endif /* INCLUDED_JAY_BIT_PACKER_IMPL_H */