From 122fbb086b91d1b4043ad77b8e5f45b07ac7b5e6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 14 Jul 2012 01:30:10 -0700 Subject: [PATCH] added msg many to one to combine msg ports --- grc/CMakeLists.txt | 1 + grc/extras_block_tree.xml | 1 + grc/extras_msg_many_to_one.xml | 25 +++++++++ include/gnuradio/extras/CMakeLists.txt | 1 + include/gnuradio/extras/msg_many_to_one.h | 39 +++++++++++++ lib/CMakeLists.txt | 1 + lib/msg_many_to_one.cc | 68 +++++++++++++++++++++++ swig/extras_blobs.i | 3 + 8 files changed, 139 insertions(+) create mode 100644 grc/extras_msg_many_to_one.xml create mode 100644 include/gnuradio/extras/msg_many_to_one.h create mode 100644 lib/msg_many_to_one.cc diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index 87e3139..c727f3c 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -47,6 +47,7 @@ list(APPEND grc_sources extras_packet_deframer.xml extras_stream_selector.xml extras_pmt_rpc.xml + extras_msg_many_to_one.xml ) install( diff --git a/grc/extras_block_tree.xml b/grc/extras_block_tree.xml index 91a1374..e738c9f 100644 --- a/grc/extras_block_tree.xml +++ b/grc/extras_block_tree.xml @@ -50,5 +50,6 @@ extras_uhd_amsg_source extras_decim_fir extras_pmt_rpc + extras_msg_many_to_one diff --git a/grc/extras_msg_many_to_one.xml b/grc/extras_msg_many_to_one.xml new file mode 100644 index 0000000..0d0b998 --- /dev/null +++ b/grc/extras_msg_many_to_one.xml @@ -0,0 +1,25 @@ + + + Extras: Msg M21 + extras_msg_many_to_one + import gnuradio.extras as gr_extras + gr_extras.msg_many_to_one($num_inputs) + + Num Inputs + num_inputs + 2 + int + + + in + + $num_inputs + + + out + + + +The message many to one block combines messages from several inputs. + + diff --git a/include/gnuradio/extras/CMakeLists.txt b/include/gnuradio/extras/CMakeLists.txt index b2b2bb8..8cd81b9 100644 --- a/include/gnuradio/extras/CMakeLists.txt +++ b/include/gnuradio/extras/CMakeLists.txt @@ -47,6 +47,7 @@ list(APPEND include_sources socket_to_blob.h stream_to_blob.h tuntap.h + msg_many_to_one.h ) install( diff --git a/include/gnuradio/extras/msg_many_to_one.h b/include/gnuradio/extras/msg_many_to_one.h new file mode 100644 index 0000000..0ee4b4f --- /dev/null +++ b/include/gnuradio/extras/msg_many_to_one.h @@ -0,0 +1,39 @@ +/* + * 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. + */ + +#ifndef INCLUDED_GR_EXTRAS_MSG_MANY_TO_ONE_H +#define INCLUDED_GR_EXTRAS_MSG_MANY_TO_ONE_H + +#include +#include + +namespace gnuradio{ namespace extras{ + +class GR_EXTRAS_API msg_many_to_one : virtual public block{ +public: + typedef boost::shared_ptr sptr; + + static sptr make(const size_t num_inputs); +}; + +}} + +#endif /* INCLUDED_GR_EXTRAS_MSG_MANY_TO_ONE_H */ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 53da014..e4ba286 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -56,6 +56,7 @@ list(APPEND gr_extras_sources socket_to_blob.cc stream_to_blob.cc tuntap.cc + msg_many_to_one.cc ) list(APPEND gr_extras_libs diff --git a/lib/msg_many_to_one.cc b/lib/msg_many_to_one.cc new file mode 100644 index 0000000..983f164 --- /dev/null +++ b/lib/msg_many_to_one.cc @@ -0,0 +1,68 @@ +/* + * 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. + */ + +#include +#include +#include + +using namespace gnuradio::extras; + +class msg_many_to_one_impl : public msg_many_to_one +{ +public: + msg_many_to_one_impl(const size_t num_inputs): + block( + "message many to one", + gr_make_io_signature(num_inputs, num_inputs, 1), + gr_make_io_signature(1, 1, 1) + ) + { + _tags.reserve(1024); //something reasonably large so we dont malloc + } + + int work( + const InputItems &input_items, + const OutputItems &output_items + ){ + std::vector tags; + for (size_t i = 0; i < input_items.size(); i++) + { + const uint64_t nread = this->nitems_read(i); //number of items read on port i + + //read all tags associated with port i for items in this work function + this->get_tags_in_range(_tags, i, nread, nread+input_items[i].size()); + + BOOST_FOREACH(const gr_tag_t &tag, _tags) + { + this->add_item_tag(0, tag); + } + } + + return output_items[0].size(); + } + + std::vector _tags; +}; + +msg_many_to_one::sptr msg_many_to_one::make(const size_t num_inputs) +{ + return gnuradio::get_initial_sptr(new msg_many_to_one_impl(num_inputs)); +} diff --git a/swig/extras_blobs.i b/swig/extras_blobs.i index bc53741..afd3b92 100644 --- a/swig/extras_blobs.i +++ b/swig/extras_blobs.i @@ -30,6 +30,7 @@ #include #include #include +#include %} %include @@ -39,6 +40,7 @@ %include %include %include +%include //////////////////////////////////////////////////////////////////////// // block magic @@ -51,3 +53,4 @@ GR_EXTRAS_SWIG_BLOCK_FACTORY(filedes_to_blob) GR_EXTRAS_SWIG_BLOCK_FACTORY(socket_to_blob) GR_EXTRAS_SWIG_BLOCK_FACTORY(stream_to_blob) GR_EXTRAS_SWIG_BLOCK_FACTORY(tuntap) +GR_EXTRAS_SWIG_BLOCK_FACTORY(msg_many_to_one)