summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rondeau <trondeau@vt.edu>2013-03-06 22:00:36 -0500
committerTom Rondeau <trondeau@vt.edu>2013-03-06 22:00:36 -0500
commit6e5dfe1a3e2613df24fd1b47f5eb764eaf3dbd9f (patch)
tree6b6ced438fef13284a9eb0fc870c15367971c777
parent64d8f82c531a477262304bf93b98c2de4eb83d35 (diff)
blocks: moved burst_tagger to gr-blocks.
-rw-r--r--gr-blocks/grc/blocks_block_tree.xml1
-rw-r--r--gr-blocks/grc/blocks_burst_tagger.xml87
-rw-r--r--gr-blocks/include/blocks/CMakeLists.txt1
-rw-r--r--gr-blocks/include/blocks/burst_tagger.h74
-rw-r--r--gr-blocks/lib/CMakeLists.txt1
-rw-r--r--gr-blocks/lib/burst_tagger_impl.cc116
-rw-r--r--gr-blocks/lib/burst_tagger_impl.h59
-rw-r--r--gr-blocks/python/qa_burst_tagger.py60
-rw-r--r--gr-blocks/swig/blocks_swig.i3
9 files changed, 402 insertions, 0 deletions
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 76b32c35e5..40061dd663 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -110,6 +110,7 @@
<block>blocks_regenerate_bb</block>
<block>blocks_stretch_ff</block>
<block>blocks_threshold_ff</block>
+ <block>blocks_burst_tagger</block>
</cat>
<cat>
<name>Misc Conversions (New) </name>
diff --git a/gr-blocks/grc/blocks_burst_tagger.xml b/gr-blocks/grc/blocks_burst_tagger.xml
new file mode 100644
index 0000000000..f603b53489
--- /dev/null
+++ b/gr-blocks/grc/blocks_burst_tagger.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Burst tagger:
+## all types, 1 output, 2 input: stream & trigger (short)
+###################################################
+ -->
+<block>
+ <name>Burst Tagger</name>
+ <key>blocks_burst_tagger</key>
+ <import>from gnuradio import blocks</import>
+ <make>blocks.burst_tagger($type.size)
+self.$(id).set_true_tag($true_key,$true_value)
+self.$(id).set_false_tag($false_key,$false_value)
+ </make>
+ <callback>set_true_tag($true_key,$true_value)</callback>
+ <callback>set_false_tag($false_key,$false_value)</callback>
+ <param>
+ <name>Stream Type</name>
+ <key>type</key>
+ <type>enum</type>
+ <option>
+ <name>Complex</name>
+ <key>complex</key>
+ <opt>size:gr.sizeof_gr_complex</opt>
+ </option>
+ <option>
+ <name>Float</name>
+ <key>float</key>
+ <opt>size:gr.sizeof_float</opt>
+ </option>
+ <option>
+ <name>Int</name>
+ <key>int</key>
+ <opt>size:gr.sizeof_int</opt>
+ </option>
+ <option>
+ <name>Short</name>
+ <key>short</key>
+ <opt>size:gr.sizeof_short</opt>
+ </option>
+ <option>
+ <name>Byte</name>
+ <key>byte</key>
+ <opt>size:gr.sizeof_char</opt>
+ </option>
+ </param>
+ <param>
+ <name>True KeyID</name>
+ <key>true_key</key>
+ <value>burst</value>
+ <type>string</type>
+ </param>
+ <param>
+ <name>True Value</name>
+ <key>true_value</key>
+ <value>True</value>
+ <type>bool</type>
+ </param>
+ <param>
+ <name>False KeyID</name>
+ <key>false_key</key>
+ <value>burst</value>
+ <type>string</type>
+ </param>
+ <param>
+ <name>False Value</name>
+ <key>false_value</key>
+ <value>False</value>
+ <type>bool</type>
+ </param>
+ <sink>
+ <name>in</name>
+ <type>$type</type>
+ <vlen>1</vlen>
+ </sink>
+ <sink>
+ <name>trigger</name>
+ <type>short</type>
+ <vlen>1</vlen>
+ </sink>
+ <source>
+ <name>out</name>
+ <type>$type</type>
+ <vlen>1</vlen>
+ </source>
+</block>
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 79f095d265..16f495616e 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -102,6 +102,7 @@ install(FILES
count_bits.h
log2_const.h
add_ff.h
+ burst_tagger.h
char_to_float.h
char_to_short.h
complex_to_interleaved_short.h
diff --git a/gr-blocks/include/blocks/burst_tagger.h b/gr-blocks/include/blocks/burst_tagger.h
new file mode 100644
index 0000000000..408405f97b
--- /dev/null
+++ b/gr-blocks/include/blocks/burst_tagger.h
@@ -0,0 +1,74 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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.
+ */
+
+#ifndef INCLUDED_GR_BURST_TAGGER_H
+#define INCLUDED_GR_BURST_TAGGER_H
+
+#include <blocks/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Sets a burst on/off tag based on the value of the trigger input.
+ * \ingroup misc_blk
+ *
+ * This block takes two inputs, a signal stream on the input
+ * stream 0 and a trigger stream of shorts on input stream 1. If
+ * the trigger stream goes above 0, a tag with the key "burst"
+ * will be transmitted as a pmt::PMT_T. When the trigger signal
+ * falls below 0, the "burst" tag will be transmitted as
+ * pmt::PMT_F.
+ *
+ * The signal on stream 0 is retransmitted to output stream 0.
+ */
+ class BLOCKS_API burst_tagger : virtual public gr_sync_block
+ {
+ public:
+ // gr::blocks::burst_tagger::sptr
+ typedef boost::shared_ptr<burst_tagger> sptr;
+
+ /*!
+ * Build a burst tagger blocks.
+ *
+ * \param itemsize itemsize of the signal stream on input 0.
+ */
+ static sptr make(size_t itemsize);
+
+ /*!
+ * For the true burst tag, change the key name to \p key and a
+ * new value of \p value.
+ */
+ virtual void set_true_tag(const std::string &key, bool value) = 0;
+
+ /*!
+ * For the false burst tag, change the key name to \p key and a
+ * new value of \p value.
+ */
+ virtual void set_false_tag(const std::string &key, bool value) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_BURST_TAGGER_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 27b4e233a6..8afc77822f 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -138,6 +138,7 @@ list(APPEND gr_blocks_sources
${generated_sources}
count_bits.cc
add_ff_impl.cc
+ burst_tagger_impl.cc
char_to_float_impl.cc
char_to_short_impl.cc
complex_to_interleaved_short_impl.cc
diff --git a/gr-blocks/lib/burst_tagger_impl.cc b/gr-blocks/lib/burst_tagger_impl.cc
new file mode 100644
index 0000000000..5d0691bde6
--- /dev/null
+++ b/gr-blocks/lib/burst_tagger_impl.cc
@@ -0,0 +1,116 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "burst_tagger_impl.h"
+#include <gr_io_signature.h>
+#include <string.h>
+
+namespace gr {
+ namespace blocks {
+
+ burst_tagger::sptr
+ burst_tagger::make(size_t itemsize)
+ {
+ return gnuradio::get_initial_sptr
+ (new burst_tagger_impl(itemsize));
+ }
+
+ burst_tagger_impl::burst_tagger_impl(size_t itemsize)
+ : gr_sync_block("burst_tagger",
+ gr_make_io_signature2(2, 2, itemsize, sizeof(short)),
+ gr_make_io_signature(1, 1, itemsize)),
+ d_itemsize(itemsize), d_state(false)
+ {
+ std::stringstream str;
+ str << name() << unique_id();
+
+ d_true_key = pmt::pmt_string_to_symbol("burst");
+ d_true_value = pmt::PMT_T;
+
+ d_false_key = pmt::pmt_string_to_symbol("burst");
+ d_false_value = pmt::PMT_F;
+
+ d_id = pmt::pmt_string_to_symbol(str.str());
+ }
+
+ burst_tagger_impl::~burst_tagger_impl()
+ {
+ }
+
+ void
+ burst_tagger_impl::set_true_tag(const std::string &key, bool value)
+ {
+ d_true_key = pmt::pmt_string_to_symbol(key);
+ if(value == true) {
+ d_true_value = pmt::PMT_T;
+ }
+ else {
+ d_true_value = pmt::PMT_F;
+ }
+ }
+
+ void
+ burst_tagger_impl::set_false_tag (const std::string &key, bool value)
+ {
+ d_false_key = pmt::pmt_string_to_symbol(key);
+ if(value == true) {
+ d_false_value = pmt::PMT_T;
+ }
+ else {
+ d_false_value = pmt::PMT_F;
+ }
+ }
+
+ int
+ burst_tagger_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const char *signal = (const char*)input_items[0];
+ const short *trigger = (const short*)input_items[1];
+ char *out = (char*)output_items[0];
+
+ memcpy(out, signal, noutput_items * d_itemsize);
+
+ for(int i = 0; i < noutput_items; i++) {
+ if(trigger[i] > 0) {
+ if(d_state == false) {
+ d_state = true;
+ add_item_tag(0, nitems_written(0)+i, d_true_key, d_true_value, d_id);
+ }
+ }
+ else {
+ if(d_state == true) {
+ d_state = false;
+ add_item_tag(0, nitems_written(0)+i, d_false_key, d_false_value, d_id);
+ }
+ }
+ }
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/burst_tagger_impl.h b/gr-blocks/lib/burst_tagger_impl.h
new file mode 100644
index 0000000000..80bdec12fb
--- /dev/null
+++ b/gr-blocks/lib/burst_tagger_impl.h
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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.
+ */
+
+#ifndef INCLUDED_GR_BURST_TAGGER_IMPL_H
+#define INCLUDED_GR_BURST_TAGGER_IMPL_H
+
+#include <blocks/burst_tagger.h>
+
+namespace gr {
+ namespace blocks {
+
+ class burst_tagger_impl : public burst_tagger
+ {
+ private:
+ size_t d_itemsize;
+ bool d_state;
+ pmt::pmt_t d_true_key;
+ pmt::pmt_t d_true_value;
+
+ pmt::pmt_t d_false_key;
+ pmt::pmt_t d_false_value;
+
+ pmt::pmt_t d_id;
+
+ public:
+ burst_tagger_impl(size_t itemsize);
+ ~burst_tagger_impl();
+
+ void set_true_tag(const std::string &key, bool value);
+ void set_false_tag(const std::string &key, bool value);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_BURST_TAGGER_IMPL_H */
diff --git a/gr-blocks/python/qa_burst_tagger.py b/gr-blocks/python/qa_burst_tagger.py
new file mode 100644
index 0000000000..5e249cb8b9
--- /dev/null
+++ b/gr-blocks/python/qa_burst_tagger.py
@@ -0,0 +1,60 @@
+#!/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 pmt
+
+class test_burst_tagger(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_001(self):
+ # Just run some data through and make sure it doesn't puke.
+ src_data = ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+ trg_data = (-1, -1, 1, 1, -1, -1, 1, 1, -1, -1)
+ src = gr.vector_source_i(src_data)
+ trg = gr.vector_source_s(trg_data)
+ op = blocks.burst_tagger(gr.sizeof_int)
+ snk = blocks.tag_debug(gr.sizeof_int, "burst tagger QA")
+ self.tb.connect(src, (op,0))
+ self.tb.connect(trg, (op,1))
+ self.tb.connect(op, snk)
+ self.tb.run()
+
+ x = snk.current_tags()
+ self.assertEqual(2, x[0].offset)
+ self.assertEqual(4, x[1].offset)
+ self.assertEqual(6, x[2].offset)
+ self.assertEqual(8, x[3].offset)
+
+ self.assertEqual(True, pmt.pmt_to_bool(x[0].value))
+ self.assertEqual(False, pmt.pmt_to_bool(x[1].value))
+ self.assertEqual(True, pmt.pmt_to_bool(x[2].value))
+ self.assertEqual(False, pmt.pmt_to_bool(x[3].value))
+
+if __name__ == '__main__':
+ gr_unittest.run(test_burst_tagger, "test_burst_tagger.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 456eccc194..2c734cd60c 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -52,6 +52,7 @@
#include "blocks/argmax_fs.h"
#include "blocks/argmax_is.h"
#include "blocks/argmax_ss.h"
+#include "blocks/burst_tagger.h"
#include "blocks/char_to_float.h"
#include "blocks/char_to_short.h"
#include "blocks/complex_to_interleaved_short.h"
@@ -202,6 +203,7 @@
%include "blocks/argmax_is.h"
%include "blocks/argmax_ss.h"
%include "blocks/char_to_float.h"
+%include "blocks/burst_tagger.h"
%include "blocks/char_to_short.h"
%include "blocks/complex_to_interleaved_short.h"
%include "blocks/complex_to_float.h"
@@ -349,6 +351,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, and_const_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, argmax_fs);
GR_SWIG_BLOCK_MAGIC2(blocks, argmax_is);
GR_SWIG_BLOCK_MAGIC2(blocks, argmax_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, burst_tagger);
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);