summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnathan Corgan <jcorgan@corganenterprises.com>2012-07-02 09:13:13 -0700
committerJohnathan Corgan <jcorgan@corganenterprises.com>2012-07-02 09:13:13 -0700
commit025f323d9857715a31a1117693c5debd19393a46 (patch)
tree6a947bbb5d49cbe7b4a42201b696b5c3bdff5826
parentcc085e128901a9f3e8bfcc45d1834a62d747726c (diff)
blocks: added gr::blocks::and_const_XX (bb ss ii)
-rw-r--r--gr-blocks/grc/blocks_and_const_xx.xml48
-rw-r--r--gr-blocks/grc/blocks_block_tree.xml1
-rw-r--r--gr-blocks/include/blocks/CMakeLists.txt1
-rw-r--r--gr-blocks/include/blocks/and_const_XX.h.t68
-rw-r--r--gr-blocks/lib/CMakeLists.txt1
-rw-r--r--gr-blocks/lib/and_const_XX_impl.cc.t77
-rw-r--r--gr-blocks/lib/and_const_XX_impl.h.t51
-rwxr-xr-xgr-blocks/python/qa_boolean_operators.py33
-rw-r--r--gr-blocks/swig/blocks_swig.i9
9 files changed, 289 insertions, 0 deletions
diff --git a/gr-blocks/grc/blocks_and_const_xx.xml b/gr-blocks/grc/blocks_and_const_xx.xml
new file mode 100644
index 0000000000..d0abbfe51b
--- /dev/null
+++ b/gr-blocks/grc/blocks_and_const_xx.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+## And Const Block:
+## all types, 1 output, 1 input & const
+###################################################
+ -->
+<block>
+ <name>And Const</name>
+ <key>blocks_and_const_xx</key>
+ <import>from gnuradio import blocks</import>
+ <make>blocks.and_const_$(type.fcn)($const)</make>
+ <callback>set_k($const)</callback>
+ <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>Constant</name>
+ <key>const</key>
+ <value>0</value>
+ <type>int</type>
+ </param>
+ <sink>
+ <name>in</name>
+ <type>$type</type>
+ </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 3aed8dc220..e5566ee43f 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -44,6 +44,7 @@
<cat>
<name>Boolean Operations (New) </name>
<block>blocks_and_xx.xml</block>
+ <block>blocks_and_const_xx.xml</block>
</cat>
<cat>
<name>Stream Type Conversions (New) </name>
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 1db3eab2fc..5b29219cc6 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -68,6 +68,7 @@ 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(and_const_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_const_XX.h.t b/gr-blocks/include/blocks/and_const_XX.h.t
new file mode 100644
index 0000000000..945a1f48b7
--- /dev/null
+++ b/gr-blocks/include/blocks/and_const_XX.h.t
@@ -0,0 +1,68 @@
+/* -*- 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_N = input_N & value
+ * \ingroup math_blk
+ *
+ * bitwise boolean and of const to the data stream.
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ /*!
+ * \brief Create an instance of @NAME@
+ * \param k AND constant
+ */
+ static sptr make(@O_TYPE@ k);
+
+ /*!
+ * \brief Return AND constant
+ */
+ virtual @O_TYPE@ k() const = 0;
+
+ /*!
+ * \brief Set AND constant
+ */
+ virtual void set_k(@O_TYPE@ k) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 4aa737b6f5..9c67c7b036 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -89,6 +89,7 @@ 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(and_const_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_const_XX_impl.cc.t b/gr-blocks/lib/and_const_XX_impl.cc.t
new file mode 100644
index 0000000000..8ff5ac3713
--- /dev/null
+++ b/gr-blocks/lib/and_const_XX_impl.cc.t
@@ -0,0 +1,77 @@
+/* -*- 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(@O_TYPE@ k)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(k));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(@O_TYPE@ k)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, 1, sizeof (@I_TYPE@)),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@))),
+ d_k(k)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @I_TYPE@ *iptr = (@I_TYPE@ *) input_items[0];
+ @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+
+ int size = noutput_items;
+
+ while (size >= 8){
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ size -= 8;
+ }
+
+ while (size-- > 0)
+ *optr++ = *iptr++ & d_k;
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/and_const_XX_impl.h.t b/gr-blocks/lib/and_const_XX_impl.h.t
new file mode 100644
index 0000000000..2c379feb84
--- /dev/null
+++ b/gr-blocks/lib/and_const_XX_impl.h.t
@@ -0,0 +1,51 @@
+/* -*- 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@
+ {
+ @O_TYPE@ d_k;
+
+ public:
+ @NAME_IMPL@(@O_TYPE@ k);
+
+ @O_TYPE@ k() const { return d_k; }
+ void set_k(@O_TYPE@ k) { d_k = k; }
+
+ 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
index 5bd1e7550f..8dad41a92f 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)
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index f4612f5d83..4482757ecf 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -43,6 +43,9 @@
#include "blocks/and_bb.h"
#include "blocks/and_ss.h"
#include "blocks/and_ii.h"
+#include "blocks/and_const_bb.h"
+#include "blocks/and_const_ss.h"
+#include "blocks/and_const_ii.h"
#include "blocks/char_to_float.h"
#include "blocks/char_to_short.h"
#include "blocks/complex_to_interleaved_short.h"
@@ -106,6 +109,9 @@
%include "blocks/and_bb.h"
%include "blocks/and_ss.h"
%include "blocks/and_ii.h"
+%include "blocks/and_const_bb.h"
+%include "blocks/and_const_ss.h"
+%include "blocks/and_const_ii.h"
%include "blocks/char_to_float.h"
%include "blocks/char_to_short.h"
%include "blocks/complex_to_interleaved_short.h"
@@ -168,6 +174,9 @@ 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, and_const_bb);
+GR_SWIG_BLOCK_MAGIC2(blocks, and_const_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, and_const_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);