3 # Copyright 2009 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
23 from gnuradio import gr
24 from gnuradio import msdd_rs
25 from gnuradio import eng_notation
26 from gnuradio.eng_option import eng_option
27 from gnuradio.qtgui import qtgui
28 from optparse import OptionParser
32 from gnuradio.qtgui import qtgui
33 from PyQt4 import QtGui, QtCore
36 print "Please install gr-qtgui."
40 from msdd_display_qtgui import Ui_MainWindow
42 print "Error: could not find msdd_display_qtgui.py:"
43 print "\t\"pyuic4 msdd_display_qtgui.ui -o msdd_display_qtgui.py\""
47 # ////////////////////////////////////////////////////////////////////
48 # Define the QT Interface and Control Dialog
49 # ////////////////////////////////////////////////////////////////////
52 class main_window(QtGui.QMainWindow):
53 def __init__(self, snk, fg, parent=None):
55 QtGui.QWidget.__init__(self, parent)
56 self.gui = Ui_MainWindow()
57 self.gui.setupUi(self)
61 # Add the qtsnk widgets to the layout box
62 self.gui.sinkLayout.addWidget(snk)
64 self.gui.dcGainEdit.setText(QtCore.QString("%1").arg(0.001))
66 # Connect up some signals
67 self.connect(self.gui.pauseButton, QtCore.SIGNAL("clicked()"),
69 self.connect(self.gui.frequencyEdit, QtCore.SIGNAL("editingFinished()"),
70 self.frequencyEditText)
71 self.connect(self.gui.gainEdit, QtCore.SIGNAL("editingFinished()"),
73 self.connect(self.gui.bandwidthEdit, QtCore.SIGNAL("editingFinished()"),
74 self.bandwidthEditText)
75 self.connect(self.gui.amplifierEdit, QtCore.SIGNAL("editingFinished()"),
76 self.amplifierEditText)
78 self.connect(self.gui.actionSaveData, QtCore.SIGNAL("activated()"),
80 self.gui.actionSaveData.setShortcut(QtGui.QKeySequence.Save)
82 self.connect(self.gui.dcGainEdit, QtCore.SIGNAL("editingFinished()"),
84 self.connect(self.gui.dcCancelCheckBox, QtCore.SIGNAL("clicked(bool)"),
88 if(self.gui.pauseButton.text() == "Pause"):
92 self.gui.pauseButton.setText("Unpause")
96 self.gui.pauseButton.setText("Pause")
99 # Functions to set the values in the GUI
100 def set_frequency(self, freq):
102 sfreq = eng_notation.num_to_str(self.freq)
103 self.gui.frequencyEdit.setText(QtCore.QString("%1").arg(sfreq))
105 def set_gain(self, gain):
107 self.gui.gainEdit.setText(QtCore.QString("%1").arg(self.gain))
109 def set_bandwidth(self, bw):
111 sbw = eng_notation.num_to_str(self.bw)
112 self.gui.bandwidthEdit.setText(QtCore.QString("%1").arg(sbw))
114 def set_amplifier(self, amp):
116 self.gui.amplifierEdit.setText(QtCore.QString("%1").arg(self.amp))
119 # Functions called when signals are triggered in the GUI
120 def frequencyEditText(self):
122 freq = eng_notation.str_to_num(self.gui.frequencyEdit.text().toAscii())
123 self.fg.set_frequency(freq)
128 def gainEditText(self):
130 gain = float(self.gui.gainEdit.text())
131 self.fg.set_gain(gain)
136 def bandwidthEditText(self):
138 bw = eng_notation.str_to_num(self.gui.bandwidthEdit.text().toAscii())
139 self.fg.set_bandwidth(bw)
144 def amplifierEditText(self):
146 amp = float(self.gui.amplifierEdit.text())
147 self.fg.set_amplifier_gain(amp)
153 fileName = QtGui.QFileDialog.getSaveFileName(self, "Save data to file", ".");
155 self.fg.save_to_file(str(fileName))
157 def dcGainEditText(self):
158 gain = float(self.gui.dcGainEdit.text())
159 self.fg.set_dc_gain(gain)
161 def dcCancelClicked(self, state):
162 self.dcGainEditText()
163 self.fg.cancel_dc(state)
167 class my_top_block(gr.top_block):
169 gr.top_block.__init__(self)
171 parser = OptionParser(option_class=eng_option)
172 parser.add_option("-e", "--interface", type="string", default="eth0",
173 help="select Ethernet interface, default is eth0")
174 parser.add_option("-m", "--mac-addr", type="string", default="",
175 help="select USRP by MAC address, default is auto-select")
176 parser.add_option("-W", "--bw", type="float", default=1e6,
177 help="set bandwidth of receiver [default=%default]")
178 parser.add_option("-f", "--freq", type="eng_float", default="2.4G",
179 help="set frequency to FREQ", metavar="FREQ")
180 parser.add_option("-g", "--gain", type="eng_float", default=None,
181 help="set gain in dB (default is midpoint)")
182 parser.add_option("--fft-size", type="int", default=2048,
183 help="Set number of FFT bins [default=%default]")
184 (options, args) = parser.parse_args()
189 self.options = options
190 self.show_debug_info = True
192 self.qapp = QtGui.QApplication(sys.argv)
194 # self.u = usrp2.source_32fc(options.interface, options.mac_addr)
195 self.u = msdd_rs.source_simple("192.168.1.20", 10000);
196 self.conv = gr.interleaved_short_to_complex();
197 self._adc_rate = self.u.pull_adc_freq()
198 self.set_bandwidth(options.bw)
200 if options.gain is None:
201 # if no gain was specified, use the mid-point in dB
202 # g = self.u.gain_range()
204 #options.gain = float(g[0]+g[1])/2
205 options.gain = float(0)
206 self.set_gain(options.gain)
208 if options.freq is None:
209 options.freq = 2.4e9;
210 # # if no frequency was specified, use the mid-point of the subdev
211 # f = self.u.freq_range()
212 # options.freq = float(f[0]+f[1])/2
214 self.set_frequency(options.freq)
216 self._fftsize = options.fft_size
219 self._freq = options.freq;
220 self._bandwidth = 400;
222 self.set_bandwidth(self._bandwidth);
224 self.snk = qtgui.sink_c(options.fft_size, gr.firdes.WIN_BLACKMAN_hARRIS,
225 self._freq, self._bandwidth,
227 True, True, False, True, False)
229 # Set up internal amplifier
230 self.amp = gr.multiply_const_cc(0.0)
231 self.set_amplifier_gain(0.01)
233 # Create a single-pole IIR filter to remove DC
234 # but don't connect it yet
236 self.dc = gr.single_pole_iir_filter_cc(self.dc_gain)
237 self.dc_sub = gr.sub_cc()
239 self.agc = gr.agc2_cc(1e-3, 1e-5, 0.01, 0.01, 10);
241 self.connect(self.u, self.conv, self.snk)
242 #self.connect(self.u, self.conv, self.amp, self.snk)
244 if self.show_debug_info:
245 print "Decimation rate: ", self._decim
246 print "Bandwidth: ", self._bandwidth
247 # print "D'board: ", self.u.daughterboard_id()
249 # Get the reference pointer to the SpectrumDisplayForm QWidget
250 # Wrap the pointer as a PyQt SIP object
251 # This can now be manipulated as a PyQt4.QtGui.QWidget
252 self.pysink = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget)
254 self.main_win = main_window(self.pysink, self)
256 self.main_win.set_frequency(self._freq)
257 self.main_win.set_gain(self._gain)
258 self.main_win.set_bandwidth(self._bandwidth)
259 self.main_win.set_amplifier(self._amp_value)
264 def save_to_file(self, name):
267 # Add file sink to save data
268 self.file_sink = gr.file_sink(gr.sizeof_gr_complex, name)
269 self.connect(self.conv, self.file_sink)
273 def set_gain(self, gain):
275 self.u.set_ddc_gain(self._gain)
277 def set_frequency(self, freq):
279 r = self.u.set_rx_freq(freq)
282 self.snk.set_frequency_range(self._freq, self._bandwidth)
286 def set_bandwidth(self, bw):
288 self._decim = int(self._adc_rate / self._bandwidth)
289 # self.u.set_decim_rate(self._decim)
290 r1 = self.u.set_ddc_samp_rate( bw );
291 r2 = self.u.set_ddc_bw( bw );
298 bw = self.u.pull_ddc_bw();
299 sr = self.u.pull_ddc_samp_rate();
300 fc = self.u.pull_rx_freq();
302 #self.snk.d_bandwidth = sr;
311 self.snk.set_frequency_range(self._freq, self._bandwidth)
315 def set_amplifier_gain(self, amp):
316 self._amp_value = amp
317 self.amp.set_k(self._amp_value)
319 def set_dc_gain(self, gain):
320 self.dc.set_taps(gain)
322 def cancel_dc(self, state):
326 self.disconnect(self.u, self.amp)
327 self.connect(self.u, (self.dc_sub,0))
328 self.connect(self.u, self.dc, (self.dc_sub,1))
329 self.connect(self.dc_sub, self.amp)
331 self.disconnect(self.dc_sub, self.amp)
332 self.disconnect(self.dc, (self.dc_sub,1))
333 self.disconnect(self.u, self.dc)
334 self.disconnect(self.u, (self.dc_sub,0))
335 self.connect(self.u, self.amp)
345 if __name__ == '__main__':
348 except KeyboardInterrupt: