summaryrefslogtreecommitdiff
path: root/gnuradio-core/src
diff options
context:
space:
mode:
authorJohnathan Corgan2012-06-11 09:47:47 -0700
committerJohnathan Corgan2012-06-11 09:47:47 -0700
commit926f7cba99c4fa3906853e11ff4e91eea93a5a53 (patch)
tree23df2c822d887e4b6b8c68c9ca8b99766d8ab7a8 /gnuradio-core/src
parent6260c4263231718c81770916c2574f8d395d10d6 (diff)
parent92ce6ff434763c8c9360c23435e715e19681b346 (diff)
downloadgnuradio-926f7cba99c4fa3906853e11ff4e91eea93a5a53.tar.gz
gnuradio-926f7cba99c4fa3906853e11ff4e91eea93a5a53.tar.bz2
gnuradio-926f7cba99c4fa3906853e11ff4e91eea93a5a53.zip
Merge commit 'v3.6.1' into wip/gr-blocks-master
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r--gnuradio-core/src/lib/general/gr_add_ff.cc2
-rw-r--r--gnuradio-core/src/lib/general/gr_char_to_float.cc2
-rw-r--r--gnuradio-core/src/lib/general/gr_char_to_short.cc2
-rw-r--r--gnuradio-core/src/lib/general/gr_complex_to_xxx.cc12
-rw-r--r--gnuradio-core/src/lib/general/gr_conjugate_cc.cc2
-rw-r--r--gnuradio-core/src/lib/general/gr_float_to_char.cc2
-rw-r--r--gnuradio-core/src/lib/general/gr_float_to_int.cc2
-rw-r--r--gnuradio-core/src/lib/general/gr_float_to_short.cc2
-rw-r--r--gnuradio-core/src/lib/general/gr_int_to_float.cc2
-rw-r--r--gnuradio-core/src/lib/general/gr_keep_m_in_n.cc46
-rw-r--r--gnuradio-core/src/lib/general/gr_keep_m_in_n.h11
-rw-r--r--gnuradio-core/src/lib/general/gr_multiply_cc.cc6
-rw-r--r--gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc6
-rw-r--r--gnuradio-core/src/lib/general/gr_multiply_const_cc.cc6
-rw-r--r--gnuradio-core/src/lib/general/gr_multiply_const_ff.cc6
-rw-r--r--gnuradio-core/src/lib/general/gr_multiply_ff.cc2
-rw-r--r--gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc2
-rw-r--r--gnuradio-core/src/lib/general/gr_short_to_char.cc2
-rw-r--r--gnuradio-core/src/lib/general/gr_short_to_float.cc2
-rwxr-xr-xgnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py58
-rwxr-xr-xgnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py67
21 files changed, 192 insertions, 50 deletions
diff --git a/gnuradio-core/src/lib/general/gr_add_ff.cc b/gnuradio-core/src/lib/general/gr_add_ff.cc
index 2e45673d3..5f6676bb7 100644
--- a/gnuradio-core/src/lib/general/gr_add_ff.cc
+++ b/gnuradio-core/src/lib/general/gr_add_ff.cc
@@ -42,7 +42,7 @@ gr_add_ff::gr_add_ff (size_t vlen)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
int
diff --git a/gnuradio-core/src/lib/general/gr_char_to_float.cc b/gnuradio-core/src/lib/general/gr_char_to_float.cc
index aec7ad852..f63aa5b16 100644
--- a/gnuradio-core/src/lib/general/gr_char_to_float.cc
+++ b/gnuradio-core/src/lib/general/gr_char_to_float.cc
@@ -42,7 +42,7 @@ gr_char_to_float::gr_char_to_float (size_t vlen, float scale)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
float
diff --git a/gnuradio-core/src/lib/general/gr_char_to_short.cc b/gnuradio-core/src/lib/general/gr_char_to_short.cc
index c20d6cd88..bb9bd8909 100644
--- a/gnuradio-core/src/lib/general/gr_char_to_short.cc
+++ b/gnuradio-core/src/lib/general/gr_char_to_short.cc
@@ -42,7 +42,7 @@ gr_char_to_short::gr_char_to_short (size_t vlen)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(char);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
int
diff --git a/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc b/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc
index 3b1fbf9ac..cdf6d7f3a 100644
--- a/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc
+++ b/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc
@@ -45,7 +45,7 @@ gr_complex_to_float::gr_complex_to_float (unsigned int vlen)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
int
@@ -106,7 +106,7 @@ gr_complex_to_real::gr_complex_to_real (unsigned int vlen)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
int
@@ -146,7 +146,7 @@ gr_complex_to_imag::gr_complex_to_imag (unsigned int vlen)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
int
@@ -186,7 +186,7 @@ gr_complex_to_mag::gr_complex_to_mag (unsigned int vlen)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
int
@@ -220,7 +220,7 @@ gr_complex_to_mag_squared::gr_complex_to_mag_squared (unsigned int vlen)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
int
@@ -258,7 +258,7 @@ gr_complex_to_arg::gr_complex_to_arg (unsigned int vlen)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
int
diff --git a/gnuradio-core/src/lib/general/gr_conjugate_cc.cc b/gnuradio-core/src/lib/general/gr_conjugate_cc.cc
index aaa7f490c..94ac3e162 100644
--- a/gnuradio-core/src/lib/general/gr_conjugate_cc.cc
+++ b/gnuradio-core/src/lib/general/gr_conjugate_cc.cc
@@ -43,7 +43,7 @@ gr_conjugate_cc::gr_conjugate_cc ()
{
const int alignment_multiple =
volk_get_alignment() / sizeof(gr_complex);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
int
diff --git a/gnuradio-core/src/lib/general/gr_float_to_char.cc b/gnuradio-core/src/lib/general/gr_float_to_char.cc
index 3602ad745..d67ded3ea 100644
--- a/gnuradio-core/src/lib/general/gr_float_to_char.cc
+++ b/gnuradio-core/src/lib/general/gr_float_to_char.cc
@@ -42,7 +42,7 @@ gr_float_to_char::gr_float_to_char (size_t vlen, float scale)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(char);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
float
diff --git a/gnuradio-core/src/lib/general/gr_float_to_int.cc b/gnuradio-core/src/lib/general/gr_float_to_int.cc
index bd3cd6a3b..43b851895 100644
--- a/gnuradio-core/src/lib/general/gr_float_to_int.cc
+++ b/gnuradio-core/src/lib/general/gr_float_to_int.cc
@@ -43,7 +43,7 @@ gr_float_to_int::gr_float_to_int (size_t vlen, float scale)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(int);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
float
diff --git a/gnuradio-core/src/lib/general/gr_float_to_short.cc b/gnuradio-core/src/lib/general/gr_float_to_short.cc
index 07995c99a..ab720168b 100644
--- a/gnuradio-core/src/lib/general/gr_float_to_short.cc
+++ b/gnuradio-core/src/lib/general/gr_float_to_short.cc
@@ -42,7 +42,7 @@ gr_float_to_short::gr_float_to_short (size_t vlen, float scale)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(short);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
float
diff --git a/gnuradio-core/src/lib/general/gr_int_to_float.cc b/gnuradio-core/src/lib/general/gr_int_to_float.cc
index a28485305..a7fb24dc6 100644
--- a/gnuradio-core/src/lib/general/gr_int_to_float.cc
+++ b/gnuradio-core/src/lib/general/gr_int_to_float.cc
@@ -42,7 +42,7 @@ gr_int_to_float::gr_int_to_float (size_t vlen, float scale)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
int
diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc
index 760a01c8c..1becbfa11 100644
--- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc
+++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc
@@ -44,43 +44,55 @@ gr_make_keep_m_in_n(size_t item_size, int m, int n, int offset)
* we take m items out of each n
*/
gr_keep_m_in_n::gr_keep_m_in_n(size_t item_size, int m, int n, int offset)
- : gr_sync_block ("keep_m_in_n",
- gr_make_io_signature(1, 1, n*item_size),
- gr_make_io_signature(1, 1, m*item_size)),
+ : gr_block("keep_m_in_n",
+ gr_make_io_signature(1, 1, item_size),
+ gr_make_io_signature(1, 1, item_size)),
d_n(n),
d_m(m),
- d_offset(offset)
+ d_offset(offset),
+ d_itemsize(item_size)
{
// sanity checking
assert(d_m > 0);
assert(d_n > 0);
assert(d_m <= d_n);
assert(d_offset <= (d_n-d_m));
+
+ set_output_multiple(m);
}
-void gr_keep_m_in_n::set_offset(int offset)
+void
+gr_keep_m_in_n::forecast(int noutput_items, gr_vector_int &ninput_items_required)
{
- d_offset = offset;
+ ninput_items_required[0] = d_n*(noutput_items/d_m);
}
+void
+gr_keep_m_in_n::set_offset(int offset)
+{
+ d_offset = offset;
+}
int
-gr_keep_m_in_n::work(int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
+gr_keep_m_in_n::general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
{
uint8_t* out = (uint8_t*)output_items[0];
const uint8_t* in = (const uint8_t*)input_items[0];
- int in_item( input_signature()->sizeof_stream_item(0) );
- int out_item( output_signature()->sizeof_stream_item(0) );
- int single_size = in_item/d_n;
-
// iterate over data blocks of size {n, input : m, output}
- for(int i = 0; i < noutput_items; i++) {
- memcpy(&out[out_item*i], &in[in_item*i + single_size*d_offset], out_item);
+ int blks = std::min(noutput_items/d_m, ninput_items[0]/d_n);
+ for(int i=0; i<blks; i++) {
+ // set up copy pointers
+ const uint8_t* iptr = &in[(i*d_n + d_offset)*d_itemsize];
+ uint8_t* optr = &out[i*d_m*d_itemsize];
+ // perform copy
+ memcpy( optr, iptr, d_m*d_itemsize );
}
-
- return noutput_items;
+
+ consume_each(d_n);
+ return d_m;
}
diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.h b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h
index 4783aaba3..c6bf40ecf 100644
--- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.h
+++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h
@@ -24,7 +24,7 @@
#define INCLUDED_GR_KEEP_M_IN_N_H
#include <gr_core_api.h>
-#include <gr_sync_block.h>
+#include <gr_block.h>
class gr_keep_m_in_n;
typedef boost::shared_ptr<gr_keep_m_in_n> gr_keep_m_in_n_sptr;
@@ -37,7 +37,7 @@ gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset);
* \brief decimate a stream, keeping one item out of every n.
* \ingroup slicedice_blk
*/
-class GR_CORE_API gr_keep_m_in_n : public gr_sync_block
+class GR_CORE_API gr_keep_m_in_n : public gr_block
{
friend GR_CORE_API gr_keep_m_in_n_sptr
gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset);
@@ -46,16 +46,21 @@ class GR_CORE_API gr_keep_m_in_n : public gr_sync_block
int d_m;
int d_count;
int d_offset;
+ int d_itemsize;
protected:
gr_keep_m_in_n (size_t item_size, int m, int n, int offset);
+ void forecast (int noutput_items, gr_vector_int &ninput_items_required);
public:
- int work (int noutput_items,
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
void set_offset(int offset);
+ void set_n(int n){ d_n = n; }
+ void set_m(int m){ d_m = m; }
};
diff --git a/gnuradio-core/src/lib/general/gr_multiply_cc.cc b/gnuradio-core/src/lib/general/gr_multiply_cc.cc
index 32c44a19e..4a3751419 100644
--- a/gnuradio-core/src/lib/general/gr_multiply_cc.cc
+++ b/gnuradio-core/src/lib/general/gr_multiply_cc.cc
@@ -40,9 +40,9 @@ gr_multiply_cc::gr_multiply_cc (size_t vlen)
gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen)),
d_vlen(vlen)
{
- const int alignment_multiple =
- volk_get_alignment() / sizeof(gr_complex);
- set_alignment(alignment_multiple);
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(gr_complex);
+ set_alignment(std::max(1,alignment_multiple));
}
int
diff --git a/gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc b/gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc
index 53ede2eed..0c5fb4a92 100644
--- a/gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc
+++ b/gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc
@@ -40,9 +40,9 @@ gr_multiply_conjugate_cc::gr_multiply_conjugate_cc (size_t vlen)
gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen)),
d_vlen(vlen)
{
- const int alignment_multiple =
- volk_get_alignment() / sizeof(gr_complex);
- set_alignment(alignment_multiple);
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(gr_complex);
+ set_alignment(std::max(1,alignment_multiple));
}
int
diff --git a/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc b/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc
index 359ab6ba0..bd4511937 100644
--- a/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc
+++ b/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc
@@ -40,9 +40,9 @@ gr_multiply_const_cc::gr_multiply_const_cc (gr_complex k, size_t vlen)
gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen)),
d_k(k), d_vlen(vlen)
{
- const int alignment_multiple =
- volk_get_alignment() / sizeof(gr_complex);
- set_alignment(alignment_multiple);
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(gr_complex);
+ set_alignment(std::max(1,alignment_multiple));
}
gr_complex
diff --git a/gnuradio-core/src/lib/general/gr_multiply_const_ff.cc b/gnuradio-core/src/lib/general/gr_multiply_const_ff.cc
index 263f06610..16ba39df9 100644
--- a/gnuradio-core/src/lib/general/gr_multiply_const_ff.cc
+++ b/gnuradio-core/src/lib/general/gr_multiply_const_ff.cc
@@ -40,9 +40,9 @@ gr_multiply_const_ff::gr_multiply_const_ff (float k, size_t vlen)
gr_make_io_signature (1, 1, sizeof (float)*vlen)),
d_k(k), d_vlen(vlen)
{
- const int alignment_multiple =
- volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1,alignment_multiple));
}
float
diff --git a/gnuradio-core/src/lib/general/gr_multiply_ff.cc b/gnuradio-core/src/lib/general/gr_multiply_ff.cc
index f764a71e8..bb7bd0755 100644
--- a/gnuradio-core/src/lib/general/gr_multiply_ff.cc
+++ b/gnuradio-core/src/lib/general/gr_multiply_ff.cc
@@ -42,7 +42,7 @@ gr_multiply_ff::gr_multiply_ff (size_t vlen)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
int
diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc
index 4bd7ca4bb..0ea0c9e38 100644
--- a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc
+++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc
@@ -61,7 +61,7 @@ gr_pack_k_bits_bb::work(int noutput_items,
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])<<j;
+ out[i] |= (0x01 & in[i*d_k+j])<<(d_k-j-1);
}
}
diff --git a/gnuradio-core/src/lib/general/gr_short_to_char.cc b/gnuradio-core/src/lib/general/gr_short_to_char.cc
index 9d6c41406..8c146a351 100644
--- a/gnuradio-core/src/lib/general/gr_short_to_char.cc
+++ b/gnuradio-core/src/lib/general/gr_short_to_char.cc
@@ -42,7 +42,7 @@ gr_short_to_char::gr_short_to_char (size_t vlen)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(char);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
int
diff --git a/gnuradio-core/src/lib/general/gr_short_to_float.cc b/gnuradio-core/src/lib/general/gr_short_to_float.cc
index 960cf644d..093d6024f 100644
--- a/gnuradio-core/src/lib/general/gr_short_to_float.cc
+++ b/gnuradio-core/src/lib/general/gr_short_to_float.cc
@@ -42,7 +42,7 @@ gr_short_to_float::gr_short_to_float (size_t vlen, float scale)
{
const int alignment_multiple =
volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1,alignment_multiple));
}
float
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py b/gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py
new file mode 100755
index 000000000..922671d02
--- /dev/null
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+#
+# Copyright 2008,2010 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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+from gnuradio import gr, gr_unittest
+import sys
+import random
+
+class test_keep_m_in_n(gr_unittest.TestCase):
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_001(self):
+ self.maxDiff = None;
+ tb = gr.top_block()
+ src = gr.vector_source_b( range(0,100) )
+
+ # itemsize, M, N, offset
+ km2 = gr.keep_m_in_n( 1, 1, 2, 0 );
+ km3 = gr.keep_m_in_n( 1, 1, 3, 1 );
+ km7 = gr.keep_m_in_n( 1, 1, 7, 2 );
+ snk2 = gr.vector_sink_b();
+ snk3 = gr.vector_sink_b();
+ snk7 = gr.vector_sink_b();
+ tb.connect(src,km2,snk2);
+ tb.connect(src,km3,snk3);
+ tb.connect(src,km7,snk7);
+ tb.run();
+
+ self.assertEqual(range(0,100,2), list(snk2.data()));
+ self.assertEqual(range(1,100,3), list(snk3.data()));
+ self.assertEqual(range(2,100,7), list(snk7.data()));
+
+
+if __name__ == '__main__':
+ gr_unittest.run(test_keep_m_in_n, "test_keep_m_in_n.xml")
+
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py b/gnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py
new file mode 100755
index 000000000..25fc5e9fc
--- /dev/null
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+#
+# Copyright 2006,2010 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 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 = gr.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 = gr.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 = gr.pack_k_bits_bb(2);
+ unpack = gr.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")
+