From b434b7329301fee49ab82a81ac68517f8ab042eb Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Thu, 30 Aug 2012 14:29:28 -0700
Subject: blocks: added gr::blocks::stream_to_streams
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_stream_to_streams.xml | 67 +++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/stream_to_streams.h | 52 ++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/stream_to_streams_impl.cc | 70 ++++++++++++++
gr-blocks/lib/stream_to_streams_impl.h | 44 +++++++++
gr-blocks/python/qa_pipe_fittings.py | 138 +++++++++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 3 +
9 files changed, 377 insertions(+)
create mode 100644 gr-blocks/grc/blocks_stream_to_streams.xml
create mode 100644 gr-blocks/include/blocks/stream_to_streams.h
create mode 100644 gr-blocks/lib/stream_to_streams_impl.cc
create mode 100644 gr-blocks/lib/stream_to_streams_impl.h
create mode 100755 gr-blocks/python/qa_pipe_fittings.py
(limited to 'gr-blocks')
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 8f98f15e0..076c1b221 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -79,5 +79,6 @@
blocks_keep_one_in_n.xmlblocks_repeat.xmlstream_mux.xml
+ stream_to_streams.xml
diff --git a/gr-blocks/grc/blocks_stream_to_streams.xml b/gr-blocks/grc/blocks_stream_to_streams.xml
new file mode 100644
index 000000000..c164e477b
--- /dev/null
+++ b/gr-blocks/grc/blocks_stream_to_streams.xml
@@ -0,0 +1,67 @@
+
+
+
+ Stream to Streams
+ blocks_stream_to_streams
+ from gnuradio import blocks
+ blocks.stream_to_streams($type.size*$vlen, $num_streams)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+
+ Num Streams
+ num_streams
+ 2
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $num_streams > 0
+ $vlen >= 1
+
+ in
+ $type
+ $vlen
+
+
+ out
+ $type
+ $vlen
+ $num_streams
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 7ec0524ae..191f15031 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -121,6 +121,7 @@ install(FILES
short_to_char.h
short_to_float.h
stream_mux.h
+ stream_to_streams.h
uchar_to_float.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
diff --git a/gr-blocks/include/blocks/stream_to_streams.h b/gr-blocks/include/blocks/stream_to_streams.h
new file mode 100644
index 000000000..fc39f1687
--- /dev/null
+++ b/gr-blocks/include/blocks/stream_to_streams.h
@@ -0,0 +1,52 @@
+/* -*- 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_STREAMS_H
+#define INCLUDED_BLOCKS_STREAM_TO_STREAMS_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief convert a stream of items into a N streams of items
+ * \ingroup slicedice_blk
+ *
+ * Converts a stream of N items into N streams of 1 item.
+ * Repeat ad infinitum.
+ */
+ class BLOCKS_API stream_to_streams : virtual public gr_sync_decimator
+ {
+ public:
+
+ // gr::blocks::stream_to_streams::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t itemsize, size_t nstreams);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_STREAM_TO_STREAMS_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 72e09d5f9..4cb3bc995 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -158,6 +158,7 @@ list(APPEND gr_blocks_sources
short_to_char_impl.cc
short_to_float_impl.cc
stream_mux_impl.cc
+ stream_to_streams_impl.cc
uchar_array_to_float.cc
uchar_to_float_impl.cc
)
diff --git a/gr-blocks/lib/stream_to_streams_impl.cc b/gr-blocks/lib/stream_to_streams_impl.cc
new file mode 100644
index 000000000..9e9052e7d
--- /dev/null
+++ b/gr-blocks/lib/stream_to_streams_impl.cc
@@ -0,0 +1,70 @@
+/* -*- 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_streams_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ stream_to_streams::sptr stream_to_streams::make(size_t itemsize, size_t nstreams)
+ {
+ return gnuradio::get_initial_sptr(new stream_to_streams_impl(itemsize, nstreams));
+ }
+
+ stream_to_streams_impl::stream_to_streams_impl(size_t itemsize, size_t nstreams)
+ : gr_sync_decimator("stream_to_streams",
+ gr_make_io_signature (1, 1, itemsize),
+ gr_make_io_signature (nstreams, nstreams, itemsize),
+ nstreams)
+ {
+ }
+
+ int
+ stream_to_streams_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ size_t item_size = output_signature()->sizeof_stream_item(0);
+
+ const char *in = (const char *)input_items[0];
+ char **outv = (char **)&output_items[0];
+ int nstreams = output_items.size();
+
+ for (int i = 0; i < noutput_items; i++) {
+ for (int j = 0; j < nstreams; j++) {
+ memcpy(outv[j], in, item_size);
+ outv[j] += item_size;
+ in += item_size;
+ }
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/stream_to_streams_impl.h b/gr-blocks/lib/stream_to_streams_impl.h
new file mode 100644
index 000000000..9a96983ff
--- /dev/null
+++ b/gr-blocks/lib/stream_to_streams_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_STREAMS_IMPL_H
+#define INCLUDED_STREAM_TO_STREAMS_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API stream_to_streams_impl : public stream_to_streams
+ {
+ public:
+ stream_to_streams_impl(size_t itemsize, size_t nstreams);
+
+ 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_STREAMS_IMPL_H */
diff --git a/gr-blocks/python/qa_pipe_fittings.py b/gr-blocks/python/qa_pipe_fittings.py
new file mode 100755
index 000000000..097856867
--- /dev/null
+++ b/gr-blocks/python/qa_pipe_fittings.py
@@ -0,0 +1,138 @@
+#!/usr/bin/env python
+#
+# Copyright 2005,2007,2010,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.
+#
+
+from gnuradio import gr, gr_unittest
+import blocks_swig
+
+def calc_expected_result(src_data, n):
+ assert (len(src_data) % n) == 0
+ result = [list() for x in range(n)]
+ #print "len(result) =", len(result)
+ for i in xrange(len(src_data)):
+ (result[i % n]).append(src_data[i])
+ return [tuple(x) for x in result]
+
+
+class test_pipe_fittings(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block ()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_001(self):
+ """
+ Test stream_to_streams.
+ """
+ n = 8
+ src_len = n * 8
+ src_data = range(src_len)
+
+ expected_results = calc_expected_result(src_data, n)
+ #print "expected results: ", expected_results
+ src = gr.vector_source_i(src_data)
+ op = gr.stream_to_streams(gr.sizeof_int, n)
+ self.tb.connect(src, op)
+
+ dsts = []
+ for i in range(n):
+ dst = gr.vector_sink_i()
+ self.tb.connect((op, i), (dst, 0))
+ dsts.append(dst)
+
+ self.tb.run()
+
+ for d in range(n):
+ self.assertEqual(expected_results[d], dsts[d].data())
+ """
+ def test_002(self):
+
+ # Test streams_to_stream (using stream_to_streams).
+
+ n = 8
+ src_len = n * 8
+ src_data = tuple(range(src_len))
+ expected_results = src_data
+
+ src = gr.vector_source_i(src_data)
+ op1 = gr.stream_to_streams(gr.sizeof_int, n)
+ op2 = gr.streams_to_stream(gr.sizeof_int, n)
+ dst = gr.vector_sink_i()
+
+ self.tb.connect(src, op1)
+ for i in range(n):
+ self.tb.connect((op1, i), (op2, i))
+ self.tb.connect(op2, dst)
+
+ self.tb.run()
+ self.assertEqual(expected_results, dst.data())
+
+ def test_003(self):
+
+ #Test streams_to_vector (using stream_to_streams & vector_to_stream).
+
+ n = 8
+ src_len = n * 8
+ src_data = tuple(range(src_len))
+ expected_results = src_data
+
+ src = gr.vector_source_i(src_data)
+ op1 = gr.stream_to_streams(gr.sizeof_int, n)
+ op2 = gr.streams_to_vector(gr.sizeof_int, n)
+ op3 = gr.vector_to_stream(gr.sizeof_int, n)
+ dst = gr.vector_sink_i()
+
+ self.tb.connect(src, op1)
+ for i in range(n):
+ self.tb.connect((op1, i), (op2, i))
+ self.tb.connect(op2, op3, dst)
+
+ self.tb.run()
+ self.assertEqual(expected_results, dst.data())
+
+ def test_004(self):
+
+ #Test vector_to_streams.
+
+ n = 8
+ src_len = n * 8
+ src_data = tuple(range(src_len))
+ expected_results = src_data
+
+ src = gr.vector_source_i(src_data)
+ op1 = gr.stream_to_vector(gr.sizeof_int, n)
+ op2 = gr.vector_to_streams(gr.sizeof_int, n)
+ op3 = gr.streams_to_stream(gr.sizeof_int, n)
+ dst = gr.vector_sink_i()
+
+ self.tb.connect(src, op1, op2)
+ for i in range(n):
+ self.tb.connect((op2, i), (op3, i))
+ self.tb.connect(op3, dst)
+
+ self.tb.run()
+ self.assertEqual(expected_results, dst.data())
+ """
+
+if __name__ == '__main__':
+ gr_unittest.run(test_pipe_fittings, "test_pipe_fittings.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index a99d90d4f..903f56550 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -99,6 +99,7 @@
#include "blocks/short_to_char.h"
#include "blocks/short_to_float.h"
#include "blocks/stream_mux.h"
+#include "blocks/stream_to_streams.h"
#include "blocks/sub_ff.h"
#include "blocks/sub_ss.h"
#include "blocks/sub_ii.h"
@@ -180,6 +181,7 @@
%include "blocks/short_to_char.h"
%include "blocks/short_to_float.h"
%include "blocks/stream_mux.h"
+%include "blocks/stream_to_streams.h"
%include "blocks/sub_ff.h"
%include "blocks/sub_ss.h"
%include "blocks/sub_ii.h"
@@ -260,6 +262,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, repeat);
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, sub_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
--
cgit