From 28681c497376cc7e5723f7dda268ca7b943bc052 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sun, 10 Feb 2019 15:55:43 +0000 Subject: [PATCH] - added Bit Packer git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@423 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- gr-jay/grc/jay_bit_packer.xml | 48 ++++++++++++ gr-jay/include/jay/bit_packer.h | 56 +++++++++++++ gr-jay/lib/bit_packer_impl.cc | 134 ++++++++++++++++++++++++++++++++ gr-jay/lib/bit_packer_impl.h | 57 ++++++++++++++ 4 files changed, 295 insertions(+) create mode 100644 gr-jay/grc/jay_bit_packer.xml create mode 100644 gr-jay/include/jay/bit_packer.h create mode 100644 gr-jay/lib/bit_packer_impl.cc create mode 100644 gr-jay/lib/bit_packer_impl.h diff --git a/gr-jay/grc/jay_bit_packer.xml b/gr-jay/grc/jay_bit_packer.xml new file mode 100644 index 0000000..bcb1a94 --- /dev/null +++ b/gr-jay/grc/jay_bit_packer.xml @@ -0,0 +1,48 @@ + + + Bit Packer + jay_bit_packer + [JAY] + import jay + jay.bit_packer($numBitsIn, $numBitsOut, $endianess) + + + Number of input bits + numBitsIn + int + + + Number of output bits + numBitsOut, + int + + + Endianess + endianess + int + + + + + in + int + + + + + out + int + + diff --git a/gr-jay/include/jay/bit_packer.h b/gr-jay/include/jay/bit_packer.h new file mode 100644 index 0000000..584cde2 --- /dev/null +++ b/gr-jay/include/jay/bit_packer.h @@ -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 +#include + +namespace gr { + namespace jay { + + /*! + * \brief <+description of block+> + * \ingroup jay + * + */ + class JAY_API bit_packer : virtual public gr::block + { + public: + typedef boost::shared_ptr 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 */ + diff --git a/gr-jay/lib/bit_packer_impl.cc b/gr-jay/lib/bit_packer_impl.cc new file mode 100644 index 0000000..479d1ad --- /dev/null +++ b/gr-jay/lib/bit_packer_impl.cc @@ -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 +#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 */ + diff --git a/gr-jay/lib/bit_packer_impl.h b/gr-jay/lib/bit_packer_impl.h new file mode 100644 index 0000000..23abc3e --- /dev/null +++ b/gr-jay/lib/bit_packer_impl.h @@ -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 + +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 */ +