diff options
author | Josh Blum | 2009-12-03 10:42:49 -0500 |
---|---|---|
committer | Josh Blum | 2009-12-03 10:42:49 -0500 |
commit | a4a1ada03e5da936d90a5d6e3bd31943a5ad9513 (patch) | |
tree | 3d7fa1541042b14d7068e92ba7d798b1bfaaca0f /grc/python | |
parent | a198e5134b00a1d5b98b5447aafd3cdba8508609 (diff) | |
download | gnuradio-a4a1ada03e5da936d90a5d6e3bd31943a5ad9513.tar.gz gnuradio-a4a1ada03e5da936d90a5d6e3bd31943a5ad9513.tar.bz2 gnuradio-a4a1ada03e5da936d90a5d6e3bd31943a5ad9513.zip |
Allow for multiple io pads per hier flow graph.
Each io pad can have a different io signature.
Uses the iosignaturev for hier implementation.
Backwards compadible with exception:
Pad blocks that used multiple ports must be replaced with multiple pad blocks
as the new pad io blocks only support one port per block.
Diffstat (limited to 'grc/python')
-rw-r--r-- | grc/python/FlowGraph.py | 34 | ||||
-rw-r--r-- | grc/python/convert_hier.py | 14 | ||||
-rw-r--r-- | grc/python/flow_graph.tmpl | 18 |
3 files changed, 33 insertions, 33 deletions
diff --git a/grc/python/FlowGraph.py b/grc/python/FlowGraph.py index 4dd18a81f..24e4aac3b 100644 --- a/grc/python/FlowGraph.py +++ b/grc/python/FlowGraph.py @@ -50,44 +50,36 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph): #return from cache return self._eval_cache[my_hash] - def _get_io_signature(self, pad_key): + def _get_io_signaturev(self, pad_key): """ - Get an io signature for this flow graph. + Get a list of io signatures for this flow graph. The pad key determines the directionality of the io signature. @param pad_key a string of pad_source or pad_sink - @return a dict with: type, nports, vlen, size + @return a list of dicts with: type, label, vlen, size """ pads = filter(lambda b: b.get_key() == pad_key, self.get_enabled_blocks()) - if not pads: return { - 'nports': '0', - 'type': '', - 'vlen': '0', - 'size': '0', - } - pad = pads[0] #take only the first, user should not have more than 1 + sorted_pads = sorted(pads, lambda x, y: cmp(x.get_id(), y.get_id())) #load io signature - return { - 'nports': str(pad.get_param('nports').get_evaluated()), + 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'), - } + } for pad in sorted_pads] - def get_input_signature(self): + def get_input_signaturev(self): """ Get the io signature for the input side of this flow graph. - The io signature with be "0", "0" if no pad source is present. - @return a string tuple of type, num_ports, port_size + @return a list of io signature structures """ - return self._get_io_signature('pad_source') + return self._get_io_signaturev('pad_source') - def get_output_signature(self): + def get_output_signaturev(self): """ Get the io signature for the output side of this flow graph. - The io signature with be "0", "0" if no pad sink is present. - @return a string tuple of type, num_ports, port_size + @return a list of io signature structures """ - return self._get_io_signature('pad_sink') + return self._get_io_signaturev('pad_sink') def get_imports(self): """ diff --git a/grc/python/convert_hier.py b/grc/python/convert_hier.py index bdafbcbc1..befddccea 100644 --- a/grc/python/convert_hier.py +++ b/grc/python/convert_hier.py @@ -23,8 +23,8 @@ from .. base import odict def convert_hier(flow_graph, python_file): #extract info from the flow graph - input_sig = flow_graph.get_input_signature() - output_sig = flow_graph.get_output_signature() + input_sigs = flow_graph.get_input_signaturev() + output_sigs = flow_graph.get_output_signaturev() parameters = flow_graph.get_parameters() block_key = flow_graph.get_option('id') block_name = flow_graph.get_option('title') @@ -56,20 +56,18 @@ def convert_hier(flow_graph, python_file): params_n.append(param_n) block_n['param'] = params_n #sink data - if int(input_sig['nports']): + for input_sig in input_sigs: sink_n = odict() - sink_n['name'] = 'in' + sink_n['name'] = input_sig['label'] sink_n['type'] = input_sig['type'] sink_n['vlen'] = input_sig['vlen'] - sink_n['nports'] = input_sig['nports'] block_n['sink'] = sink_n #source data - if int(output_sig['nports']): + for output_sig in output_sigs: source_n = odict() - source_n['name'] = 'out' + source_n['name'] = output_sig['label'] source_n['type'] = output_sig['type'] source_n['vlen'] = output_sig['vlen'] - source_n['nports'] = output_sig['nports'] block_n['source'] = source_n #doc data block_n['doc'] = "%s\n%s\n%s"%(block_author, block_desc, python_file) diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl index ab764006c..a1a9308aa 100644 --- a/grc/python/flow_graph.tmpl +++ b/grc/python/flow_graph.tmpl @@ -65,15 +65,25 @@ class $(class_name)(gr.top_block): def __init__($param_str): gr.top_block.__init__(self, "$title") #elif $generate_options == 'hb' - #set $in_sig = $flow_graph.get_input_signature() - #set $out_sig = $flow_graph.get_output_signature() + #set $in_sigs = $flow_graph.get_input_signaturev() + #set $out_sigs = $flow_graph.get_output_signaturev() class $(class_name)(gr.hier_block2): +#def make_io_sig($io_sigs) + #set $size_strs = ['%s*%s'%(io_sig['size'], io_sig['vlen']) for io_sig in $io_sigs] + #if len($io_sigs) == 0 +gr.io_signature(0, 0, 0)#slurp + #elif len($io_sigs) == 1 +gr.io_signature(1, 1, $size_strs[0])#slurp + #else +gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))])#slurp + #end if +#end def def __init__($param_str): gr.hier_block2.__init__( self, "$title", - gr.io_signature($in_sig.nports, $in_sig.nports, $in_sig.size*$in_sig.vlen), - gr.io_signature($out_sig.nports, $out_sig.nports, $out_sig.size*$out_sig.vlen), + $make_io_sig($in_sigs), + $make_io_sig($out_sigs), ) #end if ######################################################## |