From b1c0d62060dc54d3f6609d09a9814b77949b2e7a Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Tue, 26 Feb 2013 19:53:58 -0500 Subject: blocks: turning off controlport for these tests. If a port is specified, it can clash. --- gr-blocks/python/qa_file_metadata.py | 1 + gr-blocks/python/qa_stream_mux.py | 2 ++ 2 files changed, 3 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_file_metadata.py b/gr-blocks/python/qa_file_metadata.py index 69974d6dad..c2319a800e 100644 --- a/gr-blocks/python/qa_file_metadata.py +++ b/gr-blocks/python/qa_file_metadata.py @@ -35,6 +35,7 @@ def sig_source_c(samp_rate, freq, amp, N): class test_file_metadata(gr_unittest.TestCase): def setUp(self): + os.environ['GR_CONF_CONTROLPORT_ON'] = 'False' self.tb = gr.top_block() def tearDown(self): diff --git a/gr-blocks/python/qa_stream_mux.py b/gr-blocks/python/qa_stream_mux.py index f21a9bbbc9..657bd3d63f 100755 --- a/gr-blocks/python/qa_stream_mux.py +++ b/gr-blocks/python/qa_stream_mux.py @@ -22,10 +22,12 @@ from gnuradio import gr, gr_unittest import blocks_swig +import os class test_stream_mux (gr_unittest.TestCase): def setUp (self): + os.environ['GR_CONF_CONTROLPORT_ON'] = 'False' self.tb = gr.top_block () def tearDown (self): -- cgit v1.2.3 From a0d1c359697f6b6bdcecbc3e7c43c1b4ee2d5570 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Tue, 26 Feb 2013 20:45:40 -0500 Subject: blocks: moving unpack_k_bits to gr-blocks. --- gr-blocks/grc/blocks_block_tree.xml | 4 ++ gr-blocks/grc/blocks_unpack_k_bits_bb.xml | 25 ++++++++++ gr-blocks/include/blocks/CMakeLists.txt | 1 + gr-blocks/include/blocks/unpack_k_bits_bb.h | 52 +++++++++++++++++++ gr-blocks/lib/CMakeLists.txt | 1 + gr-blocks/lib/unpack_k_bits_bb_impl.cc | 77 +++++++++++++++++++++++++++++ gr-blocks/lib/unpack_k_bits_bb_impl.h | 48 ++++++++++++++++++ gr-blocks/python/qa_unpack_k_bits.py | 57 +++++++++++++++++++++ gr-blocks/swig/blocks_swig.i | 3 ++ 9 files changed, 268 insertions(+) create mode 100644 gr-blocks/grc/blocks_unpack_k_bits_bb.xml create mode 100644 gr-blocks/include/blocks/unpack_k_bits_bb.h create mode 100644 gr-blocks/lib/unpack_k_bits_bb_impl.cc create mode 100644 gr-blocks/lib/unpack_k_bits_bb_impl.h create mode 100755 gr-blocks/python/qa_unpack_k_bits.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 0077ec9484..826392cda9 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -104,6 +104,10 @@ <block>blocks_stretch_ff</block> <block>blocks_threshold_ff</block> </cat> + <cat> + <name>Misc Conversions (New) </name> + <block>blocks_unpack_k_bits_bb</block> + </cat> <cat> <name>Misc (New) </name> <block>blocks_throttle</block> diff --git a/gr-blocks/grc/blocks_unpack_k_bits_bb.xml b/gr-blocks/grc/blocks_unpack_k_bits_bb.xml new file mode 100644 index 0000000000..90d7493af0 --- /dev/null +++ b/gr-blocks/grc/blocks_unpack_k_bits_bb.xml @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Unpack K Bits +################################################### + --> +<block> + <name>Unpack K Bits</name> + <key>blocks_unpack_k_bits_bb</key> + <import>from gnuradio import blocks</import> + <make>blocks.unpack_k_bits_bb($k)</make> + <param> + <name>K</name> + <key>k</key> + <type>int</type> + </param> + <sink> + <name>in</name> + <type>byte</type> + </sink> + <source> + <name>out</name> + <type>byte</type> + </source> +</block> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index d3c08f6e6d..0d9213b592 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -143,6 +143,7 @@ install(FILES throttle.h transcendental.h uchar_to_float.h + unpack_k_bits_bb.h vector_to_stream.h vector_to_streams.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks diff --git a/gr-blocks/include/blocks/unpack_k_bits_bb.h b/gr-blocks/include/blocks/unpack_k_bits_bb.h new file mode 100644 index 0000000000..b716ded1d3 --- /dev/null +++ b/gr-blocks/include/blocks/unpack_k_bits_bb.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_UNPACK_K_BITS_BB_H +#define INCLUDED_GR_UNPACK_K_BITS_BB_H + +#include <blocks/api.h> +#include <gr_sync_interpolator.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Converts a byte with k relevent bits to k output bytes with 1 bit in the LSB. + * \ingroup converter_blk + */ + class BLOCKS_API unpack_k_bits_bb : virtual public gr_sync_interpolator + { + public: + // gr::blocks::unpack_k_bits_bb::sptr + typedef boost::shared_ptr<unpack_k_bits_bb> sptr; + + /*! + * \brief Make an unpack_k_bits block. + * \param k number of bits to unpack. + */ + static sptr make(unsigned k); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_UNPACK_K_BITS_BB_H */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 20e3ae4aa6..6466347347 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -183,6 +183,7 @@ list(APPEND gr_blocks_sources transcendental_impl.cc uchar_array_to_float.cc uchar_to_float_impl.cc + unpack_k_bits_bb_impl.cc vector_to_stream_impl.cc vector_to_streams_impl.cc ) diff --git a/gr-blocks/lib/unpack_k_bits_bb_impl.cc b/gr-blocks/lib/unpack_k_bits_bb_impl.cc new file mode 100644 index 0000000000..367100be84 --- /dev/null +++ b/gr-blocks/lib/unpack_k_bits_bb_impl.cc @@ -0,0 +1,77 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2010,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include "unpack_k_bits_bb_impl.h" +#include <gr_io_signature.h> +#include <stdexcept> +#include <iostream> + +namespace gr { + namespace blocks { + + unpack_k_bits_bb::sptr + unpack_k_bits_bb::make(unsigned k) + { + return gnuradio::get_initial_sptr + (new unpack_k_bits_bb_impl(k)); + } + + unpack_k_bits_bb_impl::unpack_k_bits_bb_impl(unsigned k) + : gr_sync_interpolator("unpack_k_bits_bb", + gr_make_io_signature(1, 1, sizeof(unsigned char)), + gr_make_io_signature(1, 1, sizeof(unsigned char)), + k), + d_k(k) + { + if(d_k == 0) + throw std::out_of_range("interpolation must be > 0"); + } + + unpack_k_bits_bb_impl::~unpack_k_bits_bb_impl() + { + } + + int + unpack_k_bits_bb_impl::work(int noutput_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]; + + int n = 0; + for(unsigned int i = 0; i < noutput_items/d_k; i++) { + unsigned int t = in[i]; + for(int j = d_k - 1; j >= 0; j--) + out[n++] = (t >> j) & 0x01; + } + + assert(n == noutput_items); + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/unpack_k_bits_bb_impl.h b/gr-blocks/lib/unpack_k_bits_bb_impl.h new file mode 100644 index 0000000000..c72d16ebf8 --- /dev/null +++ b/gr-blocks/lib/unpack_k_bits_bb_impl.h @@ -0,0 +1,48 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_UNPACK_K_BITS_BB_IMPL_H +#define INCLUDED_GR_UNPACK_K_BITS_BB_IMPL_H + +#include <blocks/unpack_k_bits_bb.h> + +namespace gr { + namespace blocks { + + class unpack_k_bits_bb_impl : public unpack_k_bits_bb + { + private: + unsigned d_k; // number of relevent bits to unpack into k output bytes + + public: + unpack_k_bits_bb_impl(unsigned k); + ~unpack_k_bits_bb_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_UNPACK_K_BITS_BB_IMPL_H */ diff --git a/gr-blocks/python/qa_unpack_k_bits.py b/gr-blocks/python/qa_unpack_k_bits.py new file mode 100755 index 0000000000..e038d5a03a --- /dev/null +++ b/gr-blocks/python/qa_unpack_k_bits.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# +# Copyright 2006,2010,2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio 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. +# +# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks +import random + +class test_unpack(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block () + + def tearDown(self): + self.tb = None + + def test_001(self): + src_data = (1,0,1,1,0,1,1,0) + expected_results = (1,0,1,1,0,1,1,0) + src = gr.vector_source_b(src_data,False) + op = blocks.unpack_k_bits_bb(1) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_results, dst.data()) + + def test_002(self): + src_data = ( 2, 3, 0, 1) + expected_results = (1,0,1,1,0,0,0,1) + src = gr.vector_source_b(src_data,False) + op = blocks.unpack_k_bits_bb(2) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_results, dst.data()) + +if __name__ == '__main__': + gr_unittest.run(test_unpack, "test_unpack.xml") + diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index db8af34368..b4f7ba78ba 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -126,6 +126,7 @@ #include "blocks/throttle.h" #include "blocks/transcendental.h" #include "blocks/uchar_to_float.h" +#include "blocks/unpack_k_bits_bb.h" #include "blocks/unpacked_to_packed_bb.h" #include "blocks/unpacked_to_packed_ss.h" #include "blocks/unpacked_to_packed_ii.h" @@ -232,6 +233,7 @@ %include "blocks/throttle.h" %include "blocks/transcendental.h" %include "blocks/uchar_to_float.h" +%include "blocks/unpack_k_bits_bb.h" %include "blocks/unpacked_to_packed_bb.h" %include "blocks/unpacked_to_packed_ss.h" %include "blocks/unpacked_to_packed_ii.h" @@ -337,6 +339,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, threshold_ff); GR_SWIG_BLOCK_MAGIC2(blocks, throttle); GR_SWIG_BLOCK_MAGIC2(blocks, transcendental); GR_SWIG_BLOCK_MAGIC2(blocks, uchar_to_float); +GR_SWIG_BLOCK_MAGIC2(blocks, unpack_k_bits_bb); GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_bb); GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_ss); GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_ii); -- cgit v1.2.3 From b274f583a92b9c1ebbe8bbb2fcdaa3679b7fc1e3 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Tue, 26 Feb 2013 22:12:40 -0500 Subject: blocks: moved pack_k_bits to gr-blocks. --- gr-blocks/grc/blocks_block_tree.xml | 5 +- gr-blocks/grc/blocks_pack_k_bits_bb.xml | 30 ++++++++++++ gr-blocks/include/blocks/CMakeLists.txt | 1 + gr-blocks/include/blocks/pack_k_bits_bb.h | 53 +++++++++++++++++++++ gr-blocks/lib/CMakeLists.txt | 1 + gr-blocks/lib/pack_k_bits_bb_impl.cc | 76 +++++++++++++++++++++++++++++++ gr-blocks/lib/pack_k_bits_bb_impl.h | 48 +++++++++++++++++++ gr-blocks/python/qa_pack_k_bits.py | 68 +++++++++++++++++++++++++++ gr-blocks/swig/blocks_swig.i | 11 +++-- 9 files changed, 287 insertions(+), 6 deletions(-) create mode 100644 gr-blocks/grc/blocks_pack_k_bits_bb.xml create mode 100644 gr-blocks/include/blocks/pack_k_bits_bb.h create mode 100644 gr-blocks/lib/pack_k_bits_bb_impl.cc create mode 100644 gr-blocks/lib/pack_k_bits_bb_impl.h create mode 100755 gr-blocks/python/qa_pack_k_bits.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 826392cda9..c10414afc5 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -85,8 +85,6 @@ <cat> <name>Stream Operations (New) </name> <block>blocks_delay</block> - <block>blocks_packed_to_unpacked_xx</block> - <block>blocks_unpacked_to_packed_xx</block> <block>blocks_deinterleave</block> <block>blocks_interleave</block> <block>blocks_keep_m_in_n</block> @@ -106,6 +104,9 @@ </cat> <cat> <name>Misc Conversions (New) </name> + <block>blocks_packed_to_unpacked_xx</block> + <block>blocks_unpacked_to_packed_xx</block> + <block>blocks_pack_k_bits_bb</block> <block>blocks_unpack_k_bits_bb</block> </cat> <cat> diff --git a/gr-blocks/grc/blocks_pack_k_bits_bb.xml b/gr-blocks/grc/blocks_pack_k_bits_bb.xml new file mode 100644 index 0000000000..5400eb4af9 --- /dev/null +++ b/gr-blocks/grc/blocks_pack_k_bits_bb.xml @@ -0,0 +1,30 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Pack K Bits +################################################### + --> +<block> + <name>Pack K Bits</name> + <key>blocks_pack_k_bits_bb</key> + <import>from gnuradio import blocks</import> + <make>blocks.pack_k_bits_bb($k)</make> + <param> + <name>K</name> + <key>k</key> + <type>int</type> + </param> + <sink> + <name>in</name> + <type>byte</type> + </sink> + <source> + <name>out</name> + <type>byte</type> + </source> + + <doc> + Pack K unpacked bits (one bit per byte) into a single packed byte containing k bits and 8 - k zeros. + </doc> + +</block> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index 0d9213b592..c6537222e2 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -125,6 +125,7 @@ install(FILES multiply_const_cc.h multiply_const_ff.h nlog10_ff.h + pack_k_bits_bb.h patterned_interleaver.h peak_detector2_fb.h regenerate_bb.h diff --git a/gr-blocks/include/blocks/pack_k_bits_bb.h b/gr-blocks/include/blocks/pack_k_bits_bb.h new file mode 100644 index 0000000000..5bf71c9c3e --- /dev/null +++ b/gr-blocks/include/blocks/pack_k_bits_bb.h @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_PACK_K_BITS_BB_H +#define INCLUDED_GR_PACK_K_BITS_BB_H + +#include <blocks/api.h> +#include <gr_sync_decimator.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Converts a stream of bytes with 1 bit in the LSB to a + * byte with k relevent bits. + * \ingroup converter_blk + */ + class BLOCKS_API pack_k_bits_bb : virtual public gr_sync_decimator + { + public: + // gr::blocks::pack_k_bits_bb::sptr + typedef boost::shared_ptr<pack_k_bits_bb> sptr; + + /*! + * \brief Make a pack_k_bits block. + * \param k number of bits to be packed. + */ + static sptr make(unsigned k); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_PACK_K_BITS_BB_H */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 6466347347..0aa8d9020d 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -164,6 +164,7 @@ list(APPEND gr_blocks_sources multiply_const_cc_impl.cc multiply_const_ff_impl.cc nlog10_ff_impl.cc + pack_k_bits_bb_impl.cc patterned_interleaver_impl.cc peak_detector2_fb_impl.cc regenerate_bb_impl.cc diff --git a/gr-blocks/lib/pack_k_bits_bb_impl.cc b/gr-blocks/lib/pack_k_bits_bb_impl.cc new file mode 100644 index 0000000000..2a7fcc04cb --- /dev/null +++ b/gr-blocks/lib/pack_k_bits_bb_impl.cc @@ -0,0 +1,76 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include "pack_k_bits_bb_impl.h" +#include <gr_io_signature.h> +#include <stdexcept> +#include <iostream> + +namespace gr { + namespace blocks { + + pack_k_bits_bb::sptr + pack_k_bits_bb::make(unsigned k) + { + return gnuradio::get_initial_sptr + (new pack_k_bits_bb_impl(k)); + } + + pack_k_bits_bb_impl::pack_k_bits_bb_impl(unsigned k) + : gr_sync_decimator("pack_k_bits_bb", + gr_make_io_signature(1, 1, sizeof(unsigned char)), + gr_make_io_signature(1, 1, sizeof(unsigned char)), + k), + d_k(k) + { + if(d_k == 0) + throw std::out_of_range("interpolation must be > 0"); + } + + pack_k_bits_bb_impl::~pack_k_bits_bb_impl() + { + } + + int + pack_k_bits_bb_impl::work(int noutput_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]; + + for(int i = 0; i < noutput_items; i++) { + out[i] = 0x00; + for(unsigned int j = 0; j < d_k; j++) { + out[i] |= (0x01 & in[i*d_k+j])<<(d_k-j-1); + } + } + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/pack_k_bits_bb_impl.h b/gr-blocks/lib/pack_k_bits_bb_impl.h new file mode 100644 index 0000000000..668d438a46 --- /dev/null +++ b/gr-blocks/lib/pack_k_bits_bb_impl.h @@ -0,0 +1,48 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_PACK_K_BITS_BB_IMPL_H +#define INCLUDED_GR_PACK_K_BITS_BB_IMPL_H + +#include <blocks/pack_k_bits_bb.h> + +namespace gr { + namespace blocks { + + class pack_k_bits_bb_impl : public pack_k_bits_bb + { + private: + unsigned d_k; // number of relevent bits to pack from k input bytes + + public: + pack_k_bits_bb_impl(unsigned k); + ~pack_k_bits_bb_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_PACK_K_BITS_BB_IMPL_H */ diff --git a/gr-blocks/python/qa_pack_k_bits.py b/gr-blocks/python/qa_pack_k_bits.py new file mode 100755 index 0000000000..cd55d2f200 --- /dev/null +++ b/gr-blocks/python/qa_pack_k_bits.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# +# Copyright 2006,2010,2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio 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. +# +# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks +import random + +class test_pack(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + src_data = (1,0,1,1,0,1,1,0) + expected_results = (1,0,1,1,0,1,1,0) + src = gr.vector_source_b(src_data,False) + op = blocks.pack_k_bits_bb(1) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_results, dst.data()) + + def test_002(self): + src_data = (1,0,1,1,0,0,0,1) + expected_results = ( 2, 3, 0, 1) + src = gr.vector_source_b(src_data,False) + op = blocks.pack_k_bits_bb(2) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + #self.assertEqual(expected_results, dst.data()) + self.assertEqual(expected_results, dst.data()) + + def test_003(self): + src_data = expected_results = map(lambda x: random.randint(0,3), range(10)); + src = gr.vector_source_b( src_data ); + pack = blocks.pack_k_bits_bb(2); + unpack = blocks.unpack_k_bits_bb(2); + snk = gr.vector_sink_b(); + self.tb.connect(src,unpack,pack,snk); + self.tb.run() + self.assertEqual(list(expected_results), list(snk.data())); + +if __name__ == '__main__': + gr_unittest.run(test_pack, "test_pack.xml") + diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index b4f7ba78ba..b45bb454cf 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -99,6 +99,7 @@ #include "blocks/not_ss.h" #include "blocks/not_ii.h" #include "blocks/patterned_interleaver.h" +#include "blocks/pack_k_bits_bb.h" #include "blocks/packed_to_unpacked_bb.h" #include "blocks/packed_to_unpacked_ss.h" #include "blocks/packed_to_unpacked_ii.h" @@ -205,14 +206,15 @@ %include "blocks/not_bb.h" %include "blocks/not_ss.h" %include "blocks/not_ii.h" -%include "blocks/patterned_interleaver.h" +%include "blocks/or_bb.h" +%include "blocks/or_ss.h" +%include "blocks/or_ii.h" +%include "blocks/pack_k_bits_bb.h" %include "blocks/packed_to_unpacked_bb.h" %include "blocks/packed_to_unpacked_ss.h" %include "blocks/packed_to_unpacked_ii.h" +%include "blocks/patterned_interleaver.h" %include "blocks/peak_detector2_fb.h" -%include "blocks/or_bb.h" -%include "blocks/or_ss.h" -%include "blocks/or_ii.h" %include "blocks/regenerate_bb.h" %include "blocks/repeat.h" %include "blocks/rms_cf.h" @@ -312,6 +314,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, not_bb); GR_SWIG_BLOCK_MAGIC2(blocks, not_ss); GR_SWIG_BLOCK_MAGIC2(blocks, not_ii); GR_SWIG_BLOCK_MAGIC2(blocks, patterned_interleaver); +GR_SWIG_BLOCK_MAGIC2(blocks, pack_k_bits_bb); GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_bb); GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ss); GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ii); -- cgit v1.2.3