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_sig = $flow_graph.get_input_signature()
69 #set $out_sig = $flow_graph.get_output_signature()
70 class $(class_name)(gr.hier_block2):
72 def __init__($param_str):
73 gr.hier_block2.__init__(
75 gr.io_signature($in_sig.nports, $in_sig.nports, $in_sig.size*$in_sig.vlen),
76 gr.io_signature($out_sig.nports, $out_sig.nports, $out_sig.size*$out_sig.vlen),
79 ########################################################
81 ## Set the parameter to a property of self.
82 ########################################################
89 #for $param in $parameters
90 $indent($param.get_var_make())
92 ########################################################
94 ########################################################
101 #for $var in $variables
102 $indent($var.get_var_make())
104 ########################################################
106 ########################################################
113 #for $notebook in $notebooks
114 $indent($notebook.get_make())
116 ########################################################
118 ########################################################
125 #for $ctrl in $controls
126 $indent($ctrl.get_make())
128 ########################################################
129 ##Create Message Queues
130 ########################################################
137 #for $msg in $messages
138 $(msg.get_source().get_parent().get_id())_msgq = $(msg.get_sink().get_parent().get_id())_msgq = gr.msg_queue(2)
140 ########################################################
142 ########################################################
149 #for $blk in filter(lambda b: b.get_make(), $blocks)
150 self.$blk.get_id() = $indent($blk.get_make())
152 ########################################################
154 ## The port name should be the id of the parent block.
155 ## However, port names for IO pads should be self.
156 ########################################################
163 #for $con in $connections
164 #set $source = $con.get_source()
165 #set $sink = $con.get_sink()
166 #if $source.get_parent().get_key() == 'pad_source'
167 #set $source_name = 'self'
169 #set $source_name = 'self.' + $source.get_parent().get_id()
171 #if $sink.get_parent().get_key() == 'pad_sink'
172 #set $sink_name = 'self'
174 #set $sink_name = 'self.' + $sink.get_parent().get_id()
176 self.connect(($source_name, $source.get_key()), ($sink_name, $sink.get_key()))
179 ########################################################
181 ## Write a set method for this variable that calls the callbacks
182 ########################################################
183 #for $var in $parameters + $variables
184 #set $id = $var.get_id()
185 def set_$(id)(self, $id):
187 #for $callback in $var_id2cbs[$id]
192 ########################################################
194 ## For top block code, generate a main routine.
195 ## Instantiate the top block and run as gui or cli.
196 ########################################################
197 #if $generate_options != 'hb'
198 if __name__ == '__main__':
199 parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
200 #set $params_eq_list = list()
201 #for $param in $parameters
202 #set $type = $param.get_param('type').get_value()
204 #silent $params_eq_list.append('%s=options.%s'%($param.get_id(), $param.get_id()))
205 #set $short_id = $param.get_param('short_id').get_evaluated()
207 #set $short_id = '-' + $short_id
209 parser.add_option("$short_id", "--$param.get_id()", dest="$param.get_id()", type="$type", default=$param.get_make(),
210 help="Set $($param.get_param('label').evaluate() or $param.get_id()) [default=%default]")
213 (options, args) = parser.parse_args()
214 #if $flow_graph.get_option('realtime_scheduling')
215 if gr.enable_realtime_scheduling() != gr.RT_OK:
216 print "Error: failed to enable realtime scheduling."
218 tb = $(class_name)($(', '.join($params_eq_list)))
219 #if $generate_options == 'wx_gui'
220 tb.Run($flow_graph.get_option('run'))
221 #elif $generate_options == 'no_gui'
223 raw_input('Press Enter to quit: ')