diff options
author | Tim O'Shea <tim.oshea753@gmail.com> | 2013-11-19 17:01:33 -0500 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2013-11-26 08:53:38 -0500 |
commit | fa3187a1c03f87d944c261c764f61453d77d8244 (patch) | |
tree | 78e9957b637962df52a69fe7183fe5bedb814284 | |
parent | a4d2ba4bfc9b62d6c53d74f5f70a3c0656025cee (diff) |
blocks: adding tagged_stream_multiply_length for scaling item lengths (useful in conjunction with stream blocks that interpolate or decimate at fixed rates)
-rw-r--r-- | gr-blocks/grc/blocks_block_tree.xml | 1 | ||||
-rw-r--r-- | gr-blocks/grc/blocks_tagged_stream_multiply_length.xml | 70 | ||||
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/tagged_stream_multiply_length.h | 60 | ||||
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/lib/tagged_stream_multiply_length_impl.cc | 89 | ||||
-rw-r--r-- | gr-blocks/lib/tagged_stream_multiply_length_impl.h | 62 | ||||
-rw-r--r-- | gr-blocks/swig/blocks_swig5.i | 3 |
8 files changed, 287 insertions, 0 deletions
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 18e6a05213..e63128337d 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -120,6 +120,7 @@ <block>blocks_message_strobe</block> <block>blocks_message_debug</block> <block>blocks_pdu_to_tagged_stream</block> + <block>blocks_tagged_stream_multiply_length</block> <block>blocks_tagged_stream_to_pdu</block> <block>blocks_random_pdu</block> </cat> diff --git a/gr-blocks/grc/blocks_tagged_stream_multiply_length.xml b/gr-blocks/grc/blocks_tagged_stream_multiply_length.xml new file mode 100644 index 0000000000..f4abb92903 --- /dev/null +++ b/gr-blocks/grc/blocks_tagged_stream_multiply_length.xml @@ -0,0 +1,70 @@ +<block> + <name>Tagged Stream Multiply Length Tag</name> + <key>blocks_tagged_stream_multiply_length</key> + <import>from gnuradio import blocks</import> + <make>blocks.tagged_stream_multiply_length($type.size*$vlen, $lengthtagname, $c)</make> + <callback>set_scalar($c)</callback> + <param> + <name>IO 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>Length tag names</name> + <key>lengthtagname</key> + <type>string</type> + </param> + <param> + <name>Vector Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <param> + <name>Length Scalar</name> + <key>c</key> + <value>1.0</value> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$vlen</vlen> + </sink> + <sink> + <name>set_scalar</name> + <type>message</type> + <optional>1</optional> + </sink> + <source> + <name>out</name> + <type>$type</type> + <vlen>$vlen</vlen> + </source> +</block> + diff --git a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt index 83338b771d..90a32f386b 100644 --- a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt +++ b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt @@ -192,6 +192,7 @@ install(FILES tag_gate.h tagged_file_sink.h tagged_stream_mux.h + tagged_stream_multiply_length.h tagged_stream_to_pdu.h tags_strobe.h threshold_ff.h diff --git a/gr-blocks/include/gnuradio/blocks/tagged_stream_multiply_length.h b/gr-blocks/include/gnuradio/blocks/tagged_stream_multiply_length.h new file mode 100644 index 0000000000..de46516f24 --- /dev/null +++ b/gr-blocks/include/gnuradio/blocks/tagged_stream_multiply_length.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* 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. + */ + +#ifndef INCLUDED_TAGGED_STREAM_MULTIPLY_LENGTH_H +#define INCLUDED_TAGGED_STREAM_MULTIPLY_LENGTH_H + +#include <gnuradio/blocks/api.h> +#include <gnuradio/tagged_stream_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Allows scaling of a tagged stream length tag + * \ingroup stream_operators_blk + * + * \details + * Searches for a specific tagged stream length tag and multiplies + * that length by a constant - for constant rate change blocks + * in a tagged stream + */ + class BLOCKS_API tagged_stream_multiply_length : virtual public block + { + public: + typedef boost::shared_ptr<tagged_stream_multiply_length> sptr; + virtual void set_scalar(double scalar) = 0; + + /*! + * Make a tagged stream multiply_length block. + * + * \param itemsize Items size (number of bytes per item) + * \param lengthtagname Length tag key + * \param scalar value to scale length tag values by + */ + static sptr make(size_t itemsize, const std::string &lengthtagname, double scalar); + }; + + } // namespace blocks +} // namespace gr + +#endif /* INCLUDED_TAGGED_STREAM_MULTIPLY_LENGTH_H */ + diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 6eded4a273..ab6c7e95be 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -232,6 +232,7 @@ list(APPEND gr_blocks_sources stretch_ff_impl.cc tagged_file_sink_impl.cc tagged_stream_to_pdu_impl.cc + tagged_stream_multiply_length_impl.cc tags_strobe_impl.cc threshold_ff_impl.cc throttle_impl.cc diff --git a/gr-blocks/lib/tagged_stream_multiply_length_impl.cc b/gr-blocks/lib/tagged_stream_multiply_length_impl.cc new file mode 100644 index 0000000000..18a8eef1e9 --- /dev/null +++ b/gr-blocks/lib/tagged_stream_multiply_length_impl.cc @@ -0,0 +1,89 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gnuradio/io_signature.h> +#include "tagged_stream_multiply_length_impl.h" + +namespace gr { + namespace blocks { + + tagged_stream_multiply_length::sptr + tagged_stream_multiply_length::make(size_t itemsize, const std::string &lengthtagname, double scalar) + { + return gnuradio::get_initial_sptr (new tagged_stream_multiply_length_impl(itemsize, lengthtagname, scalar)); + } + + tagged_stream_multiply_length_impl::tagged_stream_multiply_length_impl(size_t itemsize, const std::string &lengthtagname, double scalar) + : block("tagged_stream_multiply_length", + io_signature::make(1, 1, itemsize), + io_signature::make(1, 1, itemsize)), + d_lengthtag(pmt::mp(lengthtagname)), + d_scalar(scalar), + d_itemsize(itemsize) + { + set_tag_propagation_policy(TPP_DONT); + set_relative_rate(1); + message_port_register_in(pmt::intern("set_scalar")); + set_msg_handler(pmt::intern("set_scalar"), + boost::bind(&tagged_stream_multiply_length_impl::set_scalar_pmt, this, _1)); + } + + tagged_stream_multiply_length_impl::~tagged_stream_multiply_length_impl() + { + } + + int + tagged_stream_multiply_length_impl::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const void* in = input_items[0]; + void* out = output_items[0]; + + // move data across ( wasteful memcopy :< ) + memcpy(out, in, noutput_items*d_itemsize); + + // move and update tags + std::vector<tag_t> tags; + get_tags_in_range(tags, 0, nitems_read(0), nitems_read(0)+ninput_items[0]); + for(size_t i=0; i<tags.size(); i++){ + if(pmt::eqv( tags[i].key , d_lengthtag)){ + // propagate with value update (scaled) + add_item_tag(0, tags[i].offset, tags[i].key, pmt::from_long(pmt::to_long(tags[i].value) * d_scalar), tags[i].srcid ); + } else { + // propagate unmodified + add_item_tag(0, tags[i].offset, tags[i].key, tags[i].value, tags[i].srcid ); + } + } + + consume_each(noutput_items); + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ + diff --git a/gr-blocks/lib/tagged_stream_multiply_length_impl.h b/gr-blocks/lib/tagged_stream_multiply_length_impl.h new file mode 100644 index 0000000000..5d61650369 --- /dev/null +++ b/gr-blocks/lib/tagged_stream_multiply_length_impl.h @@ -0,0 +1,62 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifndef INCLUDED_TAGGED_STREAM_MULTIPLY_LENGTH_IMPL_H +#define INCLUDED_TAGGED_STREAM_MULTIPLY_LENGTH_IMPL_H + +#include <vector> +#include <gnuradio/blocks/tagged_stream_multiply_length.h> + +namespace gr { + namespace blocks { + + class tagged_stream_multiply_length_impl : public tagged_stream_multiply_length + { + private: + pmt::pmt_t d_lengthtag; + double d_scalar; + size_t d_itemsize; + + public: + tagged_stream_multiply_length_impl(size_t itemsize, const std::string &lengthtagname, double scalar); + ~tagged_stream_multiply_length_impl(); + + int general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void set_scalar(double scalar){ + d_scalar = scalar; + } + + void set_scalar_pmt(pmt::pmt_t msg){ + set_scalar(pmt::to_double(msg)); + } + + }; + + } // namespace blocks +} // namespace gr + +#endif + diff --git a/gr-blocks/swig/blocks_swig5.i b/gr-blocks/swig/blocks_swig5.i index 09679531d9..deb3b5a045 100644 --- a/gr-blocks/swig/blocks_swig5.i +++ b/gr-blocks/swig/blocks_swig5.i @@ -51,6 +51,7 @@ #include "gnuradio/blocks/sub_cc.h" #include "gnuradio/blocks/tag_gate.h" #include "gnuradio/blocks/tagged_stream_mux.h" +#include "gnuradio/blocks/tagged_stream_multiply_length.h" #include "gnuradio/blocks/tagged_stream_to_pdu.h" #include "gnuradio/blocks/tags_strobe.h" #include "gnuradio/blocks/threshold_ff.h" @@ -90,6 +91,7 @@ %include "gnuradio/blocks/sub_cc.h" %include "gnuradio/blocks/tag_gate.h" %include "gnuradio/blocks/tagged_stream_mux.h" +%include "gnuradio/blocks/tagged_stream_multiply_length.h" %include "gnuradio/blocks/tagged_stream_to_pdu.h" %include "gnuradio/blocks/tags_strobe.h" %include "gnuradio/blocks/threshold_ff.h" @@ -128,6 +130,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii); GR_SWIG_BLOCK_MAGIC2(blocks, sub_cc); GR_SWIG_BLOCK_MAGIC2(blocks, tag_gate); GR_SWIG_BLOCK_MAGIC2(blocks, tagged_stream_mux); +GR_SWIG_BLOCK_MAGIC2(blocks, tagged_stream_multiply_length); GR_SWIG_BLOCK_MAGIC2(blocks, tagged_stream_to_pdu); GR_SWIG_BLOCK_MAGIC2(blocks, tags_strobe); GR_SWIG_BLOCK_MAGIC2(blocks, threshold_ff); |