From: Johnathan Corgan Date: Tue, 8 Dec 2009 03:39:18 +0000 (-0500) Subject: Merge branch 'wip/grc/pads' of http://gnuradio.org/git/jblum X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=dc253f4ad382bd68bf1064b7fa0a818216556595;hp=72a8a242ea58eb624dcecf50409a199daead543f;p=debian%2Fgnuradio Merge branch 'wip/grc/pads' of gnuradio.org/git/jblum --- diff --git a/grc/blocks/pad_sink.xml b/grc/blocks/pad_sink.xml index 73452679..2e949526 100644 --- a/grc/blocks/pad_sink.xml +++ b/grc/blocks/pad_sink.xml @@ -9,10 +9,10 @@ pad_sink - Num Inputs - nports - 1 - int + Label + label + out + string Input Type @@ -51,15 +51,14 @@ int $vlen > 0 - 0 < $nports in $type $vlen - $nports -The inputs of this block will become the outputs to this flow graph when it is instantiated as a hierarchical block. \ -Limit one sink pad block per flow graph. +The inputs of this block will become the outputs to this flow graph when it is instantiated as a hierarchical block. + +Pad sink will be ordered alphabetically by their ids. The first pad sink will have an index of 0. diff --git a/grc/blocks/pad_source.xml b/grc/blocks/pad_source.xml index f44d9623..7b2210cb 100644 --- a/grc/blocks/pad_source.xml +++ b/grc/blocks/pad_source.xml @@ -9,10 +9,10 @@ pad_source - Num Outputs - nports - 1 - int + Label + label + in + string Output Type @@ -51,16 +51,14 @@ int $vlen > 0 - 0 < $nports out $type $vlen - $nports -The outputs of this block will become the inputs to this flow graph when it is instantiated as a hierarchical block. \ -Limit one source pad block per flow graph. \ -The "pad sink id" will be ignored in this mode. +The outputs of this block will become the inputs to this flow graph when it is instantiated as a hierarchical block. + +Pad sources will be ordered alphabetically by their ids. The first pad source will have an index of 0. diff --git a/grc/python/FlowGraph.py b/grc/python/FlowGraph.py index 4dd18a81..24e4aac3 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 bdafbcbc..befddcce 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 ab764006..a1a9308a 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 ########################################################