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 controls the variables with gui controls
9 ##@param parameters the paramater blocks
10 ##@param blocks the signal blocks
11 ##@param connections the connections
12 ##@param generate_options the type of flow graph
13 ##@param var_id2cbs variable id map to callback strings
14 ########################################################
16 #set $code = '\n\t\t'.join(str($code).splitlines())
20 #set $DIVIDER = '#'*50
22 # Gnuradio Python Flow Graph
24 #if $flow_graph.get_option('author')
25 # Author: $flow_graph.get_option('author')
27 #if $flow_graph.get_option('description')
28 # Description: $flow_graph.get_option('description')
30 # Generated: $time.ctime()
33 ########################################################
35 ########################################################
40 ########################################################
42 ## Write the class declaration for a top or hier block.
43 ## The parameter names are the arguments to __init__.
44 ## Determine the absolute icon path (wx gui only).
45 ## Setup the IO signature (hier block only).
46 ########################################################
47 #set $class_name = $flow_graph.get_option('id')
48 #set $param_str = ', '.join(['self'] + ['%s=%s'%(param.get_id(), param.get_make()) for param in $parameters])
49 #if $generate_options == 'wx_gui'
51 #set $icon = gtk.IconTheme().lookup_icon('gnuradio-grc', 32, 0)
52 class $(class_name)(grc_wxgui.top_block_gui):
54 def __init__($param_str):
55 grc_wxgui.top_block_gui.__init__(
59 icon="$icon.get_filename()",
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__(
76 gr.io_signature($in_sig.nports, $in_sig.nports, $in_sig.size*$in_sig.vlen),
77 gr.io_signature($out_sig.nports, $out_sig.nports, $out_sig.size*$out_sig.vlen),
80 ########################################################
82 ## Set the parameter to a property of self.
83 ########################################################
90 #for $param in $parameters
91 $indent($param.get_var_make())
93 ########################################################
95 ## Set the variable to a property of self.
96 ## Write the first line of the variable make.
97 ########################################################
104 #for $var in $variables
105 $indent($var.get_var_make())
107 ########################################################
109 ## Write the variable make (excluding first line).
110 ## Indent each line with 2 tabs.
111 ########################################################
118 #for $ctrl in $controls
119 $indent($ctrl.get_make())
121 ########################################################
123 ## Write the block make, and indent with 2 tabs.
124 ########################################################
131 #for $blk in filter(lambda b: b.get_make(), $blocks)
132 self.$blk.get_id() = $indent($blk.get_make())
134 ########################################################
136 ## The port name should be the id of the parent block.
137 ## However, port names for IO pads should be self.
138 ########################################################
145 #for $con in $connections
146 #set $source = $con.get_source()
147 #set $sink = $con.get_sink()
148 #if $source.get_parent().get_key() == 'pad_source'
149 #set $source_name = 'self'
151 #set $source_name = 'self.' + $source.get_parent().get_id()
153 #if $sink.get_parent().get_key() == 'pad_sink'
154 #set $sink_name = 'self'
156 #set $sink_name = 'self.' + $sink.get_parent().get_id()
158 self.connect(($source_name, $source.get_key()), ($sink_name, $sink.get_key()))
161 ########################################################
163 ## Write a set method for this variable that calls the callbacks
164 ## and sets the direct variable dependencies.
165 ########################################################
166 #for $var in $parameters + $variables
167 #set $id = $var.get_id()
168 def set_$(id)(self, $id):
170 #for $callback in $var_id2cbs[$id]
175 ########################################################
177 ## For top block code, generate a main routine.
178 ## Instantiate the top block and run as gui or cli.
179 ########################################################
180 #if $generate_options != 'hb'
181 if __name__ == '__main__':
182 parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
183 #set $params_eq_list = list()
184 #for $param in $parameters
185 #set $type = $param.get_param('type').get_value()
187 #silent $params_eq_list.append('%s=options.%s'%($param.get_id(), $param.get_id()))
188 parser.add_option("--$param.get_id()", dest="$param.get_id()", type="$type", default=$param.get_make())
191 (options, args) = parser.parse_args()
192 #if $flow_graph.get_option('realtime_scheduling')
193 if gr.enable_realtime_scheduling() != gr.RT_OK:
194 print "Error: failed to enable realtime scheduling."
196 tb = $(class_name)($(', '.join($params_eq_list)))
197 #if $generate_options == 'wx_gui'
198 tb.Run($flow_graph.get_option('autostart'))
199 #elif $generate_options == 'no_gui'
201 raw_input('Press Enter to quit: ')