Skip to content

Commit

Permalink
added msg many to one to combine msg ports
Browse files Browse the repository at this point in the history
  • Loading branch information
guruofquality committed Jul 14, 2012
1 parent 8c6b7ea commit 122fbb0
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 0 deletions.
1 change: 1 addition & 0 deletions grc/CMakeLists.txt
Expand Up @@ -47,6 +47,7 @@ list(APPEND grc_sources
extras_packet_deframer.xml extras_packet_deframer.xml
extras_stream_selector.xml extras_stream_selector.xml
extras_pmt_rpc.xml extras_pmt_rpc.xml
extras_msg_many_to_one.xml
) )


install( install(
Expand Down
1 change: 1 addition & 0 deletions grc/extras_block_tree.xml
Expand Up @@ -50,5 +50,6 @@
<block>extras_uhd_amsg_source</block> <block>extras_uhd_amsg_source</block>
<block>extras_decim_fir</block> <block>extras_decim_fir</block>
<block>extras_pmt_rpc</block> <block>extras_pmt_rpc</block>
<block>extras_msg_many_to_one</block>
</cat> </cat>
</cat> </cat>
25 changes: 25 additions & 0 deletions grc/extras_msg_many_to_one.xml
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<block>
<name>Extras: Msg M21</name>
<key>extras_msg_many_to_one</key>
<import>import gnuradio.extras as gr_extras</import>
<make>gr_extras.msg_many_to_one($num_inputs)</make>
<param>
<name>Num Inputs</name>
<key>num_inputs</key>
<value>2</value>
<type>int</type>
</param>
<sink>
<name>in</name>
<type></type>
<nports>$num_inputs</nports>
</sink>
<source>
<name>out</name>
<type></type>
</source>
<doc>
The message many to one block combines messages from several inputs.
</doc>
</block>
1 change: 1 addition & 0 deletions include/gnuradio/extras/CMakeLists.txt
Expand Up @@ -47,6 +47,7 @@ list(APPEND include_sources
socket_to_blob.h socket_to_blob.h
stream_to_blob.h stream_to_blob.h
tuntap.h tuntap.h
msg_many_to_one.h
) )


install( install(
Expand Down
39 changes: 39 additions & 0 deletions 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 <gnuradio/extras/api.h>
#include <gnuradio/block.h>

namespace gnuradio{ namespace extras{

class GR_EXTRAS_API msg_many_to_one : virtual public block{
public:
typedef boost::shared_ptr<msg_many_to_one> sptr;

static sptr make(const size_t num_inputs);
};

}}

#endif /* INCLUDED_GR_EXTRAS_MSG_MANY_TO_ONE_H */
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Expand Up @@ -56,6 +56,7 @@ list(APPEND gr_extras_sources
socket_to_blob.cc socket_to_blob.cc
stream_to_blob.cc stream_to_blob.cc
tuntap.cc tuntap.cc
msg_many_to_one.cc
) )


list(APPEND gr_extras_libs list(APPEND gr_extras_libs
Expand Down
68 changes: 68 additions & 0 deletions 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 <gnuradio/extras/msg_many_to_one.h>
#include <gr_io_signature.h>
#include <boost/foreach.hpp>

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<gr_tag_t> 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<gr_tag_t> _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));
}
3 changes: 3 additions & 0 deletions swig/extras_blobs.i
Expand Up @@ -30,6 +30,7 @@
#include <gnuradio/extras/socket_to_blob.h> #include <gnuradio/extras/socket_to_blob.h>
#include <gnuradio/extras/stream_to_blob.h> #include <gnuradio/extras/stream_to_blob.h>
#include <gnuradio/extras/tuntap.h> #include <gnuradio/extras/tuntap.h>
#include <gnuradio/extras/msg_many_to_one.h>
%} %}


%include <gnuradio/extras/blob_to_filedes.h> %include <gnuradio/extras/blob_to_filedes.h>
Expand All @@ -39,6 +40,7 @@
%include <gnuradio/extras/socket_to_blob.h> %include <gnuradio/extras/socket_to_blob.h>
%include <gnuradio/extras/stream_to_blob.h> %include <gnuradio/extras/stream_to_blob.h>
%include <gnuradio/extras/tuntap.h> %include <gnuradio/extras/tuntap.h>
%include <gnuradio/extras/msg_many_to_one.h>


//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// block magic // block magic
Expand All @@ -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(socket_to_blob)
GR_EXTRAS_SWIG_BLOCK_FACTORY(stream_to_blob) GR_EXTRAS_SWIG_BLOCK_FACTORY(stream_to_blob)
GR_EXTRAS_SWIG_BLOCK_FACTORY(tuntap) GR_EXTRAS_SWIG_BLOCK_FACTORY(tuntap)
GR_EXTRAS_SWIG_BLOCK_FACTORY(msg_many_to_one)

0 comments on commit 122fbb0

Please sign in to comment.