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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
#!/usr/bin/env python
#
# Copyright 2009,2011 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
import wx
from gnuradio import gr
from gnuradio.gr.pubsub import pubsub
from gnuradio.wxgui import gui, forms
import uhd_siggen
import sys, math
class app_gui(pubsub):
def __init__(self, frame, panel, vbox, top_block, options, args):
pubsub.__init__(self)
self.frame = frame # Use for top-level application window frame
self.panel = panel # Use as parent class for created windows
self.vbox = vbox # Use as sizer for created windows
self.tb = top_block # GUI-unaware flowgraph class
self.options = options # Supplied command-line options
self.args = args # Supplied command-line arguments
self.build_gui()
# Event response handlers
def evt_set_status_msg(self, msg):
self.frame.SetStatusText(msg, 0)
# GUI construction
def build_gui(self):
self.vbox.AddSpacer(5)
self.vbox.AddStretchSpacer()
##################################################
# Baseband controls
##################################################
bb_vbox = forms.static_box_sizer(parent=self.panel, label="Baseband Modulation", orient=wx.VERTICAL, bold=True)
self.vbox.Add(bb_vbox, 0, wx.EXPAND)
sine_bb_hbox = wx.BoxSizer(wx.HORIZONTAL)
sweep_bb_hbox = wx.BoxSizer(wx.HORIZONTAL)
tone_bb_hbox = wx.BoxSizer(wx.HORIZONTAL)
self.vbox.AddSpacer(10)
self.vbox.AddStretchSpacer()
#callback to show/hide forms
def set_type(type):
sine_bb_hbox.ShowItems(type == gr.GR_SIN_WAVE)
sweep_bb_hbox.ShowItems(type == 'sweep')
tone_bb_hbox.ShowItems(type == '2tone')
self.vbox.Layout()
self.tb.subscribe(uhd_siggen.TYPE_KEY, set_type)
#create sine forms
sine_bb_hbox.AddSpacer(10)
forms.text_box(
parent=self.panel, sizer=sine_bb_hbox,
label='Frequency (Hz)',
ps=self.tb,
key=uhd_siggen.WAVEFORM_FREQ_KEY,
converter=forms.float_converter(),
)
sine_bb_hbox.AddStretchSpacer()
#create sweep forms
sweep_bb_hbox.AddSpacer(10)
forms.text_box(
parent=self.panel, sizer=sweep_bb_hbox,
label='Sweep Width (Hz)',
ps=self.tb,
key=uhd_siggen.WAVEFORM_FREQ_KEY,
converter=forms.float_converter(),
)
sweep_bb_hbox.AddStretchSpacer()
forms.text_box(
parent=self.panel, sizer=sweep_bb_hbox,
label='Sweep Rate (Hz)',
ps=self.tb,
key=uhd_siggen.WAVEFORM2_FREQ_KEY,
converter=forms.float_converter(),
)
sweep_bb_hbox.AddStretchSpacer()
#create 2tone forms
tone_bb_hbox.AddSpacer(10)
forms.text_box(
parent=self.panel, sizer=tone_bb_hbox,
label='Tone 1 (Hz)',
ps=self.tb,
key=uhd_siggen.WAVEFORM_FREQ_KEY,
converter=forms.float_converter(),
)
tone_bb_hbox.AddStretchSpacer()
forms.text_box(
parent=self.panel, sizer=tone_bb_hbox,
label='Tone 2 (Hz)',
ps=self.tb,
key=uhd_siggen.WAVEFORM2_FREQ_KEY,
converter=forms.float_converter(),
)
tone_bb_hbox.AddStretchSpacer()
forms.radio_buttons(
parent=self.panel, sizer=bb_vbox,
choices=uhd_siggen.waveforms.keys(),
labels=uhd_siggen.waveforms.values(),
ps=self.tb,
key=uhd_siggen.TYPE_KEY,
style=wx.NO_BORDER | wx.RA_HORIZONTAL,
)
bb_vbox.AddSpacer(10)
bb_vbox.Add(sine_bb_hbox, 0, wx.EXPAND)
bb_vbox.Add(sweep_bb_hbox, 0, wx.EXPAND)
bb_vbox.Add(tone_bb_hbox, 0, wx.EXPAND)
set_type(self.tb[uhd_siggen.TYPE_KEY])
##################################################
# Frequency controls
##################################################
fc_vbox = forms.static_box_sizer(parent=self.panel,
label="Center Frequency",
orient=wx.VERTICAL,
bold=True)
fc_vbox.AddSpacer(5)
# First row of frequency controls (center frequency)
freq_hbox = wx.BoxSizer(wx.HORIZONTAL)
fc_vbox.Add(freq_hbox, 0, wx.EXPAND)
fc_vbox.AddSpacer(10)
# Second row of frequency controls (results)
tr_hbox = wx.BoxSizer(wx.HORIZONTAL)
fc_vbox.Add(tr_hbox, 0, wx.EXPAND)
fc_vbox.AddSpacer(5)
# Add frequency controls to top window sizer
self.vbox.Add(fc_vbox, 0, wx.EXPAND)
self.vbox.AddSpacer(10)
self.vbox.AddStretchSpacer()
freq_hbox.AddSpacer(5)
forms.text_box(
parent=self.panel, sizer=freq_hbox,
proportion=1,
converter=forms.float_converter(),
ps=self.tb,
key=uhd_siggen.TX_FREQ_KEY,
)
freq_hbox.AddSpacer(10)
forms.slider(
parent=self.panel, sizer=freq_hbox,
proportion=2,
ps=self.tb,
key=uhd_siggen.TX_FREQ_KEY,
minimum=self.tb[uhd_siggen.FREQ_RANGE_KEY].start(),
maximum=self.tb[uhd_siggen.FREQ_RANGE_KEY].stop(),
num_steps=100,
)
freq_hbox.AddSpacer(5)
tr_hbox.AddSpacer(5)
forms.static_text(
parent=self.panel, sizer=tr_hbox,
label='RF Frequency',
ps=self.tb,
key=uhd_siggen.RF_FREQ_KEY,
converter=forms.float_converter(),
proportion=1,
)
tr_hbox.AddSpacer(10)
forms.static_text(
parent=self.panel, sizer=tr_hbox,
label='DSP Frequency',
ps=self.tb,
key=uhd_siggen.DSP_FREQ_KEY,
converter=forms.float_converter(),
proportion=1,
)
tr_hbox.AddSpacer(5)
##################################################
# Amplitude controls
##################################################
amp_hbox = forms.static_box_sizer(parent=self.panel,
label="Amplitude",
orient=wx.VERTICAL,
bold=True)
amp_hbox.AddSpacer(5)
# First row of amp controls (ampl)
lvl_hbox = wx.BoxSizer(wx.HORIZONTAL)
amp_hbox.Add(lvl_hbox, 0, wx.EXPAND)
amp_hbox.AddSpacer(10)
# Second row of amp controls (tx gain)
gain_hbox = wx.BoxSizer(wx.HORIZONTAL)
amp_hbox.Add(gain_hbox, 0, wx.EXPAND)
amp_hbox.AddSpacer(5)
self.vbox.Add(amp_hbox, 0, wx.EXPAND)
self.vbox.AddSpacer(10)
self.vbox.AddStretchSpacer()
lvl_hbox.AddSpacer(5)
forms.text_box(
parent=self.panel, sizer=lvl_hbox,
proportion=1,
converter=forms.float_converter(),
ps=self.tb,
key=uhd_siggen.AMPLITUDE_KEY,
label="Level (0.0-1.0)",
)
lvl_hbox.AddSpacer(10)
forms.log_slider(
parent=self.panel, sizer=lvl_hbox,
proportion=2,
ps=self.tb,
key=uhd_siggen.AMPLITUDE_KEY,
min_exp=-6,
max_exp=0,
base=10,
num_steps=100,
)
lvl_hbox.AddSpacer(5)
if self.tb[uhd_siggen.GAIN_RANGE_KEY].start() < self.tb[uhd_siggen.GAIN_RANGE_KEY].stop():
gain_hbox.AddSpacer(5)
forms.text_box(
parent=self.panel, sizer=gain_hbox,
proportion=1,
converter=forms.float_converter(),
ps=self.tb,
key=uhd_siggen.GAIN_KEY,
label="TX Gain (dB)",
)
gain_hbox.AddSpacer(10)
forms.slider(
parent=self.panel, sizer=gain_hbox,
proportion=2,
ps=self.tb,
key=uhd_siggen.GAIN_KEY,
minimum=self.tb[uhd_siggen.GAIN_RANGE_KEY].start(),
maximum=self.tb[uhd_siggen.GAIN_RANGE_KEY].stop(),
step_size=self.tb[uhd_siggen.GAIN_RANGE_KEY].step(),
)
gain_hbox.AddSpacer(5)
##################################################
# Sample Rate controls
##################################################
sam_hbox = forms.static_box_sizer(parent=self.panel,
label="Sample Rate",
orient=wx.HORIZONTAL,
bold=True)
self.vbox.Add(sam_hbox, 0, wx.EXPAND)
self.vbox.AddSpacer(10)
self.vbox.AddStretchSpacer()
sam_hbox.AddStretchSpacer(20)
forms.static_text(
parent=self.panel, sizer=sam_hbox,
label='Sample Rate (sps)',
ps=self.tb,
key=uhd_siggen.SAMP_RATE_KEY,
converter=forms.float_converter(),
)
sam_hbox.AddStretchSpacer(20)
##################################################
# UHD status
##################################################
u2_hbox = forms.static_box_sizer(parent=self.panel,
label="UHD Status",
orient=wx.HORIZONTAL,
bold=True)
self.vbox.Add(u2_hbox, 0, wx.EXPAND)
self.vbox.AddSpacer(10)
self.vbox.AddStretchSpacer()
u2_hbox.AddSpacer(10)
forms.static_text(
parent=self.panel, sizer=u2_hbox,
ps=self.tb,
key=uhd_siggen.DESC_KEY,
converter=forms.str_converter(),
)
self.vbox.AddSpacer(5)
self.vbox.AddStretchSpacer()
def main():
try:
# Get command line parameters
(options, args) = uhd_siggen.get_options()
# Create the top block using these
tb = uhd_siggen.top_block(options, args)
# Create the GUI application
app = gui.app(top_block=tb, # Constructed top block
gui=app_gui, # User interface class
options=options, # Command line options
args=args, # Command line args
title="UHD Signal Generator", # Top window title
nstatus=1, # Number of status lines
start=True, # Whether to start flowgraph
realtime=True) # Whether to set realtime priority
# And run it
app.MainLoop()
except RuntimeError, e:
print e
sys.exit(1)
# Make sure to create the top block (tb) within a function: That code
# in main will allow tb to go out of scope on return, which will call
# the decontructor on uhd device and stop transmit. Whats odd is that
# grc works fine with tb in the __main__, perhaps its because the
# try/except clauses around tb.
if __name__ == "__main__": main()
|