Merge branch 'wip/grc/pads' of http://gnuradio.org/git/jblum
authorJohnathan Corgan <jcorgan@corganenterprises.com>
Tue, 8 Dec 2009 03:39:18 +0000 (22:39 -0500)
committerJohnathan Corgan <jcorgan@corganenterprises.com>
Tue, 8 Dec 2009 03:39:18 +0000 (22:39 -0500)
grc/blocks/pad_sink.xml
grc/blocks/pad_source.xml
grc/python/FlowGraph.py
grc/python/convert_hier.py
grc/python/flow_graph.tmpl

index 734526793fae96b1c1ef890faf61feeab0c3167b..2e949526039150e0e166c9deb1bcfc415815bfcc 100644 (file)
@@ -9,10 +9,10 @@
        <key>pad_sink</key>
        <make></make>
        <param>
-               <name>Num Inputs</name>
-               <key>nports</key>
-               <value>1</value>
-               <type>int</type>
+               <name>Label</name>
+               <key>label</key>
+               <value>out</value>
+               <type>string</type>
        </param>
        <param>
                <name>Input Type</name>
                <type>int</type>
        </param>
        <check>$vlen &gt; 0</check>
-       <check>0 &lt; $nports</check>
        <sink>
                <name>in</name>
                <type>$type</type>
                <vlen>$vlen</vlen>
-               <nports>$nports</nports>
        </sink>
        <doc>
-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.
        </doc>
 </block>
index f44d9623879d77b1c35026b82eeddf745bdc3b3c..7b2210cbbc75f74df47c526f7d4040ab414edb19 100644 (file)
@@ -9,10 +9,10 @@
        <key>pad_source</key>
        <make></make>
        <param>
-               <name>Num Outputs</name>
-               <key>nports</key>
-               <value>1</value>
-               <type>int</type>
+               <name>Label</name>
+               <key>label</key>
+               <value>in</value>
+               <type>string</type>
        </param>
        <param>
                <name>Output Type</name>
                <type>int</type>
        </param>
        <check>$vlen &gt; 0</check>
-       <check>0 &lt; $nports</check>
        <source>
                <name>out</name>
                <type>$type</type>
                <vlen>$vlen</vlen>
-               <nports>$nports</nports>
        </source>
        <doc>
-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.
        </doc>
 </block>
index 4dd18a81f4cd230dbec042dfb77a2068129ed859..24e4aac3b8576e7a53bb4c0b1ab908bd390b3496 100644 (file)
@@ -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):
                """
index bdafbcbc13dde8d9dc2fa7c028996f9cc7426c7b..befddccea0ce2e947befdf59c200cae18c603e7f 100644 (file)
@@ -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)
index ab764006c06e304f9a663a655b7a2edd66ed75bb..a1a9308aa30335fb2228a252536c2215421dd83c 100644 (file)
@@ -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
 ########################################################