diff options
author | Tom Rondeau <trondeau@vt.edu> | 2013-03-16 23:34:34 -0400 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2013-03-16 23:52:20 -0400 |
commit | 51cbe589f7cd74056be613587e82e8d3b3168e84 (patch) | |
tree | 22d22d0919e52147286ce888343724c9529d8dcd | |
parent | a792bb88f3c3caa347506503de973aafaf78e0af (diff) |
blocks: moved nop, null source/sink, copy, vector_map to gr-blocks.
24 files changed, 1136 insertions, 12 deletions
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 618539354b..810ac300b5 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -40,6 +40,7 @@ <block>blocks_wavfile_source</block> <block>blocks_vector_source_x</block> <block>blocks_vector_insert_x</block> + <block>blocks_null_source</block> </cat> <cat> <name>Sinks (New)</name> @@ -53,6 +54,7 @@ <block>blocks_udp_sink</block> <block>blocks_wavfile_sink</block> <block>blocks_vector_sink_x</block> + <block>blocks_null_sink</block> </cat> <cat> <name>Math Operations (New) </name> @@ -140,6 +142,7 @@ <block>blocks_head</block> <block>blocks_skiphead</block> <block>blocks_copy</block> + <block>blocks_nop</block> </cat> <cat> <name>Networking</name> diff --git a/gr-blocks/grc/blocks_nop.xml b/gr-blocks/grc/blocks_nop.xml new file mode 100644 index 0000000000..d38c23839d --- /dev/null +++ b/gr-blocks/grc/blocks_nop.xml @@ -0,0 +1,68 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Nop +################################################### + --> +<block> + <name>Nop</name> + <key>blocks_nop</key> + <import>from gnuradio import blocks</import> + <make>blocks.nop($type.size*$vlen)</make> + <param> + <name>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>Num Ports</name> + <key>num_ports</key> + <value>1</value> + <type>int</type> + </param> + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <check>$num_ports > 0</check> + <check>$vlen > 0</check> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$vlen</vlen> + <nports>$num_ports</nports> + </sink> + <source> + <name>out</name> + <type>$type</type> + <vlen>$vlen</vlen> + <nports>$num_ports</nports> + </source> +</block> diff --git a/gr-blocks/grc/blocks_null_sink.xml b/gr-blocks/grc/blocks_null_sink.xml new file mode 100644 index 0000000000..2ae20e619a --- /dev/null +++ b/gr-blocks/grc/blocks_null_sink.xml @@ -0,0 +1,54 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Null Sink +################################################### + --> +<block> + <name>Null Sink</name> + <key>blocks_null_sink</key> + <import>from gnuradio import blocks</import> + <make>blocks.null_sink($type.size*$vlen)</make> + <param> + <name>Input 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>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <check>$vlen > 0</check> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$vlen</vlen> + </sink> +</block> diff --git a/gr-blocks/grc/blocks_null_source.xml b/gr-blocks/grc/blocks_null_source.xml new file mode 100644 index 0000000000..01d3905cab --- /dev/null +++ b/gr-blocks/grc/blocks_null_source.xml @@ -0,0 +1,54 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Null Source +################################################### + --> +<block> + <name>Null Source</name> + <key>blocks_null_source</key> + <import>from gnuradio import blocks</import> + <make>blocks.null_source($type.size*$vlen)</make> + <param> + <name>Output 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>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <check>$vlen > 0</check> + <source> + <name>out</name> + <type>$type</type> + <vlen>$vlen</vlen> + </source> +</block> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index a7cc1e0a31..b34809ae59 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -158,6 +158,9 @@ install(FILES multiply_const_cc.h multiply_const_ff.h nlog10_ff.h + nop.h + null_sink.h + null_source.h pack_k_bits_bb.h patterned_interleaver.h pdu.h @@ -192,6 +195,7 @@ install(FILES udp_source.h unpack_k_bits_bb.h vco_f.h + vector_map.h vector_to_stream.h vector_to_streams.h wavfile_sink.h diff --git a/gr-blocks/include/blocks/nop.h b/gr-blocks/include/blocks/nop.h new file mode 100644 index 0000000000..b3135e1cc8 --- /dev/null +++ b/gr-blocks/include/blocks/nop.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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_NOP_H +#define INCLUDED_GR_NOP_H + +#include <blocks/api.h> +#include <gr_block.h> +#include <stddef.h> // size_t + +namespace gr { + namespace blocks { + + /*! + * \brief Does nothing. Used for testing only. + * \ingroup misc_blk + */ + class BLOCKS_API nop : virtual public gr_block + { + public: + // gr::blocks::nop::sptr + typedef boost::shared_ptr<nop> sptr; + + /*! + * Build a nop block. + * + * \param sizeof_stream_item size of the stream items in bytes. + */ + static sptr make(size_t sizeof_stream_item); + + virtual int nmsgs_received() const = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_NOP_H */ diff --git a/gr-blocks/include/blocks/null_sink.h b/gr-blocks/include/blocks/null_sink.h new file mode 100644 index 0000000000..c13a7552c6 --- /dev/null +++ b/gr-blocks/include/blocks/null_sink.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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_NULL_SINK_H +#define INCLUDED_GR_NULL_SINK_H + +#include <blocks/api.h> +#include <gr_sync_block.h> +#include <stddef.h> // size_t + +namespace gr { + namespace blocks { + + /*! + * \brief Bit bucket. Use as a termination point when a sink is + * required and we don't want to do anything real. + * \ingroup sink_blk + */ + class BLOCKS_API null_sink : virtual public gr_sync_block + { + public: + // gr::blocks::null_sink::sptr + typedef boost::shared_ptr<null_sink> sptr; + + /*! + * Build a null sink block. + * + * \param sizeof_stream_item size of the stream items in bytes. + */ + static sptr make(size_t sizeof_stream_item); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_NULL_SINK_H */ diff --git a/gr-blocks/include/blocks/null_source.h b/gr-blocks/include/blocks/null_source.h new file mode 100644 index 0000000000..904a0c1ba3 --- /dev/null +++ b/gr-blocks/include/blocks/null_source.h @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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_NULL_SOURCE_H +#define INCLUDED_GR_NULL_SOURCE_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief A source of zeros used mainly for testing. + * \ingroup source_blk + */ + class BLOCKS_API null_source : virtual public gr_sync_block + { + public: + // gr::blocks::null_source::sptr + typedef boost::shared_ptr<null_source> sptr; + + /*! + * Build a null source block. + * + * \param sizeof_stream_item size of the stream items in bytes. + */ + static sptr make(size_t sizeof_stream_item); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_NULL_SOURCE_H */ diff --git a/gr-blocks/include/blocks/vector_map.h b/gr-blocks/include/blocks/vector_map.h new file mode 100644 index 0000000000..64c8744975 --- /dev/null +++ b/gr-blocks/include/blocks/vector_map.h @@ -0,0 +1,71 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012,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_VECTOR_MAP_H +#define INCLUDED_GR_VECTOR_MAP_H + +#include <blocks/api.h> +#include <vector> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Maps elements from a set of input vectors to a set of output vectors. + * \ingroup slicedice_blk + * + * If in[i] is the input vector in the i'th stream then the output + * vector in the j'th stream is: + * + * out[j][k] = in[mapping[j][k][0]][mapping[j][k][1]] + * + * That is mapping is of the form (out_stream1_mapping, + * out_stream2_mapping, ...) and out_stream1_mapping is of the + * form (element1_mapping, element2_mapping, ...) and + * element1_mapping is of the form (in_stream, in_element). + */ + class BLOCKS_API vector_map : virtual public gr_sync_block + { + public: + // gr::blocks::vector_map::sptr + typedef boost::shared_ptr<vector_map> sptr; + + /*! + * Build a vector map block. + * + * \param item_size (integer) size of vector elements + * \param in_vlens (vector of integers) number of elements in each + * input vector + * \param mapping (vector of vectors of vectors of integers) how to + * map elements from input to output vectors + */ + static sptr make(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping); + + virtual void set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping) = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_VECTOR_MAP_H */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index b0f3ef15cd..3f456b6b04 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -195,6 +195,9 @@ list(APPEND gr_blocks_sources multiply_const_cc_impl.cc multiply_const_ff_impl.cc nlog10_ff_impl.cc + nop_impl.cc + null_sink_impl.cc + null_source_impl.cc pack_k_bits_bb_impl.cc patterned_interleaver_impl.cc pdu.cc @@ -232,6 +235,7 @@ list(APPEND gr_blocks_sources udp_source_impl.cc unpack_k_bits_bb_impl.cc vco_f_impl.cc + vector_map_impl.cc vector_to_stream_impl.cc vector_to_streams_impl.cc wavfile_sink_impl.cc diff --git a/gr-blocks/lib/copy_impl.cc b/gr-blocks/lib/copy_impl.cc index f489b03c0c..929f22b7d3 100644 --- a/gr-blocks/lib/copy_impl.cc +++ b/gr-blocks/lib/copy_impl.cc @@ -40,8 +40,8 @@ namespace gr { copy_impl::copy_impl(size_t itemsize) : gr_block("copy", - gr_make_io_signature(1, 1, itemsize), - gr_make_io_signature(1, 1, itemsize)), + gr_make_io_signature(1, -1, itemsize), + gr_make_io_signature(1, -1, itemsize)), d_itemsize(itemsize), d_enabled(true) { @@ -51,6 +51,14 @@ namespace gr { { } + void + copy_impl::forecast(int noutput_items, gr_vector_int &ninput_items_required) + { + unsigned ninputs = ninput_items_required.size(); + for (unsigned i = 0; i < ninputs; i++) + ninput_items_required[i] = noutput_items; + } + bool copy_impl::check_topology(int ninputs, int noutputs) { @@ -63,19 +71,20 @@ namespace gr { gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - const uint8_t *in = (const uint8_t*)input_items[0]; - uint8_t *out = (uint8_t*)output_items[0]; - - int n = std::min<int>(ninput_items[0], noutput_items); - int j = 0; + const uint8_t **in = (const uint8_t**)&input_items[0]; + uint8_t **out = (uint8_t**)&output_items[0]; + int n = 0; if(d_enabled) { - memcpy(out, in, n*d_itemsize); - j = n; + int ninputs = input_items.size(); + for(int i = 0; i < ninputs; i++) { + memcpy(out[i], in[i], noutput_items*d_itemsize); + } + n = noutput_items; } - consume_each(n); - return j; + consume_each(noutput_items); + return n; } } /* namespace blocks */ diff --git a/gr-blocks/lib/copy_impl.h b/gr-blocks/lib/copy_impl.h index f462ffebdc..1f0f1a655e 100644 --- a/gr-blocks/lib/copy_impl.h +++ b/gr-blocks/lib/copy_impl.h @@ -38,6 +38,7 @@ namespace gr { copy_impl(size_t itemsize); ~copy_impl(); + void forecast(int noutput_items, gr_vector_int &ninput_items_required); bool check_topology(int ninputs, int noutputs); void set_enabled(bool enable) { d_enabled = enable; } diff --git a/gr-blocks/lib/nop_impl.cc b/gr-blocks/lib/nop_impl.cc new file mode 100644 index 0000000000..766f07e2b8 --- /dev/null +++ b/gr-blocks/lib/nop_impl.cc @@ -0,0 +1,78 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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 "nop_impl.h" +#include <gr_io_signature.h> +#include <boost/bind.hpp> + +namespace gr { + namespace blocks { + + nop::sptr + nop::make(size_t sizeof_stream_item) + { + return gnuradio::get_initial_sptr + (new nop_impl(sizeof_stream_item)); + } + + nop_impl::nop_impl (size_t sizeof_stream_item) + : gr_block("nop", + gr_make_io_signature(0, -1, sizeof_stream_item), + gr_make_io_signature(0, -1, sizeof_stream_item)), + d_nmsgs_recvd(0) + { + // Arrange to have count_received_msgs called when messages are received. + message_port_register_in(pmt::mp("port")); + set_msg_handler(pmt::mp("port"), boost::bind(&nop_impl::count_received_msgs, this, _1)); + } + + nop_impl::~nop_impl() + { + } + + // Trivial message handler that just counts them. + // (N.B., This feature is used in qa_set_msg_handler) + void + nop_impl::count_received_msgs(pmt::pmt_t msg) + { + d_nmsgs_recvd++; + } + + int + nop_impl::general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + // eat any input that's available + for(unsigned i = 0; i < ninput_items.size (); i++) + consume(i, ninput_items[i]); + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/nop_impl.h b/gr-blocks/lib/nop_impl.h new file mode 100644 index 0000000000..b236abb7aa --- /dev/null +++ b/gr-blocks/lib/nop_impl.h @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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_NOP_IMPL_H +#define INCLUDED_GR_NOP_IMPL_H + +#include <blocks/nop.h> + +namespace gr { + namespace blocks { + + class nop_impl : public nop + { + protected: + int d_nmsgs_recvd; + + // Method that just counts any received messages. + void count_received_msgs(pmt::pmt_t msg); + + public: + nop_impl(size_t sizeof_stream_item); + ~nop_impl(); + + int nmsgs_received() const { return d_nmsgs_recvd; } + + int general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_NOP_IMPL_H */ diff --git a/gr-blocks/lib/null_sink_impl.cc b/gr-blocks/lib/null_sink_impl.cc new file mode 100644 index 0000000000..b780a2405a --- /dev/null +++ b/gr-blocks/lib/null_sink_impl.cc @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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 "null_sink_impl.h" +#include <gr_io_signature.h> + +namespace gr { + namespace blocks { + + null_sink::sptr + null_sink::make(size_t sizeof_stream_item) + { + return gnuradio::get_initial_sptr + (new null_sink_impl(sizeof_stream_item)); + } + + null_sink_impl::null_sink_impl(size_t sizeof_stream_item) + : gr_sync_block("null_sink", + gr_make_io_signature(1, 1, sizeof_stream_item), + gr_make_io_signature(0, 0, 0)) + { + } + + null_sink_impl::~null_sink_impl() + { + } + + int + null_sink_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/null_sink_impl.h b/gr-blocks/lib/null_sink_impl.h new file mode 100644 index 0000000000..bb4c695c23 --- /dev/null +++ b/gr-blocks/lib/null_sink_impl.h @@ -0,0 +1,45 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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_NULL_SINK_IMPL_H +#define INCLUDED_GR_NULL_SINK_IMPL_H + +#include <blocks/null_sink.h> + +namespace gr { + namespace blocks { + + class null_sink_impl : public null_sink + { + public: + null_sink_impl(size_t sizeof_stream_item); + ~null_sink_impl(); + + 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_NULL_SINK_IMPL_H */ diff --git a/gr-blocks/lib/null_source_impl.cc b/gr-blocks/lib/null_source_impl.cc new file mode 100644 index 0000000000..81999d0501 --- /dev/null +++ b/gr-blocks/lib/null_source_impl.cc @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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 "null_source_impl.h" +#include <gr_io_signature.h> +#include <string.h> + +namespace gr { + namespace blocks { + + null_source::sptr + null_source::make(size_t sizeof_stream_item) + { + return gnuradio::get_initial_sptr + (new null_source_impl(sizeof_stream_item)); + } + + null_source_impl::null_source_impl (size_t sizeof_stream_item) + : gr_sync_block("null_source", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, sizeof_stream_item)) + { + } + + null_source_impl::~null_source_impl() + { + } + + int + null_source_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + void *optr = (void*)output_items[0]; + memset(optr, 0, noutput_items * output_signature()->sizeof_stream_item(0)); + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/null_source_impl.h b/gr-blocks/lib/null_source_impl.h new file mode 100644 index 0000000000..36201d54b6 --- /dev/null +++ b/gr-blocks/lib/null_source_impl.h @@ -0,0 +1,45 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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_NULL_SOURCE_IMPL_H +#define INCLUDED_GR_NULL_SOURCE_IMPL_H + +#include <blocks/null_source.h> + +namespace gr { + namespace blocks { + + class null_source_impl : public null_source + { + public: + null_source_impl(size_t sizeof_stream_item); + ~null_source_impl(); + + 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_NULL_SOURCE_IMPL_H */ diff --git a/gr-blocks/lib/vector_map_impl.cc b/gr-blocks/lib/vector_map_impl.cc new file mode 100644 index 0000000000..cefaaeea35 --- /dev/null +++ b/gr-blocks/lib/vector_map_impl.cc @@ -0,0 +1,127 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012,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 "vector_map_impl.h" +#include <gr_io_signature.h> +#include <string.h> + +namespace gr { + namespace blocks { + + std::vector<int> + get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens) + { + std::vector<int> in_sizeofs; + for(unsigned int i = 0; i < in_vlens.size(); i++) { + in_sizeofs.push_back(in_vlens[i]*item_size); + } + return in_sizeofs; + } + + std::vector<int> + get_out_sizeofs(size_t item_size, + std::vector< std::vector< std::vector<size_t> > > mapping) + { + std::vector<int> out_sizeofs; + for(unsigned int i = 0; i < mapping.size(); i++) { + out_sizeofs.push_back(mapping[i].size()*item_size); + } + return out_sizeofs; + } + + vector_map::sptr + vector_map::make(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping) + { + return gnuradio::get_initial_sptr + (new vector_map_impl(item_size, in_vlens, mapping)); + } + + vector_map_impl::vector_map_impl(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping) + : gr_sync_block("vector_map", + gr_make_io_signaturev(in_vlens.size(), in_vlens.size(), + get_in_sizeofs(item_size, in_vlens)), + gr_make_io_signaturev(mapping.size(), mapping.size(), + get_out_sizeofs(item_size, mapping))), + d_item_size(item_size), d_in_vlens(in_vlens) + { + set_mapping(mapping); + } + + vector_map_impl::~vector_map_impl() + { + } + + void + vector_map_impl::set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping) + { + // Make sure the contents of the mapping vectors are possible. + for(unsigned int i=0; i<mapping.size(); i++) { + for(unsigned int j=0; j<mapping[i].size(); j++) { + if(mapping[i][j].size() != 2) { + throw std::runtime_error("Mapping must be of the form (out_mapping_stream1, out_mapping_stream2, ...), where out_mapping_stream1 is of the form (mapping_element1, mapping_element2, ...), where mapping_element1 is of the form (input_stream, input_element). This error is raised because a mapping_element vector does not contain exactly 2 items."); + } + unsigned int s = mapping[i][j][0]; + unsigned int index = mapping[i][j][1]; + if(s >= d_in_vlens.size()) { + throw std::runtime_error("Stream numbers in mapping must be less than the number of input streams."); + } + if((index < 0) || (index >= d_in_vlens[s])) { + throw std::runtime_error ("Indices in mapping must be greater than 0 and less than the input vector lengths."); + } + } + } + gruel::scoped_lock guard(d_mutex); + d_mapping = mapping; + } + + int + vector_map_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const char **inv = (const char**)&input_items[0]; + char **outv = (char**)&output_items[0]; + + for(unsigned int n = 0; n < (unsigned int)(noutput_items); n++) { + for(unsigned int i = 0; i < d_mapping.size(); i++) { + unsigned int out_vlen = d_mapping[i].size(); + for(unsigned int j = 0; j < out_vlen; j++) { + unsigned int s = d_mapping[i][j][0]; + unsigned int k = d_mapping[i][j][1]; + memcpy(outv[i] + out_vlen*d_item_size*n + + d_item_size*j, inv[s] + d_in_vlens[s]*d_item_size*n + + k*d_item_size, d_item_size); + } + } + } + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/vector_map_impl.h b/gr-blocks/lib/vector_map_impl.h new file mode 100644 index 0000000000..e27b3b9cec --- /dev/null +++ b/gr-blocks/lib/vector_map_impl.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012,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_VECTOR_MAP_IMPL_H +#define INCLUDED_GR_VECTOR_MAP_IMPL_H + +#include <blocks/vector_map.h> +#include <gruel/thread.h> + +namespace gr { + namespace blocks { + + class vector_map_impl : public vector_map + { + private: + size_t d_item_size; + std::vector<size_t> d_in_vlens; + std::vector< std::vector< std::vector<size_t> > > d_mapping; + gruel::mutex d_mutex; // mutex to protect set/work access + + public: + vector_map_impl(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping); + ~vector_map_impl(); + + void set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping); + + 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_VECTOR_MAP_IMPL_H */ diff --git a/gr-blocks/python/qa_copy.py b/gr-blocks/python/qa_copy.py index 04f6454231..012d790609 100755 --- a/gr-blocks/python/qa_copy.py +++ b/gr-blocks/python/qa_copy.py @@ -46,7 +46,7 @@ class test_copy(gr_unittest.TestCase): src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) expected_result = () src = blocks.vector_source_b(src_data) - op = blocks.copy(gr.sizeof_char) + op = gr.copy(gr.sizeof_char) op.set_enabled(False) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) diff --git a/gr-blocks/python/qa_null_sink_source.py b/gr-blocks/python/qa_null_sink_source.py new file mode 100644 index 0000000000..60552cb207 --- /dev/null +++ b/gr-blocks/python/qa_null_sink_source.py @@ -0,0 +1,46 @@ +#!/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 math + +class test_null_sink_source(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + # Just running some data through null source/sink + src = blocks.null_source(gr.sizeof_float) + hed = blocks.head(gr.sizeof_float, 100) + dst = blocks.null_sink(gr.sizeof_float) + + self.tb.connect(src, hed, dst) + self.tb.run() + +if __name__ == '__main__': + gr_unittest.run(test_null_sink_source, "test_null_sink_source.xml") + diff --git a/gr-blocks/python/qa_vector_map.py b/gr-blocks/python/qa_vector_map.py new file mode 100644 index 0000000000..54565fe443 --- /dev/null +++ b/gr-blocks/python/qa_vector_map.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# +# Copyright 2012,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 math + +class test_vector_map(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_reversing(self): + # Chunk data in blocks of N and reverse the block contents. + N = 5 + src_data = range(0, 20) + expected_result = [] + for i in range(N-1, len(src_data), N): + for j in range(0, N): + expected_result.append(1.0*(i-j)) + mapping = [list(reversed([(0, i) for i in range(0, N)]))] + src = blocks.vector_source_f(src_data, False, N) + vmap = blocks.vector_map(gr.sizeof_float, (N, ), mapping) + dst = blocks.vector_sink_f(N) + self.tb.connect(src, vmap, dst) + self.tb.run() + result_data = list(dst.data()) + self.assertEqual(expected_result, result_data) + + def test_vector_to_streams(self): + # Split an input vector into N streams. + N = 5 + M = 20 + src_data = range(0, M) + expected_results = [] + for n in range(0, N): + expected_results.append(range(n, M, N)) + mapping = [[(0, n)] for n in range(0, N)] + src = blocks.vector_source_f(src_data, False, N) + vmap = blocks.vector_map(gr.sizeof_float, (N, ), mapping) + dsts = [blocks.vector_sink_f(1) for n in range(0, N)] + self.tb.connect(src, vmap) + for n in range(0, N): + self.tb.connect((vmap, n), dsts[n]) + self.tb.run() + for n in range(0, N): + result_data = list(dsts[n].data()) + self.assertEqual(expected_results[n], result_data) + + def test_interleaving(self): + # Takes 3 streams (a, b and c) + # Outputs 2 streams. + # First (d) is interleaving of a and b. + # Second (e) is interleaving of a and b and c. c is taken in + # chunks of 2 which are reversed. + A = (1, 2, 3, 4, 5) + B = (11, 12, 13, 14, 15) + C = (99, 98, 97, 96, 95, 94, 93, 92, 91, 90) + expected_D = (1, 11, 2, 12, 3, 13, 4, 14, 5, 15) + expected_E = (1, 11, 98, 99, 2, 12, 96, 97, 3, 13, 94, 95, + 4, 14, 92, 93, 5, 15, 90, 91) + mapping = [[(0, 0), (1, 0)], # mapping to produce D + [(0, 0), (1, 0), (2, 1), (2, 0)], # mapping to produce E + ] + srcA = blocks.vector_source_f(A, False, 1) + srcB = blocks.vector_source_f(B, False, 1) + srcC = blocks.vector_source_f(C, False, 2) + vmap = blocks.vector_map(gr.sizeof_int, (1, 1, 2), mapping) + dstD = blocks.vector_sink_f(2) + dstE = blocks.vector_sink_f(4) + self.tb.connect(srcA, (vmap, 0)) + self.tb.connect(srcB, (vmap, 1)) + self.tb.connect(srcC, (vmap, 2)) + self.tb.connect((vmap, 0), dstD) + self.tb.connect((vmap, 1), dstE) + self.tb.run() + self.assertEqual(expected_D, dstD.data()) + self.assertEqual(expected_E, dstE.data()) + +if __name__ == '__main__': + gr_unittest.run(test_vector_map, "test_vector_map.xml") + diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index 41202bb4b1..37d9c251ae 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -30,6 +30,9 @@ %include <gr_endianness.h> +%template() std::vector<size_t>; +%template() std::vector< std::vector< std::vector<size_t> > >; + %{ #include "blocks/add_ff.h" #include "blocks/add_ss.h" @@ -124,9 +127,12 @@ #include "blocks/mute_ff.h" #include "blocks/mute_cc.h" #include "blocks/nlog10_ff.h" +#include "blocks/nop.h" #include "blocks/not_bb.h" #include "blocks/not_ss.h" #include "blocks/not_ii.h" +#include "blocks/null_sink.h" +#include "blocks/null_source.h" #include "blocks/patterned_interleaver.h" #include "blocks/pack_k_bits_bb.h" #include "blocks/packed_to_unpacked_bb.h" @@ -190,6 +196,7 @@ #include "blocks/unpacked_to_packed_ss.h" #include "blocks/unpacked_to_packed_ii.h" #include "blocks/vco_f.h" +#include "blocks/vector_map.h" #include "blocks/vector_to_stream.h" #include "blocks/vector_to_streams.h" #include "blocks/vector_insert_b.h" @@ -307,9 +314,12 @@ %include "blocks/mute_ff.h" %include "blocks/mute_cc.h" %include "blocks/nlog10_ff.h" +%include "blocks/nop.h" %include "blocks/not_bb.h" %include "blocks/not_ss.h" %include "blocks/not_ii.h" +%include "blocks/null_sink.h" +%include "blocks/null_source.h" %include "blocks/probe_signal_b.h" %include "blocks/probe_signal_s.h" %include "blocks/probe_signal_i.h" @@ -373,6 +383,7 @@ %include "blocks/unpacked_to_packed_ss.h" %include "blocks/unpacked_to_packed_ii.h" %include "blocks/vco_f.h" +%include "blocks/vector_map.h" %include "blocks/vector_to_stream.h" %include "blocks/vector_to_streams.h" %include "blocks/vector_insert_b.h" @@ -488,9 +499,12 @@ GR_SWIG_BLOCK_MAGIC2(blocks, mute_ii); GR_SWIG_BLOCK_MAGIC2(blocks, mute_ff); GR_SWIG_BLOCK_MAGIC2(blocks, mute_cc); GR_SWIG_BLOCK_MAGIC2(blocks, nlog10_ff); +GR_SWIG_BLOCK_MAGIC2(blocks, nop); GR_SWIG_BLOCK_MAGIC2(blocks, not_bb); GR_SWIG_BLOCK_MAGIC2(blocks, not_ss); GR_SWIG_BLOCK_MAGIC2(blocks, not_ii); +GR_SWIG_BLOCK_MAGIC2(blocks, null_sink); +GR_SWIG_BLOCK_MAGIC2(blocks, null_source); GR_SWIG_BLOCK_MAGIC2(blocks, patterned_interleaver); GR_SWIG_BLOCK_MAGIC2(blocks, pack_k_bits_bb); GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_bb); @@ -554,6 +568,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_bb); GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_ss); GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_ii); GR_SWIG_BLOCK_MAGIC2(blocks, vco_f); +GR_SWIG_BLOCK_MAGIC2(blocks, vector_map); GR_SWIG_BLOCK_MAGIC2(blocks, vector_to_stream); GR_SWIG_BLOCK_MAGIC2(blocks, vector_to_streams); GR_SWIG_BLOCK_MAGIC2(blocks, vector_insert_b); |