diff options
author | Johnathan Corgan | 2012-07-02 08:36:46 -0700 |
---|---|---|
committer | Johnathan Corgan | 2012-07-02 08:36:46 -0700 |
commit | cc085e128901a9f3e8bfcc45d1834a62d747726c (patch) | |
tree | 18c7542c4751fd3d0dbe6504a6d5f35b8d3bb392 /gr-blocks | |
parent | 70d89e2051264876055fe9f73cbcb2823806b3ee (diff) | |
download | gnuradio-cc085e128901a9f3e8bfcc45d1834a62d747726c.tar.gz gnuradio-cc085e128901a9f3e8bfcc45d1834a62d747726c.tar.bz2 gnuradio-cc085e128901a9f3e8bfcc45d1834a62d747726c.zip |
blocks: added gr::blocks::add_XX (bb ss ii)
Diffstat (limited to 'gr-blocks')
-rw-r--r-- | gr-blocks/grc/blocks_and_xx.xml | 48 | ||||
-rw-r--r-- | gr-blocks/grc/blocks_block_tree.xml | 6 | ||||
-rw-r--r-- | gr-blocks/include/blocks/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/include/blocks/and_XX.h.t | 53 | ||||
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/lib/and_XX_impl.cc.t | 69 | ||||
-rw-r--r-- | gr-blocks/lib/and_XX_impl.h.t | 48 | ||||
-rwxr-xr-x | gr-blocks/python/qa_boolean_operators.py | 163 | ||||
-rw-r--r-- | gr-blocks/swig/blocks_swig.i | 9 |
9 files changed, 397 insertions, 1 deletions
diff --git a/gr-blocks/grc/blocks_and_xx.xml b/gr-blocks/grc/blocks_and_xx.xml new file mode 100644 index 000000000..317a0f645 --- /dev/null +++ b/gr-blocks/grc/blocks_and_xx.xml @@ -0,0 +1,48 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Logical And Block +################################################### + --> +<block> + <name>And</name> + <key>blocks_and_xx</key> + <import>from gnuradio import blocks</import> + <make>blocks.and_$(type.fcn)()</make> + <param> + <name>IO Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Int</name> + <key>int</key> + <opt>fcn:ii</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>fcn:ss</opt> + </option> + <option> + <name>Byte</name> + <key>byte</key> + <opt>fcn:bb</opt> + </option> + </param> + <param> + <name>Num Inputs</name> + <key>num_inputs</key> + <value>2</value> + <type>int</type> + </param> + <check>$num_inputs >= 2</check> + <sink> + <name>in</name> + <type>$type</type> + <nports>$num_inputs</nports> + </sink> + <source> + <name>out</name> + <type>$type</type> + </source> +</block> diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 721a6d238..3aed8dc22 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -27,7 +27,7 @@ ################################################### --> <cat> - <name></name> <!-- Blank for Root Name --> + <name></name> <!-- Blank for Root Name --> <cat> <name>Math Operations (New) </name> <block>blocks_add_xx</block> @@ -42,6 +42,10 @@ <block>blocks_nlog10_ff</block> </cat> <cat> + <name>Boolean Operations (New) </name> + <block>blocks_and_xx.xml</block> + </cat> + <cat> <name>Stream Type Conversions (New) </name> <block>blocks_char_to_float</block> <block>blocks_char_to_short</block> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index b816544be..1db3eab2f 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -67,6 +67,7 @@ endmacro(expand_h) expand_h(add_XX ss ii cc) expand_h(add_const_XX ss ii ff cc) expand_h(add_const_vXX ss ii ff cc) +expand_h(and_XX bb ss ii) expand_h(divide_XX ss ii ff cc) expand_h(integrate_XX ss ii ff cc) expand_h(multiply_XX ss ii) diff --git a/gr-blocks/include/blocks/and_XX.h.t b/gr-blocks/include/blocks/and_XX.h.t new file mode 100644 index 000000000..68ddcc33d --- /dev/null +++ b/gr-blocks/include/blocks/and_XX.h.t @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME@ +#define @GUARD_NAME@ + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief output = input_0 & input_1 & , ... & input_N) + * \ingroup math_blk + * + * bitwise boolean and across all input streams. + */ + class BLOCKS_API @NAME@ : virtual public gr_sync_block + { + public: + + // gr::blocks::@NAME@::sptr + typedef boost::shared_ptr<@NAME@> sptr; + + static sptr make(size_t vlen=1); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME@ */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index cd07cef2f..4aa737b6f 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -88,6 +88,7 @@ endmacro(expand_cc_h_impl) expand_cc_h_impl(add_XX ss ii cc) expand_cc_h_impl(add_const_XX ss ii ff cc) expand_cc_h_impl(add_const_vXX ss ii ff cc) +expand_cc_h_impl(and_XX bb ss ii) expand_cc_h_impl(divide_XX ss ii ff cc) expand_cc_h_impl(integrate_XX ss ii ff cc) expand_cc_h_impl(multiply_XX ss ii) diff --git a/gr-blocks/lib/and_XX_impl.cc.t b/gr-blocks/lib/and_XX_impl.cc.t new file mode 100644 index 000000000..3218a8c74 --- /dev/null +++ b/gr-blocks/lib/and_XX_impl.cc.t @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +// @WARNING@ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <@NAME_IMPL@.h> +#include <gr_io_signature.h> + +namespace gr { + namespace blocks { + + @NAME@::sptr @NAME@::make(size_t vlen) + { + return gnuradio::get_initial_sptr(new @NAME_IMPL@(vlen)); + } + + @NAME_IMPL@::@NAME_IMPL@(size_t vlen) + : gr_sync_block ("@NAME@", + gr_make_io_signature (1, -1, sizeof (@I_TYPE@)*vlen), + gr_make_io_signature (1, 1, sizeof (@O_TYPE@)*vlen)), + d_vlen(vlen) + { + } + + int + @NAME_IMPL@::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0]; + + int ninputs = input_items.size (); + + for (size_t i = 0; i < noutput_items*d_vlen; i++){ + @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i]; + for (int j = 1; j < ninputs; j++) + acc &= ((@I_TYPE@ *) input_items[j])[i]; + + *optr++ = (@O_TYPE@) acc; + } + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/and_XX_impl.h.t b/gr-blocks/lib/and_XX_impl.h.t new file mode 100644 index 000000000..25f0da0c8 --- /dev/null +++ b/gr-blocks/lib/and_XX_impl.h.t @@ -0,0 +1,48 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME_IMPL@ +#define @GUARD_NAME_IMPL@ + +#include <blocks/@NAME@.h> + +namespace gr { + namespace blocks { + + class BLOCKS_API @NAME_IMPL@ : public @NAME@ + { + size_t d_vlen; + + public: + @NAME_IMPL@(size_t vlen); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME_IMPL@ */ 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") diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index f70e536b2..f4612f5d8 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -40,6 +40,9 @@ #include "blocks/add_const_vss.h" #include "blocks/add_const_vii.h" #include "blocks/add_const_vcc.h" +#include "blocks/and_bb.h" +#include "blocks/and_ss.h" +#include "blocks/and_ii.h" #include "blocks/char_to_float.h" #include "blocks/char_to_short.h" #include "blocks/complex_to_interleaved_short.h" @@ -100,6 +103,9 @@ %include "blocks/add_const_vss.h" %include "blocks/add_const_vii.h" %include "blocks/add_const_vcc.h" +%include "blocks/and_bb.h" +%include "blocks/and_ss.h" +%include "blocks/and_ii.h" %include "blocks/char_to_float.h" %include "blocks/char_to_short.h" %include "blocks/complex_to_interleaved_short.h" @@ -159,6 +165,9 @@ GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vff); GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vss); GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vii); GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vcc); +GR_SWIG_BLOCK_MAGIC2(blocks, and_bb); +GR_SWIG_BLOCK_MAGIC2(blocks, and_ss); +GR_SWIG_BLOCK_MAGIC2(blocks, and_ii); GR_SWIG_BLOCK_MAGIC2(blocks, char_to_float); GR_SWIG_BLOCK_MAGIC2(blocks, char_to_short); GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_interleaved_short); |