~ubuntu-branches/ubuntu/trusty/gnuradio/trusty-updates

« back to all changes in this revision

Viewing changes to gr-shd/grc/gen_shd_smini_blocks.py

  • Committer: Package Import Robot
  • Author(s): A. Maitland Bottoms
  • Date: 2012-02-26 21:26:16 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120226212616-vsfkbi1158xshdql
Tags: 3.5.1-1
* new upstream version, re-packaged from scratch with modern tools
    closes: #642716, #645332, #394849, #616832, #590048, #642580,
    #647018, #557050, #559640, #631863
* CMake build

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Copyright 2011 Free Software Foundation, Inc.
 
3
 
 
4
This file is part of GNU Radio
 
5
 
 
6
GNU Radio Companion is free software; you can redistribute it and/or
 
7
modify it under the terms of the GNU General Public License
 
8
as published by the Free Software Foundation; either version 2
 
9
of the License, or (at your option) any later version.
 
10
 
 
11
GNU Radio Companion is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with this program; if not, write to the Free Software
 
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
19
"""
 
20
 
 
21
MAIN_TMPL = """\
 
22
<?xml version="1.0"?>
 
23
<block>
 
24
        <name>SHD: SMINI $sourk.title()</name>
 
25
        <key>shd_smini_$(sourk)</key>
 
26
        <import>from gnuradio import shd</import>
 
27
        <make>shd.smini_$(sourk)(
 
28
        device_addr=\$dev_addr,
 
29
        io_type=shd.io_type.\$type.type,
 
30
        num_channels=\$nchan,
 
31
)
 
32
\#if \$clock_rate()
 
33
self.\$(id).set_clock_rate(\$clock_rate, shd.ALL_MBOARDS)
 
34
\#end if
 
35
#for $m in range($max_mboards)
 
36
########################################################################
 
37
\#if \$num_mboards() > $m and \$ref_source$(m)() == 'external'
 
38
self.\$(id).set_clock_config(shd.clock_config.external(), $m)
 
39
\#end if
 
40
########################################################################
 
41
\#if \$num_mboards() > $m and \$ref_source$(m)() == 'internal'
 
42
self.\$(id).set_clock_config(shd.clock_config.internal(), $m)
 
43
\#end if
 
44
########################################################################
 
45
\#if \$num_mboards() > $m and \$ref_source$(m)() == 'mimo'
 
46
_config = shd.clock_config()
 
47
_config.ref_source = shd.clock_config.REF_MIMO
 
48
_config.pps_source = shd.clock_config.PPS_MIMO
 
49
self.\$(id).set_clock_config(_config, $m)
 
50
\#end if
 
51
########################################################################
 
52
\#if \$num_mboards() > $m and \$sd_spec$(m)()
 
53
self.\$(id).set_subdev_spec(\$sd_spec$(m), $m)
 
54
\#end if
 
55
########################################################################
 
56
#end for
 
57
\#if \$sync()
 
58
self.\$(id).set_time_unknown_pps(shd.time_spec())
 
59
\#end if
 
60
self.\$(id).set_samp_rate(\$samp_rate)
 
61
#for $n in range($max_nchan)
 
62
\#if \$nchan() > $n
 
63
self.\$(id).set_center_freq(\$center_freq$(n), $n)
 
64
self.\$(id).set_gain(\$gain$(n), $n)
 
65
\#end if
 
66
#end for
 
67
</make>
 
68
        <callback>set_samp_rate(\$samp_rate)</callback>
 
69
        #for $n in range($max_nchan)
 
70
        <callback>set_center_freq(\$center_freq$(n), $n)</callback>
 
71
        <callback>set_gain(\$gain$(n), $n)</callback>
 
72
        #end for
 
73
        <param>
 
74
                <name>$(direction.title())put Type</name>
 
75
                <key>type</key>
 
76
                <type>enum</type>
 
77
                <option>
 
78
                        <name>Complex</name>
 
79
                        <key>complex</key>
 
80
                        <opt>type:COMPLEX_FLOAT32</opt>
 
81
                        <opt>vlen:1</opt>
 
82
                </option>
 
83
                <option>
 
84
                        <name>Short</name>
 
85
                        <key>short</key>
 
86
                        <opt>type:COMPLEX_INT16</opt>
 
87
                        <opt>vlen:2</opt>
 
88
                </option>
 
89
        </param>
 
90
        <param>
 
91
                <name>Device Addr</name>
 
92
                <key>dev_addr</key>
 
93
                <value></value>
 
94
                <type>string</type>
 
95
                <hide>
 
96
                        \#if \$dev_addr()
 
97
                                none
 
98
                        \#else
 
99
                                part
 
100
                        \#end if
 
101
                </hide>
 
102
        </param>
 
103
        <param>
 
104
                <name>Sync</name>
 
105
                <key>sync</key>
 
106
                <value></value>
 
107
                <type>enum</type>
 
108
                <hide>\#if \$sync() then 'none' else 'part'#</hide>
 
109
                <option>
 
110
                        <name>unknown PPS</name>
 
111
                        <key>sync</key>
 
112
                </option>
 
113
                <option>
 
114
                        <name>don't sync</name>
 
115
                        <key></key>
 
116
                </option>
 
117
        </param>
 
118
        <param>
 
119
                <name>Clock Rate (Hz)</name>
 
120
                <key>clock_rate</key>
 
121
                <value>0.0</value>
 
122
                <type>real</type>
 
123
                <hide>\#if \$clock_rate() then 'none' else 'part'#</hide>
 
124
                <option>
 
125
                        <name>Default</name>
 
126
                        <key>0.0</key>
 
127
                </option>
 
128
        </param>
 
129
        <param>
 
130
                <name>Num Mboards</name>
 
131
                <key>num_mboards</key>
 
132
                <value>1</value>
 
133
                <type>int</type>
 
134
                <hide>part</hide>
 
135
                #for $m in range(1, $max_mboards+1)
 
136
                <option>
 
137
                        <name>$(m)</name>
 
138
                        <key>$m</key>
 
139
                </option>
 
140
                #end for
 
141
        </param>
 
142
        #for $m in range($max_mboards)
 
143
        <param>
 
144
                <name>Mb$(m): Ref Source</name>
 
145
                <key>ref_source$(m)</key>
 
146
                <value></value>
 
147
                <type>enum</type>
 
148
                <hide>
 
149
                        \#if not \$num_mboards() > $m
 
150
                                all
 
151
                        \#elif \$ref_source$(m)()
 
152
                                none
 
153
                        \#else
 
154
                                part
 
155
                        \#end if
 
156
                </hide>
 
157
                <option><name>Default</name><key></key></option>
 
158
                <option><name>Internal</name><key>internal</key></option>
 
159
                <option><name>External</name><key>external</key></option>
 
160
                <option><name>MIMO Cable</name><key>mimo</key></option>
 
161
        </param>
 
162
        <param>
 
163
                <name>Mb$(m): Subdev Spec</name>
 
164
                <key>sd_spec$(m)</key>
 
165
                <value></value>
 
166
                <type>string</type>
 
167
                <hide>
 
168
                        \#if not \$num_mboards() > $m
 
169
                                all
 
170
                        \#elif \$sd_spec$(m)()
 
171
                                none
 
172
                        \#else
 
173
                                part
 
174
                        \#end if
 
175
                </hide>
 
176
        </param>
 
177
        #end for
 
178
        <param>
 
179
                <name>Num Channels</name>
 
180
                <key>nchan</key>
 
181
                <value>1</value>
 
182
                <type>int</type>
 
183
                #for $n in range(1, $max_nchan+1)
 
184
                <option>
 
185
                        <name>$(n)</name>
 
186
                        <key>$n</key>
 
187
                </option>
 
188
                #end for
 
189
        </param>
 
190
        <param>
 
191
                <name>Samp Rate (Sps)</name>
 
192
                <key>samp_rate</key>
 
193
                <value>samp_rate</value>
 
194
                <type>real</type>
 
195
        </param>
 
196
        $params
 
197
        <check>$max_nchan >= \$nchan</check>
 
198
        <check>\$nchan > 0</check>
 
199
        <check>$max_mboards >= \$num_mboards</check>
 
200
        <check>\$num_mboards > 0</check>
 
201
        <check>\$nchan >= \$num_mboards</check>
 
202
        <$sourk>
 
203
                <name>$direction</name>
 
204
                <type>\$type</type>
 
205
                <vlen>\$type.vlen</vlen>
 
206
                <nports>\$nchan</nports>
 
207
        </$sourk>
 
208
        <doc>
 
209
The SHD SMINI $sourk.title() Block:
 
210
 
 
211
Device Address:
 
212
The device address is a delimited string used to locate SHD devices on your system. \\
 
213
If left blank, the first SHD device found will be used. \\
 
214
Use the device address to specify a specific device or list of devices.
 
215
SMINI1 Example: serial=12345678
 
216
SMINI2 Example: type=xmini
 
217
 
 
218
Num Motherboards:
 
219
Selects the number of SMINI motherboards in this device configuration.
 
220
 
 
221
Reference Source:
 
222
Where the motherboard should sync its time and clock references.
 
223
If source and sink blocks reference the same device,
 
224
it is only necessary to set the reference source on one of the blocks.
 
225
 
 
226
Subdevice specification:
 
227
Each motherboard should have its own subdevice specification \\
 
228
and all subdevice specifications should be the same length. \\
 
229
Select the subdevice or subdevices for each channel using a markup string. \\
 
230
The markup string consists of a list of dboard_slot:subdev_name pairs (one pair per channel). \\
 
231
If left blank, the SHD will try to select the first subdevice on your system. \\
 
232
See the application notes for further details.
 
233
Single channel example: :AB
 
234
Dual channel example: :A :B
 
235
 
 
236
Num Channels:
 
237
Selects the total number of channels in this multi-SMINI configuration.
 
238
Ex: 4 motherboards with 2 channels per board = 8 channels total
 
239
 
 
240
Sample rate:
 
241
The sample rate is the number of samples per second input by this block. \\
 
242
The SHD device driver will try its best to match the requested sample rate. \\
 
243
If the requested rate is not possible, the SHD block will print an error at runtime.
 
244
 
 
245
Center frequency:
 
246
The center frequency is the overall frequency of the RF chain. \\
 
247
For greater control of how the SHD tunes elements in the RF chain, \\
 
248
pass a tune_request object rather than a simple target frequency.
 
249
Tuning with an LO offset example: shd.tune_request(freq, lo_off)
 
250
 
 
251
        </doc>
 
252
</block>
 
253
"""
 
254
 
 
255
PARAMS_TMPL = """
 
256
        <param>
 
257
                <name>Ch$(n): Center Freq (Hz)</name>
 
258
                <key>center_freq$(n)</key>
 
259
                <value>0</value>
 
260
                <type>real</type>
 
261
                <hide>\#if \$nchan() > $n then 'none' else 'all'#</hide>
 
262
        </param>
 
263
        <param>
 
264
                <name>Ch$(n): Gain (dB)</name>
 
265
                <key>gain$(n)</key>
 
266
                <value>0</value>
 
267
                <type>real</type>
 
268
                <hide>\#if \$nchan() > $n then 'none' else 'all'#</hide>
 
269
        </param>
 
270
"""
 
271
 
 
272
def parse_tmpl(_tmpl, **kwargs):
 
273
        from Cheetah import Template
 
274
        return str(Template.Template(_tmpl, kwargs))
 
275
 
 
276
max_num_mboards = 8
 
277
max_num_channels = max_num_mboards*4
 
278
 
 
279
if __name__ == '__main__':
 
280
        import sys
 
281
        for file in sys.argv[1:]:
 
282
                if 'source' in file:
 
283
                        sourk = 'source'
 
284
                        direction = 'out'
 
285
                elif 'sink' in file:
 
286
                        sourk = 'sink'
 
287
                        direction = 'in'
 
288
                else: raise Exception, 'is %s a source or sink?'%file
 
289
 
 
290
                params = ''.join([parse_tmpl(PARAMS_TMPL, n=n) for n in range(max_num_channels)])
 
291
                open(file, 'w').write(parse_tmpl(MAIN_TMPL,
 
292
                        max_nchan=max_num_channels,
 
293
                        max_mboards=max_num_mboards,
 
294
                        params=params,
 
295
                        sourk=sourk,
 
296
                        direction=direction,
 
297
                ))