From 09b03871e81da2b09792a454ee3caf28bdad4c3c Mon Sep 17 00:00:00 2001
From: Tom Rondeau <tom@trondeau.com>
Date: Wed, 7 Oct 2015 07:15:56 -0400
Subject: ctrlport: provides a ControlPort model that connects directly with a
 block's message handler.

We still need to register this in setup_rpc, but there might be a way
to automate the registering of this during set_msg_handler if
ControlPort is enabled.
---
 .../python/gnuradio/ctrlport/RPCConnection.py           |  3 +++
 .../python/gnuradio/ctrlport/RPCConnectionThrift.py     | 17 +++++++++++++++++
 2 files changed, 20 insertions(+)

(limited to 'gnuradio-runtime/python')

diff --git a/gnuradio-runtime/python/gnuradio/ctrlport/RPCConnection.py b/gnuradio-runtime/python/gnuradio/ctrlport/RPCConnection.py
index e14cc0cea7..1b129534c9 100644
--- a/gnuradio-runtime/python/gnuradio/ctrlport/RPCConnection.py
+++ b/gnuradio-runtime/python/gnuradio/ctrlport/RPCConnection.py
@@ -105,6 +105,9 @@ class RPCConnection(object):
     def getRe(self,*args):
         raise exceptions.NotImplementedError()
 
+    def postMessage(self,*args):
+        raise exceptions.NotImplementedError()
+
     def setKnobs(self,*args):
         raise exceptions.NotImplementedError()
 
diff --git a/gnuradio-runtime/python/gnuradio/ctrlport/RPCConnectionThrift.py b/gnuradio-runtime/python/gnuradio/ctrlport/RPCConnectionThrift.py
index 9a2a302af5..522c74117b 100644
--- a/gnuradio-runtime/python/gnuradio/ctrlport/RPCConnectionThrift.py
+++ b/gnuradio-runtime/python/gnuradio/ctrlport/RPCConnectionThrift.py
@@ -27,6 +27,7 @@ from thrift.protocol import TBinaryProtocol
 from gnuradio.ctrlport.GNURadio import ControlPort
 from gnuradio.ctrlport import RPCConnection
 from gnuradio import gr
+import pmt
 import sys
 
 class ThriftRadioClient:
@@ -196,6 +197,22 @@ class RPCConnectionThrift(RPCConnection.RPCConnection):
     def shutdown(self):
         self.thriftclient.radio.shutdown()
 
+    def postMessage(self, blk_alias, port, msg):
+        '''
+        blk_alias: the alias of the block we are posting the message
+                   to; must have an open message port named 'port'.
+                   Provide as a string.
+        port: The name of the message port we are sending the message to.
+              Provide as a string.
+        msg: The actual message. Provide this as a PMT of the form
+             right for the message port.
+        The alias and port names are converted to PMT symbols and
+        serialized. The msg is already a PMT and so just serialized.
+        '''
+        self.thriftclient.radio.postMessage(pmt.serialize_str(pmt.intern(blk_alias)),
+                                            pmt.serialize_str(pmt.intern(port)),
+                                            pmt.serialize_str(msg));
+
     def printProperties(self, props):
         info = ""
         info += "Item:\t\t{0}\n".format(props.description)
-- 
cgit v1.2.3