From ac5495a48abacd740c37f9e79d1bbfff218107c3 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 18 Feb 2008 17:20:15 +0000 Subject: [PATCH] Merged r7732:7734 from jcorgan/boolean into trunk. Add's Tim Meehan's gr.xor_* blocks. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7735 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/gengen/Makefile.am | 5 +- gnuradio-core/src/lib/gengen/Makefile.gen | 15 ++- .../src/lib/gengen/generate_common.py | 3 +- .../src/lib/gengen/gengen_generated.i | 6 ++ gnuradio-core/src/lib/gengen/gr_xor_XX.cc.t | 62 +++++++++++++ gnuradio-core/src/lib/gengen/gr_xor_XX.h.t | 54 +++++++++++ gnuradio-core/src/lib/gengen/gr_xor_XX.i.t | 33 +++++++ .../gnuradio/gr/qa_boolean_operators.py | 91 +++++++++++++++++++ 8 files changed, 264 insertions(+), 5 deletions(-) create mode 100644 gnuradio-core/src/lib/gengen/gr_xor_XX.cc.t create mode 100644 gnuradio-core/src/lib/gengen/gr_xor_XX.h.t create mode 100644 gnuradio-core/src/lib/gengen/gr_xor_XX.i.t create mode 100755 gnuradio-core/src/python/gnuradio/gr/qa_boolean_operators.py diff --git a/gnuradio-core/src/lib/gengen/Makefile.am b/gnuradio-core/src/lib/gengen/Makefile.am index f4418660..05c67ca6 100644 --- a/gnuradio-core/src/lib/gengen/Makefile.am +++ b/gnuradio-core/src/lib/gengen/Makefile.am @@ -94,7 +94,10 @@ CODE_GENERATOR = \ gr_vector_source_X.i.t \ gr_vector_sink_X.cc.t \ gr_vector_sink_X.h.t \ - gr_vector_sink_X.i.t + gr_vector_sink_X.i.t \ + gr_xor_XX.cc.t \ + gr_xor_XX.h.t \ + gr_xor_XX.i.t # include $(srcdir)/Makefile.gen include Makefile.gen diff --git a/gnuradio-core/src/lib/gengen/Makefile.gen b/gnuradio-core/src/lib/gengen/Makefile.gen index 238622bd..e8ccdc8d 100644 --- a/gnuradio-core/src/lib/gengen/Makefile.gen +++ b/gnuradio-core/src/lib/gengen/Makefile.gen @@ -89,7 +89,10 @@ GENERATED_H = \ gr_vector_source_c.h \ gr_vector_source_f.h \ gr_vector_source_i.h \ - gr_vector_source_s.h + gr_vector_source_s.h \ + gr_xor_bb.h \ + gr_xor_ii.h \ + gr_xor_ss.h GENERATED_I = \ gr_add_cc.i \ @@ -179,7 +182,10 @@ GENERATED_I = \ gr_vector_source_c.i \ gr_vector_source_f.i \ gr_vector_source_i.i \ - gr_vector_source_s.i + gr_vector_source_s.i \ + gr_xor_bb.i \ + gr_xor_ii.i \ + gr_xor_ss.i GENERATED_CC = \ gr_add_cc.cc \ @@ -269,5 +275,8 @@ GENERATED_CC = \ gr_vector_source_c.cc \ gr_vector_source_f.cc \ gr_vector_source_i.cc \ - gr_vector_source_s.cc + gr_vector_source_s.cc \ + gr_xor_bb.cc \ + gr_xor_ii.cc \ + gr_xor_ss.cc diff --git a/gnuradio-core/src/lib/gengen/generate_common.py b/gnuradio-core/src/lib/gengen/generate_common.py index 7471d668..70b5a595 100755 --- a/gnuradio-core/src/lib/gengen/generate_common.py +++ b/gnuradio-core/src/lib/gengen/generate_common.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2004,2006,2007 Free Software Foundation, Inc. +# Copyright 2004,2006,2007,2008 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -58,6 +58,7 @@ others = ( ('gr_chunks_to_symbols_XX', ('bf', 'bc', 'sf', 'sc', 'if', 'ic')), ('gr_unpacked_to_packed_XX', ('bb','ss','ii')), ('gr_packed_to_unpacked_XX', ('bb','ss','ii')), + ('gr_xor_XX', ('bb','ss','ii')), ('gr_sample_and_hold_XX', ('bb','ss','ii','ff')), ('gr_argmax_XX', ('fs','is','ss')), ('gr_max_XX', ('ff','ii','ss')), diff --git a/gnuradio-core/src/lib/gengen/gengen_generated.i b/gnuradio-core/src/lib/gengen/gengen_generated.i index 26dd3f41..39d9a0bb 100644 --- a/gnuradio-core/src/lib/gengen/gengen_generated.i +++ b/gnuradio-core/src/lib/gengen/gengen_generated.i @@ -90,6 +90,9 @@ #include #include #include +#include +#include +#include %} %include @@ -180,3 +183,6 @@ %include %include %include +%include +%include +%include diff --git a/gnuradio-core/src/lib/gengen/gr_xor_XX.cc.t b/gnuradio-core/src/lib/gengen/gr_xor_XX.cc.t new file mode 100644 index 00000000..f64dd1c9 --- /dev/null +++ b/gnuradio-core/src/lib/gengen/gr_xor_XX.cc.t @@ -0,0 +1,62 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2008 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@.h> +#include + +@SPTR_NAME@ +gr_make_@BASE_NAME@ () +{ + return @SPTR_NAME@ (new @NAME@ ()); +} + +@NAME@::@NAME@ () + : gr_sync_block ("@BASE_NAME@", + gr_make_io_signature (1, -1, sizeof (@I_TYPE@)), + gr_make_io_signature (1, 1, sizeof (@O_TYPE@))) +{ +} + +int +@NAME@::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 (int i = 0; i < noutput_items; i++) { + @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i]; + for (int j = 1; j < ninputs; j++) + acc = acc ^ ((@I_TYPE@ *) input_items[j])[i]; + + *optr++ = (@O_TYPE@) acc; + } + return noutput_items; +} diff --git a/gnuradio-core/src/lib/gengen/gr_xor_XX.h.t b/gnuradio-core/src/lib/gengen/gr_xor_XX.h.t new file mode 100644 index 00000000..82e89941 --- /dev/null +++ b/gnuradio-core/src/lib/gengen/gr_xor_XX.h.t @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2008 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 + +class @NAME@; +typedef boost::shared_ptr<@NAME@> @SPTR_NAME@; + +@SPTR_NAME@ gr_make_@BASE_NAME@ (); + +/*! + * \brief output = input_0 ^ input_1 ^ , ... ^ input_N) + * \ingroup math + * + * bitwise boolean xor across all input streams. + */ +class @NAME@ : public gr_sync_block +{ + friend @SPTR_NAME@ gr_make_@BASE_NAME@ (); + + @NAME@ (); + + public: + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif diff --git a/gnuradio-core/src/lib/gengen/gr_xor_XX.i.t b/gnuradio-core/src/lib/gengen/gr_xor_XX.i.t new file mode 100644 index 00000000..e17d40ee --- /dev/null +++ b/gnuradio-core/src/lib/gengen/gr_xor_XX.i.t @@ -0,0 +1,33 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2008 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@ + +GR_SWIG_BLOCK_MAGIC(gr,@BASE_NAME@) + +@SPTR_NAME@ gr_make_@BASE_NAME@ (); + +class @NAME@ : public gr_sync_block +{ + private: + @NAME@ (); +}; diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_boolean_operators.py b/gnuradio-core/src/python/gnuradio/gr/qa_boolean_operators.py new file mode 100755 index 00000000..d64cfd1a --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_boolean_operators.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,2008 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 + +class test_head (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) + + + +if __name__ == '__main__': + gr_unittest.main () -- 2.30.2