]> git.gag.com Git - debian/gnuradio/commitdiff
Added optional vlen parameter to vector_source_* and vector_sink_*.
authoreb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Mon, 27 Oct 2008 07:02:48 +0000 (07:02 +0000)
committereb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Mon, 27 Oct 2008 07:02:48 +0000 (07:02 +0000)
Merged from eb/frank 9627:9868 to trunk.

git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9869 221aa14e-8319-0410-a670-987f0aec2ac5

gnuradio-core/src/lib/gengen/gr_vector_sink_X.cc.t
gnuradio-core/src/lib/gengen/gr_vector_sink_X.h.t
gnuradio-core/src/lib/gengen/gr_vector_sink_X.i.t
gnuradio-core/src/lib/gengen/gr_vector_source_X.cc.t
gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t
gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t
gnuradio-core/src/python/gnuradio/gr/qa_vector_sink_source.py [new file with mode: 0755]

index 303ac4cdd100257ca9ae59ddd8ca9b72a81cd280..b2a6c4ac4e66d1e68f01031095c2f686ef6a42ca 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2004 Free Software Foundation, Inc.
+ * Copyright 2004,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
 #include <gr_io_signature.h>
 
 
-@NAME@::@NAME@ ()
+@NAME@::@NAME@ (int vlen)
   : gr_sync_block ("@BASE_NAME@",
-              gr_make_io_signature (1, 1, sizeof (@TYPE@)),
-              gr_make_io_signature (0, 0, 0))
+                  gr_make_io_signature (1, 1, sizeof (@TYPE@) * vlen),
+                  gr_make_io_signature (0, 0, 0)),
+    d_vlen(vlen)
 {
 }
 
@@ -43,7 +44,7 @@ int
                    gr_vector_void_star &output_items)
 {
   @TYPE@ *iptr = (@TYPE@ *) input_items[0];
-  for (int i = 0; i < noutput_items; i++)
+  for (int i = 0; i < noutput_items * d_vlen; i++)
     d_data.push_back (iptr[i]);
 
   return noutput_items;
@@ -51,9 +52,9 @@ int
 
 
 @NAME@_sptr
-gr_make_@BASE_NAME@ ()
+gr_make_@BASE_NAME@ (int vlen)
 {
-  return @NAME@_sptr (new @NAME@ ());
+  return @NAME@_sptr (new @NAME@ (vlen));
 }
 
 std::vector<@TYPE@>
index ec0ebb8bbf36123d04d45b10b3eaf02f6328e872..70711d63c46a6538997343089f5edb3d11d62c58 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2004 Free Software Foundation, Inc.
+ * Copyright 2004,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -31,7 +31,7 @@ class @NAME@;
 typedef boost::shared_ptr<@NAME@> @NAME@_sptr;
 
 @NAME@_sptr
-gr_make_@BASE_NAME@ ();
+gr_make_@BASE_NAME@ (int vlen = 1);
 
 
 /*!
@@ -40,9 +40,10 @@ gr_make_@BASE_NAME@ ();
  */
 
 class @NAME@ : public gr_sync_block {
-  friend @NAME@_sptr gr_make_@BASE_NAME@ ();
+  friend @NAME@_sptr gr_make_@BASE_NAME@ (int vlen);
   std::vector<@TYPE@>  d_data;
-  @NAME@ ();
+  int                  d_vlen;
+  @NAME@ (int vlen);
 
  public:
   virtual int work (int noutput_items,
index 56317112373272eb75ed5d947ba53db0e6d1d37d..22d6faa1aa73bb8789e1a9d131bb20b1002b9ff7 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2004 Free Software Foundation, Inc.
+ * Copyright 2004,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
 
 GR_SWIG_BLOCK_MAGIC(gr,@BASE_NAME@);
 
-@SPTR_NAME@ gr_make_@BASE_NAME@ ();
+@SPTR_NAME@ gr_make_@BASE_NAME@ (int vlen = 1);
 
 class @NAME@ : public gr_sync_block {
  private:
-  @NAME@ ();
+  @NAME@ (int vlen);
 
  public:
   void clear() {d_data.clear();}
index 528a7c40d274bbbcca78f47f9e875a352288d576..889a6f22c27adb2a9b730ab79f422a2a20a00766 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2004 Free Software Foundation, Inc.
+ * Copyright 2004,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
 #include <@NAME@.h>
 #include <algorithm>
 #include <gr_io_signature.h>
+#include <stdexcept>
 
 
-@NAME@::@NAME@ (const std::vector<@TYPE@> &data, bool repeat)
+@NAME@::@NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen)
   : gr_sync_block ("@BASE_NAME@",
               gr_make_io_signature (0, 0, 0),
-              gr_make_io_signature (1, 1, sizeof (@TYPE@))),
+              gr_make_io_signature (1, 1, sizeof (@TYPE@) * vlen)),
     d_data (data),
     d_repeat (repeat),
-    d_offset (0)
+    d_offset (0),
+    d_vlen (vlen)
 {
+  if ((data.size() % vlen) != 0)
+    throw std::invalid_argument("data length must be a multiple of vlen");
 }
 
 int
@@ -54,7 +58,7 @@ int
     if (size == 0)
       return -1;
     
-    for (int i = 0; i < noutput_items; i++){
+    for (int i = 0; i < noutput_items*d_vlen; i++){
       optr[i] = d_data[offset++];
       if (offset >= size)
        offset = 0;
@@ -68,18 +72,18 @@ int
       return -1;                       // Done!
 
     unsigned n = std::min ((unsigned) d_data.size () - d_offset,
-                          (unsigned) noutput_items);
+                          (unsigned) noutput_items*d_vlen);
     for (unsigned i = 0; i < n; i++)
       optr[i] = d_data[d_offset + i];
 
     d_offset += n;
-    return n;
+    return n/d_vlen;
   }
 }
 
 @NAME@_sptr
-gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat)
+gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen)
 {
-  return @NAME@_sptr (new @NAME@ (data, repeat));
+  return @NAME@_sptr (new @NAME@ (data, repeat, vlen));
 }
 
index 0b8d92a9c9215779ca628f1b4c460210eba9f54d..88d34f362208f9822b8b12beee20c1755b7eda22 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2004 Free Software Foundation, Inc.
+ * Copyright 2004,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -37,13 +37,14 @@ typedef boost::shared_ptr<@NAME@> @NAME@_sptr;
 
 class @NAME@ : public gr_sync_block {
   friend @NAME@_sptr 
-  gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat = false);
+  gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen);
 
   std::vector<@TYPE@>  d_data;
   bool                 d_repeat;
   unsigned int         d_offset;
+  int                  d_vlen;
 
-  @NAME@ (const std::vector<@TYPE@> &data, bool repeat);
+  @NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen);
 
  public:
   void rewind() {d_offset=0;}
@@ -53,6 +54,6 @@ class @NAME@ : public gr_sync_block {
 };
 
 @NAME@_sptr
-gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat);
+gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat = false, int vlen = 1);
 
 #endif
index 1e94ce401abc21915ed08db79672e524bc74e52b..a22157893598ea73b57d0f708e4699397ddc43ba 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2004 Free Software Foundation, Inc.
+ * Copyright 2004,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
 GR_SWIG_BLOCK_MAGIC(gr,@BASE_NAME@);
 
 @NAME@_sptr
-gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat = false);
+gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat = false, int vlen = 1)
+  throw(std::invalid_argument);
 
 class @NAME@ : public gr_sync_block {
  public:
   void rewind() {d_offset=0;}
  private:
-  @NAME@ (const std::vector<@TYPE@> &data);
+  @NAME@ (const std::vector<@TYPE@> &data, int vlen);
 };
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_vector_sink_source.py b/gnuradio-core/src/python/gnuradio/gr/qa_vector_sink_source.py
new file mode 100755 (executable)
index 0000000..149c669
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+#
+# Copyright 2008 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 math
+
+class test_sink_source(gr_unittest.TestCase):
+
+    def setUp (self):
+        self.tb = gr.top_block ()
+
+    def tearDown (self):
+        self.tb = None
+
+    def test_001(self):
+        src_data = [float(x) for x in range(16)]
+        expected_result = tuple(src_data)
+
+        src = gr.vector_source_f(src_data)
+        dst = gr.vector_sink_f()
+
+        self.tb.connect(src, dst)
+        self.tb.run()
+        result_data = dst.data()
+        self.assertEqual(expected_result, result_data)
+
+    def test_002(self):
+        src_data = [float(x) for x in range(16)]
+        expected_result = tuple(src_data)
+
+        src = gr.vector_source_f(src_data, False, 2)
+        dst = gr.vector_sink_f(2)
+
+        self.tb.connect(src, dst)
+        self.tb.run()
+        result_data = dst.data()
+        self.assertEqual(expected_result, result_data)
+
+    def test_003(self):
+        src_data = [float(x) for x in range(16)]
+        expected_result = tuple(src_data)
+        self.assertRaises(ValueError, lambda : gr.vector_source_f(src_data, False, 3))
+
+if __name__ == '__main__':
+    gr_unittest.main ()
+