From 0aec5b7f568b0cfc320a202631757efc247aca6e Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 4 Sep 2012 15:21:35 -0700 Subject: blocks: added gr::blocks::stream_to_vector --- gr-blocks/grc/blocks_block_tree.xml | 1 + gr-blocks/grc/blocks_stream_to_vector.xml | 66 +++++++++++++++++++++++++++++ gr-blocks/include/blocks/CMakeLists.txt | 1 + gr-blocks/include/blocks/stream_to_vector.h | 49 +++++++++++++++++++++ gr-blocks/lib/CMakeLists.txt | 1 + gr-blocks/lib/stream_to_vector_impl.cc | 62 +++++++++++++++++++++++++++ gr-blocks/lib/stream_to_vector_impl.h | 44 +++++++++++++++++++ gr-blocks/swig/blocks_swig.i | 3 ++ 8 files changed, 227 insertions(+) create mode 100644 gr-blocks/grc/blocks_stream_to_vector.xml create mode 100644 gr-blocks/include/blocks/stream_to_vector.h create mode 100644 gr-blocks/lib/stream_to_vector_impl.cc create mode 100644 gr-blocks/lib/stream_to_vector_impl.h (limited to 'gr-blocks') diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 076c1b221..6bd39c4f4 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -80,5 +80,6 @@ blocks_repeat.xml stream_mux.xml stream_to_streams.xml + stream_to_vector.xml diff --git a/gr-blocks/grc/blocks_stream_to_vector.xml b/gr-blocks/grc/blocks_stream_to_vector.xml new file mode 100644 index 000000000..8965dfbfe --- /dev/null +++ b/gr-blocks/grc/blocks_stream_to_vector.xml @@ -0,0 +1,66 @@ + + + + Stream to Vector + blocks_stream_to_vector + from gnuradio import blocks + blocks.stream_to_vector($type.size*$vlen, $num_items) + + IO Type + type + enum + + + + + + + + Num Items + num_items + 2 + int + + + Vec Length + vlen + 1 + int + + $num_items > 0 + $vlen >= 1 + + in + $type + $vlen + + + out + $type + $vlen*$num_items + + diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index 191f15031..1612ea7ec 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -122,6 +122,7 @@ install(FILES short_to_float.h stream_mux.h stream_to_streams.h + stream_to_vector.h uchar_to_float.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks COMPONENT "blocks_devel" diff --git a/gr-blocks/include/blocks/stream_to_vector.h b/gr-blocks/include/blocks/stream_to_vector.h new file mode 100644 index 000000000..8311eb350 --- /dev/null +++ b/gr-blocks/include/blocks/stream_to_vector.h @@ -0,0 +1,49 @@ +/* -*- c++ -*- */ +/* + * 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_BLOCKS_STREAM_TO_VECTOR_H +#define INCLUDED_BLOCKS_STREAM_TO_VECTOR_H + +#include +#include + +namespace gr { + namespace blocks { + + /*! + * \brief convert a stream of items into a stream of blocks containing nitems_per_block + * \ingroup slicedice_blk + */ + class BLOCKS_API stream_to_vector : virtual public gr_sync_decimator + { + public: + + // gr::blocks::stream_to_vector::sptr + typedef boost::shared_ptr sptr; + + static sptr make(size_t itemsize, size_t nitems_per_block); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_BLOCKS_STREAM_TO_VECTOR_H */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 4cb3bc995..df0fa87af 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -159,6 +159,7 @@ list(APPEND gr_blocks_sources short_to_float_impl.cc stream_mux_impl.cc stream_to_streams_impl.cc + stream_to_vector_impl.cc uchar_array_to_float.cc uchar_to_float_impl.cc ) diff --git a/gr-blocks/lib/stream_to_vector_impl.cc b/gr-blocks/lib/stream_to_vector_impl.cc new file mode 100644 index 000000000..80ced5a74 --- /dev/null +++ b/gr-blocks/lib/stream_to_vector_impl.cc @@ -0,0 +1,62 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "stream_to_vector_impl.h" +#include + +namespace gr { + namespace blocks { + + stream_to_vector::sptr stream_to_vector::make(size_t itemsize, size_t nitems_per_block) + { + return gnuradio::get_initial_sptr(new stream_to_vector_impl(itemsize, nitems_per_block)); + } + + stream_to_vector_impl::stream_to_vector_impl(size_t itemsize, size_t nitems_per_block) + : gr_sync_decimator ("stream_to_vector", + gr_make_io_signature (1, 1, itemsize), + gr_make_io_signature (1, 1, itemsize * nitems_per_block), + nitems_per_block) + { + } + + int + stream_to_vector_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + size_t block_size = output_signature()->sizeof_stream_item (0); + + const char *in = (const char *) input_items[0]; + char *out = (char *) output_items[0]; + + memcpy (out, in, noutput_items * block_size); + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/stream_to_vector_impl.h b/gr-blocks/lib/stream_to_vector_impl.h new file mode 100644 index 000000000..f8031f005 --- /dev/null +++ b/gr-blocks/lib/stream_to_vector_impl.h @@ -0,0 +1,44 @@ +/* -*- c++ -*- */ +/* + * 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_STREAM_TO_VECTOR_IMPL_H +#define INCLUDED_STREAM_TO_VECTOR_IMPL_H + +#include + +namespace gr { + namespace blocks { + + class BLOCKS_API stream_to_vector_impl : public stream_to_vector + { + public: + stream_to_vector_impl(size_t itemsize, size_t nitems_per_block); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_STREAM_TO_VECTOR_IMPL_H */ diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index 903f56550..64996f2b2 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -100,6 +100,7 @@ #include "blocks/short_to_float.h" #include "blocks/stream_mux.h" #include "blocks/stream_to_streams.h" +#include "blocks/stream_to_vector.h" #include "blocks/sub_ff.h" #include "blocks/sub_ss.h" #include "blocks/sub_ii.h" @@ -182,6 +183,7 @@ %include "blocks/short_to_float.h" %include "blocks/stream_mux.h" %include "blocks/stream_to_streams.h" +%include "blocks/stream_to_vector.h" %include "blocks/sub_ff.h" %include "blocks/sub_ss.h" %include "blocks/sub_ii.h" @@ -263,6 +265,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, short_to_char); GR_SWIG_BLOCK_MAGIC2(blocks, short_to_float); GR_SWIG_BLOCK_MAGIC2(blocks, stream_mux); GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_streams); +GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_vector); GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff); GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss); GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii); -- cgit