2 ########################################################
3 ##Cheetah template - gnuradio_python
5 ##@param imports the import statements
6 ##@param flow_graph the flow_graph
7 ##@param variables the variable blocks
8 ##@param notebooks a list of notebook blocks
9 ##@param controls the variables with gui controls
10 ##@param parameters the paramater blocks
11 ##@param blocks the signal blocks
12 ##@param connections the connections
13 ##@param messages the msg type connections
14 ##@param generate_options the type of flow graph
15 ##@param var_id2cbs variable id map to callback strings
16 ########################################################
18 #set $code = '\n\t\t'.join(str($code).splitlines())
22 #set $DIVIDER = '#'*50
24 # Gnuradio Python Flow Graph
26 #if $flow_graph.get_option('author')
27 # Author: $flow_graph.get_option('author')
29 #if $flow_graph.get_option('description')
30 # Description: $flow_graph.get_option('description')
32 # Generated: $time.ctime()
35 ########################################################
37 ########################################################
42 ########################################################
44 ## Write the class declaration for a top or hier block.
45 ## The parameter names are the arguments to __init__.
46 ## Determine the absolute icon path (wx gui only).
47 ## Setup the IO signature (hier block only).
48 ########################################################
49 #set $class_name = $flow_graph.get_option('id')
50 #set $param_str = ', '.join(['self'] + ['%s=%s'%(param.get_id(), param.get_make()) for param in $parameters])
51 #if $generate_options == 'wx_gui'
53 #set $icon = gtk.IconTheme().lookup_icon('gnuradio-grc', 32, 0)
54 class $(class_name)(grc_wxgui.top_block_gui):
56 def __init__($param_str):
57 grc_wxgui.top_block_gui.__init__(self, title="$title")
59 _icon_path = "$icon.get_filename()"
60 self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
62 #elif $generate_options == 'no_gui'
63 class $(class_name)(gr.top_block):
65 def __init__($param_str):
66 gr.top_block.__init__(self, "$title")
67 #elif $generate_options == 'hb'
68 #set $in_sigs = $flow_graph.get_input_signaturev()
69 #set $out_sigs = $flow_graph.get_output_signaturev()
70 class $(class_name)(gr.hier_block2):
71 #def make_io_sig($io_sigs)
72 #set $size_strs = ['%s*%s'%(io_sig['size'], io_sig['vlen']) for io_sig in $io_sigs]
73 #if len($io_sigs) == 0
74 gr.io_signature(0, 0, 0)#slurp
75 #elif len($io_sigs) == 1
76 gr.io_signature(1, 1, $size_strs[0])#slurp
78 gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))])#slurp
82 def __init__($param_str):
83 gr.hier_block2.__init__(
85 $make_io_sig($in_sigs),
86 $make_io_sig($out_sigs),
89 ########################################################
91 ## Set the parameter to a property of self.
92 ########################################################
99 #for $param in $parameters
100 $indent($param.get_var_make())
102 ########################################################
104 ########################################################
111 #for $var in $variables
112 $indent($var.get_var_make())
114 ########################################################
116 ########################################################
123 #for $notebook in $notebooks
124 $indent($notebook.get_make())
126 ########################################################
128 ########################################################
135 #for $ctrl in $controls
136 $indent($ctrl.get_make())
138 ########################################################
139 ##Create Message Queues
140 ########################################################
147 #for $msg in $messages
148 $(msg.get_source().get_parent().get_id())_msgq_out = $(msg.get_sink().get_parent().get_id())_msgq_in = gr.msg_queue(2)
150 ########################################################
152 ########################################################
159 #for $blk in filter(lambda b: b.get_make(), $blocks)
160 self.$blk.get_id() = $indent($blk.get_make())
162 ########################################################
164 ## The port name should be the id of the parent block.
165 ## However, port names for IO pads should be self.
166 ########################################################
167 #def make_port_name($port)
168 #if $port.get_parent().get_key().startswith('pad_')
171 self.$port.get_parent().get_id()#slurp
180 #for $con in $connections
181 #set $source = $con.get_source()
182 #set $sink = $con.get_sink()
183 ##resolve virtual sources to the actual sources
184 #if $source.get_parent().is_virtual_source()
185 #set $source = $source.resolve_virtual_source()
187 ##do not generate connections with virtual sinks
188 #if not $sink.get_parent().is_virtual_sink()
189 self.connect(($make_port_name($source), $source.get_key()), ($make_port_name($sink), $sink.get_key()))
193 ########################################################
195 ## Write a set method for this variable that calls the callbacks
196 ########################################################
197 #for $var in $parameters + $variables
198 #set $id = $var.get_id()
199 def set_$(id)(self, $id):
201 #for $callback in $var_id2cbs[$id]
206 ########################################################
208 ## For top block code, generate a main routine.
209 ## Instantiate the top block and run as gui or cli.
210 ########################################################
211 #def make_default($type, $param)
212 #if $type == 'eng_float'
213 eng_notation.num_to_str($param.get_make())#slurp
215 $param.get_make()#slurp
218 #def make_short_id($param)
219 #set $short_id = $param.get_param('short_id').get_evaluated()
221 #set $short_id = '-' + $short_id
225 #if $generate_options != 'hb'
226 if __name__ == '__main__':
227 parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
228 #set $params_eq_list = list()
229 #for $param in $parameters
230 #set $type = $param.get_param('type').get_value()
232 #silent $params_eq_list.append('%s=options.%s'%($param.get_id(), $param.get_id()))
233 parser.add_option("$make_short_id($param)", "--$param.get_id().replace('_', '-')", dest="$param.get_id()", type="$type", default=$make_default($type, $param),
234 help="Set $($param.get_param('label').get_evaluated() or $param.get_id()) [default=%default]")
237 (options, args) = parser.parse_args()
238 #if $flow_graph.get_option('realtime_scheduling')
239 if gr.enable_realtime_scheduling() != gr.RT_OK:
240 print "Error: failed to enable realtime scheduling."
242 tb = $(class_name)($(', '.join($params_eq_list)))
243 #if $generate_options == 'wx_gui'
244 tb.Run($flow_graph.get_option('run'))
245 #elif $generate_options == 'no_gui'
246 #set $run_options = $flow_graph.get_option('run_options')
247 #if $run_options == 'prompt'
249 raw_input('Press Enter to quit: ')
251 #elif $run_options == 'run'