diff options
-rw-r--r-- | gr-blocks/grc/blocks_repack_bits_bb.xml | 22 | ||||
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/repack_bits_bb.h | 12 | ||||
-rw-r--r-- | gr-blocks/lib/repack_bits_bb_impl.cc | 117 | ||||
-rw-r--r-- | gr-blocks/lib/repack_bits_bb_impl.h | 7 | ||||
-rwxr-xr-x | gr-blocks/python/blocks/qa_repack_bits_bb.py | 14 |
5 files changed, 56 insertions, 116 deletions
diff --git a/gr-blocks/grc/blocks_repack_bits_bb.xml b/gr-blocks/grc/blocks_repack_bits_bb.xml index 47aa73b02c..4ad5ec631b 100644 --- a/gr-blocks/grc/blocks_repack_bits_bb.xml +++ b/gr-blocks/grc/blocks_repack_bits_bb.xml @@ -2,29 +2,25 @@ <name>Repack Bits</name> <key>blocks_repack_bits_bb</key> <import>from gnuradio import blocks</import> - <make>blocks.repack_bits_bb($k, $l, $len_tag_key, $align_output, $swap)</make> - + <make>blocks.repack_bits_bb($k, $l, $len_tag_key, $align_output)</make> <param> <name>Bits per input byte</name> <key>k</key> <value>1</value> <type>int</type> </param> - <param> <name>Bits per output byte</name> <key>l</key> <value>8</value> <type>int</type> </param> - <param> <name>Length Tag Key</name> <key>len_tag_key</key> <value>""</value> <type>string</type> </param> - <param> <name>Packet Alignment</name> <key>align_output</key> @@ -39,22 +35,6 @@ <key>False</key> </option> </param> - - <param> - <name>Swap Bits</name> - <key>swap</key> - <value>False</value> - <type>enum</type> - <option> - <name>Yes</name> - <key>True</key> - </option> - <option> - <name>No</name> - <key>False</key> - </option> - </param> - <sink> <name>in</name> <type>byte</type> diff --git a/gr-blocks/include/gnuradio/blocks/repack_bits_bb.h b/gr-blocks/include/gnuradio/blocks/repack_bits_bb.h index 425cfa0855..c594966e6e 100644 --- a/gr-blocks/include/gnuradio/blocks/repack_bits_bb.h +++ b/gr-blocks/include/gnuradio/blocks/repack_bits_bb.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2012,2014 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -25,7 +25,6 @@ #include <gnuradio/blocks/api.h> #include <gnuradio/tagged_stream_block.h> -#include <gnuradio/endianness.h> namespace gr { namespace blocks { @@ -51,18 +50,17 @@ namespace gr { typedef boost::shared_ptr<repack_bits_bb> sptr; /*! - * \param k Number of relevant bits on the input stream. - * \param l Number of relevant bits on the output stream. + * \param k Number of relevant bits on the input stream + * \param l Number of relevant bits on the output stream * \param len_tag_key If not empty, this is the key for the length tag. * \param align_output If len_tag_key is given, this controls if the input * or the output is aligned. - * \param swap Swaps the output bits */ - static sptr make(int k, int l=8, const std::string &len_tag_key="", - bool align_output=false, bool swap=false); + static sptr make(int k, int l=8, const std::string &len_tag_key="", bool align_output=false); }; } // namespace blocks } // namespace gr #endif /* INCLUDED_BLOCKS_REPACK_BITS_BB_H */ + diff --git a/gr-blocks/lib/repack_bits_bb_impl.cc b/gr-blocks/lib/repack_bits_bb_impl.cc index acf133e83a..af83187e92 100644 --- a/gr-blocks/lib/repack_bits_bb_impl.cc +++ b/gr-blocks/lib/repack_bits_bb_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2012,2014 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -31,30 +31,26 @@ namespace gr { namespace blocks { repack_bits_bb::sptr - repack_bits_bb::make(int k, int l, const std::string &len_tag_key, - bool align_output, bool swap) + repack_bits_bb::make(int k, int l, const std::string &len_tag_key, bool align_output) { - return gnuradio::get_initial_sptr - (new repack_bits_bb_impl(k, l, len_tag_key, - align_output, swap)); + return gnuradio::get_initial_sptr (new repack_bits_bb_impl(k, l, len_tag_key, align_output)); } - repack_bits_bb_impl::repack_bits_bb_impl(int k, int l, - const std::string &len_tag_key, - bool align_output, bool swap) + repack_bits_bb_impl::repack_bits_bb_impl(int k, int l, const std::string &len_tag_key, bool align_output) : tagged_stream_block("repack_bits_bb", - io_signature::make(1, 1, sizeof (char)), - io_signature::make(1, 1, sizeof (char)), - len_tag_key), - d_k(k), d_l(l), d_packet_mode(!len_tag_key.empty()), - d_in_index(0), d_out_index(0), d_align_output(align_output), - d_swap(swap) + io_signature::make(1, 1, sizeof (char)), + io_signature::make(1, 1, sizeof (char)), + len_tag_key), + d_k(k), d_l(l), + d_packet_mode(!len_tag_key.empty()), + d_in_index(0), d_out_index(0), + d_align_output(align_output) { - if(d_k > 8 || d_k < 1 || d_l > 8 || d_l < 1) { + if (d_k > 8 || d_k < 1 || d_l > 8 || d_l < 1) { throw std::invalid_argument("k and l must be in [1, 8]"); } - set_relative_rate(static_cast<double>(d_k) / static_cast<double>(d_l)); + set_relative_rate((double) d_k / d_l); } repack_bits_bb_impl::~repack_bits_bb_impl() @@ -65,7 +61,7 @@ namespace gr { repack_bits_bb_impl::calculate_output_stream_length(const gr_vector_int &ninput_items) { int n_out_bytes_required = (ninput_items[0] * d_k) / d_l; - if((ninput_items[0] * d_k) % d_l && (!d_packet_mode || (d_packet_mode && !d_align_output))) { + if ((ninput_items[0] * d_k) % d_l && (!d_packet_mode || (d_packet_mode && !d_align_output))) { n_out_bytes_required++; } @@ -73,72 +69,50 @@ namespace gr { } int - repack_bits_bb_impl::work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) + repack_bits_bb_impl::work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { - const unsigned char *in = (const unsigned char *)input_items[0]; - unsigned char *out = (unsigned char *)output_items[0]; + const unsigned char *in = (const unsigned char *) input_items[0]; + unsigned char *out = (unsigned char *) output_items[0]; int bytes_to_write = noutput_items; - if(d_packet_mode) { // noutput_items could be larger than necessary + if (d_packet_mode) { // noutput_items could be larger than necessary int bytes_to_read = ninput_items[0]; bytes_to_write = bytes_to_read * d_k / d_l; - if(!d_align_output && (((bytes_to_read * d_k) % d_l) != 0)) { + if (!d_align_output && (((bytes_to_read * d_k) % d_l) != 0)) { bytes_to_write++; } } int n_read = 0; int n_written = 0; - if(!d_swap) { - while(n_written < bytes_to_write && n_read < ninput_items[0]) { - if(d_out_index == 0) { // Starting a fresh byte - out[n_written] = 0; - } - out[n_written] |= ((in[n_read] >> d_in_index) & 0x01) << d_out_index; - - d_in_index = (d_in_index + 1) % d_k; - d_out_index = (d_out_index + 1) % d_l; - if(d_in_index == 0) { - n_read++; - d_in_index = 0; - } - if(d_out_index == 0) { - n_written++; - d_out_index = 0; - } - } - } - else { - while(n_written < bytes_to_write && n_read < ninput_items[0]) { - if(d_out_index == 0) { // Starting a fresh byte - out[n_written] = 0; - } - out[n_written] |= ((in[n_read] >> d_in_index) & 0x01) << (d_l-1-d_out_index); - - d_in_index = (d_in_index + 1) % d_k; - d_out_index = (d_out_index + 1) % d_l; - if(d_in_index == 0) { - n_read++; - d_in_index = 0; - } - if(d_out_index == 0) { - n_written++; - d_out_index = 0; - } - } - } + while(n_written < bytes_to_write && n_read < ninput_items[0]) { + if (d_out_index == 0) { // Starting a fresh byte + out[n_written] = 0; + } + out[n_written] |= ((in[n_read] >> d_in_index) & 0x01) << d_out_index; - if(d_packet_mode) { - if(d_out_index) { - n_written++; - d_out_index = 0; - } + d_in_index = (d_in_index + 1) % d_k; + d_out_index = (d_out_index + 1) % d_l; + if (d_in_index == 0) { + n_read++; + d_in_index = 0; + } + if (d_out_index == 0) { + n_written++; + d_out_index = 0; + } } - else { - consume_each(n_read); + + if (d_packet_mode) { + if (d_out_index) { + n_written++; + d_out_index = 0; + } + } else { + consume_each(n_read); } return n_written; @@ -146,3 +120,4 @@ namespace gr { } /* namespace blocks */ } /* namespace gr */ + diff --git a/gr-blocks/lib/repack_bits_bb_impl.h b/gr-blocks/lib/repack_bits_bb_impl.h index 3e7d9e6e45..ffb8349d35 100644 --- a/gr-blocks/lib/repack_bits_bb_impl.h +++ b/gr-blocks/lib/repack_bits_bb_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2012,2014 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -37,14 +37,12 @@ namespace gr { int d_in_index; // Current bit of input byte int d_out_index; // Current bit of output byte bool d_align_output; //! true if the output shall be aligned, false if the input shall be aligned - bool d_swap; protected: int calculate_output_stream_length(const gr_vector_int &ninput_items); public: - repack_bits_bb_impl(int k, int l, const std::string &len_tag_key, - bool align_output, bool swap=false); + repack_bits_bb_impl(int k, int l, const std::string &len_tag_key, bool align_output); ~repack_bits_bb_impl(); int work(int noutput_items, @@ -57,3 +55,4 @@ namespace gr { } // namespace gr #endif /* INCLUDED_BLOCKS_REPACK_BITS_BB_IMPL_H */ + diff --git a/gr-blocks/python/blocks/qa_repack_bits_bb.py b/gr-blocks/python/blocks/qa_repack_bits_bb.py index ad3f7728b1..d9bbfe4fac 100755 --- a/gr-blocks/python/blocks/qa_repack_bits_bb.py +++ b/gr-blocks/python/blocks/qa_repack_bits_bb.py @@ -121,18 +121,6 @@ class qa_repack_bits_bb (gr_unittest.TestCase): self.assertEqual(pmt.symbol_to_string(out_tag.key), tag_name) self.assertEqual(pmt.to_long(out_tag.value), len(expected_data)) - def test_006_msb0 (self): - """ 8 -> 3 """ - src_data = 200*(0b11110100, 0b11111111, 0b00111111) - expected_data = 200*((0b001,) + (0b011,) + (0b111,)*5 + (0b100,)) - k = 8 - l = 3 - src = blocks.vector_source_b(src_data, False, 1) - repack = blocks.repack_bits_bb(k, l, swap=True) - sink = blocks.vector_sink_b() - self.tb.connect(src, repack, sink) - self.tb.run () - self.assertEqual(sink.data(), expected_data) - if __name__ == '__main__': gr_unittest.run(qa_repack_bits_bb, "qa_repack_bits_bb.xml") + |