From 630cd06cb33d628fa6426866f006580aad30f84b Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 5 May 2012 13:21:38 -0700 Subject: blocks: adds new top-level component gr-blocks with first block gr::blocks::add_XX --- gr-blocks/python/CMakeLists.txt | 47 ++++++++ gr-blocks/python/__init__.py | 28 +++++ gr-blocks/python/qa_add_and_friends.py | 195 +++++++++++++++++++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 gr-blocks/python/CMakeLists.txt create mode 100644 gr-blocks/python/__init__.py create mode 100755 gr-blocks/python/qa_add_and_friends.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/CMakeLists.txt b/gr-blocks/python/CMakeLists.txt new file mode 100644 index 000000000..a7f0e741a --- /dev/null +++ b/gr-blocks/python/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright 2012 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. + +######################################################################## +include(GrPython) + +GR_PYTHON_INSTALL( + FILES + __init__.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/blocks + COMPONENT "blocks_python" +) + +######################################################################## +# Handle the unit tests +######################################################################## +if(ENABLE_TESTING) +include(GrTest) +file(GLOB py_qa_test_files "qa_*.py") +foreach(py_qa_test_file ${py_qa_test_files}) + get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) + set(GR_TEST_PYTHON_DIRS + ${CMAKE_BINARY_DIR}/gnuradio-core/src/python + ${CMAKE_BINARY_DIR}/gnuradio-core/src/lib/swig + ${CMAKE_BINARY_DIR}/gr-blocks/python + ${CMAKE_BINARY_DIR}/gr-blocks/swig + ) + set(GR_TEST_TARGET_DEPS gruel gnuradio-core gnuradio-blocks) + GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${py_qa_test_file}) +endforeach(py_qa_test_file) +endif(ENABLE_TESTING) diff --git a/gr-blocks/python/__init__.py b/gr-blocks/python/__init__.py new file mode 100644 index 000000000..c786d3a22 --- /dev/null +++ b/gr-blocks/python/__init__.py @@ -0,0 +1,28 @@ +# +# Copyright 2012 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. +# + +''' +This is the gr-blocks package. This package provides GNU Radio +processing blocks common to many flowgraphs. +''' + +from blocks_swig import * + diff --git a/gr-blocks/python/qa_add_and_friends.py b/gr-blocks/python/qa_add_and_friends.py new file mode 100755 index 000000000..7d008202b --- /dev/null +++ b/gr-blocks/python/qa_add_and_friends.py @@ -0,0 +1,195 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,2010,2012 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 + +class test_add_and_friends(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def help_ii(self, src_data, exp_data, op): + for s in zip(range(len(src_data)), src_data): + src = gr.vector_source_i(s[1]) + self.tb.connect(src, (op, s[0])) + dst = gr.vector_sink_i() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_ss(self, src_data, exp_data, op): + for s in zip(range(len(src_data)), src_data): + src = gr.vector_source_s(s[1]) + self.tb.connect(src, (op, s[0])) + dst = gr.vector_sink_s() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_ff(self, src_data, exp_data, op): + for s in zip(range(len(src_data)), src_data): + src = gr.vector_source_f(s[1]) + self.tb.connect(src, (op, s[0])) + dst = gr.vector_sink_f() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_cc(self, src_data, exp_data, op): + for s in zip(range(len(src_data)), src_data): + src = gr.vector_source_c(s[1]) + self.tb.connect(src, (op, s[0])) + dst = gr.vector_sink_c() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def test_add_ff(self): + src1_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src2_data = (8.0, -3.0, 4.0, 8.0, 2.0) + expected_result = (9.0, -1.0, 7.0, 12.0, 7.0) + op = blocks_swig.add_ff() + self.help_ff((src1_data, src2_data), expected_result, op) + + def test_add_ss(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (9, -1, 7, 12, 7) + op = blocks_swig.add_ss() + self.help_ss((src1_data, src2_data), expected_result, op) + + def test_add_ii(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (9, -1, 7, 12, 7) + op = blocks_swig.add_ii() + self.help_ii((src1_data, src2_data), expected_result, op) + + def test_add_cc(self): + src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) + src2_data = (8+8j, -3-3j, 4+4j, 8+8j, 2+2j) + expected_result = (9+9j, -1-1j, 7+7j, 12+12j, 7+7j) + op = blocks_swig.add_cc() + self.help_cc((src1_data, src2_data), expected_result, op) + + """ + def test_add_const_ii(self): + src_data = (1, 2, 3, 4, 5) + expected_result = (6, 7, 8, 9, 10) + op = gr.add_const_ii(5) + self.help_ii((src_data,), expected_result, op) + + def test_add_const_cc(self): + src_data = (1, 2, 3, 4, 5) + expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j) + op = gr.add_const_cc(5j) + self.help_cc((src_data,), expected_result, op) + + def test_mult_const_ii(self): + src_data = (-1, 0, 1, 2, 3) + expected_result = (-5, 0, 5, 10, 15) + op = gr.multiply_const_ii(5) + self.help_ii((src_data,), expected_result, op) + + def test_mult_const_ff(self): + src_data = (-1, 0, 1, 2, 3) + expected_result = (-5, 0, 5, 10, 15) + op = gr.multiply_const_cc(5) + self.help_cc((src_data,), expected_result, op) + + def test_mult_const_cc(self): + src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) + expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j) + op = gr.multiply_const_cc(5) + self.help_cc((src_data,), expected_result, op) + + def test_mult_const_cc2(self): + src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) + expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j) + op = gr.multiply_const_cc(5+2j) + self.help_cc((src_data,), expected_result, op) + + def test_mult_ii(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (8, -6, 12, 32, 10) + op = gr.multiply_ii() + self.help_ii((src1_data, src2_data), + expected_result, op) + + def test_mult_ff(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (8, -6, 12, 32, 10) + op = gr.multiply_ff() + self.help_ff((src1_data, src2_data), + expected_result, op) + + def test_mult_cc(self): + src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) + src2_data = (8, -3, 4, 8, 2) + expected_result = (8+8j, -6-6j, 12+12j, 32+32j, 10+10j) + op = gr.multiply_cc() + self.help_cc((src1_data, src2_data), + expected_result, op) + + def test_sub_ii_1(self): + src1_data = (1, 2, 3, 4, 5) + expected_result = (-1, -2, -3, -4, -5) + op = gr.sub_ii() + self.help_ii((src1_data,), + expected_result, op) + + def test_sub_ii_2(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (-7, 5, -1, -4, 3) + op = gr.sub_ii() + self.help_ii((src1_data, src2_data), + expected_result, op) + + def test_div_ff_1(self): + src1_data = (1, 2, 4, -8) + expected_result = (1, 0.5, 0.25, -.125) + op = gr.divide_ff() + self.help_ff((src1_data,), + expected_result, op) + + def test_div_ff_2(self): + src1_data = ( 5, 9, -15, 1024) + src2_data = (10, 3, -5, 64) + expected_result = (0.5, 3, 3, 16) + op = gr.divide_ff() + self.help_ff((src1_data, src2_data), + expected_result, op) + """ + +if __name__ == '__main__': + gr_unittest.run(test_add_and_friends, "test_add_and_friends.xml") -- cgit From 9752fabd851d05c77b0526e7a28c9c7099e54fc6 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Fri, 8 Jun 2012 14:48:46 -0700 Subject: blocks: added blocks_add_const_xx --- gr-blocks/python/qa_add_and_friends.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_add_and_friends.py b/gr-blocks/python/qa_add_and_friends.py index 7d008202b..f38c135f2 100755 --- a/gr-blocks/python/qa_add_and_friends.py +++ b/gr-blocks/python/qa_add_and_friends.py @@ -99,19 +99,18 @@ class test_add_and_friends(gr_unittest.TestCase): op = blocks_swig.add_cc() self.help_cc((src1_data, src2_data), expected_result, op) - """ def test_add_const_ii(self): src_data = (1, 2, 3, 4, 5) expected_result = (6, 7, 8, 9, 10) - op = gr.add_const_ii(5) + op = blocks_swig.add_const_ii(5) self.help_ii((src_data,), expected_result, op) def test_add_const_cc(self): src_data = (1, 2, 3, 4, 5) expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j) - op = gr.add_const_cc(5j) + op = blocks_swig.add_const_cc(5j) self.help_cc((src_data,), expected_result, op) - + """ def test_mult_const_ii(self): src_data = (-1, 0, 1, 2, 3) expected_result = (-5, 0, 5, 10, 15) -- cgit From 6a2d514fab10f692d49f724d1d09afce1c603fa0 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 14 Jun 2012 10:09:14 -0700 Subject: blocks: added multiply_xx, some cleanup on add_xx --- gr-blocks/python/qa_add_and_friends.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_add_and_friends.py b/gr-blocks/python/qa_add_and_friends.py index f38c135f2..0c8a91ce9 100755 --- a/gr-blocks/python/qa_add_and_friends.py +++ b/gr-blocks/python/qa_add_and_friends.py @@ -134,12 +134,12 @@ class test_add_and_friends(gr_unittest.TestCase): expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j) op = gr.multiply_const_cc(5+2j) self.help_cc((src_data,), expected_result, op) - + """ def test_mult_ii(self): src1_data = (1, 2, 3, 4, 5) src2_data = (8, -3, 4, 8, 2) expected_result = (8, -6, 12, 32, 10) - op = gr.multiply_ii() + op = blocks_swig.multiply_ii() self.help_ii((src1_data, src2_data), expected_result, op) @@ -147,7 +147,7 @@ class test_add_and_friends(gr_unittest.TestCase): src1_data = (1, 2, 3, 4, 5) src2_data = (8, -3, 4, 8, 2) expected_result = (8, -6, 12, 32, 10) - op = gr.multiply_ff() + op = blocks_swig.multiply_ff() self.help_ff((src1_data, src2_data), expected_result, op) @@ -155,10 +155,10 @@ class test_add_and_friends(gr_unittest.TestCase): src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) src2_data = (8, -3, 4, 8, 2) expected_result = (8+8j, -6-6j, 12+12j, 32+32j, 10+10j) - op = gr.multiply_cc() + op = blocks_swig.multiply_cc() self.help_cc((src1_data, src2_data), expected_result, op) - + """ def test_sub_ii_1(self): src1_data = (1, 2, 3, 4, 5) expected_result = (-1, -2, -3, -4, -5) -- cgit From 59f49f4663d5795adc7d7cc573d24c0747afad0f Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 16 Jun 2012 12:07:58 -0700 Subject: blocks: completed transition of add and multiply blocks * gr::blocks::add_* * gr::blocks::add_const_* * gr::blocks::add_const_v* * gr::blocks::multiply_* * gr::blocks::multiply_const_* * gr::blocks::multiply_const_v* Each of these has ss, ii, ff, and cc versions, for a total of 24 blocks. --- gr-blocks/python/__init__.py | 9 + gr-blocks/python/qa_add_and_friends.py | 194 ----------------- gr-blocks/python/qa_add_mult_div_sub.py | 230 ++++++++++++++++++++ gr-blocks/python/qa_add_mult_v.py | 360 ++++++++++++++++++++++++++++++++ 4 files changed, 599 insertions(+), 194 deletions(-) delete mode 100755 gr-blocks/python/qa_add_and_friends.py create mode 100755 gr-blocks/python/qa_add_mult_div_sub.py create mode 100755 gr-blocks/python/qa_add_mult_v.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/__init__.py b/gr-blocks/python/__init__.py index c786d3a22..6577d933e 100644 --- a/gr-blocks/python/__init__.py +++ b/gr-blocks/python/__init__.py @@ -26,3 +26,12 @@ processing blocks common to many flowgraphs. from blocks_swig import * +#alias old gr_add_vXX and gr_multiply_vXX +add_vcc = add_cc +add_vff = add_ff +add_vii = add_ii +add_vss = add_ss +multiply_vcc = multiply_cc +multiply_vff = multiply_ff +multiply_vii = multiply_ii +multiply_vss = multiply_ss diff --git a/gr-blocks/python/qa_add_and_friends.py b/gr-blocks/python/qa_add_and_friends.py deleted file mode 100755 index 0c8a91ce9..000000000 --- a/gr-blocks/python/qa_add_and_friends.py +++ /dev/null @@ -1,194 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2007,2010,2012 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 - -class test_add_and_friends(gr_unittest.TestCase): - - def setUp(self): - self.tb = gr.top_block() - - def tearDown(self): - self.tb = None - - def help_ii(self, src_data, exp_data, op): - for s in zip(range(len(src_data)), src_data): - src = gr.vector_source_i(s[1]) - self.tb.connect(src, (op, s[0])) - dst = gr.vector_sink_i() - self.tb.connect(op, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(exp_data, result_data) - - def help_ss(self, src_data, exp_data, op): - for s in zip(range(len(src_data)), src_data): - src = gr.vector_source_s(s[1]) - self.tb.connect(src, (op, s[0])) - dst = gr.vector_sink_s() - self.tb.connect(op, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(exp_data, result_data) - - def help_ff(self, src_data, exp_data, op): - for s in zip(range(len(src_data)), src_data): - src = gr.vector_source_f(s[1]) - self.tb.connect(src, (op, s[0])) - dst = gr.vector_sink_f() - self.tb.connect(op, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(exp_data, result_data) - - def help_cc(self, src_data, exp_data, op): - for s in zip(range(len(src_data)), src_data): - src = gr.vector_source_c(s[1]) - self.tb.connect(src, (op, s[0])) - dst = gr.vector_sink_c() - self.tb.connect(op, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(exp_data, result_data) - - def test_add_ff(self): - src1_data = (1.0, 2.0, 3.0, 4.0, 5.0) - src2_data = (8.0, -3.0, 4.0, 8.0, 2.0) - expected_result = (9.0, -1.0, 7.0, 12.0, 7.0) - op = blocks_swig.add_ff() - self.help_ff((src1_data, src2_data), expected_result, op) - - def test_add_ss(self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (8, -3, 4, 8, 2) - expected_result = (9, -1, 7, 12, 7) - op = blocks_swig.add_ss() - self.help_ss((src1_data, src2_data), expected_result, op) - - def test_add_ii(self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (8, -3, 4, 8, 2) - expected_result = (9, -1, 7, 12, 7) - op = blocks_swig.add_ii() - self.help_ii((src1_data, src2_data), expected_result, op) - - def test_add_cc(self): - src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) - src2_data = (8+8j, -3-3j, 4+4j, 8+8j, 2+2j) - expected_result = (9+9j, -1-1j, 7+7j, 12+12j, 7+7j) - op = blocks_swig.add_cc() - self.help_cc((src1_data, src2_data), expected_result, op) - - def test_add_const_ii(self): - src_data = (1, 2, 3, 4, 5) - expected_result = (6, 7, 8, 9, 10) - op = blocks_swig.add_const_ii(5) - self.help_ii((src_data,), expected_result, op) - - def test_add_const_cc(self): - src_data = (1, 2, 3, 4, 5) - expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j) - op = blocks_swig.add_const_cc(5j) - self.help_cc((src_data,), expected_result, op) - """ - def test_mult_const_ii(self): - src_data = (-1, 0, 1, 2, 3) - expected_result = (-5, 0, 5, 10, 15) - op = gr.multiply_const_ii(5) - self.help_ii((src_data,), expected_result, op) - - def test_mult_const_ff(self): - src_data = (-1, 0, 1, 2, 3) - expected_result = (-5, 0, 5, 10, 15) - op = gr.multiply_const_cc(5) - self.help_cc((src_data,), expected_result, op) - - def test_mult_const_cc(self): - src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) - expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j) - op = gr.multiply_const_cc(5) - self.help_cc((src_data,), expected_result, op) - - def test_mult_const_cc2(self): - src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) - expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j) - op = gr.multiply_const_cc(5+2j) - self.help_cc((src_data,), expected_result, op) - """ - def test_mult_ii(self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (8, -3, 4, 8, 2) - expected_result = (8, -6, 12, 32, 10) - op = blocks_swig.multiply_ii() - self.help_ii((src1_data, src2_data), - expected_result, op) - - def test_mult_ff(self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (8, -3, 4, 8, 2) - expected_result = (8, -6, 12, 32, 10) - op = blocks_swig.multiply_ff() - self.help_ff((src1_data, src2_data), - expected_result, op) - - def test_mult_cc(self): - src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) - src2_data = (8, -3, 4, 8, 2) - expected_result = (8+8j, -6-6j, 12+12j, 32+32j, 10+10j) - op = blocks_swig.multiply_cc() - self.help_cc((src1_data, src2_data), - expected_result, op) - """ - def test_sub_ii_1(self): - src1_data = (1, 2, 3, 4, 5) - expected_result = (-1, -2, -3, -4, -5) - op = gr.sub_ii() - self.help_ii((src1_data,), - expected_result, op) - - def test_sub_ii_2(self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (8, -3, 4, 8, 2) - expected_result = (-7, 5, -1, -4, 3) - op = gr.sub_ii() - self.help_ii((src1_data, src2_data), - expected_result, op) - - def test_div_ff_1(self): - src1_data = (1, 2, 4, -8) - expected_result = (1, 0.5, 0.25, -.125) - op = gr.divide_ff() - self.help_ff((src1_data,), - expected_result, op) - - def test_div_ff_2(self): - src1_data = ( 5, 9, -15, 1024) - src2_data = (10, 3, -5, 64) - expected_result = (0.5, 3, 3, 16) - op = gr.divide_ff() - self.help_ff((src1_data, src2_data), - expected_result, op) - """ - -if __name__ == '__main__': - gr_unittest.run(test_add_and_friends, "test_add_and_friends.xml") diff --git a/gr-blocks/python/qa_add_mult_div_sub.py b/gr-blocks/python/qa_add_mult_div_sub.py new file mode 100755 index 000000000..05a3b2384 --- /dev/null +++ b/gr-blocks/python/qa_add_mult_div_sub.py @@ -0,0 +1,230 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,2010,2012 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 + +class test_add_mult_div_sub(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def help_ii(self, src_data, exp_data, op): + for s in zip(range(len(src_data)), src_data): + src = gr.vector_source_i(s[1]) + self.tb.connect(src, (op, s[0])) + dst = gr.vector_sink_i() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_ss(self, src_data, exp_data, op): + for s in zip(range(len(src_data)), src_data): + src = gr.vector_source_s(s[1]) + self.tb.connect(src, (op, s[0])) + dst = gr.vector_sink_s() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_ff(self, src_data, exp_data, op): + for s in zip(range(len(src_data)), src_data): + src = gr.vector_source_f(s[1]) + self.tb.connect(src, (op, s[0])) + dst = gr.vector_sink_f() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_cc(self, src_data, exp_data, op): + for s in zip(range(len(src_data)), src_data): + src = gr.vector_source_c(s[1]) + self.tb.connect(src, (op, s[0])) + dst = gr.vector_sink_c() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + # add_XX + + def test_add_ss(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (9, -1, 7, 12, 7) + op = blocks_swig.add_ss() + self.help_ss((src1_data, src2_data), expected_result, op) + + def test_add_ii(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (9, -1, 7, 12, 7) + op = blocks_swig.add_ii() + self.help_ii((src1_data, src2_data), expected_result, op) + + def test_add_ff(self): + src1_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src2_data = (8.0, -3.0, 4.0, 8.0, 2.0) + expected_result = (9.0, -1.0, 7.0, 12.0, 7.0) + op = blocks_swig.add_ff() + self.help_ff((src1_data, src2_data), expected_result, op) + + def test_add_cc(self): + src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) + src2_data = (8+8j, -3-3j, 4+4j, 8+8j, 2+2j) + expected_result = (9+9j, -1-1j, 7+7j, 12+12j, 7+7j) + op = blocks_swig.add_cc() + self.help_cc((src1_data, src2_data), expected_result, op) + + # add_const_XX + + def test_add_const_ss(self): + src_data = (1, 2, 3, 4, 5) + expected_result = (6, 7, 8, 9, 10) + op = blocks_swig.add_const_ss(5) + self.help_ss((src_data,), expected_result, op) + + def test_add_const_ii(self): + src_data = (1, 2, 3, 4, 5) + expected_result = (6, 7, 8, 9, 10) + op = blocks_swig.add_const_ii(5) + self.help_ii((src_data,), expected_result, op) + + def test_add_const_ff(self): + src_data = (1, 2, 3, 4, 5) + expected_result = (6, 7, 8, 9, 10) + op = blocks_swig.add_const_ff(5) + self.help_ff((src_data,), expected_result, op) + + def test_add_const_cc(self): + src_data = (1, 2, 3, 4, 5) + expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j) + op = blocks_swig.add_const_cc(5j) + self.help_cc((src_data,), expected_result, op) + + # multiply_XX + + def test_multiply_ss(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (8, -6, 12, 32, 10) + op = blocks_swig.multiply_ss() + self.help_ss((src1_data, src2_data), + expected_result, op) + + def test_multiply_ii(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (8, -6, 12, 32, 10) + op = blocks_swig.multiply_ii() + self.help_ii((src1_data, src2_data), + expected_result, op) + + def test_multiply_ff(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (8, -6, 12, 32, 10) + op = blocks_swig.multiply_ff() + self.help_ff((src1_data, src2_data), + expected_result, op) + + def test_multiply_cc(self): + src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) + src2_data = (8, -3, 4, 8, 2) + expected_result = (8+8j, -6-6j, 12+12j, 32+32j, 10+10j) + op = blocks_swig.multiply_cc() + self.help_cc((src1_data, src2_data), + expected_result, op) + + # multiply_const_XX + + def test_multiply_const_ss(self): + src_data = (-1, 0, 1, 2, 3) + expected_result = (-5, 0, 5, 10, 15) + op = gr.multiply_const_ss(5) + self.help_ss((src_data,), expected_result, op) + + def test_multiply_const_ii(self): + src_data = (-1, 0, 1, 2, 3) + expected_result = (-5, 0, 5, 10, 15) + op = gr.multiply_const_ii(5) + self.help_ii((src_data,), expected_result, op) + + def test_multiply_const_ff(self): + src_data = (-1, 0, 1, 2, 3) + expected_result = (-5, 0, 5, 10, 15) + op = gr.multiply_const_ff(5) + self.help_ff((src_data,), expected_result, op) + + def test_multiply_const_cc(self): + src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) + expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j) + op = gr.multiply_const_cc(5) + self.help_cc((src_data,), expected_result, op) + + def test_multiply_const_cc2(self): + src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) + expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j) + op = gr.multiply_const_cc(5+2j) + self.help_cc((src_data,), expected_result, op) + + + """ + def test_sub_ii_1(self): + src1_data = (1, 2, 3, 4, 5) + expected_result = (-1, -2, -3, -4, -5) + op = gr.sub_ii() + self.help_ii((src1_data,), + expected_result, op) + + def test_sub_ii_2(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (-7, 5, -1, -4, 3) + op = gr.sub_ii() + self.help_ii((src1_data, src2_data), + expected_result, op) + + def test_div_ff_1(self): + src1_data = (1, 2, 4, -8) + expected_result = (1, 0.5, 0.25, -.125) + op = gr.divide_ff() + self.help_ff((src1_data,), + expected_result, op) + + def test_div_ff_2(self): + src1_data = ( 5, 9, -15, 1024) + src2_data = (10, 3, -5, 64) + expected_result = (0.5, 3, 3, 16) + op = gr.divide_ff() + self.help_ff((src1_data, src2_data), + expected_result, op) + """ + +if __name__ == '__main__': + gr_unittest.run(test_add_mult_div_sub, "test_add_mult_div_sub.xml") diff --git a/gr-blocks/python/qa_add_mult_v.py b/gr-blocks/python/qa_add_mult_v.py new file mode 100755 index 000000000..d362cb885 --- /dev/null +++ b/gr-blocks/python/qa_add_mult_v.py @@ -0,0 +1,360 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,2010,2012 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 + +class test_add_mult_v(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def help_ss(self, size, src_data, exp_data, op): + for s in zip(range (len (src_data)), src_data): + src = gr.vector_source_s(s[1]) + srcv = gr.stream_to_vector(gr.sizeof_short, size) + self.tb.connect(src, srcv) + self.tb.connect(srcv, (op, s[0])) + rhs = gr.vector_to_stream(gr.sizeof_short, size) + dst = gr.vector_sink_s() + self.tb.connect(op, rhs, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_ii(self, size, src_data, exp_data, op): + for s in zip(range (len (src_data)), src_data): + src = gr.vector_source_i(s[1]) + srcv = gr.stream_to_vector(gr.sizeof_int, size) + self.tb.connect(src, srcv) + self.tb.connect(srcv, (op, s[0])) + rhs = gr.vector_to_stream(gr.sizeof_int, size) + dst = gr.vector_sink_i() + self.tb.connect(op, rhs, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_ff(self, size, src_data, exp_data, op): + for s in zip(range (len (src_data)), src_data): + src = gr.vector_source_f(s[1]) + srcv = gr.stream_to_vector(gr.sizeof_float, size) + self.tb.connect(src, srcv) + self.tb.connect(srcv, (op, s[0])) + rhs = gr.vector_to_stream(gr.sizeof_float, size) + dst = gr.vector_sink_f() + self.tb.connect(op, rhs, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_cc(self, size, src_data, exp_data, op): + for s in zip(range (len (src_data)), src_data): + src = gr.vector_source_c(s[1]) + srcv = gr.stream_to_vector(gr.sizeof_gr_complex, size) + self.tb.connect(src, srcv) + self.tb.connect(srcv, (op, s[0])) + rhs = gr.vector_to_stream(gr.sizeof_gr_complex, size) + dst = gr.vector_sink_c() + self.tb.connect(op, rhs, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_const_ss(self, src_data, exp_data, op): + src = gr.vector_source_s(src_data) + srcv = gr.stream_to_vector(gr.sizeof_short, len(src_data)) + rhs = gr.vector_to_stream(gr.sizeof_short, len(src_data)) + dst = gr.vector_sink_s() + self.tb.connect(src, srcv, op, rhs, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_const_ii(self, src_data, exp_data, op): + src = gr.vector_source_i(src_data) + srcv = gr.stream_to_vector(gr.sizeof_int, len(src_data)) + rhs = gr.vector_to_stream(gr.sizeof_int, len(src_data)) + dst = gr.vector_sink_i() + self.tb.connect(src, srcv, op, rhs, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_const_ff(self, src_data, exp_data, op): + src = gr.vector_source_f(src_data) + srcv = gr.stream_to_vector(gr.sizeof_float, len(src_data)) + rhs = gr.vector_to_stream(gr.sizeof_float, len(src_data)) + dst = gr.vector_sink_f() + self.tb.connect(src, srcv, op, rhs, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_const_cc(self, src_data, exp_data, op): + src = gr.vector_source_c(src_data) + srcv = gr.stream_to_vector(gr.sizeof_gr_complex, len(src_data)) + rhs = gr.vector_to_stream(gr.sizeof_gr_complex, len(src_data)) + dst = gr.vector_sink_c() + self.tb.connect(src, srcv, op, rhs, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + # add_vXX + + def test_add_vss_one(self): + src1_data = (1,) + src2_data = (2,) + src3_data = (3,) + expected_result = (6,) + op = blocks_swig.add_ss(1) + self.help_ss(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vss_five(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (6, 7, 8, 9, 10) + src3_data = (11, 12, 13, 14, 15) + expected_result = (18, 21, 24, 27, 30) + op = blocks_swig.add_ss(5) + self.help_ss(5, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vii_one(self): + src1_data = (1,) + src2_data = (2,) + src3_data = (3,) + expected_result = (6,) + op = blocks_swig.add_ii(1) + self.help_ii(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vii_five(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (6, 7, 8, 9, 10) + src3_data = (11, 12, 13, 14, 15) + expected_result = (18, 21, 24, 27, 30) + op = blocks_swig.add_ii(5) + self.help_ii(5, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vff_one(self): + src1_data = (1.0,) + src2_data = (2.0,) + src3_data = (3.0,) + expected_result = (6.0,) + op = blocks_swig.add_ff(1) + self.help_ff(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vff_five(self): + src1_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src2_data = (6.0, 7.0, 8.0, 9.0, 10.0) + src3_data = (11.0, 12.0, 13.0, 14.0, 15.0) + expected_result = (18.0, 21.0, 24.0, 27.0, 30.0) + op = blocks_swig.add_ff(5) + self.help_ff(5, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vcc_one(self): + src1_data = (1.0+2.0j,) + src2_data = (3.0+4.0j,) + src3_data = (5.0+6.0j,) + expected_result = (9.0+12j,) + op = blocks_swig.add_cc(1) + self.help_cc(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vcc_five(self): + src1_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j) + src2_data = (11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j) + src3_data = (21.0+22.0j, 23.0+24.0j, 25.0+26.0j, 27.0+28.0j, 29.0+30.0j) + expected_result = (33.0+36.0j, 39.0+42.0j, 45.0+48.0j, 51.0+54.0j, 57.0+60.0j) + op = blocks_swig.add_cc(5) + self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op) + + # add_const_vXX + + def test_add_const_vss_one(self): + src_data = (1,) + op = blocks_swig.add_const_vss((2,)) + exp_data = (3,) + self.help_const_ss(src_data, exp_data, op) + + def test_add_const_vss_five(self): + src_data = (1, 2, 3, 4, 5) + op = blocks_swig.add_const_vss((6, 7, 8, 9, 10)) + exp_data = (7, 9, 11, 13, 15) + self.help_const_ss(src_data, exp_data, op) + + def test_add_const_vii_one(self): + src_data = (1,) + op = blocks_swig.add_const_vii((2,)) + exp_data = (3,) + self.help_const_ii(src_data, exp_data, op) + + def test_add_const_vii_five(self): + src_data = (1, 2, 3, 4, 5) + op = blocks_swig.add_const_vii((6, 7, 8, 9, 10)) + exp_data = (7, 9, 11, 13, 15) + self.help_const_ii(src_data, exp_data, op) + + def test_add_const_vff_one(self): + src_data = (1.0,) + op = blocks_swig.add_const_vff((2.0,)) + exp_data = (3.0,) + self.help_const_ff(src_data, exp_data, op) + + def test_add_const_vff_five(self): + src_data = (1.0, 2.0, 3.0, 4.0, 5.0) + op = blocks_swig.add_const_vff((6.0, 7.0, 8.0, 9.0, 10.0)) + exp_data = (7.0, 9.0, 11.0, 13.0, 15.0) + self.help_const_ff(src_data, exp_data, op) + + def test_add_const_vcc_one(self): + src_data = (1.0+2.0j,) + op = blocks_swig.add_const_vcc((2.0+3.0j,)) + exp_data = (3.0+5.0j,) + self.help_const_cc(src_data, exp_data, op) + + def test_add_const_vcc_five(self): + src_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j) + op = blocks_swig.add_const_vcc((11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j)) + exp_data = (12.0+14.0j, 16.0+18.0j, 20.0+22.0j, 24.0+26.0j, 28.0+30.0j) + self.help_const_cc(src_data, exp_data, op) + + # multiply_vXX + + def test_multiply_vss_one(self): + src1_data = (1,) + src2_data = (2,) + src3_data = (3,) + expected_result = (6,) + op = gr.multiply_vss(1) + self.help_ss(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vss_five(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (6, 7, 8, 9, 10) + src3_data = (11, 12, 13, 14, 15) + expected_result = (66, 168, 312, 504, 750) + op = gr.multiply_vss(5) + self.help_ss(5, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vii_one(self): + src1_data = (1,) + src2_data = (2,) + src3_data = (3,) + expected_result = (6,) + op = gr.multiply_vii(1) + self.help_ii(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vii_five(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (6, 7, 8, 9, 10) + src3_data = (11, 12, 13, 14, 15) + expected_result = (66, 168, 312, 504, 750) + op = gr.multiply_vii(5) + self.help_ii(5, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vff_one(self): + src1_data = (1.0,) + src2_data = (2.0,) + src3_data = (3.0,) + expected_result = (6.0,) + op = gr.multiply_vff(1) + self.help_ff(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vff_five(self): + src1_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src2_data = (6.0, 7.0, 8.0, 9.0, 10.0) + src3_data = (11.0, 12.0, 13.0, 14.0, 15.0) + expected_result = (66.0, 168.0, 312.0, 504.0, 750.0) + op = gr.multiply_vff(5) + self.help_ff(5, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vcc_one(self): + src1_data = (1.0+2.0j,) + src2_data = (3.0+4.0j,) + src3_data = (5.0+6.0j,) + expected_result = (-85+20j,) + op = gr.multiply_vcc(1) + self.help_cc(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vcc_five(self): + src1_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j) + src2_data = (11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j) + src3_data = (21.0+22.0j, 23.0+24.0j, 25.0+26.0j, 27.0+28.0j, 29.0+30.0j) + expected_result = (-1021.0+428.0j, -2647.0+1754.0j, -4945.0+3704.0j, -8011.0+6374.0j, -11941.0+9860.0j) + op = gr.multiply_vcc(5) + self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op) + + # multiply_const_vXX + + def test_multiply_const_vss_one(self): + src_data = (2,) + op = gr.multiply_const_vss((3,)) + exp_data = (6,) + self.help_const_ss(src_data, exp_data, op) + + def test_multiply_const_vss_five(self): + src_data = (1, 2, 3, 4, 5) + op = gr.multiply_const_vss((6, 7, 8, 9, 10)) + exp_data = (6, 14, 24, 36, 50) + self.help_const_ss(src_data, exp_data, op) + + def test_multiply_const_vii_one(self): + src_data = (2,) + op = gr.multiply_const_vii((3,)) + exp_data = (6,) + self.help_const_ii(src_data, exp_data, op) + + def test_multiply_const_vii_five(self): + src_data = (1, 2, 3, 4, 5) + op = gr.multiply_const_vii((6, 7, 8, 9, 10)) + exp_data = (6, 14, 24, 36, 50) + self.help_const_ii(src_data, exp_data, op) + + def test_multiply_const_vff_one(self): + src_data = (2.0,) + op = gr.multiply_const_vff((3.0,)) + exp_data = (6.0,) + self.help_const_ff(src_data, exp_data, op) + + def test_multiply_const_vff_five(self): + src_data = (1.0, 2.0, 3.0, 4.0, 5.0) + op = gr.multiply_const_vff((6.0, 7.0, 8.0, 9.0, 10.0)) + exp_data = (6.0, 14.0, 24.0, 36.0, 50.0) + self.help_const_ff(src_data, exp_data, op) + + def test_multiply_const_vcc_one(self): + src_data = (1.0+2.0j,) + op = gr.multiply_const_vcc((2.0+3.0j,)) + exp_data = (-4.0+7.0j,) + self.help_const_cc(src_data, exp_data, op) + + def test_multiply_const_vcc_five(self): + src_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j) + op = gr.multiply_const_vcc((11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j)) + exp_data = (-13.0+34.0j, -17.0+94.0j, -21.0+170.0j, -25.0+262.0j, -29.0+370.0j) + self.help_const_cc(src_data, exp_data, op) + + +if __name__ == '__main__': + gr_unittest.run(test_add_mult_v, "test_add_mult_v.xml") -- cgit From 24962cd24c623c6822733fed4c911a4adabbdd57 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Mon, 18 Jun 2012 12:28:48 -0700 Subject: blocks: added div_XX and sub_XX blocks --- gr-blocks/python/qa_add_mult_div_sub.py | 38 +++++++++------------------------ 1 file changed, 10 insertions(+), 28 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_add_mult_div_sub.py b/gr-blocks/python/qa_add_mult_div_sub.py index 05a3b2384..0aca03d3f 100755 --- a/gr-blocks/python/qa_add_mult_div_sub.py +++ b/gr-blocks/python/qa_add_mult_div_sub.py @@ -166,65 +166,47 @@ class test_add_mult_div_sub(gr_unittest.TestCase): def test_multiply_const_ss(self): src_data = (-1, 0, 1, 2, 3) expected_result = (-5, 0, 5, 10, 15) - op = gr.multiply_const_ss(5) + op = blocks_swig.multiply_const_ss(5) self.help_ss((src_data,), expected_result, op) def test_multiply_const_ii(self): src_data = (-1, 0, 1, 2, 3) expected_result = (-5, 0, 5, 10, 15) - op = gr.multiply_const_ii(5) + op = blocks_swig.multiply_const_ii(5) self.help_ii((src_data,), expected_result, op) def test_multiply_const_ff(self): src_data = (-1, 0, 1, 2, 3) expected_result = (-5, 0, 5, 10, 15) - op = gr.multiply_const_ff(5) + op = blocks_swig.multiply_const_ff(5) self.help_ff((src_data,), expected_result, op) def test_multiply_const_cc(self): src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j) - op = gr.multiply_const_cc(5) + op = blocks_swig.multiply_const_cc(5) self.help_cc((src_data,), expected_result, op) def test_multiply_const_cc2(self): src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j) - op = gr.multiply_const_cc(5+2j) + op = blocks_swig.multiply_const_cc(5+2j) self.help_cc((src_data,), expected_result, op) - - """ - def test_sub_ii_1(self): - src1_data = (1, 2, 3, 4, 5) - expected_result = (-1, -2, -3, -4, -5) - op = gr.sub_ii() - self.help_ii((src1_data,), - expected_result, op) - - def test_sub_ii_2(self): + def test_sub_ii(self): src1_data = (1, 2, 3, 4, 5) src2_data = (8, -3, 4, 8, 2) expected_result = (-7, 5, -1, -4, 3) - op = gr.sub_ii() + op = blocks_swig.sub_ii() self.help_ii((src1_data, src2_data), expected_result, op) - def test_div_ff_1(self): - src1_data = (1, 2, 4, -8) - expected_result = (1, 0.5, 0.25, -.125) - op = gr.divide_ff() - self.help_ff((src1_data,), - expected_result, op) - - def test_div_ff_2(self): + def test_div_ff(self): src1_data = ( 5, 9, -15, 1024) src2_data = (10, 3, -5, 64) expected_result = (0.5, 3, 3, 16) - op = gr.divide_ff() - self.help_ff((src1_data, src2_data), - expected_result, op) - """ + op = blocks_swig.divide_ff() + self.help_ff((src1_data, src2_data), expected_result, op) if __name__ == '__main__': gr_unittest.run(test_add_mult_div_sub, "test_add_mult_div_sub.xml") -- cgit From 439b427e80ebc767db6e4e732213d89c2a6febd4 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 19 Jun 2012 10:00:28 -0700 Subject: blocks: added gr::blocks::char_to_float --- gr-blocks/python/qa_type_conversions.py | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 gr-blocks/python/qa_type_conversions.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py new file mode 100755 index 000000000..bc65a2781 --- /dev/null +++ b/gr-blocks/python/qa_type_conversions.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# +# Copyright 2012 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 + +class test_type_conversions(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_char_to_float_identity(self): + src_data = (1, 2, 3, 4, 5) + expected_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src = gr.vector_source_b(src_data) + op = blocks_swig.char_to_float() + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + + def test_char_to_float_scale(self): + src_data = (1, 2, 3, 4, 5) + expected_data = (0.5, 1.0, 1.5, 2.0, 2.5) + src = gr.vector_source_b(src_data) + op = blocks_swig.char_to_float(scale=2.0) + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + +if __name__ == '__main__': + gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From 75f11771a9ee4b2854297fdb2c9db5761bde1c45 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Fri, 22 Jun 2012 16:58:50 -0700 Subject: blocks: added gr::blocks:char_to_short --- gr-blocks/python/qa_type_conversions.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index bc65a2781..ff2e5c609 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -51,5 +51,16 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + def test_char_to_short(self): + src_data = (1, 2, 3, 4, 5) + expected_data = (256, 512, 768, 1024, 1280) + src = gr.vector_source_b(src_data) + op = blocks_swig.char_to_short() + dst = gr.vector_sink_s() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) + + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From c16e6eba638ebe3bdf5ee4770ce409481c8e1c7a Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 23 Jun 2012 07:46:42 -0700 Subject: blocks: added gr::blocks::complex_to_interleaved_short --- gr-blocks/python/qa_type_conversions.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index ff2e5c609..b03103bfe 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -61,6 +61,15 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_data, dst.data()) + def test_complex_to_interleaved_short(self): + src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + expected_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + src = gr.vector_source_c(src_data) + op = blocks_swig.complex_to_interleaved_short() + dst = gr.vector_sink_s() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From 6eb1447df04883af78ed78eb8449378e67d67bf6 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 23 Jun 2012 08:12:30 -0700 Subject: blocks: added gr::blocks::complex_to_float --- gr-blocks/python/qa_type_conversions.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index b03103bfe..5d477eef1 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -71,5 +71,31 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_data, dst.data()) + def test_complex_to_float_1(self): + src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + expected_data = (1.0, 3.0, 5.0, 7.0, 9.0) + src = gr.vector_source_c(src_data) + op = blocks_swig.complex_to_float() + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + + def test_complex_to_float_2(self): + src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + expected_data1 = (1.0, 3.0, 5.0, 7.0, 9.0) + expected_data2 = (2.0, 4.0, 6.0, 8.0, 10.0) + src = gr.vector_source_c(src_data) + op = blocks_swig.complex_to_float() + dst1 = gr.vector_sink_f() + dst2 = gr.vector_sink_f() + self.tb.connect(src, op) + self.tb.connect((op, 0), dst1) + self.tb.connect((op, 1), dst2) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data1, dst1.data()) + self.assertFloatTuplesAlmostEqual(expected_data2, dst2.data()) + + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From 11a702b94a43cac127c146654f5fc10415f2bb6e Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 23 Jun 2012 08:32:59 -0700 Subject: blocks: added gr::blocks::complex_to_real --- gr-blocks/python/qa_type_conversions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index 5d477eef1..7c27a9c51 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -96,6 +96,16 @@ class test_type_conversions(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(expected_data1, dst1.data()) self.assertFloatTuplesAlmostEqual(expected_data2, dst2.data()) + def test_complex_to_real(self): + src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + expected_data = (1.0, 3.0, 5.0, 7.0, 9.0) + src = gr.vector_source_c(src_data) + op = blocks_swig.complex_to_real() + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From ed0dffa3c1a84a4b8f3201969896f61af39b86a3 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 23 Jun 2012 08:44:47 -0700 Subject: blocks: added gr::blocks::complex_to_imag --- gr-blocks/python/qa_type_conversions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index 7c27a9c51..1faf83ad8 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -106,6 +106,16 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + def test_complex_to_imag(self): + src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + expected_data = (2.0, 4.0, 6.0, 8.0, 10.0) + src = gr.vector_source_c(src_data) + op = blocks_swig.complex_to_imag() + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From 48ba99044710dc69c0ebdd3fbe97798622713a9f Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 23 Jun 2012 09:06:19 -0700 Subject: blocks: added gr::blocks::complex_to_mag --- gr-blocks/python/qa_type_conversions.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index 1faf83ad8..92590feac 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -22,6 +22,7 @@ from gnuradio import gr, gr_unittest import blocks_swig +import math class test_type_conversions(gr_unittest.TestCase): @@ -116,6 +117,16 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + def test_complex_to_mag(self): + src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j) + expected_data = (math.sqrt(5), math.sqrt(25), math.sqrt(61), math.sqrt(113), math.sqrt(181)) + src = gr.vector_source_c(src_data) + op = blocks_swig.complex_to_mag() + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 5) + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From 737b3dc0c41a867ea38c1475a3877bc0fb6f3ee2 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 23 Jun 2012 09:25:42 -0700 Subject: blocks: added gr::blocks::complex_to_mag_squared --- gr-blocks/python/qa_type_conversions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index 92590feac..4b8904f0e 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -127,6 +127,16 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 5) + def test_complex_to_mag_squared(self): + src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j) + expected_data = (5.0, 25.0, 61.0, 113.0, 181.0) + src = gr.vector_source_c(src_data) + op = blocks_swig.complex_to_mag_squared() + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From 80aa560bbb59cad4d4d351a1e9c8c1fb56897397 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 23 Jun 2012 09:57:06 -0700 Subject: blocks: added gr::blocks::complex_to_arg --- gr-blocks/python/qa_type_conversions.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index 4b8904f0e..579ce2246 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -22,7 +22,7 @@ from gnuradio import gr, gr_unittest import blocks_swig -import math +from math import sqrt, atan2 class test_type_conversions(gr_unittest.TestCase): @@ -119,7 +119,7 @@ class test_type_conversions(gr_unittest.TestCase): def test_complex_to_mag(self): src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j) - expected_data = (math.sqrt(5), math.sqrt(25), math.sqrt(61), math.sqrt(113), math.sqrt(181)) + expected_data = (sqrt(5), sqrt(25), sqrt(61), sqrt(113), sqrt(181)) src = gr.vector_source_c(src_data) op = blocks_swig.complex_to_mag() dst = gr.vector_sink_f() @@ -137,6 +137,16 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + def test_complex_to_arg(self): + src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j) + expected_data = (atan2(2, 1), atan2(-4,3), atan2(6, 5), atan2(-8, 7), atan2(10,-9)) + src = gr.vector_source_c(src_data) + op = blocks_swig.complex_to_arg() + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 2) + print dst.data() if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From b48716fe0b666cf2be605c0c7d79111c6caf96c5 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sun, 24 Jun 2012 11:20:03 -0700 Subject: blocks: added gr::blocks::float_to_char --- gr-blocks/python/qa_type_conversions.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index 579ce2246..2caa283d2 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -146,7 +146,26 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.connect(src, op, dst) self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 2) - print dst.data() + + def test_float_to_char_identity(self): + src_data = (1.0, 2.0, 3.0, 4.0, 5.0) + expected_data = (1, 2, 3, 4, 5) + src = gr.vector_source_f(src_data) + op = blocks_swig.float_to_char() + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) + + def test_float_to_char_scale(self): + src_data = (1.0, 2.0, 3.0, 4.0, 5.0) + expected_data = (5, 10, 15, 20, 25) + src = gr.vector_source_f(src_data) + op = blocks_swig.float_to_char(1, 5) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From 8c23d9f9ebfe04b60d59efc636c6d5b02baacc99 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sun, 24 Jun 2012 11:42:20 -0700 Subject: blocks: added gr::blocks::float_to_complex --- gr-blocks/python/qa_type_conversions.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index 2caa283d2..4daf5f602 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -167,5 +167,30 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_data, dst.data()) + def test_float_to_complex_1(self): + src_data = (1.0, 3.0, 5.0, 7.0, 9.0) + expected_data = (1+0j, 3+0j, 5+0j, 7+0j, 9+0j) + src = gr.vector_source_f(src_data) + op = blocks_swig.float_to_complex() + dst = gr.vector_sink_c() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + + def test_float_to_complex_2(self): + src1_data = (1.0, 3.0, 5.0, 7.0, 9.0) + src2_data = (2.0, 4.0, 6.0, 8.0, 10.0) + expected_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + src1 = gr.vector_source_f(src1_data) + src2 = gr.vector_source_f(src2_data) + op = blocks_swig.float_to_complex() + dst = gr.vector_sink_c() + self.tb.connect(src1, (op, 0)) + self.tb.connect(src2, (op, 1)) + self.tb.connect(op, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From 31c61c16e2073f0c3f54a8d0523d8c4f10ca5dd2 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Mon, 25 Jun 2012 06:25:04 -0700 Subject: blocks: added gr::blocks::float_to_int --- gr-blocks/python/qa_type_conversions.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index 4daf5f602..fba38ab00 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -191,6 +191,26 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + def test_float_to_int_identity(self): + src_data = (1.0, 2.0, 3.0, 4.0, 5.0) + expected_data = (1, 2, 3, 4, 5) + src = gr.vector_source_f(src_data) + op = blocks_swig.float_to_int() + dst = gr.vector_sink_i() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) + + def test_float_to_int_scale(self): + src_data = (1.0, 2.0, 3.0, 4.0, 5.0) + expected_data = (5, 10, 15, 20, 25) + src = gr.vector_source_f(src_data) + op = blocks_swig.float_to_int(1, 5) + dst = gr.vector_sink_i() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From 86f15ba3488cde9eededa2af5af8dcadc01e9e47 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 26 Jun 2012 06:47:26 -0700 Subject: blocks: added gr::blocks::float_to_short --- gr-blocks/python/qa_type_conversions.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index fba38ab00..d41fe690d 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -211,6 +211,26 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_data, dst.data()) + def test_float_to_short_identity(self): + src_data = (1.0, 2.0, 3.0, 4.0, 5.0) + expected_data = (1, 2, 3, 4, 5) + src = gr.vector_source_f(src_data) + op = blocks_swig.float_to_short() + dst = gr.vector_sink_s() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) + + def test_float_to_short_scale(self): + src_data = (1.0, 2.0, 3.0, 4.0, 5.0) + expected_data = (5, 10, 15, 20, 25) + src = gr.vector_source_f(src_data) + op = blocks_swig.float_to_short(1, 5) + dst = gr.vector_sink_s() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From 0b7655a76e5c73b8f5a8310909cf038f12cbb869 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 26 Jun 2012 07:06:53 -0700 Subject: blocks: added gr::blocks::float_to_uchar --- gr-blocks/python/qa_type_conversions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index d41fe690d..a97203566 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -231,6 +231,16 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_data, dst.data()) + def test_float_to_uchar(self): + src_data = (1.0, -2.0, 3.0, -4.0, 256.0) + expected_data = (1, 0, 3, 0, 255) + src = gr.vector_source_f(src_data) + op = blocks_swig.float_to_uchar() + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From 3de0c77ed91e417c0b54972a78ffbad62f4bbb87 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 26 Jun 2012 19:43:01 -0700 Subject: blocks: added gr::blocks::float_to_int --- gr-blocks/python/qa_type_conversions.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index a97203566..354cf9392 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -241,6 +241,26 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_data, dst.data()) + def test_int_to_float_identity(self): + src_data = (1, 2, 3, 4, 5) + expected_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src = gr.vector_source_i(src_data) + op = blocks_swig.int_to_float() + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + + def test_int_to_float_scale(self): + src_data = (1, 2, 3, 4, 5) + expected_data = (0.2, 0.4, 0.6, 0.8, 1.0) + src = gr.vector_source_i(src_data) + op = blocks_swig.int_to_float(1, 5) + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From be1219b0623bbceb5bca6a6f6774f0669f52bdde Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Wed, 27 Jun 2012 06:50:22 -0700 Subject: blocks: added gr::blocks::interleaved_short_to_complex --- gr-blocks/python/qa_type_conversions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index 354cf9392..92e0a7ca4 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -261,6 +261,16 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) + def test_interleaved_short_to_complex(self): + src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + expected_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + src = gr.vector_source_s(src_data) + op = blocks_swig.interleaved_short_to_complex() + dst = gr.vector_sink_c() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From c128e5aee66838c849ffc2ac45217ff1efab42e8 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 28 Jun 2012 09:02:58 -0700 Subject: blocks: added gr::blocks::short_to_char --- gr-blocks/python/qa_type_conversions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index 92e0a7ca4..ddb876b3d 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -271,6 +271,16 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_data, dst.data()) + def test_short_to_char(self): + src_data = (256, 512, 768, 1024, 1280) + expected_data = (1, 2, 3, 4, 5) + src = gr.vector_source_s(src_data) + op = blocks_swig.short_to_char() + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From 9482c8986d0a7bd4772a78972880a9e574531052 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 28 Jun 2012 09:27:59 -0700 Subject: blocks: added gr::blocks::short_to_float --- gr-blocks/python/qa_type_conversions.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index ddb876b3d..a77fe8af5 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -281,6 +281,26 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_data, dst.data()) + def test_short_to_float_identity(self): + src_data = (1, 2, 3, 4, 5) + expected_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src = gr.vector_source_s(src_data) + op = blocks_swig.short_to_float() + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) + + def test_short_to_float_scale(self): + src_data = (5, 10, 15, 20, 25) + expected_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src = gr.vector_source_s(src_data) + op = blocks_swig.short_to_float(1, 5) + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From a3b74a25fcba67f61bf3cabb25286201f1263b0a Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 28 Jun 2012 09:46:38 -0700 Subject: blocks: added gr::blocks::uchar_to_float --- gr-blocks/python/qa_type_conversions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index a77fe8af5..eb1b42b63 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -301,6 +301,16 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_data, dst.data()) + def test_uchar_to_float(self): + src_data = (1, 2, 3, 4, 5) + expected_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src = gr.vector_source_b(src_data) + op = blocks_swig.uchar_to_float() + dst = gr.vector_sink_f() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) + if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") -- cgit From f2e815329402f170231c054e108b531094d046be Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Fri, 29 Jun 2012 08:10:15 -0700 Subject: blocks: added gr::blocks::conjugate_cc --- gr-blocks/python/qa_conjugate.py | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 gr-blocks/python/qa_conjugate.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_conjugate.py b/gr-blocks/python/qa_conjugate.py new file mode 100644 index 000000000..1808aa9c0 --- /dev/null +++ b/gr-blocks/python/qa_conjugate.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# +# Copyright 2012 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 + +class test_conjugate (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_000 (self): + src_data = (-2-2j, -1-1j, -2+2j, -1+1j, + 2-2j, 1-1j, 2+2j, 1+1j, + 0+0j) + + exp_data = (-2+2j, -1+1j, -2-2j, -1-1j, + 2+2j, 1+1j, 2-2j, 1-1j, + 0-0j) + + src = gr.vector_source_c(src_data) + op = blocks_swig.conjugate_cc () + dst = gr.vector_sink_c () + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data () + self.assertEqual (exp_data, result_data) + +if __name__ == '__main__': + gr_unittest.run(test_conjugate, "test_conjugate.xml") -- cgit From bfcc9dc634cc8d7da77b109a7ad9cd90714fd768 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Fri, 29 Jun 2012 08:30:23 -0700 Subject: blocks: added gr::blocks::integrate_XX with ss ii ff cc --- gr-blocks/python/qa_integrate.py | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 gr-blocks/python/qa_integrate.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_integrate.py b/gr-blocks/python/qa_integrate.py new file mode 100755 index 000000000..c404f1b30 --- /dev/null +++ b/gr-blocks/python/qa_integrate.py @@ -0,0 +1,76 @@ +#!/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 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 +import math + +class test_integrate (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_000_ss(self): + src_data = (1, 2, 3, 4, 5, 6) + dst_data = (6, 15) + src = gr.vector_source_s(src_data) + itg = blocks_swig.integrate_ss(3) + dst = gr.vector_sink_s() + self.tb.connect(src, itg, dst) + self.tb.run() + self.assertEqual(dst_data, dst.data()) + + def test_001_ii(self): + src_data = (1, 2, 3, 4, 5, 6) + dst_data = (6, 15) + src = gr.vector_source_i(src_data) + itg = blocks_swig.integrate_ii(3) + dst = gr.vector_sink_i() + self.tb.connect(src, itg, dst) + self.tb.run() + self.assertEqual(dst_data, dst.data()) + + def test_002_ff(self): + src_data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] + dst_data = [6.0, 15.0] + src = gr.vector_source_f(src_data) + itg = blocks_swig.integrate_ff(3) + dst = gr.vector_sink_f() + self.tb.connect(src, itg, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(dst_data, dst.data(), 6) + + def test_003_cc(self): + src_data = [1.0+1.0j, 2.0+2.0j, 3.0+3.0j, 4.0+4.0j, 5.0+5.0j, 6.0+6.0j] + dst_data = [6.0+6.0j, 15.0+15.0j] + src = gr.vector_source_c(src_data) + itg = blocks_swig.integrate_cc(3) + dst = gr.vector_sink_c() + self.tb.connect(src, itg, dst) + self.tb.run() + self.assertComplexTuplesAlmostEqual(dst_data, dst.data(), 6) + +if __name__ == '__main__': + gr_unittest.run(test_integrate, "test_integrate.xml") -- cgit From ee1a53b4a971e4b9623f504628231a273157f462 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 30 Jun 2012 08:26:58 -0700 Subject: blocks: aded gr::blocks::multiply_conjugate_cc --- gr-blocks/python/qa_multiply_conjugate.py | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 gr-blocks/python/qa_multiply_conjugate.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_multiply_conjugate.py b/gr-blocks/python/qa_multiply_conjugate.py new file mode 100644 index 000000000..f51563f85 --- /dev/null +++ b/gr-blocks/python/qa_multiply_conjugate.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# +# Copyright 2012 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 + +class test_multiply_conjugate (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_000 (self): + src_data0 = (-2-2j, -1-1j, -2+2j, -1+1j, + 2-2j, 1-1j, 2+2j, 1+1j, + 0+0j) + src_data1 = (-3-3j, -4-4j, -3+3j, -4+4j, + 3-3j, 4-4j, 3+3j, 4+4j, + 0+0j) + + exp_data = (12+0j, 8+0j, 12+0j, 8+0j, + 12+0j, 8+0j, 12+0j, 8+0j, + 0+0j) + src0 = gr.vector_source_c(src_data0) + src1 = gr.vector_source_c(src_data1) + op = blocks_swig.multiply_conjugate_cc () + dst = gr.vector_sink_c () + + self.tb.connect(src0, (op,0)) + self.tb.connect(src1, (op,1)) + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data () + self.assertEqual (exp_data, result_data) + +if __name__ == '__main__': + gr_unittest.run(test_multiply_conjugate, "test_multiply_conjugate.xml") -- cgit From 70d89e2051264876055fe9f73cbcb2823806b3ee Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sun, 1 Jul 2012 09:15:14 -0700 Subject: blocks: added gr::blocks::nlog10_ff --- gr-blocks/python/qa_nlog10.py | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 gr-blocks/python/qa_nlog10.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_nlog10.py b/gr-blocks/python/qa_nlog10.py new file mode 100755 index 000000000..cc2a3e8cc --- /dev/null +++ b/gr-blocks/python/qa_nlog10.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# +# Copyright 2005,2007,2010,2012 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 + +class test_nlog10(gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001(self): + src_data = (-10, 0, 10, 100, 1000, 10000, 100000) + expected_result = (-180, -180, 10, 20, 30, 40, 50) + src = gr.vector_source_f(src_data) + op = blocks_swig.nlog10_ff(10) + dst = gr.vector_sink_f() + self.tb.connect (src, op, dst) + self.tb.run() + result_data = dst.data() + self.assertFloatTuplesAlmostEqual (expected_result, result_data) + + +if __name__ == '__main__': + gr_unittest.run(test_nlog10, "test_nlog10.xml") + -- cgit From cc085e128901a9f3e8bfcc45d1834a62d747726c Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Mon, 2 Jul 2012 08:36:46 -0700 Subject: blocks: added gr::blocks::add_XX (bb ss ii) --- gr-blocks/python/qa_boolean_operators.py | 163 +++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100755 gr-blocks/python/qa_boolean_operators.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_boolean_operators.py b/gr-blocks/python/qa_boolean_operators.py new file mode 100755 index 000000000..5bd1e7550 --- /dev/null +++ b/gr-blocks/python/qa_boolean_operators.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,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 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 + +class test_boolean_operators (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def help_ss (self, src_data, exp_data, op): + for s in zip (range (len (src_data)), src_data): + src = gr.vector_source_s (s[1]) + self.tb.connect (src, (op, s[0])) + dst = gr.vector_sink_s () + self.tb.connect (op, dst) + self.tb.run () + result_data = dst.data () + self.assertEqual (exp_data, result_data) + + def help_bb (self, src_data, exp_data, op): + for s in zip (range (len (src_data)), src_data): + src = gr.vector_source_b (s[1]) + self.tb.connect (src, (op, s[0])) + dst = gr.vector_sink_b () + self.tb.connect (op, dst) + self.tb.run () + result_data = dst.data () + self.assertEqual (exp_data, result_data) + + def help_ii (self, src_data, exp_data, op): + for s in zip (range (len (src_data)), src_data): + src = gr.vector_source_i (s[1]) + self.tb.connect (src, (op, s[0])) + dst = gr.vector_sink_i () + self.tb.connect (op, dst) + self.tb.run () + result_data = dst.data () + self.assertEqual (exp_data, result_data) + """ + def test_xor_ss (self): + src1_data = (1, 2, 3, 0x5004, 0x1150) + src2_data = (8, 2, 1 , 0x0508, 0x1105) + expected_result = (9, 0, 2, 0x550C, 0x0055) + op = gr.xor_ss () + self.help_ss ((src1_data, src2_data), + expected_result, op) + + def test_xor_bb (self): + src1_data = (1, 2, 3, 4, 0x50) + src2_data = (8, 2, 1 , 8, 0x05) + expected_result = (9, 0, 2, 0xC, 0x55) + op = gr.xor_bb () + self.help_bb ((src1_data, src2_data), + expected_result, op) + + + def test_xor_ii (self): + src1_data = (1, 2, 3, 0x5000004, 0x11000050) + src2_data = (8, 2, 1 , 0x0500008, 0x11000005) + expected_result = (9, 0, 2, 0x550000C, 0x00000055) + op = gr.xor_ii () + self.help_ii ((src1_data, src2_data), + expected_result, op) + """ + def test_and_ss (self): + src1_data = (1, 2, 3, 0x5004, 0x1150) + src2_data = (8, 2, 1 , 0x0508, 0x1105) + expected_result = (0, 2, 1, 0x0000, 0x1100) + op = blocks_swig.and_ss () + self.help_ss ((src1_data, src2_data), + expected_result, op) + + def test_and_bb (self): + src1_data = (1, 2, 2, 3, 0x04, 0x50) + src2_data = (8, 2, 2, 1, 0x08, 0x05) + src3_data = (8, 2, 1, 1, 0x08, 0x05) + expected_result = (0, 2, 0, 1, 0x00, 0x00) + op = blocks_swig.and_bb () + self.help_bb ((src1_data, src2_data, src3_data), + expected_result, op) + + def test_and_ii (self): + src1_data = (1, 2, 3, 0x50005004, 0x11001150) + src2_data = (8, 2, 1 , 0x05000508, 0x11001105) + expected_result = (0, 2, 1, 0x00000000, 0x11001100) + op = blocks_swig.and_ii () + self.help_ii ((src1_data, src2_data), + expected_result, op) + """ + def test_or_ss (self): + src1_data = (1, 2, 3, 0x5004, 0x1150) + src2_data = (8, 2, 1 , 0x0508, 0x1105) + expected_result = (9, 2, 3, 0x550C, 0x1155) + op = gr.or_ss () + self.help_ss ((src1_data, src2_data), + expected_result, op) + + def test_or_bb (self): + src1_data = (1, 2, 2, 3, 0x04, 0x50) + src2_data = (8, 2, 2, 1 , 0x08, 0x05) + src3_data = (8, 2, 1, 1 , 0x08, 0x05) + expected_result = (9, 2, 3, 3, 0x0C, 0x55) + op = gr.or_bb () + self.help_bb ((src1_data, src2_data, src3_data), + expected_result, op) + + def test_or_ii (self): + src1_data = (1, 2, 3, 0x50005004, 0x11001150) + src2_data = (8, 2, 1 , 0x05000508, 0x11001105) + expected_result = (9, 2, 3, 0x5500550C, 0x11001155) + op = gr.or_ii () + self.help_ii ((src1_data, src2_data), + expected_result, op) + + def test_not_ss (self): + src1_data = (1, 2, 3, 0x5004, 0x1150) + expected_result = (~1, ~2, ~3, ~0x5004, ~0x1150) + op = gr.not_ss () + self.help_ss ((((src1_data),)), + expected_result, op) + + def test_not_bb (self): + src1_data = (1, 2, 2, 3, 0x04, 0x50) + expected_result = (0xFE, 0xFD, 0xFD, 0xFC, 0xFB, 0xAF) + op = gr.not_bb () + self.help_bb (((src1_data), ), + expected_result, op) + + def test_not_ii (self): + src1_data = (1, 2, 3, 0x50005004, 0x11001150) + expected_result = (~1 , ~2, ~3, ~0x50005004, ~0x11001150) + op = gr.not_ii () + self.help_ii (((src1_data),), + expected_result, op) + """ + + +if __name__ == '__main__': + gr_unittest.run(test_boolean_operators, "test_boolean_operators.xml") -- cgit From 025f323d9857715a31a1117693c5debd19393a46 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Mon, 2 Jul 2012 09:13:13 -0700 Subject: blocks: added gr::blocks::and_const_XX (bb ss ii) --- gr-blocks/python/qa_boolean_operators.py | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_boolean_operators.py b/gr-blocks/python/qa_boolean_operators.py index 5bd1e7550..8dad41a92 100755 --- a/gr-blocks/python/qa_boolean_operators.py +++ b/gr-blocks/python/qa_boolean_operators.py @@ -110,6 +110,39 @@ class test_boolean_operators (gr_unittest.TestCase): op = blocks_swig.and_ii () self.help_ii ((src1_data, src2_data), expected_result, op) + + def test_and_const_ss (self): + src_data = (1, 2, 3, 0x5004, 0x1150) + expected_result = (0, 2, 2, 0x5000, 0x1100) + src = gr.vector_source_s(src_data) + op = blocks_swig.and_const_ss (0x55AA) + dst = gr.vector_sink_s() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(dst.data(), expected_result) + + def test_and_const_bb (self): + src_data = (1, 2, 3, 0x50, 0x11) + expected_result = (0, 2, 2, 0x00, 0x00) + src = gr.vector_source_b(src_data) + op = blocks_swig.and_const_bb (0xAA) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(dst.data(), expected_result) + + + def test_and_const_ii (self): + src_data = (1, 2, 3, 0x5004, 0x1150) + expected_result = (0, 2, 2, 0x5000, 0x1100) + src = gr.vector_source_i(src_data) + op = blocks_swig.and_const_ii (0x55AA) + dst = gr.vector_sink_i() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(dst.data(), expected_result) + + """ def test_or_ss (self): src1_data = (1, 2, 3, 0x5004, 0x1150) -- cgit From 84f9822b4a8fe4290e971c09b2bd99f1bf59517b Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 3 Jul 2012 09:49:20 -0700 Subject: blocks: added gr::blocks::not_XX (bb ss ii) --- gr-blocks/python/qa_boolean_operators.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_boolean_operators.py b/gr-blocks/python/qa_boolean_operators.py index 8dad41a92..dc011c14e 100755 --- a/gr-blocks/python/qa_boolean_operators.py +++ b/gr-blocks/python/qa_boolean_operators.py @@ -169,27 +169,27 @@ class test_boolean_operators (gr_unittest.TestCase): self.help_ii ((src1_data, src2_data), expected_result, op) + """ def test_not_ss (self): src1_data = (1, 2, 3, 0x5004, 0x1150) expected_result = (~1, ~2, ~3, ~0x5004, ~0x1150) - op = gr.not_ss () + op = blocks_swig.not_ss () self.help_ss ((((src1_data),)), expected_result, op) def test_not_bb (self): src1_data = (1, 2, 2, 3, 0x04, 0x50) expected_result = (0xFE, 0xFD, 0xFD, 0xFC, 0xFB, 0xAF) - op = gr.not_bb () + op = blocks_swig.not_bb () self.help_bb (((src1_data), ), expected_result, op) def test_not_ii (self): src1_data = (1, 2, 3, 0x50005004, 0x11001150) expected_result = (~1 , ~2, ~3, ~0x50005004, ~0x11001150) - op = gr.not_ii () + op = blocks_swig.not_ii () self.help_ii (((src1_data),), expected_result, op) - """ if __name__ == '__main__': -- cgit From 4c85f46aee089432b090b988dedbc42091084ba3 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Wed, 4 Jul 2012 07:11:51 -0700 Subject: blocks: added gr::blocks::or_XX (bb ss ii) --- gr-blocks/python/qa_boolean_operators.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_boolean_operators.py b/gr-blocks/python/qa_boolean_operators.py index dc011c14e..43de72a89 100755 --- a/gr-blocks/python/qa_boolean_operators.py +++ b/gr-blocks/python/qa_boolean_operators.py @@ -143,12 +143,11 @@ class test_boolean_operators (gr_unittest.TestCase): self.assertEqual(dst.data(), expected_result) - """ def test_or_ss (self): src1_data = (1, 2, 3, 0x5004, 0x1150) src2_data = (8, 2, 1 , 0x0508, 0x1105) expected_result = (9, 2, 3, 0x550C, 0x1155) - op = gr.or_ss () + op = blocks_swig.or_ss () self.help_ss ((src1_data, src2_data), expected_result, op) @@ -157,7 +156,7 @@ class test_boolean_operators (gr_unittest.TestCase): src2_data = (8, 2, 2, 1 , 0x08, 0x05) src3_data = (8, 2, 1, 1 , 0x08, 0x05) expected_result = (9, 2, 3, 3, 0x0C, 0x55) - op = gr.or_bb () + op = blocks_swig.or_bb () self.help_bb ((src1_data, src2_data, src3_data), expected_result, op) @@ -165,11 +164,10 @@ class test_boolean_operators (gr_unittest.TestCase): src1_data = (1, 2, 3, 0x50005004, 0x11001150) src2_data = (8, 2, 1 , 0x05000508, 0x11001105) expected_result = (9, 2, 3, 0x5500550C, 0x11001155) - op = gr.or_ii () + op = blocks_swig.or_ii () self.help_ii ((src1_data, src2_data), expected_result, op) - """ def test_not_ss (self): src1_data = (1, 2, 3, 0x5004, 0x1150) expected_result = (~1, ~2, ~3, ~0x5004, ~0x1150) -- cgit From a76cd7d47576054d7fac37710a8f79b908d18b00 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Wed, 4 Jul 2012 07:22:49 -0700 Subject: blocks: added gr::blocks::xor_XX (bb ss ii) --- gr-blocks/python/qa_boolean_operators.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_boolean_operators.py b/gr-blocks/python/qa_boolean_operators.py index 43de72a89..5572f60ac 100755 --- a/gr-blocks/python/qa_boolean_operators.py +++ b/gr-blocks/python/qa_boolean_operators.py @@ -60,12 +60,12 @@ class test_boolean_operators (gr_unittest.TestCase): self.tb.run () result_data = dst.data () self.assertEqual (exp_data, result_data) - """ + def test_xor_ss (self): src1_data = (1, 2, 3, 0x5004, 0x1150) src2_data = (8, 2, 1 , 0x0508, 0x1105) expected_result = (9, 0, 2, 0x550C, 0x0055) - op = gr.xor_ss () + op = blocks_swig.xor_ss () self.help_ss ((src1_data, src2_data), expected_result, op) @@ -73,7 +73,7 @@ class test_boolean_operators (gr_unittest.TestCase): src1_data = (1, 2, 3, 4, 0x50) src2_data = (8, 2, 1 , 8, 0x05) expected_result = (9, 0, 2, 0xC, 0x55) - op = gr.xor_bb () + op = blocks_swig.xor_bb () self.help_bb ((src1_data, src2_data), expected_result, op) @@ -82,10 +82,11 @@ class test_boolean_operators (gr_unittest.TestCase): src1_data = (1, 2, 3, 0x5000004, 0x11000050) src2_data = (8, 2, 1 , 0x0500008, 0x11000005) expected_result = (9, 0, 2, 0x550000C, 0x00000055) - op = gr.xor_ii () + op = blocks_swig.xor_ii () self.help_ii ((src1_data, src2_data), expected_result, op) - """ + + def test_and_ss (self): src1_data = (1, 2, 3, 0x5004, 0x1150) src2_data = (8, 2, 1 , 0x0508, 0x1105) -- cgit From 44647064669928517b233ca26bd97cd87847a235 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 5 Jul 2012 09:25:29 -0700 Subject: blocks: added gr::blocks::deinterleave --- gr-blocks/python/qa_interleave.py | 83 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 gr-blocks/python/qa_interleave.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_interleave.py b/gr-blocks/python/qa_interleave.py new file mode 100755 index 000000000..56c8bdfdf --- /dev/null +++ b/gr-blocks/python/qa_interleave.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,2010,2012 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 +import math + +class test_interleave (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + """ + def test_int_001 (self): + lenx = 64 + src0 = gr.vector_source_f (range (0, lenx, 4)) + src1 = gr.vector_source_f (range (1, lenx, 4)) + src2 = gr.vector_source_f (range (2, lenx, 4)) + src3 = gr.vector_source_f (range (3, lenx, 4)) + op = gr.interleave (gr.sizeof_float) + dst = gr.vector_sink_f () + + self.tb.connect (src0, (op, 0)) + self.tb.connect (src1, (op, 1)) + self.tb.connect (src2, (op, 2)) + self.tb.connect (src3, (op, 3)) + self.tb.connect (op, dst) + self.tb.run () + expected_result = tuple (range (lenx)) + result_data = dst.data () + self.assertFloatTuplesAlmostEqual (expected_result, result_data) + """ + def test_deint_001 (self): + lenx = 64 + src = gr.vector_source_f (range (lenx)) + op = blocks_swig.deinterleave (gr.sizeof_float) + dst0 = gr.vector_sink_f () + dst1 = gr.vector_sink_f () + dst2 = gr.vector_sink_f () + dst3 = gr.vector_sink_f () + + self.tb.connect (src, op) + self.tb.connect ((op, 0), dst0) + self.tb.connect ((op, 1), dst1) + self.tb.connect ((op, 2), dst2) + self.tb.connect ((op, 3), dst3) + self.tb.run () + + expected_result0 = tuple (range (0, lenx, 4)) + expected_result1 = tuple (range (1, lenx, 4)) + expected_result2 = tuple (range (2, lenx, 4)) + expected_result3 = tuple (range (3, lenx, 4)) + + self.assertFloatTuplesAlmostEqual (expected_result0, dst0.data ()) + self.assertFloatTuplesAlmostEqual (expected_result1, dst1.data ()) + self.assertFloatTuplesAlmostEqual (expected_result2, dst2.data ()) + self.assertFloatTuplesAlmostEqual (expected_result3, dst3.data ()) + +if __name__ == '__main__': + gr_unittest.run(test_interleave, "test_interleave.xml") + -- cgit From 27694edd168bc1260ff04950e837a6580afc49ab Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Fri, 6 Jul 2012 08:17:40 -0700 Subject: blocks: added gr::blocks::interleave --- gr-blocks/python/qa_interleave.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_interleave.py b/gr-blocks/python/qa_interleave.py index 56c8bdfdf..376d487b1 100755 --- a/gr-blocks/python/qa_interleave.py +++ b/gr-blocks/python/qa_interleave.py @@ -32,14 +32,13 @@ class test_interleave (gr_unittest.TestCase): def tearDown (self): self.tb = None - """ def test_int_001 (self): lenx = 64 src0 = gr.vector_source_f (range (0, lenx, 4)) src1 = gr.vector_source_f (range (1, lenx, 4)) src2 = gr.vector_source_f (range (2, lenx, 4)) src3 = gr.vector_source_f (range (3, lenx, 4)) - op = gr.interleave (gr.sizeof_float) + op = blocks_swig.interleave (gr.sizeof_float) dst = gr.vector_sink_f () self.tb.connect (src0, (op, 0)) @@ -51,7 +50,7 @@ class test_interleave (gr_unittest.TestCase): expected_result = tuple (range (lenx)) result_data = dst.data () self.assertFloatTuplesAlmostEqual (expected_result, result_data) - """ + def test_deint_001 (self): lenx = 64 src = gr.vector_source_f (range (lenx)) -- cgit From 4e06f35f611aff2e1d4983327da54cf63e5b9ada Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 7 Jul 2012 07:06:51 -0700 Subject: blocks: added gr::blocks::keep_one_in_n --- gr-blocks/python/qa_keep_one_in_n.py | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 gr-blocks/python/qa_keep_one_in_n.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_keep_one_in_n.py b/gr-blocks/python/qa_keep_one_in_n.py new file mode 100755 index 000000000..8c5f44b84 --- /dev/null +++ b/gr-blocks/python/qa_keep_one_in_n.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# +# Copyright 2012 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 + +class test_keep_one_in_n(gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001(self): + src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + expected_data = (5, 10) + src = gr.vector_source_b(src_data); + op = blocks_swig.keep_one_in_n(gr.sizeof_char, 5) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(dst.data(), expected_data) + + +if __name__ == '__main__': + gr_unittest.run(test_keep_one_in_n, "test_integrate.xml") -- cgit From bbd91d7a08bfc0c229267e5dc848d1f57d629373 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 19 Jul 2012 06:27:19 -0700 Subject: blocks: added gr::blocks::keep_m_in_n --- gr-blocks/python/qa_keep_m_in_n.py | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 gr-blocks/python/qa_keep_m_in_n.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_keep_m_in_n.py b/gr-blocks/python/qa_keep_m_in_n.py new file mode 100755 index 000000000..0898217ba --- /dev/null +++ b/gr-blocks/python/qa_keep_m_in_n.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# +# Copyright 2008,2010,2012 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 blocks_swig +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 = blocks_swig.keep_m_in_n( 1, 1, 2, 0 ); + km3 = blocks_swig.keep_m_in_n( 1, 1, 3, 1 ); + km7 = blocks_swig.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") + -- cgit From 66f49de1986dd531bee011299d4b1f7c62872d39 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 19 Jul 2012 07:02:45 -0700 Subject: blocks: added gr::blocks::repeat --- gr-blocks/python/qa_repeat.py | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 gr-blocks/python/qa_repeat.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_repeat.py b/gr-blocks/python/qa_repeat.py new file mode 100755 index 000000000..69fb3ef72 --- /dev/null +++ b/gr-blocks/python/qa_repeat.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# +# Copyright 2008,2010,2012 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 +import math + +class test_repeat (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001_float(self): + src_data = [n*1.0 for n in range(100)]; + dst_data = [] + for n in range(100): + dst_data += [1.0*n, 1.0*n, 1.0*n] + + src = gr.vector_source_f(src_data) + rpt = blocks_swig.repeat(gr.sizeof_float, 3) + dst = gr.vector_sink_f() + self.tb.connect(src, rpt, dst) + self.tb.run() + self.assertFloatTuplesAlmostEqual(dst_data, dst.data(), 6) + +if __name__ == '__main__': + gr_unittest.run(test_repeat, "test_repeat.xml") -- cgit From 0a5bb996ca4f4bb350cf91b00b4c3db5a5c4eb75 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Wed, 29 Aug 2012 09:29:50 -0700 Subject: blocks: added gr::blocks::stream_mux --- gr-blocks/python/qa_stream_mux.py | 169 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100755 gr-blocks/python/qa_stream_mux.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_stream_mux.py b/gr-blocks/python/qa_stream_mux.py new file mode 100755 index 000000000..f21a9bbbc --- /dev/null +++ b/gr-blocks/python/qa_stream_mux.py @@ -0,0 +1,169 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005,2007,2010,2012 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 + +class test_stream_mux (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def help_stream_2ff(self, N, stream_sizes): + v0 = gr.vector_source_f(N*[1,], False) + v1 = gr.vector_source_f(N*[2,], False) + + mux = blocks_swig.stream_mux(gr.sizeof_float, stream_sizes) + + dst = gr.vector_sink_f () + + self.tb.connect (v0, (mux,0)) + self.tb.connect (v1, (mux,1)) + self.tb.connect (mux, dst) + self.tb.run () + + return dst.data () + + def help_stream_ramp_2ff(self, N, stream_sizes): + r1 = range(N) + r2 = range(N) + r2.reverse() + + v0 = gr.vector_source_f(r1, False) + v1 = gr.vector_source_f(r2, False) + + mux = blocks_swig.stream_mux(gr.sizeof_float, stream_sizes) + + dst = gr.vector_sink_f () + + self.tb.connect (v0, (mux,0)) + self.tb.connect (v1, (mux,1)) + self.tb.connect (mux, dst) + self.tb.run () + + return dst.data () + + def test_stream_2NN_ff(self): + N = 40 + stream_sizes = [10, 10] + result_data = self.help_stream_2ff(N, stream_sizes) + + exp_data = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0) + self.assertEqual (exp_data, result_data) + + def test_stream_ramp_2NN_ff(self): + N = 40 + stream_sizes = [10, 10] + result_data = self.help_stream_ramp_2ff(N, stream_sizes) + + exp_data = ( 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, + 39.0, 38.0, 37.0, 36.0, 35.0, 34.0, 33.0, 32.0, 31.0, 30.0, + 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, + 29.0, 28.0, 27.0, 26.0, 25.0, 24.0, 23.0, 22.0, 21.0, 20.0, + 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, + 19.0, 18.0, 17.0, 16.0, 15.0, 14.0, 13.0, 12.0, 11.0, 10.0, + 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, + 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0) + self.assertEqual (exp_data, result_data) + + def test_stream_2NM_ff(self): + N = 40 + stream_sizes = [7, 9] + self.help_stream_2ff(N, stream_sizes) + + result_data = self.help_stream_2ff(N, stream_sizes) + + exp_data = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0) + + self.assertEqual (exp_data, result_data) + + + def test_stream_2MN_ff(self): + N = 37 + stream_sizes = [7, 9] + self.help_stream_2ff(N, stream_sizes) + + result_data = self.help_stream_2ff(N, stream_sizes) + + exp_data = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 2.0) + + self.assertEqual (exp_data, result_data) + + def test_stream_2N0_ff(self): + N = 30 + stream_sizes = [7, 0] + self.help_stream_2ff(N, stream_sizes) + + result_data = self.help_stream_2ff(N, stream_sizes) + + exp_data = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0) + + self.assertEqual (exp_data, result_data) + + def test_stream_20N_ff(self): + N = 30 + stream_sizes = [0, 9] + self.help_stream_2ff(N, stream_sizes) + + result_data = self.help_stream_2ff(N, stream_sizes) + + exp_data = (2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, + 2.0, 2.0, 2.0) + + self.assertEqual (exp_data, result_data) + +if __name__ == '__main__': + gr_unittest.run(test_stream_mux, "test_stream_mux.xml") -- cgit From b434b7329301fee49ab82a81ac68517f8ab042eb Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 30 Aug 2012 14:29:28 -0700 Subject: blocks: added gr::blocks::stream_to_streams --- gr-blocks/python/qa_pipe_fittings.py | 138 +++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100755 gr-blocks/python/qa_pipe_fittings.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_pipe_fittings.py b/gr-blocks/python/qa_pipe_fittings.py new file mode 100755 index 000000000..097856867 --- /dev/null +++ b/gr-blocks/python/qa_pipe_fittings.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python +# +# Copyright 2005,2007,2010,2012 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 + +def calc_expected_result(src_data, n): + assert (len(src_data) % n) == 0 + result = [list() for x in range(n)] + #print "len(result) =", len(result) + for i in xrange(len(src_data)): + (result[i % n]).append(src_data[i]) + return [tuple(x) for x in result] + + +class test_pipe_fittings(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block () + + def tearDown(self): + self.tb = None + + def test_001(self): + """ + Test stream_to_streams. + """ + n = 8 + src_len = n * 8 + src_data = range(src_len) + + expected_results = calc_expected_result(src_data, n) + #print "expected results: ", expected_results + src = gr.vector_source_i(src_data) + op = gr.stream_to_streams(gr.sizeof_int, n) + self.tb.connect(src, op) + + dsts = [] + for i in range(n): + dst = gr.vector_sink_i() + self.tb.connect((op, i), (dst, 0)) + dsts.append(dst) + + self.tb.run() + + for d in range(n): + self.assertEqual(expected_results[d], dsts[d].data()) + """ + def test_002(self): + + # Test streams_to_stream (using stream_to_streams). + + n = 8 + src_len = n * 8 + src_data = tuple(range(src_len)) + expected_results = src_data + + src = gr.vector_source_i(src_data) + op1 = gr.stream_to_streams(gr.sizeof_int, n) + op2 = gr.streams_to_stream(gr.sizeof_int, n) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1) + for i in range(n): + self.tb.connect((op1, i), (op2, i)) + self.tb.connect(op2, dst) + + self.tb.run() + self.assertEqual(expected_results, dst.data()) + + def test_003(self): + + #Test streams_to_vector (using stream_to_streams & vector_to_stream). + + n = 8 + src_len = n * 8 + src_data = tuple(range(src_len)) + expected_results = src_data + + src = gr.vector_source_i(src_data) + op1 = gr.stream_to_streams(gr.sizeof_int, n) + op2 = gr.streams_to_vector(gr.sizeof_int, n) + op3 = gr.vector_to_stream(gr.sizeof_int, n) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1) + for i in range(n): + self.tb.connect((op1, i), (op2, i)) + self.tb.connect(op2, op3, dst) + + self.tb.run() + self.assertEqual(expected_results, dst.data()) + + def test_004(self): + + #Test vector_to_streams. + + n = 8 + src_len = n * 8 + src_data = tuple(range(src_len)) + expected_results = src_data + + src = gr.vector_source_i(src_data) + op1 = gr.stream_to_vector(gr.sizeof_int, n) + op2 = gr.vector_to_streams(gr.sizeof_int, n) + op3 = gr.streams_to_stream(gr.sizeof_int, n) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + for i in range(n): + self.tb.connect((op2, i), (op3, i)) + self.tb.connect(op3, dst) + + self.tb.run() + self.assertEqual(expected_results, dst.data()) + """ + +if __name__ == '__main__': + gr_unittest.run(test_pipe_fittings, "test_pipe_fittings.xml") -- cgit From 2065177207d9f504fdcd374ed6567379c51c7a06 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 4 Sep 2012 15:38:17 -0700 Subject: blocks: added gr::blocks::streams_to_stream --- gr-blocks/python/qa_pipe_fittings.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_pipe_fittings.py b/gr-blocks/python/qa_pipe_fittings.py index 097856867..e5335e979 100755 --- a/gr-blocks/python/qa_pipe_fittings.py +++ b/gr-blocks/python/qa_pipe_fittings.py @@ -64,7 +64,7 @@ class test_pipe_fittings(gr_unittest.TestCase): for d in range(n): self.assertEqual(expected_results[d], dsts[d].data()) - """ + def test_002(self): # Test streams_to_stream (using stream_to_streams). @@ -87,6 +87,7 @@ class test_pipe_fittings(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_results, dst.data()) + """ def test_003(self): #Test streams_to_vector (using stream_to_streams & vector_to_stream). -- cgit From 73d59860c4cc0e2b22c21d56cd5cdfcb969263eb Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 4 Sep 2012 16:25:00 -0700 Subject: blocks: added gr::blocks::vector_to_stream --- gr-blocks/python/qa_pipe_fittings.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_pipe_fittings.py b/gr-blocks/python/qa_pipe_fittings.py index e5335e979..6a4ba8b3a 100755 --- a/gr-blocks/python/qa_pipe_fittings.py +++ b/gr-blocks/python/qa_pipe_fittings.py @@ -87,7 +87,6 @@ class test_pipe_fittings(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_results, dst.data()) - """ def test_003(self): #Test streams_to_vector (using stream_to_streams & vector_to_stream). @@ -110,7 +109,7 @@ class test_pipe_fittings(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_results, dst.data()) - + """ def test_004(self): #Test vector_to_streams. -- cgit From c5ddf4c26bf8bc049622b2e9ffcdcdba3265b580 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 4 Sep 2012 16:39:30 -0700 Subject: blocks: added gr::blocks::vector_to_streams --- gr-blocks/python/qa_pipe_fittings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_pipe_fittings.py b/gr-blocks/python/qa_pipe_fittings.py index 6a4ba8b3a..321660d5e 100755 --- a/gr-blocks/python/qa_pipe_fittings.py +++ b/gr-blocks/python/qa_pipe_fittings.py @@ -109,7 +109,7 @@ class test_pipe_fittings(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_results, dst.data()) - """ + def test_004(self): #Test vector_to_streams. @@ -132,7 +132,7 @@ class test_pipe_fittings(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_results, dst.data()) - """ + if __name__ == '__main__': gr_unittest.run(test_pipe_fittings, "test_pipe_fittings.xml") -- cgit From 69d2ba539e1774a30ef44685ba82bdb0c54b5ca4 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Wed, 14 Nov 2012 09:52:26 -0800 Subject: gr: apply pattern for g37f7522 and gc4c0ce9 to gr-analog and gr-blocks --- gr-blocks/python/CMakeLists.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/CMakeLists.txt b/gr-blocks/python/CMakeLists.txt index 5044e2320..710ab155c 100644 --- a/gr-blocks/python/CMakeLists.txt +++ b/gr-blocks/python/CMakeLists.txt @@ -31,17 +31,17 @@ GR_PYTHON_INSTALL( # Handle the unit tests ######################################################################## if(ENABLE_TESTING) + +list(APPEND GR_TEST_PYTHON_DIRS + ${CMAKE_BINARY_DIR}/gr-blocks/python + ${CMAKE_BINARY_DIR}/gr-blocks/swig +) +list(APPEND GR_TEST_TARGET_DEPS gnuradio-blocks) + include(GrTest) file(GLOB py_qa_test_files "qa_*.py") foreach(py_qa_test_file ${py_qa_test_files}) get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) - set(GR_TEST_PYTHON_DIRS - ${CMAKE_BINARY_DIR}/gnuradio-core/src/python - ${CMAKE_BINARY_DIR}/gnuradio-core/src/lib/swig - ${CMAKE_BINARY_DIR}/gr-blocks/python - ${CMAKE_BINARY_DIR}/gr-blocks/swig - ) - set(GR_TEST_TARGET_DEPS gruel gnuradio-core gnuradio-blocks) GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B} ${py_qa_test_file}) endforeach(py_qa_test_file) endif(ENABLE_TESTING) -- cgit From 680c889aec7db3b18a8c81c5405ed141f1b078c7 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Wed, 28 Nov 2012 19:57:59 -0800 Subject: patterned qa added, bugs fixed --- gr-blocks/python/qa_patterned_interleaver.py | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 gr-blocks/python/qa_patterned_interleaver.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_patterned_interleaver.py b/gr-blocks/python/qa_patterned_interleaver.py new file mode 100755 index 000000000..1dc9a0d90 --- /dev/null +++ b/gr-blocks/python/qa_patterned_interleaver.py @@ -0,0 +1,56 @@ +#!/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 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 +try: + import blocks_swig +except: + from gnuradio import blocks +import math + +class test_patterned_interleaver (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_000(self): + dst_data = [0,0,1,2,0,2,1,0]; + src0 = gr.vector_source_f(200*[0]) + src1 = gr.vector_source_f(200*[1]) + src2 = gr.vector_source_f(200*[2]) + itg = blocks.patterned_interleaver(gr.sizeof_float, dst_data) + dst = gr.vector_sink_f() + head = gr.head(gr.sizeof_float, 8); + + self.tb.connect( src0, (itg,0) ); + self.tb.connect( src1, (itg,1) ); + self.tb.connect( src2, (itg,2) ); + self.tb.connect( itg, head, dst ); + + self.tb.run() + self.assertEqual(list(dst_data), list(dst.data())) + +if __name__ == '__main__': + gr_unittest.run(test_patterned_interleaver, "test_patterned_interleaver.xml") -- cgit From 0fbd1699158f01937f61c245398ccdaebe3d978b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 28 Nov 2012 21:15:50 -0800 Subject: blocks: fix for qa_patterned_interleaver. --- gr-blocks/python/qa_patterned_interleaver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_patterned_interleaver.py b/gr-blocks/python/qa_patterned_interleaver.py index 1dc9a0d90..3cf29c917 100755 --- a/gr-blocks/python/qa_patterned_interleaver.py +++ b/gr-blocks/python/qa_patterned_interleaver.py @@ -22,7 +22,7 @@ from gnuradio import gr, gr_unittest try: - import blocks_swig + import blocks_swig as blocks except: from gnuradio import blocks import math -- cgit From 461ece56b36a44b2405282630157739c7f9a26ba Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 14 Dec 2012 16:10:30 -0500 Subject: blocks: moving file metadata sink/source to gr-blocks. --- gr-blocks/python/CMakeLists.txt | 1 + gr-blocks/python/parse_file_metadata.py | 188 ++++++++++++++++++++++++++++++ gr-blocks/python/qa_file_metadata.py | 197 ++++++++++++++++++++++++++++++++ 3 files changed, 386 insertions(+) create mode 100644 gr-blocks/python/parse_file_metadata.py create mode 100644 gr-blocks/python/qa_file_metadata.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/CMakeLists.txt b/gr-blocks/python/CMakeLists.txt index 710ab155c..cab0b956f 100644 --- a/gr-blocks/python/CMakeLists.txt +++ b/gr-blocks/python/CMakeLists.txt @@ -23,6 +23,7 @@ include(GrPython) GR_PYTHON_INSTALL( FILES __init__.py + parse_file_metadata.py DESTINATION ${GR_PYTHON_DIR}/gnuradio/blocks COMPONENT "blocks_python" ) diff --git a/gr-blocks/python/parse_file_metadata.py b/gr-blocks/python/parse_file_metadata.py new file mode 100644 index 000000000..ec7bf6e80 --- /dev/null +++ b/gr-blocks/python/parse_file_metadata.py @@ -0,0 +1,188 @@ +#!/usr/bin/env python +# +# Copyright 2012 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. +# + +import sys +from gnuradio import gr +from gruel import pmt + +try: + import blocks_swig as blocks +except: + from gnuradio import blocks + +''' +sr Sample rate (samples/second) +time Time as uint64(secs), double(fractional secs) +type Type of data (see gr_file_types enum) +cplx is complex? (True or False) +strt Start of data (or size of header) in bytes +size Size of data in bytes +''' + +HEADER_LENGTH = blocks.METADATA_HEADER_SIZE + +ftype_to_string = {blocks.GR_FILE_BYTE: "bytes", + blocks.GR_FILE_SHORT: "short", + blocks.GR_FILE_INT: "int", + blocks.GR_FILE_LONG: "long", + blocks.GR_FILE_LONG_LONG: "long long", + blocks.GR_FILE_FLOAT: "float", + blocks.GR_FILE_DOUBLE: "double" } + +ftype_to_size = {blocks.GR_FILE_BYTE: gr.sizeof_char, + blocks.GR_FILE_SHORT: gr.sizeof_short, + blocks.GR_FILE_INT: gr.sizeof_int, + blocks.GR_FILE_LONG: gr.sizeof_int, + blocks.GR_FILE_LONG_LONG: 2*gr.sizeof_int, + blocks.GR_FILE_FLOAT: gr.sizeof_float, + blocks.GR_FILE_DOUBLE: gr.sizeof_double} + +def parse_header(p, VERBOSE=False): + dump = pmt.PMT_NIL + + info = dict() + + if(pmt.pmt_is_dict(p) is False): + sys.stderr.write("Header is not a PMT dictionary: invalid or corrupt data file.\n") + sys.exit(1) + + # GET FILE FORMAT VERSION NUMBER + if(pmt.pmt_dict_has_key(p, pmt.pmt_string_to_symbol("version"))): + r = pmt.pmt_dict_ref(p, pmt.pmt_string_to_symbol("version"), dump) + version = pmt.pmt_to_long(r) + if(VERBOSE): + print "Version Number: {0}".format(version) + else: + sys.stderr.write("Could not find key 'sr': invalid or corrupt data file.\n") + sys.exit(1) + + # EXTRACT SAMPLE RATE + if(pmt.pmt_dict_has_key(p, pmt.pmt_string_to_symbol("rx_rate"))): + r = pmt.pmt_dict_ref(p, pmt.pmt_string_to_symbol("rx_rate"), dump) + samp_rate = pmt.pmt_to_double(r) + info["rx_rate"] = samp_rate + if(VERBOSE): + print "Sample Rate: {0:.2f} sps".format(samp_rate) + else: + sys.stderr.write("Could not find key 'sr': invalid or corrupt data file.\n") + sys.exit(1) + + # EXTRACT TIME STAMP + if(pmt.pmt_dict_has_key(p, pmt.pmt_string_to_symbol("rx_time"))): + r = pmt.pmt_dict_ref(p, pmt.pmt_string_to_symbol("rx_time"), dump) + pmt_secs = pmt.pmt_tuple_ref(r, 0) + pmt_fracs = pmt.pmt_tuple_ref(r, 1) + secs = float(pmt.pmt_to_uint64(pmt_secs)) + fracs = pmt.pmt_to_double(pmt_fracs) + t = secs + fracs + info["rx_time"] = t + if(VERBOSE): + print "Seconds: {0:.6f}".format(t) + else: + sys.stderr.write("Could not find key 'time': invalid or corrupt data file.\n") + sys.exit(1) + + # EXTRACT ITEM SIZE + if(pmt.pmt_dict_has_key(p, pmt.pmt_string_to_symbol("size"))): + r = pmt.pmt_dict_ref(p, pmt.pmt_string_to_symbol("size"), dump) + dsize = pmt.pmt_to_long(r) + info["size"] = dsize + if(VERBOSE): + print "Item size: {0}".format(dsize) + else: + sys.stderr.write("Could not find key 'size': invalid or corrupt data file.\n") + sys.exit(1) + + # EXTRACT DATA TYPE + if(pmt.pmt_dict_has_key(p, pmt.pmt_string_to_symbol("type"))): + r = pmt.pmt_dict_ref(p, pmt.pmt_string_to_symbol("type"), dump) + dtype = pmt.pmt_to_long(r) + stype = ftype_to_string[dtype] + info["type"] = stype + if(VERBOSE): + print "Data Type: {0} ({1})".format(stype, dtype) + else: + sys.stderr.write("Could not find key 'type': invalid or corrupt data file.\n") + sys.exit(1) + + # EXTRACT COMPLEX + if(pmt.pmt_dict_has_key(p, pmt.pmt_string_to_symbol("cplx"))): + r = pmt.pmt_dict_ref(p, pmt.pmt_string_to_symbol("cplx"), dump) + cplx = pmt.pmt_to_bool(r) + info["cplx"] = cplx + if(VERBOSE): + print "Complex? {0}".format(cplx) + else: + sys.stderr.write("Could not find key 'cplx': invalid or corrupt data file.\n") + sys.exit(1) + + # EXTRACT WHERE CURRENT SEGMENT STARTS + if(pmt.pmt_dict_has_key(p, pmt.pmt_string_to_symbol("strt"))): + r = pmt.pmt_dict_ref(p, pmt.pmt_string_to_symbol("strt"), dump) + seg_start = pmt.pmt_to_uint64(r) + info["hdr_len"] = seg_start + info["extra_len"] = seg_start - HEADER_LENGTH + info["has_extra"] = info["extra_len"] > 0 + if(VERBOSE): + print "Header Length: {0} bytes".format(info["hdr_len"]) + print "Extra Length: {0}".format((info["extra_len"])) + print "Extra Header? {0}".format(info["has_extra"]) + else: + sys.stderr.write("Could not find key 'strt': invalid or corrupt data file.\n") + sys.exit(1) + + # EXTRACT SIZE OF DATA + if(pmt.pmt_dict_has_key(p, pmt.pmt_string_to_symbol("bytes"))): + r = pmt.pmt_dict_ref(p, pmt.pmt_string_to_symbol("bytes"), dump) + nbytes = pmt.pmt_to_uint64(r) + + nitems = nbytes/dsize + info["nitems"] = nitems + info["nbytes"] = nbytes + + if(VERBOSE): + print "Size of Data: {0} bytes".format(nbytes) + print " {0} items".format(nitems) + else: + sys.stderr.write("Could not find key 'size': invalid or corrupt data file.\n") + sys.exit(1) + + return info + +# IF THERE IS EXTRA DATA, PULL OUT THE DICTIONARY AND PARSE IT +def parse_extra_dict(p, info, VERBOSE=False): + if(pmt.pmt_is_dict(p) is False): + sys.stderr.write("Extra header is not a PMT dictionary: invalid or corrupt data file.\n") + sys.exit(1) + + items = pmt.pmt_dict_items(p) + nitems = pmt.pmt_length(items) + for i in xrange(nitems): + item = pmt.pmt_nth(i, items) + key = pmt.pmt_symbol_to_string(pmt.pmt_car(item)) + val = pmt.pmt_cdr(item) + info[key] = val + if(VERBOSE): + print "{0}: ".format(key) + pmt.pmt_print(val) + + return info diff --git a/gr-blocks/python/qa_file_metadata.py b/gr-blocks/python/qa_file_metadata.py new file mode 100644 index 000000000..9f4a331d6 --- /dev/null +++ b/gr-blocks/python/qa_file_metadata.py @@ -0,0 +1,197 @@ +#!/usr/bin/env python +# +# Copyright 2012 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 parse_file_metadata +import blocks_swig as blocks +import pmt +import os, time + +class test_file_metadata(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + outfile = "test_out.dat" + + detached = False + samp_rate = 200000 + key = pmt.pmt_intern("samp_rate") + val = pmt.pmt_from_double(samp_rate) + extras = pmt.pmt_make_dict() + extras = pmt.pmt_dict_add(extras, key, val) + extras_str = pmt.pmt_serialize_str(extras) + + src = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 1000, 1, 0) + head = gr.head(gr.sizeof_gr_complex, 1000) + fsnk = blocks.file_meta_sink(gr.sizeof_gr_complex, outfile, + samp_rate, 1, + blocks.GR_FILE_FLOAT, True, + 1000000, extras_str, detached) + fsnk.set_unbuffered(True) + + self.tb.connect(src, head, fsnk) + self.tb.run() + fsnk.close() + + handle = open(outfile, "rb") + header_str = handle.read(parse_file_metadata.HEADER_LENGTH) + if(len(header_str) == 0): + self.assertFalse() + + try: + header = pmt.pmt_deserialize_str(header_str) + except RuntimeError: + self.assertFalse() + + info = parse_file_metadata.parse_header(header, False) + + extra_str = handle.read(info["extra_len"]) + self.assertGreater(len(extra_str), 0) + handle.close() + + try: + extra = pmt.pmt_deserialize_str(extra_str) + except RuntimeError: + self.assertFalse() + + extra_info = parse_file_metadata.parse_extra_dict(extra, info, False) + + self.assertEqual(info['rx_rate'], samp_rate) + self.assertEqual(pmt.pmt_to_double(extra_info['samp_rate']), samp_rate) + + + # Test file metadata source + # Create a new sig source to start from the beginning + src2 = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 1000, 1, 0) + fsrc = blocks.file_meta_source(outfile, False) + vsnk = gr.vector_sink_c() + tsnk = gr.tag_debug(gr.sizeof_gr_complex, "QA") + ssnk = gr.vector_sink_c() + head.reset() + self.tb.disconnect(src, head, fsnk) + self.tb.connect(fsrc, vsnk) + self.tb.connect(fsrc, tsnk) + self.tb.connect(src2, head, ssnk) + self.tb.run() + + # Test to make sure tags with 'samp_rate' and 'rx_rate' keys + # were generated and received correctly. + tags = tsnk.current_tags() + for t in tags: + if(pmt.pmt_eq(t.key, pmt.pmt_intern("samp_rate"))): + self.assertEqual(pmt.pmt_to_double(t.value), samp_rate) + elif(pmt.pmt_eq(t.key, pmt.pmt_intern("rx_rate"))): + self.assertEqual(pmt.pmt_to_double(t.value), samp_rate) + + # Test that the data portion was extracted and received correctly. + self.assertComplexTuplesAlmostEqual(vsnk.data(), ssnk.data(), 5) + + os.remove(outfile) + + def test_002(self): + outfile = "test_out.dat" + outfile_hdr = "test_out.dat.hdr" + + detached = True + samp_rate = 200000 + key = pmt.pmt_intern("samp_rate") + val = pmt.pmt_from_double(samp_rate) + extras = pmt.pmt_make_dict() + extras = pmt.pmt_dict_add(extras, key, val) + extras_str = pmt.pmt_serialize_str(extras) + + src = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 1000, 1, 0) + head = gr.head(gr.sizeof_gr_complex, 1000) + fsnk = blocks.file_meta_sink(gr.sizeof_gr_complex, outfile, + samp_rate, 1, + blocks.GR_FILE_FLOAT, True, + 1000000, extras_str, detached) + fsnk.set_unbuffered(True) + + self.tb.connect(src, head, fsnk) + self.tb.run() + fsnk.close() + + # Open detached header for reading + handle = open(outfile_hdr, "rb") + header_str = handle.read(parse_file_metadata.HEADER_LENGTH) + if(len(header_str) == 0): + self.assertFalse() + + try: + header = pmt.pmt_deserialize_str(header_str) + except RuntimeError: + self.assertFalse() + + info = parse_file_metadata.parse_header(header, False) + + extra_str = handle.read(info["extra_len"]) + self.assertGreater(len(extra_str), 0) + handle.close() + + try: + extra = pmt.pmt_deserialize_str(extra_str) + except RuntimeError: + self.assertFalse() + + extra_info = parse_file_metadata.parse_extra_dict(extra, info, False) + + self.assertEqual(info['rx_rate'], samp_rate) + self.assertEqual(pmt.pmt_to_double(extra_info['samp_rate']), samp_rate) + + + # Test file metadata source + # Create a new sig source to start from the beginning + src2 = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 1000, 1, 0) + fsrc = blocks.file_meta_source(outfile, False, detached, outfile_hdr) + vsnk = gr.vector_sink_c() + tsnk = gr.tag_debug(gr.sizeof_gr_complex, "QA") + ssnk = gr.vector_sink_c() + head.reset() + self.tb.disconnect(src, head, fsnk) + self.tb.connect(fsrc, vsnk) + self.tb.connect(fsrc, tsnk) + self.tb.connect(src2, head, ssnk) + self.tb.run() + + # Test to make sure tags with 'samp_rate' and 'rx_rate' keys + # were generated and received correctly. + tags = tsnk.current_tags() + for t in tags: + if(pmt.pmt_eq(t.key, pmt.pmt_intern("samp_rate"))): + self.assertEqual(pmt.pmt_to_double(t.value), samp_rate) + elif(pmt.pmt_eq(t.key, pmt.pmt_intern("rx_rate"))): + self.assertEqual(pmt.pmt_to_double(t.value), samp_rate) + + # Test that the data portion was extracted and received correctly. + self.assertComplexTuplesAlmostEqual(vsnk.data(), ssnk.data(), 5) + + os.remove(outfile) + os.remove(outfile_hdr) + +if __name__ == '__main__': + gr_unittest.run(test_file_metadata, "test_file_metadata.xml") -- cgit From ff84bec5bd5de512ac578be905ee19fc1422849b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 15 Dec 2012 10:59:06 -0500 Subject: blocks: fixing up metadata parser. --- gr-blocks/python/parse_file_metadata.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/parse_file_metadata.py b/gr-blocks/python/parse_file_metadata.py index ec7bf6e80..c8ac2def9 100644 --- a/gr-blocks/python/parse_file_metadata.py +++ b/gr-blocks/python/parse_file_metadata.py @@ -22,11 +22,16 @@ import sys from gnuradio import gr -from gruel import pmt + +try: + import pmt +except ImportError: + from gruel import pmt + try: import blocks_swig as blocks -except: +except ImportError: from gnuradio import blocks ''' @@ -72,7 +77,7 @@ def parse_header(p, VERBOSE=False): if(VERBOSE): print "Version Number: {0}".format(version) else: - sys.stderr.write("Could not find key 'sr': invalid or corrupt data file.\n") + sys.stderr.write("Could not find key 'version': invalid or corrupt data file.\n") sys.exit(1) # EXTRACT SAMPLE RATE -- cgit From 6f7a9120c08badd42175737faaa896d001073fad Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 15 Dec 2012 11:07:18 -0500 Subject: blocks: fixing up QA of metadata to not rely on non-dependency components. --- gr-blocks/python/qa_file_metadata.py | 39 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_file_metadata.py b/gr-blocks/python/qa_file_metadata.py index 9f4a331d6..29ed0d1c8 100644 --- a/gr-blocks/python/qa_file_metadata.py +++ b/gr-blocks/python/qa_file_metadata.py @@ -24,7 +24,13 @@ from gnuradio import gr, gr_unittest import parse_file_metadata import blocks_swig as blocks import pmt -import os, time +import os, math + +def sig_source_c(samp_rate, freq, amp, N): + t = map(lambda x: float(x)/samp_rate, xrange(N)) + y = map(lambda x: math.cos(2.*math.pi*freq*x) + \ + 1j*math.sin(2.*math.pi*freq*x), t) + return y class test_file_metadata(gr_unittest.TestCase): @@ -35,6 +41,7 @@ class test_file_metadata(gr_unittest.TestCase): self.tb = None def test_001(self): + N = 1000 outfile = "test_out.dat" detached = False @@ -45,15 +52,15 @@ class test_file_metadata(gr_unittest.TestCase): extras = pmt.pmt_dict_add(extras, key, val) extras_str = pmt.pmt_serialize_str(extras) - src = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 1000, 1, 0) - head = gr.head(gr.sizeof_gr_complex, 1000) + data = sig_source_c(samp_rate, 1000, 1, N) + src = gr.vector_source_c(data) fsnk = blocks.file_meta_sink(gr.sizeof_gr_complex, outfile, samp_rate, 1, blocks.GR_FILE_FLOAT, True, 1000000, extras_str, detached) fsnk.set_unbuffered(True) - self.tb.connect(src, head, fsnk) + self.tb.connect(src, fsnk) self.tb.run() fsnk.close() @@ -67,6 +74,7 @@ class test_file_metadata(gr_unittest.TestCase): except RuntimeError: self.assertFalse() + print header info = parse_file_metadata.parse_header(header, False) extra_str = handle.read(info["extra_len"]) @@ -85,17 +93,15 @@ class test_file_metadata(gr_unittest.TestCase): # Test file metadata source - # Create a new sig source to start from the beginning - src2 = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 1000, 1, 0) + src.rewind() fsrc = blocks.file_meta_source(outfile, False) vsnk = gr.vector_sink_c() tsnk = gr.tag_debug(gr.sizeof_gr_complex, "QA") ssnk = gr.vector_sink_c() - head.reset() - self.tb.disconnect(src, head, fsnk) + self.tb.disconnect(src, fsnk) self.tb.connect(fsrc, vsnk) self.tb.connect(fsrc, tsnk) - self.tb.connect(src2, head, ssnk) + self.tb.connect(src, ssnk) self.tb.run() # Test to make sure tags with 'samp_rate' and 'rx_rate' keys @@ -113,6 +119,7 @@ class test_file_metadata(gr_unittest.TestCase): os.remove(outfile) def test_002(self): + N = 1000 outfile = "test_out.dat" outfile_hdr = "test_out.dat.hdr" @@ -124,15 +131,15 @@ class test_file_metadata(gr_unittest.TestCase): extras = pmt.pmt_dict_add(extras, key, val) extras_str = pmt.pmt_serialize_str(extras) - src = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 1000, 1, 0) - head = gr.head(gr.sizeof_gr_complex, 1000) + data = sig_source_c(samp_rate, 1000, 1, N) + src = gr.vector_source_c(data) fsnk = blocks.file_meta_sink(gr.sizeof_gr_complex, outfile, samp_rate, 1, blocks.GR_FILE_FLOAT, True, 1000000, extras_str, detached) fsnk.set_unbuffered(True) - self.tb.connect(src, head, fsnk) + self.tb.connect(src, fsnk) self.tb.run() fsnk.close() @@ -165,17 +172,15 @@ class test_file_metadata(gr_unittest.TestCase): # Test file metadata source - # Create a new sig source to start from the beginning - src2 = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 1000, 1, 0) + src.rewind() fsrc = blocks.file_meta_source(outfile, False, detached, outfile_hdr) vsnk = gr.vector_sink_c() tsnk = gr.tag_debug(gr.sizeof_gr_complex, "QA") ssnk = gr.vector_sink_c() - head.reset() - self.tb.disconnect(src, head, fsnk) + self.tb.disconnect(src, fsnk) self.tb.connect(fsrc, vsnk) self.tb.connect(fsrc, tsnk) - self.tb.connect(src2, head, ssnk) + self.tb.connect(src, ssnk) self.tb.run() # Test to make sure tags with 'samp_rate' and 'rx_rate' keys -- cgit From f42ef36d60348965936ede158886c1847670f774 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 21 Feb 2013 18:24:02 -0500 Subject: blocks: converting blocks to v3.7 style in gr-blocks. delay, rms, unpacked_to_packed, packed_to_unpacked --- gr-blocks/python/qa_delay.py | 65 ++++++ gr-blocks/python/qa_file_metadata.py | 4 +- gr-blocks/python/qa_packed_to_unpacked.py | 344 ++++++++++++++++++++++++++++++ gr-blocks/python/qa_rms.py | 83 +++++++ 4 files changed, 494 insertions(+), 2 deletions(-) create mode 100755 gr-blocks/python/qa_delay.py create mode 100755 gr-blocks/python/qa_packed_to_unpacked.py create mode 100644 gr-blocks/python/qa_rms.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_delay.py b/gr-blocks/python/qa_delay.py new file mode 100755 index 000000000..031cadb2d --- /dev/null +++ b/gr-blocks/python/qa_delay.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,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 + +class test_delay(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_000(self): + delta_t = 0 + tb = self.tb + src_data = [float(x) for x in range(0, 100)] + expected_result = tuple(delta_t*[0.0] + src_data) + + src = gr.vector_source_f(src_data) + op = blocks.delay(gr.sizeof_float, delta_t) + dst = gr.vector_sink_f() + + tb.connect(src, op, dst) + tb.run() + dst_data = dst.data() + self.assertEqual(expected_result, dst_data) + + def test_010(self): + delta_t = 10 + tb = self.tb + src_data = [float(x) for x in range(0, 100)] + expected_result = tuple(delta_t*[0.0] + src_data) + + src = gr.vector_source_f(src_data) + op = blocks.delay(gr.sizeof_float, delta_t) + dst = gr.vector_sink_f() + + tb.connect(src, op, dst) + tb.run() + dst_data = dst.data() + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_delay, "test_delay.xml") diff --git a/gr-blocks/python/qa_file_metadata.py b/gr-blocks/python/qa_file_metadata.py index 29ed0d1c8..c7826b1d3 100644 --- a/gr-blocks/python/qa_file_metadata.py +++ b/gr-blocks/python/qa_file_metadata.py @@ -28,8 +28,8 @@ import os, math def sig_source_c(samp_rate, freq, amp, N): t = map(lambda x: float(x)/samp_rate, xrange(N)) - y = map(lambda x: math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x), t) + y = map(lambda x: amp*math.cos(2.*math.pi*freq*x) + \ + 1j*amp*math.sin(2.*math.pi*freq*x), t) return y class test_file_metadata(gr_unittest.TestCase): diff --git a/gr-blocks/python/qa_packed_to_unpacked.py b/gr-blocks/python/qa_packed_to_unpacked.py new file mode 100755 index 000000000..98a02e78f --- /dev/null +++ b/gr-blocks/python/qa_packed_to_unpacked.py @@ -0,0 +1,344 @@ +#!/usr/bin/env python +# +# Copyright 2005,2007,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_packing(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block () + + def tearDown(self): + self.tb = None + + def test_001(self): + src_data = (0x80,) + expected_results = (1,0,0,0,0,0,0,0) + src = gr.vector_source_b(src_data, False) + op = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_002(self): + src_data = (0x80,) + expected_results = (0,0,0,0,0,0,0,1) + src = gr.vector_source_b(src_data, False) + op = blocks.packed_to_unpacked_bb(1, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_003(self): + src_data = (0x11,) + expected_results = (4, 2) + src = gr.vector_source_b(src_data, False) + op = gr.packed_to_unpacked_bb(3, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_004(self): + src_data = (0x11,) + expected_results = (0, 4) + src = gr.vector_source_b(src_data, False) + op = gr.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_005(self): + src_data = (1,0,0,0,0,0,1,0,0,1,0,1,1,0,1,0) + expected_results = (0x82, 0x5a) + src = gr.vector_source_b(src_data, False) + op = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_006(self): + src_data = (0,1,0,0,0,0,0,1,0,1,0,1,1,0,1,0) + expected_results = (0x82, 0x5a) + src = gr.vector_source_b(src_data, False) + op = gr.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_007(self): + src_data = (4, 2, 0,0,0) + expected_results = (0x11,) + src = gr.vector_source_b(src_data, False) + op = gr.unpacked_to_packed_bb(3, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_008(self): + src_data = (0, 4, 2,0,0) + expected_results = (0x11,) + src = gr.vector_source_b(src_data,False) + op = gr.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_009(self): + random.seed(0) + src_data = [] + for i in xrange(202): + src_data.append((random.randint(0,255))) + src_data = tuple(src_data) + expected_results = src_data + + src = gr.vector_source_b(tuple(src_data), False) + op1 = gr.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST) + op2 = gr.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results[0:201], dst.data()) + + def test_010(self): + random.seed(0) + src_data = [] + for i in xrange(56): + src_data.append((random.randint(0,255))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_b(tuple(src_data), False) + op1 = gr.packed_to_unpacked_bb(7, gr.GR_MSB_FIRST) + op2 = gr.unpacked_to_packed_bb(7, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results[0:201], dst.data()) + + def test_011(self): + random.seed(0) + src_data = [] + for i in xrange(56): + src_data.append((random.randint(0,255))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_b(tuple(src_data),False) + op1 = gr.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST) + op2 = gr.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results[0:201], dst.data()) + + + # tests on shorts + def test_100a(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**15,2**15-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_s(tuple(src_data), False) + op1 = gr.packed_to_unpacked_ss(1, gr.GR_MSB_FIRST) + op2 = gr.unpacked_to_packed_ss(1, gr.GR_MSB_FIRST) + dst = gr.vector_sink_s() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_100b(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**15,2**15-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_s(tuple(src_data), False) + op1 = gr.packed_to_unpacked_ss(1, gr.GR_LSB_FIRST) + op2 = gr.unpacked_to_packed_ss(1, gr.GR_LSB_FIRST) + dst = gr.vector_sink_s() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_101a(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**15,2**15-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_s(tuple(src_data), False) + op1 = gr.packed_to_unpacked_ss(8, gr.GR_MSB_FIRST) + op2 = gr.unpacked_to_packed_ss(8, gr.GR_MSB_FIRST) + dst = gr.vector_sink_s() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_101b(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**15,2**15-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_s(tuple(src_data), False) + op1 = gr.packed_to_unpacked_ss(8, gr.GR_LSB_FIRST) + op2 = gr.unpacked_to_packed_ss(8, gr.GR_LSB_FIRST) + dst = gr.vector_sink_s() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + + # tests on ints + def test_200a(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**31,2**31-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_i(tuple(src_data), False) + op1 = gr.packed_to_unpacked_ii(1, gr.GR_MSB_FIRST) + op2 = gr.unpacked_to_packed_ii(1, gr.GR_MSB_FIRST) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_200b(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**31,2**31-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_i(tuple(src_data), False) + op1 = gr.packed_to_unpacked_ii(1, gr.GR_LSB_FIRST) + op2 = gr.unpacked_to_packed_ii(1, gr.GR_LSB_FIRST) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_201a(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**31,2**31-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_i(tuple(src_data), False) + op1 = gr.packed_to_unpacked_ii(8, gr.GR_MSB_FIRST) + op2 = gr.unpacked_to_packed_ii(8, gr.GR_MSB_FIRST) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_201b(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**31,2**31-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_i(tuple(src_data), False) + op1 = gr.packed_to_unpacked_ii(8, gr.GR_LSB_FIRST) + op2 = gr.unpacked_to_packed_ii(8, gr.GR_LSB_FIRST) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + +if __name__ == '__main__': + gr_unittest.run(test_packing, "test_packing.xml") + diff --git a/gr-blocks/python/qa_rms.py b/gr-blocks/python/qa_rms.py new file mode 100644 index 000000000..f3386668a --- /dev/null +++ b/gr-blocks/python/qa_rms.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +# +# Copyright 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 math + +def sig_source_f(samp_rate, freq, amp, N): + t = map(lambda x: float(x)/samp_rate, xrange(N)) + y = map(lambda x: amp*math.cos(2.*math.pi*freq*x), t) + return y + +def sig_source_c(samp_rate, freq, amp, N): + t = map(lambda x: float(x)/samp_rate, xrange(N)) + y = map(lambda x: amp*math.cos(2.*math.pi*freq*x) + \ + 1j*amp*math.sin(2.*math.pi*freq*x), t) + return y + +class test_rms(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_ff(self): + amp = 2 + src_data = sig_source_f(1, 0.01, amp, 200) + N = 750000 + + expected_data = amp/math.sqrt(2.0) + + src = gr.vector_source_f(src_data, True) + head = gr.head(gr.sizeof_float, N) + op = blocks.rms_ff(0.0001) + dst = gr.vector_sink_f() + + self.tb.connect(src, head, op, dst) + self.tb.run() + + dst_data = dst.data() + self.assertAlmostEqual(dst_data[-1], expected_data, 4) + + def test_cf(self): + amp = 4 + src_data = sig_source_c(1, 0.01, amp, 200) + N = 750000 + + expected_data = amp + + src = gr.vector_source_c(src_data, True) + head = gr.head(gr.sizeof_gr_complex, N) + op = blocks.rms_cf(0.0001) + dst = gr.vector_sink_f() + + self.tb.connect(src, head, op, dst) + self.tb.run() + + dst_data = dst.data() + self.assertAlmostEqual(dst_data[-1], expected_data, 4) + +if __name__ == '__main__': + gr_unittest.run(test_rms, "test_rms.xml") -- cgit From 2fcf27f95b10d84dbe0e2b36a316c6ed87dc8739 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 21 Feb 2013 19:48:41 -0500 Subject: blocks: fixing use of packed/unpacked from gr-blocks in QA code. --- gr-blocks/python/qa_packed_to_unpacked.py | 56 +++++++++++++++---------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_packed_to_unpacked.py b/gr-blocks/python/qa_packed_to_unpacked.py index 98a02e78f..d84f5dbd3 100755 --- a/gr-blocks/python/qa_packed_to_unpacked.py +++ b/gr-blocks/python/qa_packed_to_unpacked.py @@ -62,7 +62,7 @@ class test_packing(gr_unittest.TestCase): src_data = (0x11,) expected_results = (4, 2) src = gr.vector_source_b(src_data, False) - op = gr.packed_to_unpacked_bb(3, gr.GR_LSB_FIRST) + op = blocks.packed_to_unpacked_bb(3, gr.GR_LSB_FIRST) dst = gr.vector_sink_b() self.tb.connect(src, op) @@ -75,7 +75,7 @@ class test_packing(gr_unittest.TestCase): src_data = (0x11,) expected_results = (0, 4) src = gr.vector_source_b(src_data, False) - op = gr.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST) + op = blocks.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST) dst = gr.vector_sink_b() self.tb.connect(src, op) @@ -88,7 +88,7 @@ class test_packing(gr_unittest.TestCase): src_data = (1,0,0,0,0,0,1,0,0,1,0,1,1,0,1,0) expected_results = (0x82, 0x5a) src = gr.vector_source_b(src_data, False) - op = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) + op = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) dst = gr.vector_sink_b() self.tb.connect(src, op) @@ -101,7 +101,7 @@ class test_packing(gr_unittest.TestCase): src_data = (0,1,0,0,0,0,0,1,0,1,0,1,1,0,1,0) expected_results = (0x82, 0x5a) src = gr.vector_source_b(src_data, False) - op = gr.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST) + op = blocks.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST) dst = gr.vector_sink_b() self.tb.connect(src, op) @@ -114,7 +114,7 @@ class test_packing(gr_unittest.TestCase): src_data = (4, 2, 0,0,0) expected_results = (0x11,) src = gr.vector_source_b(src_data, False) - op = gr.unpacked_to_packed_bb(3, gr.GR_LSB_FIRST) + op = blocks.unpacked_to_packed_bb(3, gr.GR_LSB_FIRST) dst = gr.vector_sink_b() self.tb.connect(src, op) @@ -127,7 +127,7 @@ class test_packing(gr_unittest.TestCase): src_data = (0, 4, 2,0,0) expected_results = (0x11,) src = gr.vector_source_b(src_data,False) - op = gr.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST) + op = blocks.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST) dst = gr.vector_sink_b() self.tb.connect(src, op) @@ -145,8 +145,8 @@ class test_packing(gr_unittest.TestCase): expected_results = src_data src = gr.vector_source_b(tuple(src_data), False) - op1 = gr.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST) - op2 = gr.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST) + op1 = blocks.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST) dst = gr.vector_sink_b() self.tb.connect(src, op1, op2) @@ -163,8 +163,8 @@ class test_packing(gr_unittest.TestCase): src_data = tuple(src_data) expected_results = src_data src = gr.vector_source_b(tuple(src_data), False) - op1 = gr.packed_to_unpacked_bb(7, gr.GR_MSB_FIRST) - op2 = gr.unpacked_to_packed_bb(7, gr.GR_MSB_FIRST) + op1 = blocks.packed_to_unpacked_bb(7, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_bb(7, gr.GR_MSB_FIRST) dst = gr.vector_sink_b() self.tb.connect(src, op1, op2) @@ -181,8 +181,8 @@ class test_packing(gr_unittest.TestCase): src_data = tuple(src_data) expected_results = src_data src = gr.vector_source_b(tuple(src_data),False) - op1 = gr.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST) - op2 = gr.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST) + op1 = blocks.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST) dst = gr.vector_sink_b() self.tb.connect(src, op1, op2) @@ -201,8 +201,8 @@ class test_packing(gr_unittest.TestCase): src_data = tuple(src_data) expected_results = src_data src = gr.vector_source_s(tuple(src_data), False) - op1 = gr.packed_to_unpacked_ss(1, gr.GR_MSB_FIRST) - op2 = gr.unpacked_to_packed_ss(1, gr.GR_MSB_FIRST) + op1 = blocks.packed_to_unpacked_ss(1, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_ss(1, gr.GR_MSB_FIRST) dst = gr.vector_sink_s() self.tb.connect(src, op1, op2) @@ -219,8 +219,8 @@ class test_packing(gr_unittest.TestCase): src_data = tuple(src_data) expected_results = src_data src = gr.vector_source_s(tuple(src_data), False) - op1 = gr.packed_to_unpacked_ss(1, gr.GR_LSB_FIRST) - op2 = gr.unpacked_to_packed_ss(1, gr.GR_LSB_FIRST) + op1 = blocks.packed_to_unpacked_ss(1, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_ss(1, gr.GR_LSB_FIRST) dst = gr.vector_sink_s() self.tb.connect(src, op1, op2) @@ -237,8 +237,8 @@ class test_packing(gr_unittest.TestCase): src_data = tuple(src_data) expected_results = src_data src = gr.vector_source_s(tuple(src_data), False) - op1 = gr.packed_to_unpacked_ss(8, gr.GR_MSB_FIRST) - op2 = gr.unpacked_to_packed_ss(8, gr.GR_MSB_FIRST) + op1 = blocks.packed_to_unpacked_ss(8, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_ss(8, gr.GR_MSB_FIRST) dst = gr.vector_sink_s() self.tb.connect(src, op1, op2) @@ -255,8 +255,8 @@ class test_packing(gr_unittest.TestCase): src_data = tuple(src_data) expected_results = src_data src = gr.vector_source_s(tuple(src_data), False) - op1 = gr.packed_to_unpacked_ss(8, gr.GR_LSB_FIRST) - op2 = gr.unpacked_to_packed_ss(8, gr.GR_LSB_FIRST) + op1 = blocks.packed_to_unpacked_ss(8, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_ss(8, gr.GR_LSB_FIRST) dst = gr.vector_sink_s() self.tb.connect(src, op1, op2) @@ -275,8 +275,8 @@ class test_packing(gr_unittest.TestCase): src_data = tuple(src_data) expected_results = src_data src = gr.vector_source_i(tuple(src_data), False) - op1 = gr.packed_to_unpacked_ii(1, gr.GR_MSB_FIRST) - op2 = gr.unpacked_to_packed_ii(1, gr.GR_MSB_FIRST) + op1 = blocks.packed_to_unpacked_ii(1, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_ii(1, gr.GR_MSB_FIRST) dst = gr.vector_sink_i() self.tb.connect(src, op1, op2) @@ -293,8 +293,8 @@ class test_packing(gr_unittest.TestCase): src_data = tuple(src_data) expected_results = src_data src = gr.vector_source_i(tuple(src_data), False) - op1 = gr.packed_to_unpacked_ii(1, gr.GR_LSB_FIRST) - op2 = gr.unpacked_to_packed_ii(1, gr.GR_LSB_FIRST) + op1 = blocks.packed_to_unpacked_ii(1, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_ii(1, gr.GR_LSB_FIRST) dst = gr.vector_sink_i() self.tb.connect(src, op1, op2) @@ -311,8 +311,8 @@ class test_packing(gr_unittest.TestCase): src_data = tuple(src_data) expected_results = src_data src = gr.vector_source_i(tuple(src_data), False) - op1 = gr.packed_to_unpacked_ii(8, gr.GR_MSB_FIRST) - op2 = gr.unpacked_to_packed_ii(8, gr.GR_MSB_FIRST) + op1 = blocks.packed_to_unpacked_ii(8, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_ii(8, gr.GR_MSB_FIRST) dst = gr.vector_sink_i() self.tb.connect(src, op1, op2) @@ -329,8 +329,8 @@ class test_packing(gr_unittest.TestCase): src_data = tuple(src_data) expected_results = src_data src = gr.vector_source_i(tuple(src_data), False) - op1 = gr.packed_to_unpacked_ii(8, gr.GR_LSB_FIRST) - op2 = gr.unpacked_to_packed_ii(8, gr.GR_LSB_FIRST) + op1 = blocks.packed_to_unpacked_ii(8, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_ii(8, gr.GR_LSB_FIRST) dst = gr.vector_sink_i() self.tb.connect(src, op1, op2) -- cgit From ffcaa3436cc8e608cb51bad78ca669b90bd110f2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 24 Feb 2013 14:15:05 -0500 Subject: blocks: converted peak_detector2 and regenerate to v3.7. --- gr-blocks/python/qa_peak_detector2.py | 58 ++++++++++++++++++++++ gr-blocks/python/qa_regenerate.py | 90 +++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 gr-blocks/python/qa_peak_detector2.py create mode 100755 gr-blocks/python/qa_regenerate.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_peak_detector2.py b/gr-blocks/python/qa_peak_detector2.py new file mode 100644 index 000000000..4b864e4d7 --- /dev/null +++ b/gr-blocks/python/qa_peak_detector2.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# +# Copyright 2007,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 + +class test_peak_detector2(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_regen1(self): + tb = self.tb + + data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] + + expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + + src = gr.vector_source_f(data, False) + regen = blocks.peak_detector2_fb() + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + print dst_data + + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_peak_detector2, "test_peak_detector2.xml") diff --git a/gr-blocks/python/qa_regenerate.py b/gr-blocks/python/qa_regenerate.py new file mode 100755 index 000000000..a57eeba2b --- /dev/null +++ b/gr-blocks/python/qa_regenerate.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# +# Copyright 2007,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 + +class test_regenerate(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_regen1(self): + tb = self.tb + + data = [0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + + expected_result = (0, 0, 0, + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + + src = gr.vector_source_b(data, False) + regen = blocks.regenerate_bb(5, 2) + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + + def test_regen2(self): + tb = self.tb + + data = 200*[0,] + data[9] = 1 + data[99] = 1 + + expected_result = 200*[0,] + expected_result[9] = 1 + expected_result[19] = 1 + expected_result[29] = 1 + expected_result[39] = 1 + + expected_result[99] = 1 + expected_result[109] = 1 + expected_result[119] = 1 + expected_result[129] = 1 + + src = gr.vector_source_b(data, False) + regen = blocks.regenerate_bb(10, 3) + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run () + + dst_data = dst.data() + + self.assertEqual(tuple(expected_result), dst_data) + + +if __name__ == '__main__': + gr_unittest.run(test_regenerate, "test_regenerate.xml") -- cgit From a54dc5bab6cc38513e9732be9f5c2670145b160f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 24 Feb 2013 18:55:04 -0500 Subject: blocks: adding threshold, strech, and throttle to gr-blocks. --- gr-blocks/python/qa_stretch.py | 67 ++++++++++++++++++++++++++++++++++++++++ gr-blocks/python/qa_threshold.py | 54 ++++++++++++++++++++++++++++++++ gr-blocks/python/qa_throttle.py | 39 +++++++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100755 gr-blocks/python/qa_stretch.py create mode 100644 gr-blocks/python/qa_threshold.py create mode 100755 gr-blocks/python/qa_throttle.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_stretch.py b/gr-blocks/python/qa_stretch.py new file mode 100755 index 000000000..013d878a8 --- /dev/null +++ b/gr-blocks/python/qa_stretch.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# +# Copyright 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 + +class test_stretch(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_stretch_01(self): + tb = self.tb + + data = 10*[1,] + data0 = map(lambda x: x/20.0, data) + data1 = map(lambda x: x/10.0, data) + + expected_result0 = 10*[0.05,] + expected_result1 = 10*[0.1,] + + src0 = gr.vector_source_f(data0, False) + src1 = gr.vector_source_f(data1, False) + inter = gr.streams_to_vector(gr.sizeof_float, 2) + op = blocks.stretch_ff(0.1, 2) + deinter = gr.vector_to_streams(gr.sizeof_float, 2) + dst0 = gr.vector_sink_f() + dst1 = gr.vector_sink_f() + + tb.connect(src0, (inter,0)) + tb.connect(src1, (inter,1)) + tb.connect(inter, op) + tb.connect(op, deinter) + tb.connect((deinter,0), dst0) + tb.connect((deinter,1), dst1) + tb.run() + + dst0_data = dst0.data() + dst1_data = dst1.data() + + self.assertFloatTuplesAlmostEqual(expected_result0, dst0_data, 4) + self.assertFloatTuplesAlmostEqual(expected_result1, dst1_data, 4) + +if __name__ == '__main__': + gr_unittest.run(test_stretch, "test_stretch.xml") diff --git a/gr-blocks/python/qa_threshold.py b/gr-blocks/python/qa_threshold.py new file mode 100644 index 000000000..f91af739a --- /dev/null +++ b/gr-blocks/python/qa_threshold.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# +# Copyright 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 + +class test_threshold(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_01(self): + tb = self.tb + + data = [0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2] + + expected_result = (0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1) + + src = gr.vector_source_f(data, False) + op = blocks.threshold_ff(1, 1) + dst = gr.vector_sink_f() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_threshold, "test_threshold.xml") diff --git a/gr-blocks/python/qa_throttle.py b/gr-blocks/python/qa_throttle.py new file mode 100755 index 000000000..5d462f2c9 --- /dev/null +++ b/gr-blocks/python/qa_throttle.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# +# Copyright 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 + +class test_throttle(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_01(self): + # Test that we can make the block + op = blocks.throttle(gr.sizeof_gr_complex, 1) + +if __name__ == '__main__': + gr_unittest.run(test_throttle, "test_throttle.xml") -- cgit From 5c7b8118d4d0f8413d64933cabec84b18cdaf193 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 25 Feb 2013 21:16:19 -0500 Subject: blocks: moved transcendental block to gr-blocks. --- gr-blocks/python/qa_transcendental.py | 90 +++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 gr-blocks/python/qa_transcendental.py (limited to 'gr-blocks/python') diff --git a/gr-blocks/python/qa_transcendental.py b/gr-blocks/python/qa_transcendental.py new file mode 100644 index 000000000..8174f7963 --- /dev/null +++ b/gr-blocks/python/qa_transcendental.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# +# Copyright 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 math + +class test_transcendental(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_01(self): + tb = self.tb + + data = 100*[0,] + expected_result = 100*[1,] + + src = gr.vector_source_f(data, False) + op = blocks.transcendental("cos", "float") + dst = gr.vector_sink_f() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5) + + def test_02(self): + tb = self.tb + + data = 100*[3,] + expected_result = 100*[math.log10(3),] + + src = gr.vector_source_f(data, False) + op = blocks.transcendental("log10", "float") + dst = gr.vector_sink_f() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5) + + def test_03(self): + tb = self.tb + + data = 100*[3,] + expected_result = 100*[math.tanh(3),] + + src = gr.vector_source_f(data, False) + op = blocks.transcendental("tanh", "float") + dst = gr.vector_sink_f() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5) + +if __name__ == '__main__': + gr_unittest.run(test_transcendental, "test_transcendental.xml") -- cgit