1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
#!/usr/bin/env python
########################################################
##Cheetah template - gnuradio_python
##
##@param imports the import statements
##@param flow_graph the flow_graph
##@param variables the variable blocks
##@param controls the variables with gui controls
##@param parameters the paramater blocks
##@param blocks the signal blocks
##@param connections the connections
##@param generate_options the type of flow graph
##@param var_id2expr variable id map to expression
##@param var_id2deps variable id map to direct dependencies
##@param var_id2cbs variable id map to callback strings
########################################################
#import time
#set $DIVIDER = '#'*50
$DIVIDER
# Gnuradio Python Flow Graph
$('# Title: %s'%$flow_graph.get_option('title'))
$('# Author: %s'%$flow_graph.get_option('author'))
$('# Description: %s'%$flow_graph.get_option('description'))
$('# Generated: %s'%time.ctime())
$DIVIDER
########################################################
##Create Imports
########################################################
#for $imp in $imports
$imp
#end for
########################################################
##Create Class
## Write the class declaration for a top or hier block.
## The parameter names are the arguments to __init__.
## Determine the absolute icon path (wx gui only).
## Setup the IO signature (hier block only).
########################################################
#set $class_name = $flow_graph.get_option('id')
#set $param_str = ', '.join(['self'] + ['%s=%s'%(param.get_id(), param.get_make()) for param in $parameters])
#if $generate_options == 'wx_gui'
#from gnuradio.grc.platforms.base.Constants import DATA_DIR
#from gnuradio.grc.gui.Constants import MAIN_WINDOW_PREFIX
class $(class_name)(grc_wxgui.top_block_gui):
def __init__($param_str):
grc_wxgui.top_block_gui.__init__(
self,
title="$MAIN_WINDOW_PREFIX - Executing: $flow_graph.get_option('title')",
icon="$(os.path.join($DATA_DIR, 'grc-icon-32.png'))",
)
#elif $generate_options == 'no_gui'
class $(class_name)(gr.top_block):
def __init__($param_str):
gr.top_block.__init__(self, "$flow_graph.get_option('title')")
#elif $generate_options == 'hb'
#set $in_sig = $flow_graph.get_input_signature()
#set $out_sig = $flow_graph.get_output_signature()
class $(class_name)(gr.hier_block2):
def __init__($param_str):
gr.hier_block2.__init__(
self,
"$flow_graph.get_option('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),
)
#end if
########################################################
##Create Parameters
## Set the parameter to a property of self..
########################################################
#if $parameters
$DIVIDER
# Parameters
$DIVIDER
#end if
#for $param in $parameters
self.$param.get_id() = $param.get_id()
#end for
########################################################
##Create Variables
## Set the variable to a property of self.
## Write the first line of the variable make.
########################################################
#if $variables
$DIVIDER
# Variables
$DIVIDER
#end if
#for $var in $variables
#set $code = $var.get_make().splitlines()[0]
self.$var.get_id() = $var.get_id() = $code
#end for
########################################################
##Create Controls
## Write the variable make (excluding first line).
## Indent each line with 2 tabs.
########################################################
#if $controls
$DIVIDER
# Controls
$DIVIDER
#end if
#for $ctrl in $controls
#set $code = '\n\t\t'.join($ctrl.get_make().splitlines()[1:])
$code
#end for
########################################################
##Create Blocks
## Write the block make, and indent with 2 tabs.
########################################################
#if $blocks
$DIVIDER
# Blocks
$DIVIDER
#end if
#for $blk in filter(lambda b: b.get_make(), $blocks)
#set $code = '\n\t\t'.join($blk.get_make().splitlines())
$("self.%s = %s"%($blk.get_id(), $code))
#end for
########################################################
##Create Connections
## The port name should be the id of the parent block.
## However, port names for IO pads should be self.
########################################################
#if $connections
$DIVIDER
# Connections
$DIVIDER
#end if
#for $con in $connections
#set $source = $con.get_source()
#set $sink = $con.get_sink()
#if $source.get_parent().get_key() == 'pad_source'
#set $source_name = 'self'
#else
#set $source_name = 'self.' + $source.get_parent().get_id()
#end if
#if $sink.get_parent().get_key() == 'pad_sink'
#set $sink_name = 'self'
#else
#set $sink_name = 'self.' + $sink.get_parent().get_id()
#end if
$("self.connect((%s, %s), (%s, %s))"%(
$source_name,
$source.get_key(),
$sink_name,
$sink.get_key(),
)
)
#end for
########################################################
##Create Callbacks
## Write a set method for this variable that calls the callbacks
## and sets the direct variable dependencies.
########################################################
#for $var in $parameters + $variables
#set $id = $var.get_id()
def set_$(id)(self, $id):
self.$id = $id
#for $dep in $var_id2deps[$id]
self.set_$(dep)($var_id2expr[$dep])
#end for
#for $callback in $var_id2cbs[$id]
self.$callback
#end for
#end for
########################################################
##Create Main
## For top block code, generate a main routine.
## Instantiate the top block and run as gui or cli.
########################################################
#if $generate_options != 'hb'
if __name__ == '__main__':
tb = $(class_name)()
#if $generate_options == 'wx_gui'
tb.Run()
#elif $generate_options == 'no_gui'
tb.start()
raw_input('Press Enter to quit: ')
tb.stop()
#end if
#end if
|