summaryrefslogtreecommitdiff
path: root/grc/python
diff options
context:
space:
mode:
Diffstat (limited to 'grc/python')
-rw-r--r--grc/python/Connection.py3
-rw-r--r--grc/python/Constants.py1
-rw-r--r--grc/python/FlowGraph.py11
-rw-r--r--grc/python/Generator.py4
-rw-r--r--grc/python/Port.py2
-rw-r--r--grc/python/block.dtd3
-rw-r--r--grc/python/convert_hier.py23
-rw-r--r--grc/python/flow_graph.tmpl26
8 files changed, 68 insertions, 5 deletions
diff --git a/grc/python/Connection.py b/grc/python/Connection.py
index 218baf074..341dd2d82 100644
--- a/grc/python/Connection.py
+++ b/grc/python/Connection.py
@@ -31,6 +31,9 @@ class Connection(_Connection, _GUIConnection):
def is_msg(self):
return self.get_source().get_type() == self.get_sink().get_type() == 'msg'
+ def is_message(self):
+ return self.get_source().get_type() == self.get_sink().get_type() == 'message'
+
def validate(self):
"""
Validate the connections.
diff --git a/grc/python/Constants.py b/grc/python/Constants.py
index 1a65caf1c..b8dc9a96a 100644
--- a/grc/python/Constants.py
+++ b/grc/python/Constants.py
@@ -58,6 +58,7 @@ CORE_TYPES = ( #name, key, sizeof, color
('Integer 16', 's16', 2, '#FFFF66'),
('Integer 8', 's8', 1, '#FF66FF'),
('Message Queue', 'msg', 0, '#777777'),
+ ('Async Message', 'message', 0, '#C0C0C0'),
('Wildcard', '', 0, '#FFFFFF'),
)
diff --git a/grc/python/FlowGraph.py b/grc/python/FlowGraph.py
index 89a169355..376c2e337 100644
--- a/grc/python/FlowGraph.py
+++ b/grc/python/FlowGraph.py
@@ -58,12 +58,15 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph):
'in': self.get_pad_sources(),
'out': self.get_pad_sinks(),
}[direction]
+ # we only want stream ports
+ sorted_pads = filter(lambda b: b.get_param('type').get_evaluated() != 'message', sorted_pads);
#load io signature
return [{
'label': str(pad.get_param('label').get_evaluated()),
'type': str(pad.get_param('type').get_evaluated()),
'vlen': str(pad.get_param('vlen').get_evaluated()),
'size': pad.get_param('type').get_opt('size'),
+ 'optional': bool(pad.get_param('optional').get_evaluated()),
} for pad in sorted_pads]
def get_pad_sources(self):
@@ -82,6 +85,14 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph):
pads = filter(lambda b: b.get_key() == 'pad_sink', self.get_enabled_blocks())
return sorted(pads, lambda x, y: cmp(x.get_id(), y.get_id()))
+ def get_msg_pad_sources(self):
+ ps = self.get_pad_sources();
+ return filter(lambda b: b.get_param('type').get_evaluated() == 'message', ps);
+
+ def get_msg_pad_sinks(self):
+ ps = self.get_pad_sinks();
+ return filter(lambda b: b.get_param('type').get_evaluated() == 'message', ps);
+
def get_imports(self):
"""
Get a set of all import statments in this flow graph namespace.
diff --git a/grc/python/Generator.py b/grc/python/Generator.py
index 2a6fe51d5..616ea00fc 100644
--- a/grc/python/Generator.py
+++ b/grc/python/Generator.py
@@ -116,8 +116,9 @@ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''')
#list of regular blocks (all blocks minus the special ones)
blocks = filter(lambda b: b not in (imports + parameters), blocks)
#list of connections where each endpoint is enabled
- connections = filter(lambda c: not c.is_msg(), self._flow_graph.get_enabled_connections())
+ connections = filter(lambda c: not (c.is_msg() or c.is_message()), self._flow_graph.get_enabled_connections())
messages = filter(lambda c: c.is_msg(), self._flow_graph.get_enabled_connections())
+ messages2 = filter(lambda c: c.is_message(), self._flow_graph.get_enabled_connections())
#list of variable names
var_ids = [var.get_id() for var in parameters + variables]
#prepend self.
@@ -142,6 +143,7 @@ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''')
'blocks': blocks,
'connections': connections,
'messages': messages,
+ 'messages2': messages2,
'generate_options': self._generate_options,
'var_id2cbs': var_id2cbs,
}
diff --git a/grc/python/Port.py b/grc/python/Port.py
index 9f8b50d05..738a33ba7 100644
--- a/grc/python/Port.py
+++ b/grc/python/Port.py
@@ -116,7 +116,7 @@ class Port(_Port, _GUIPort):
_Port.validate(self)
if not self.get_enabled_connections() and not self.get_optional():
self.add_error_message('Port is not connected.')
- if not self.is_source() and len(self.get_enabled_connections()) > 1:
+ if not self.is_source() and (not self.get_type() == "message") and len(self.get_enabled_connections()) > 1:
self.add_error_message('Port has too many connections.')
#message port logic
if self.get_type() == 'msg':
diff --git a/grc/python/block.dtd b/grc/python/block.dtd
index 41a744d07..292ea06cb 100644
--- a/grc/python/block.dtd
+++ b/grc/python/block.dtd
@@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Top level element.
A block contains a name, ...parameters list, and list of IO ports.
-->
-<!ELEMENT block (name, key, category?, throttle?, import*, var_make?, make, callback*, param*, check*, sink*, source*, doc?)>
+<!ELEMENT block (name, key, category?, throttle?, import*, var_make?, make, callback*, param*, check*, sink*, source*, doc?, grc_source?)>
<!--
Sub level elements.
-->
@@ -40,6 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
<!ELEMENT category (#PCDATA)>
<!ELEMENT import (#PCDATA)>
<!ELEMENT doc (#PCDATA)>
+<!ELEMENT grc_source (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT key (#PCDATA)>
<!ELEMENT check (#PCDATA)>
diff --git a/grc/python/convert_hier.py b/grc/python/convert_hier.py
index c6ca5b769..508ec63b2 100644
--- a/grc/python/convert_hier.py
+++ b/grc/python/convert_hier.py
@@ -25,6 +25,8 @@ def convert_hier(flow_graph, python_file):
#extract info from the flow graph
input_sigs = flow_graph.get_io_signaturev('in')
output_sigs = flow_graph.get_io_signaturev('out')
+ input_msgp = flow_graph.get_msg_pad_sources();
+ output_msgp = flow_graph.get_msg_pad_sinks();
parameters = flow_graph.get_parameters()
block_key = flow_graph.get_option('id')
block_name = flow_graph.get_option('title') or flow_graph.get_option('id').replace('_', ' ').title()
@@ -55,24 +57,41 @@ def convert_hier(flow_graph, python_file):
param_n['type'] = 'raw'
params_n.append(param_n)
block_n['param'] = params_n
- #sink data
+ #sink data stream ports
block_n['sink'] = list()
for input_sig in input_sigs:
sink_n = odict()
sink_n['name'] = input_sig['label']
sink_n['type'] = input_sig['type']
sink_n['vlen'] = input_sig['vlen']
+ if input_sig['optional']: sink_n['optional'] = '1'
block_n['sink'].append(sink_n)
- #source data
+ #sink data msg ports
+ for input_sig in input_msgp:
+ sink_n = odict()
+ sink_n['name'] = input_sig.get_param("label").get_value();
+ sink_n['type'] = "message"
+ sink_n['optional'] = input_sig.get_param("optional").get_value();
+ block_n['sink'].append(sink_n)
+ #source data stream ports
block_n['source'] = list()
for output_sig in output_sigs:
source_n = odict()
source_n['name'] = output_sig['label']
source_n['type'] = output_sig['type']
source_n['vlen'] = output_sig['vlen']
+ if output_sig['optional']: source_n['optional'] = '1'
+ block_n['source'].append(source_n)
+ #source data msg ports
+ for output_sig in output_msgp:
+ source_n = odict()
+ source_n['name'] = output_sig.get_param("label").get_value();
+ source_n['type'] = "message"
+ source_n['optional'] = output_sig.get_param("optional").get_value();
block_n['source'].append(source_n)
#doc data
block_n['doc'] = "%s\n%s\n%s"%(block_author, block_desc, python_file)
+ block_n['grc_source'] = "%s"%(flow_graph.grc_file_path)
#write the block_n to file
xml_file = python_file + '.xml'
ParseXML.to_file({'block': block_n}, xml_file)
diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl
index 17feb01f6..163e7f76a 100644
--- a/grc/python/flow_graph.tmpl
+++ b/grc/python/flow_graph.tmpl
@@ -191,6 +191,32 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))])
#end for
########################################################
+##Create Asynch Message Connections
+########################################################
+#if $messages2
+ $DIVIDER
+ # Asynch Message Connections
+ $DIVIDER
+#end if
+#for $msg in $messages2
+ #set $sr = $msg.get_source()
+ #set $source = "self.%s"%($sr.get_parent().get_id())
+ #set $source_port = $sr.get_name();
+ #if $sr.get_parent().get_key() == "pad_source"
+ #set $source = "self"
+ #set $source_port = $sr.get_parent().get_param("label").get_value();
+ #end if
+ #set $sk = $msg.get_sink()
+ #set $sink = "self.%s"%($sk.get_parent().get_id())
+ #set $sink_port = $sk.get_name();
+ #if $sk.get_parent().get_key() == "pad_sink"
+ #set $sink = "self"
+ #set $sink_port = $sk.get_parent().get_param("label").get_value();
+ #end if
+ self.msg_connect($source, "$source_port", $sink, "$sink_port")
+#end for
+
+########################################################
##Create Callbacks
## Write a set method for this variable that calls the callbacks
########################################################