commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 39/46: Add sub_source block and fix pub_sin


From: git
Subject: [Commit-gnuradio] [gnuradio] 39/46: Add sub_source block and fix pub_sink
Date: Fri, 16 May 2014 19:37:17 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 9970854f8938fcc015608dc163442467427cb9a6
Author: Camilo Solano <address@hidden>
Date:   Tue May 13 12:53:23 2014 +0200

    Add sub_source block and fix pub_sink
---
 gr-zeromq/examples/python/client.py                |   3 +-
 gr-zeromq/examples/python/server.py                |   3 +-
 gr-zeromq/examples/zeromq_pubsub.grc               | 481 +++++++++++++++++++++
 gr-zeromq/grc/CMakeLists.txt                       |   1 +
 gr-zeromq/grc/zeromq_pub_sink.xml                  |  16 +-
 .../{zeromq_pub_sink.xml => zeromq_sub_source.xml} |  27 +-
 gr-zeromq/include/gnuradio/zeromq/CMakeLists.txt   |   1 +
 gr-zeromq/include/gnuradio/zeromq/pub_sink.h       |   2 +-
 gr-zeromq/include/gnuradio/zeromq/pull_source.h    |   2 +-
 .../zeromq/{pull_source.h => sub_source.h}         |  16 +-
 gr-zeromq/lib/CMakeLists.txt                       |   1 +
 gr-zeromq/lib/pub_sink_impl.cc                     |  13 +-
 gr-zeromq/lib/pub_sink_impl.h                      |   3 +-
 gr-zeromq/lib/sub_source_impl.cc                   | 102 +++++
 .../lib/{pub_sink_impl.h => sub_source_impl.h}     |  28 +-
 gr-zeromq/swig/zeromq_swig.i                       |   3 +
 16 files changed, 661 insertions(+), 41 deletions(-)

diff --git a/gr-zeromq/examples/python/client.py 
b/gr-zeromq/examples/python/client.py
index 3d55cc9..7663f9a 100755
--- a/gr-zeromq/examples/python/client.py
+++ b/gr-zeromq/examples/python/client.py
@@ -50,8 +50,9 @@ class top_block(gr.top_block):
         source_adr = "tcp://"+self.options.servername+":5555"
 
         # blocks
-        self.zmq_source = zeromq.req_source(gr.sizeof_float, 1, source_adr)
+        #self.zmq_source = zeromq.req_source(gr.sizeof_float, 1, source_adr)
         #self.zmq_source = zeromq.pull_source(gr.sizeof_float, 1, source_adr)
+        self.zmq_source = zeromq.sub_source(gr.sizeof_float, 1, source_adr)
         #self.zmq_probe = zeromq.push_sink(gr.sizeof_float,probe_adr)
         self.zmq_probe = zeromq.pub_sink(gr.sizeof_float,probe_adr)
 
diff --git a/gr-zeromq/examples/python/server.py 
b/gr-zeromq/examples/python/server.py
index 28b732e..358b66c 100755
--- a/gr-zeromq/examples/python/server.py
+++ b/gr-zeromq/examples/python/server.py
@@ -56,7 +56,8 @@ class top_block(gr.top_block):
         self.gr_sig_source = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE 
, 1000, 1, 0)
         self.throttle = blocks.throttle(gr.sizeof_float, samp_rate)
         self.mult = blocks.multiply_const_ff(1)
-        self.zmq_sink = zeromq.rep_sink(gr.sizeof_float, 1, sink_adr)
+        #self.zmq_sink = zeromq.rep_sink(gr.sizeof_float, 1, sink_adr)
+        self.zmq_sink = zeromq.pub_sink(gr.sizeof_float, 1, sink_adr)
         #self.zmq_sink = zeromq.push_sink(gr.sizeof_float, 1, sink_adr)
         #self.zmq_probe = zeromq.push_sink(gr.sizeof_float, probe_adr)
         self.zmq_probe = zeromq.pub_sink(gr.sizeof_float, probe_adr)
diff --git a/gr-zeromq/examples/zeromq_pubsub.grc 
b/gr-zeromq/examples/zeromq_pubsub.grc
new file mode 100644
index 0000000..89e9802
--- /dev/null
+++ b/gr-zeromq/examples/zeromq_pubsub.grc
@@ -0,0 +1,481 @@
+<?xml version='1.0' encoding='ASCII'?>
+<flow_graph>
+  <timestamp>Tue May 13 12:47:08 2014</timestamp>
+  <block>
+    <key>options</key>
+    <param>
+      <key>id</key>
+      <value>top_block</value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>title</key>
+      <value></value>
+    </param>
+    <param>
+      <key>author</key>
+      <value></value>
+    </param>
+    <param>
+      <key>description</key>
+      <value></value>
+    </param>
+    <param>
+      <key>window_size</key>
+      <value>1280, 1024</value>
+    </param>
+    <param>
+      <key>generate_options</key>
+      <value>wx_gui</value>
+    </param>
+    <param>
+      <key>category</key>
+      <value>Custom</value>
+    </param>
+    <param>
+      <key>run_options</key>
+      <value>prompt</value>
+    </param>
+    <param>
+      <key>run</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>max_nouts</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>realtime_scheduling</key>
+      <value></value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(10, 10)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+  </block>
+  <block>
+    <key>variable</key>
+    <param>
+      <key>id</key>
+      <value>samp_rate</value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>value</key>
+      <value>32000</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(10, 170)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+  </block>
+  <block>
+    <key>analog_sig_source_x</key>
+    <param>
+      <key>id</key>
+      <value>analog_sig_source_x_0</value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>type</key>
+      <value>complex</value>
+    </param>
+    <param>
+      <key>samp_rate</key>
+      <value>samp_rate</value>
+    </param>
+    <param>
+      <key>waveform</key>
+      <value>analog.GR_TRI_WAVE</value>
+    </param>
+    <param>
+      <key>freq</key>
+      <value>2000</value>
+    </param>
+    <param>
+      <key>amp</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>offset</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>minoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>maxoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(170, 78)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+  </block>
+  <block>
+    <key>analog_fastnoise_source_x</key>
+    <param>
+      <key>id</key>
+      <value>analog_fastnoise_source_x_0</value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>type</key>
+      <value>complex</value>
+    </param>
+    <param>
+      <key>noise_type</key>
+      <value>analog.GR_GAUSSIAN</value>
+    </param>
+    <param>
+      <key>amp</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>seed</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>samples</key>
+      <value>8192</value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>minoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>maxoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(169, 196)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+  </block>
+  <block>
+    <key>blocks_add_xx</key>
+    <param>
+      <key>id</key>
+      <value>blocks_add_xx_0</value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>type</key>
+      <value>complex</value>
+    </param>
+    <param>
+      <key>num_inputs</key>
+      <value>2</value>
+    </param>
+    <param>
+      <key>vlen</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>minoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>maxoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(403, 116)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+  </block>
+  <block>
+    <key>blocks_throttle</key>
+    <param>
+      <key>id</key>
+      <value>blocks_throttle_0</value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>type</key>
+      <value>complex</value>
+    </param>
+    <param>
+      <key>samples_per_second</key>
+      <value>samp_rate</value>
+    </param>
+    <param>
+      <key>vlen</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>ignoretag</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>minoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>maxoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(537, 114)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+  </block>
+  <block>
+    <key>zeromq_sub_source</key>
+    <param>
+      <key>id</key>
+      <value>zeromq_sub_source_0</value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>type</key>
+      <value>complex</value>
+    </param>
+    <param>
+      <key>vlen</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>address</key>
+      <value>tcp://127.0.0.1:5555</value>
+    </param>
+    <param>
+      <key>timeout</key>
+      <value>100</value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>minoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>maxoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(146, 415)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+  </block>
+  <block>
+    <key>zeromq_pub_sink</key>
+    <param>
+      <key>id</key>
+      <value>zeromq_pub_sink_0</value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>type</key>
+      <value>complex</value>
+    </param>
+    <param>
+      <key>vlen</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>address</key>
+      <value>tcp://127.0.0.1:5555</value>
+    </param>
+    <param>
+      <key>timeout</key>
+      <value>100</value>
+    </param>
+    <param>
+      <key>blocking</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(753, 111)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+  </block>
+  <block>
+    <key>wxgui_scopesink2</key>
+    <param>
+      <key>id</key>
+      <value>wxgui_scopesink2_0</value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>type</key>
+      <value>complex</value>
+    </param>
+    <param>
+      <key>title</key>
+      <value>Scope Plot</value>
+    </param>
+    <param>
+      <key>samp_rate</key>
+      <value>samp_rate</value>
+    </param>
+    <param>
+      <key>v_scale</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>v_offset</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>t_scale</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>ac_couple</key>
+      <value>False</value>
+    </param>
+    <param>
+      <key>xy_mode</key>
+      <value>False</value>
+    </param>
+    <param>
+      <key>num_inputs</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>win_size</key>
+      <value></value>
+    </param>
+    <param>
+      <key>grid_pos</key>
+      <value></value>
+    </param>
+    <param>
+      <key>notebook</key>
+      <value></value>
+    </param>
+    <param>
+      <key>trig_mode</key>
+      <value>wxgui.TRIG_MODE_AUTO</value>
+    </param>
+    <param>
+      <key>y_axis_label</key>
+      <value>Counts</value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(696, 407)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+  </block>
+  <connection>
+    <source_block_id>analog_sig_source_x_0</source_block_id>
+    <sink_block_id>blocks_add_xx_0</sink_block_id>
+    <source_key>0</source_key>
+    <sink_key>0</sink_key>
+  </connection>
+  <connection>
+    <source_block_id>analog_fastnoise_source_x_0</source_block_id>
+    <sink_block_id>blocks_add_xx_0</sink_block_id>
+    <source_key>0</source_key>
+    <sink_key>1</sink_key>
+  </connection>
+  <connection>
+    <source_block_id>blocks_add_xx_0</source_block_id>
+    <sink_block_id>blocks_throttle_0</sink_block_id>
+    <source_key>0</source_key>
+    <sink_key>0</sink_key>
+  </connection>
+  <connection>
+    <source_block_id>blocks_throttle_0</source_block_id>
+    <sink_block_id>zeromq_pub_sink_0</sink_block_id>
+    <source_key>0</source_key>
+    <sink_key>0</sink_key>
+  </connection>
+  <connection>
+    <source_block_id>zeromq_sub_source_0</source_block_id>
+    <sink_block_id>wxgui_scopesink2_0</sink_block_id>
+    <source_key>0</source_key>
+    <sink_key>0</sink_key>
+  </connection>
+</flow_graph>
diff --git a/gr-zeromq/grc/CMakeLists.txt b/gr-zeromq/grc/CMakeLists.txt
index ad65f81..548c2f2 100644
--- a/gr-zeromq/grc/CMakeLists.txt
+++ b/gr-zeromq/grc/CMakeLists.txt
@@ -19,6 +19,7 @@
 
 install(FILES
     zeromq_pub_sink.xml
+    zeromq_sub_source.xml
     zeromq_push_sink.xml
     zeromq_pull_source.xml
     zeromq_rep_sink.xml
diff --git a/gr-zeromq/grc/zeromq_pub_sink.xml 
b/gr-zeromq/grc/zeromq_pub_sink.xml
index 64d26e1..7f0a886 100644
--- a/gr-zeromq/grc/zeromq_pub_sink.xml
+++ b/gr-zeromq/grc/zeromq_pub_sink.xml
@@ -4,7 +4,7 @@
   <key>zeromq_pub_sink</key>
   <category>ZeroMQ Interfaces</category>
   <import>from gnuradio import zeromq</import>
-  <make>zeromq.pub_sink($type.itemsize, $address, $blocking)</make>
+  <make>zeromq.pub_sink($type.itemsize, $vlen, $address, $blocking)</make>
 
   <param>
     <name>IO Type</name>
@@ -38,12 +38,26 @@
   </param>
 
   <param>
+    <name>Vec Length</name>
+    <key>vlen</key>
+    <value>1</value>
+    <type>int</type>
+  </param>
+ 
+  <param>
     <name>Address</name>
     <key>address</key>
     <type>string</type>
   </param>
 
   <param>
+    <name>Timeout (msec)</name>
+    <key>timeout</key>
+    <value>0.1</value>
+    <type>float</type>
+  </param>
+
+  <param>
     <name>Blocking</name>
     <key>blocking</key>
     <value>True</value>
diff --git a/gr-zeromq/grc/zeromq_pub_sink.xml 
b/gr-zeromq/grc/zeromq_sub_source.xml
similarity index 70%
copy from gr-zeromq/grc/zeromq_pub_sink.xml
copy to gr-zeromq/grc/zeromq_sub_source.xml
index 64d26e1..307c981 100644
--- a/gr-zeromq/grc/zeromq_pub_sink.xml
+++ b/gr-zeromq/grc/zeromq_sub_source.xml
@@ -1,10 +1,10 @@
 <?xml version="1.0"?>
 <block>
-  <name>ZMQ PUB Sink</name>
-  <key>zeromq_pub_sink</key>
+  <name>ZMQ SUB Source</name>
+  <key>zeromq_sub_source</key>
   <category>ZeroMQ Interfaces</category>
   <import>from gnuradio import zeromq</import>
-  <make>zeromq.pub_sink($type.itemsize, $address, $blocking)</make>
+  <make>zeromq.sub_source($type.itemsize, $vlen, $address, $timeout)</make>
 
   <param>
     <name>IO Type</name>
@@ -38,21 +38,28 @@
   </param>
 
   <param>
+    <name>Vec Length</name>
+    <key>vlen</key>
+    <value>1</value>
+    <type>int</type>
+  </param>
+
+  <param>
     <name>Address</name>
     <key>address</key>
     <type>string</type>
   </param>
 
   <param>
-    <name>Blocking</name>
-    <key>blocking</key>
-    <value>True</value>
-    <type>bool</type>
+    <name>Timeout (msec)</name>
+    <key>timeout</key>
+    <value>0.1</value>
+    <type>float</type>
   </param>
 
-  <sink>
-    <name>in</name>
+  <source>
+    <name>out</name>
     <type>$type</type>
-  </sink>
+  </source>
 
 </block>
diff --git a/gr-zeromq/include/gnuradio/zeromq/CMakeLists.txt 
b/gr-zeromq/include/gnuradio/zeromq/CMakeLists.txt
index 87e79e0..970cf1c 100644
--- a/gr-zeromq/include/gnuradio/zeromq/CMakeLists.txt
+++ b/gr-zeromq/include/gnuradio/zeromq/CMakeLists.txt
@@ -23,6 +23,7 @@
 install(FILES
   api.h
   pub_sink.h
+  sub_source.h
   pull_source.h
   push_sink.h
   rep_sink.h
diff --git a/gr-zeromq/include/gnuradio/zeromq/pub_sink.h 
b/gr-zeromq/include/gnuradio/zeromq/pub_sink.h
index 483461d..31a5364 100644
--- a/gr-zeromq/include/gnuradio/zeromq/pub_sink.h
+++ b/gr-zeromq/include/gnuradio/zeromq/pub_sink.h
@@ -53,7 +53,7 @@ namespace gr {
        * \param address  ZMQ socket address specifier
        * \param blocking Indicate whether blocking sends should be used, 
default true.
        */
-      static sptr make(size_t itemsize, size_t vlen, char *address);
+      static sptr make(size_t itemsize, size_t vlen, char *address, int 
timeout=100);
     };
 
   } // namespace zeromq
diff --git a/gr-zeromq/include/gnuradio/zeromq/pull_source.h 
b/gr-zeromq/include/gnuradio/zeromq/pull_source.h
index 3a0c943..5c1d37d 100644
--- a/gr-zeromq/include/gnuradio/zeromq/pull_source.h
+++ b/gr-zeromq/include/gnuradio/zeromq/pull_source.h
@@ -34,7 +34,7 @@ namespace gr {
      * \ingroup zeromq
      *
      * \details
-     * This block will connect to a ZMQ PULL socket, then produce all
+     * This block will connect to a ZMQ PUSH socket, then produce all
      * incoming messages as streaming output.
      */
     class ZEROMQ_API pull_source : virtual public gr::sync_block
diff --git a/gr-zeromq/include/gnuradio/zeromq/pull_source.h 
b/gr-zeromq/include/gnuradio/zeromq/sub_source.h
similarity index 80%
copy from gr-zeromq/include/gnuradio/zeromq/pull_source.h
copy to gr-zeromq/include/gnuradio/zeromq/sub_source.h
index 3a0c943..9deaa7f 100644
--- a/gr-zeromq/include/gnuradio/zeromq/pull_source.h
+++ b/gr-zeromq/include/gnuradio/zeromq/sub_source.h
@@ -20,8 +20,8 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef INCLUDED_ZEROMQ_PULL_SOURCE_H
-#define INCLUDED_ZEROMQ_PULL_SOURCE_H
+#ifndef INCLUDED_ZEROMQ_SUB_SOURCE_H
+#define INCLUDED_ZEROMQ_SUB_SOURCE_H
 
 #include <gnuradio/zeromq/api.h>
 #include <gnuradio/sync_block.h>
@@ -30,20 +30,20 @@ namespace gr {
   namespace zeromq {
 
     /*!
-     * \brief Receive messages on ZMQ PULL socket and source stream
+     * \brief Receive messages on ZMQ SUB socket and source stream
      * \ingroup zeromq
      *
      * \details
-     * This block will connect to a ZMQ PULL socket, then produce all
+     * This block will connect to a ZMQ PUB socket, then produce all
      * incoming messages as streaming output.
      */
-    class ZEROMQ_API pull_source : virtual public gr::sync_block
+    class ZEROMQ_API sub_source : virtual public gr::sync_block
     {
     public:
-      typedef boost::shared_ptr<pull_source> sptr;
+      typedef boost::shared_ptr<sub_source> sptr;
 
       /*!
-       * \brief Return a shared_ptr to a new instance of 
gr::zeromq::pull_source.
+       * \brief Return a shared_ptr to a new instance of 
gr::zeromq::sub_source.
        *
        * \param itemsize Size of a stream item in bytes
        * \param vlen Vector length of the input items. Note that one vector is 
one item.
@@ -57,4 +57,4 @@ namespace gr {
   } // namespace zeromq
 } // namespace gr
 
-#endif /* INCLUDED_ZEROMQ_PULL_SOURCE_H */
+#endif /* INCLUDED_ZEROMQ_SUB_SOURCE_H */
diff --git a/gr-zeromq/lib/CMakeLists.txt b/gr-zeromq/lib/CMakeLists.txt
index 57a4c62..cc62c79 100644
--- a/gr-zeromq/lib/CMakeLists.txt
+++ b/gr-zeromq/lib/CMakeLists.txt
@@ -39,6 +39,7 @@ endif(ENABLE_GR_CTRLPORT)
 ########################################################################
 list(APPEND zeromq_sources
   pub_sink_impl.cc
+  sub_source_impl.cc
   pull_source_impl.cc
   push_sink_impl.cc
   rep_sink_impl.cc
diff --git a/gr-zeromq/lib/pub_sink_impl.cc b/gr-zeromq/lib/pub_sink_impl.cc
index 9d387f9..13f8604 100644
--- a/gr-zeromq/lib/pub_sink_impl.cc
+++ b/gr-zeromq/lib/pub_sink_impl.cc
@@ -31,18 +31,23 @@ namespace gr {
   namespace zeromq {
 
     pub_sink::sptr
-    pub_sink::make(size_t itemsize, size_t vlen, char *address)
+    pub_sink::make(size_t itemsize, size_t vlen, char *address, int timeout)
     {
       return gnuradio::get_initial_sptr
-        (new pub_sink_impl(itemsize, vlen, address));
+        (new pub_sink_impl(itemsize, vlen, address, timeout));
     }
 
-    pub_sink_impl::pub_sink_impl(size_t itemsize, size_t vlen, char *address)
+    pub_sink_impl::pub_sink_impl(size_t itemsize, size_t vlen, char *address, 
int timeout)
       : gr::sync_block("pub_sink",
                        gr::io_signature::make(1, 1, itemsize * vlen),
                        gr::io_signature::make(0, 0, 0)),
-        d_itemsize(itemsize), d_vlen(vlen)
+        d_itemsize(itemsize), d_vlen(vlen), d_timeout(timeout)
     {
+      int major, minor, patch;
+      zmq::version (&major, &minor, &patch);
+      if (major < 3) {
+        d_timeout = timeout*1000;
+      }
       d_context = new zmq::context_t(1);
       d_socket = new zmq::socket_t(*d_context, ZMQ_PUB);
       int time = 0;
diff --git a/gr-zeromq/lib/pub_sink_impl.h b/gr-zeromq/lib/pub_sink_impl.h
index bf5abdb..9c956ef 100644
--- a/gr-zeromq/lib/pub_sink_impl.h
+++ b/gr-zeromq/lib/pub_sink_impl.h
@@ -34,11 +34,12 @@ namespace gr {
     private:
       size_t          d_itemsize;
       size_t          d_vlen;
+      float           d_timeout;
       zmq::context_t  *d_context;
       zmq::socket_t   *d_socket;
 
     public:
-      pub_sink_impl(size_t itemsize, size_t vlen, char *address);
+      pub_sink_impl(size_t itemsize, size_t vlen, char *address, int timeout);
       ~pub_sink_impl();
 
       int work(int noutput_items,
diff --git a/gr-zeromq/lib/sub_source_impl.cc b/gr-zeromq/lib/sub_source_impl.cc
new file mode 100644
index 0000000..38ddc78
--- /dev/null
+++ b/gr-zeromq/lib/sub_source_impl.cc
@@ -0,0 +1,102 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2013,2014 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio.
+ *
+ * This 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.
+ *
+ * This software 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 this software; 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 <gnuradio/io_signature.h>
+#include "sub_source_impl.h"
+
+namespace gr {
+  namespace zeromq {
+
+    sub_source::sptr
+    sub_source::make(size_t itemsize, size_t vlen, char *address, int timeout)
+    {
+      return gnuradio::get_initial_sptr
+        (new sub_source_impl(itemsize, vlen, address, timeout));
+    }
+
+    sub_source_impl::sub_source_impl(size_t itemsize, size_t vlen, char 
*address, int timeout)
+      : gr::sync_block("sub_source",
+                       gr::io_signature::make(0, 0, 0),
+                       gr::io_signature::make(1, 1, itemsize * vlen)),
+        d_itemsize(itemsize), d_vlen(vlen), d_timeout(timeout)
+    {
+      int major, minor, patch;
+      zmq::version (&major, &minor, &patch);
+      if (major < 3) {
+        d_timeout = timeout*1000;
+      }
+      d_context = new zmq::context_t(1);
+      d_socket = new zmq::socket_t(*d_context, ZMQ_SUB);
+      //int time = 0;
+      d_socket->setsockopt(ZMQ_SUBSCRIBE, "", 0);
+      d_socket->connect (address);
+    }
+
+    /*
+     * Our virtual destructor.
+     */
+    sub_source_impl::~sub_source_impl()
+    {
+      d_socket->close();
+      delete d_socket;
+      delete d_context;
+    }
+
+    int
+    sub_source_impl::work(int noutput_items,
+                           gr_vector_const_void_star &input_items,
+                           gr_vector_void_star &output_items)
+    {
+      char *out = (char*)output_items[0];
+
+      zmq::pollitem_t items[] = { { *d_socket, 0, ZMQ_POLLIN, 0 } };
+      zmq::poll (&items[0], 1, d_timeout);
+
+      //  If we got a reply, process
+      if (items[0].revents & ZMQ_POLLIN) {
+
+        // Receive data
+        zmq::message_t msg;
+        d_socket->recv(&msg);
+        // Copy to ouput buffer and return
+        if (msg.size() >= d_itemsize*d_vlen*noutput_items) {
+          memcpy(out, (void *)msg.data(), d_itemsize*d_vlen*noutput_items);
+
+          return noutput_items;
+        }
+        else {
+          memcpy(out, (void *)msg.data(), msg.size());
+
+          return msg.size()/(d_itemsize*d_vlen);
+        }
+      }
+      else {
+        return 0; // FIXME: someday when the scheduler does all the 
poll/selects
+      }
+    }
+
+  } /* namespace zeromq */
+} /* namespace gr */
diff --git a/gr-zeromq/lib/pub_sink_impl.h b/gr-zeromq/lib/sub_source_impl.h
similarity index 63%
copy from gr-zeromq/lib/pub_sink_impl.h
copy to gr-zeromq/lib/sub_source_impl.h
index bf5abdb..4464752 100644
--- a/gr-zeromq/lib/pub_sink_impl.h
+++ b/gr-zeromq/lib/sub_source_impl.h
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2013 Free Software Foundation, Inc.
+ * Copyright 2013,2014 Free Software Foundation, Inc.
  *
  * This file is part of GNU Radio.
  *
@@ -20,33 +20,35 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef INCLUDED_ZEROMQ_PUB_SINK_IMPL_H
-#define INCLUDED_ZEROMQ_PUB_SINK_IMPL_H
+#ifndef INCLUDED_ZEROMQ_SUB_SOURCE_IMPL_H
+#define INCLUDED_ZEROMQ_SUB_SOURCE_IMPL_H
 
-#include <gnuradio/zeromq/pub_sink.h>
-#include <zmq.hpp>
+#include <gnuradio/zeromq/sub_source.h>
+#include "zmq.hpp"
 
 namespace gr {
   namespace zeromq {
 
-    class pub_sink_impl : public pub_sink
+    class sub_source_impl : public sub_source
     {
-    private:
+     private:
       size_t          d_itemsize;
       size_t          d_vlen;
+      int             d_timeout; // microseconds, -1 is blocking
       zmq::context_t  *d_context;
       zmq::socket_t   *d_socket;
 
-    public:
-      pub_sink_impl(size_t itemsize, size_t vlen, char *address);
-      ~pub_sink_impl();
+     public:
+      sub_source_impl(size_t itemsize, size_t vlen, char *address, int 
timeout);
+      ~sub_source_impl();
 
       int work(int noutput_items,
-               gr_vector_const_void_star &input_items,
-               gr_vector_void_star &output_items);
+                  gr_vector_const_void_star &input_items,
+                  gr_vector_void_star &output_items);
     };
 
   } // namespace zeromq
 } // namespace gr
 
-#endif /* INCLUDED_ZEROMQ_PUB_SINK_IMPL_H */
+#endif /* INCLUDED_ZEROMQ_SUB_SOURCE_IMPL_H */
+
diff --git a/gr-zeromq/swig/zeromq_swig.i b/gr-zeromq/swig/zeromq_swig.i
index 36f8b2e..bcd9055 100644
--- a/gr-zeromq/swig/zeromq_swig.i
+++ b/gr-zeromq/swig/zeromq_swig.i
@@ -31,6 +31,7 @@
 #include "gnuradio/zeromq/pub_sink.h"
 #include "gnuradio/zeromq/push_sink.h"
 #include "gnuradio/zeromq/rep_sink.h"
+#include "gnuradio/zeromq/sub_source.h"
 #include "gnuradio/zeromq/pull_source.h"
 #include "gnuradio/zeromq/req_source.h"
 %}
@@ -38,11 +39,13 @@
 %include "gnuradio/zeromq/pub_sink.h"
 %include "gnuradio/zeromq/push_sink.h"
 %include "gnuradio/zeromq/rep_sink.h"
+%include "gnuradio/zeromq/sub_source.h"
 %include "gnuradio/zeromq/pull_source.h"
 %include "gnuradio/zeromq/req_source.h"
 
 GR_SWIG_BLOCK_MAGIC2(zeromq, pub_sink);
 GR_SWIG_BLOCK_MAGIC2(zeromq, push_sink);
 GR_SWIG_BLOCK_MAGIC2(zeromq, rep_sink);
+GR_SWIG_BLOCK_MAGIC2(zeromq, sub_source);
 GR_SWIG_BLOCK_MAGIC2(zeromq, pull_source);
 GR_SWIG_BLOCK_MAGIC2(zeromq, req_source);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]