40 |
kaklik |
1 |
#!/usr/bin/env python |
|
|
2 |
################################################## |
|
|
3 |
# Gnuradio Python Flow Graph |
|
|
4 |
# Title: UHD WBFM Receive |
|
|
5 |
# Author: Example |
|
|
6 |
# Description: WBFM Receive |
|
|
7 |
# Generated: Thu May 24 20:00:08 2012 |
|
|
8 |
################################################## |
|
|
9 |
|
|
|
10 |
from PyQt4 import Qt |
|
|
11 |
from gnuradio import audio |
|
|
12 |
from gnuradio import blks2 |
|
|
13 |
from gnuradio import eng_notation |
|
|
14 |
from gnuradio import gr |
|
|
15 |
from gnuradio.eng_option import eng_option |
|
|
16 |
from gnuradio.gr import firdes |
|
|
17 |
from gnuradio.qtgui import qtgui |
|
|
18 |
from optparse import OptionParser |
|
|
19 |
import PyQt4.Qwt5 as Qwt |
|
|
20 |
import baz |
|
|
21 |
import sip |
|
|
22 |
import sys |
|
|
23 |
|
|
|
24 |
class uhd_wbfm_receive(gr.top_block, Qt.QWidget): |
|
|
25 |
|
|
|
26 |
def __init__(self, audio_output="", freq=107.6e6, gain=10, address="addr=192.168.10.2", samp_rate=1056e3): |
|
|
27 |
gr.top_block.__init__(self, "UHD WBFM Receive") |
|
|
28 |
Qt.QWidget.__init__(self) |
|
|
29 |
self.setWindowTitle("UHD WBFM Receive") |
|
|
30 |
self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) |
|
|
31 |
self.top_scroll_layout = Qt.QVBoxLayout() |
|
|
32 |
self.setLayout(self.top_scroll_layout) |
|
|
33 |
self.top_scroll = Qt.QScrollArea() |
|
|
34 |
self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) |
|
|
35 |
self.top_scroll_layout.addWidget(self.top_scroll) |
|
|
36 |
self.top_scroll.setWidgetResizable(True) |
|
|
37 |
self.top_widget = Qt.QWidget() |
|
|
38 |
self.top_scroll.setWidget(self.top_widget) |
|
|
39 |
self.top_layout = Qt.QVBoxLayout(self.top_widget) |
|
|
40 |
self.top_grid_layout = Qt.QGridLayout() |
|
|
41 |
self.top_layout.addLayout(self.top_grid_layout) |
|
|
42 |
|
|
|
43 |
|
|
|
44 |
################################################## |
|
|
45 |
# Parameters |
|
|
46 |
################################################## |
|
|
47 |
self.audio_output = audio_output |
|
|
48 |
self.freq = freq |
|
|
49 |
self.gain = gain |
|
|
50 |
self.address = address |
|
|
51 |
self.samp_rate = samp_rate |
|
|
52 |
|
|
|
53 |
################################################## |
|
|
54 |
# Variables |
|
|
55 |
################################################## |
|
|
56 |
self.volume = volume = 2 |
|
|
57 |
self.tun_gain = tun_gain = gain |
|
|
58 |
self.tun_freq = tun_freq = 9.30825e+07 |
|
|
59 |
self.fine = fine = 0 |
|
|
60 |
self.audio_decim = audio_decim = 22 |
|
|
61 |
|
|
|
62 |
################################################## |
|
|
63 |
# Blocks |
|
|
64 |
################################################## |
|
|
65 |
self._volume_layout = Qt.QVBoxLayout() |
|
|
66 |
self._volume_knob = Qwt.QwtKnob() |
|
|
67 |
self._volume_knob.setRange(0, 10, 1e-3) |
|
|
68 |
self._volume_knob.setValue(self.volume) |
|
|
69 |
self._volume_knob.valueChanged.connect(self.set_volume) |
|
|
70 |
self._volume_layout.addWidget(self._volume_knob) |
|
|
71 |
self._volume_label = Qt.QLabel("Volume") |
|
|
72 |
self._volume_label.setAlignment(Qt.Qt.AlignTop | Qt.Qt.AlignHCenter) |
|
|
73 |
self._volume_layout.addWidget(self._volume_label) |
|
|
74 |
self.top_layout.addLayout(self._volume_layout) |
|
|
75 |
self._tun_gain_layout = Qt.QVBoxLayout() |
|
|
76 |
self._tun_gain_knob = Qwt.QwtKnob() |
|
|
77 |
self._tun_gain_knob.setRange(0, 20, 1e-2) |
|
|
78 |
self._tun_gain_knob.setValue(self.tun_gain) |
|
|
79 |
self._tun_gain_knob.valueChanged.connect(self.set_tun_gain) |
|
|
80 |
self._tun_gain_layout.addWidget(self._tun_gain_knob) |
|
|
81 |
self._tun_gain_label = Qt.QLabel("tun_gain") |
|
|
82 |
self._tun_gain_label.setAlignment(Qt.Qt.AlignTop | Qt.Qt.AlignHCenter) |
|
|
83 |
self._tun_gain_layout.addWidget(self._tun_gain_label) |
|
|
84 |
self.top_layout.addLayout(self._tun_gain_layout) |
|
|
85 |
self._tun_freq_layout = Qt.QVBoxLayout() |
|
|
86 |
self._tun_freq_tool_bar = Qt.QToolBar(self) |
|
|
87 |
self._tun_freq_layout.addWidget(self._tun_freq_tool_bar) |
|
|
88 |
self._tun_freq_tool_bar.addWidget(Qt.QLabel("Freq (Hz)"+": ")) |
|
|
89 |
self._tun_freq_counter = Qwt.QwtCounter() |
|
|
90 |
self._tun_freq_counter.setRange(80e6, 110e6, 1e-2) |
|
|
91 |
self._tun_freq_counter.setNumButtons(2) |
|
|
92 |
self._tun_freq_counter.setValue(self.tun_freq) |
|
|
93 |
self._tun_freq_tool_bar.addWidget(self._tun_freq_counter) |
|
|
94 |
self._tun_freq_counter.valueChanged.connect(self.set_tun_freq) |
|
|
95 |
self._tun_freq_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) |
|
|
96 |
self._tun_freq_slider.setRange(80e6, 110e6, 1e-2) |
|
|
97 |
self._tun_freq_slider.setValue(self.tun_freq) |
|
|
98 |
self._tun_freq_slider.setMinimumWidth(200) |
|
|
99 |
self._tun_freq_slider.valueChanged.connect(self.set_tun_freq) |
|
|
100 |
self._tun_freq_layout.addWidget(self._tun_freq_slider) |
|
|
101 |
self.top_layout.addLayout(self._tun_freq_layout) |
|
|
102 |
self._fine_layout = Qt.QVBoxLayout() |
|
|
103 |
self._fine_tool_bar = Qt.QToolBar(self) |
|
|
104 |
self._fine_layout.addWidget(self._fine_tool_bar) |
|
|
105 |
self._fine_tool_bar.addWidget(Qt.QLabel("fine"+": ")) |
|
|
106 |
self._fine_counter = Qwt.QwtCounter() |
|
|
107 |
self._fine_counter.setRange(-1e-1, 1e-1, 1e-3) |
|
|
108 |
self._fine_counter.setNumButtons(2) |
|
|
109 |
self._fine_counter.setValue(self.fine) |
|
|
110 |
self._fine_tool_bar.addWidget(self._fine_counter) |
|
|
111 |
self._fine_counter.valueChanged.connect(self.set_fine) |
|
|
112 |
self._fine_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) |
|
|
113 |
self._fine_slider.setRange(-1e-1, 1e-1, 1e-3) |
|
|
114 |
self._fine_slider.setValue(self.fine) |
|
|
115 |
self._fine_slider.setMinimumWidth(200) |
|
|
116 |
self._fine_slider.valueChanged.connect(self.set_fine) |
|
|
117 |
self._fine_layout.addWidget(self._fine_slider) |
|
|
118 |
self.top_layout.addLayout(self._fine_layout) |
|
|
119 |
self.rtl2832_source_0 = baz.rtl_source_c(defer_creation=True) |
|
|
120 |
self.rtl2832_source_0.set_verbose(True) |
|
|
121 |
self.rtl2832_source_0.set_vid(0x0) |
|
|
122 |
self.rtl2832_source_0.set_pid(0x0) |
|
|
123 |
self.rtl2832_source_0.set_tuner_name("e4000") |
|
|
124 |
self.rtl2832_source_0.set_default_timeout(0) |
|
|
125 |
self.rtl2832_source_0.set_use_buffer(True) |
|
|
126 |
self.rtl2832_source_0.set_fir_coefficients(([])) |
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
if self.rtl2832_source_0.create() == False: raise Exception("Failed to create RTL2832 Source: rtl2832_source_0") |
|
|
133 |
|
|
|
134 |
|
|
|
135 |
self.rtl2832_source_0.set_sample_rate(samp_rate) |
|
|
136 |
|
|
|
137 |
self.rtl2832_source_0.set_frequency(tun_freq+fine) |
|
|
138 |
|
|
|
139 |
|
|
|
140 |
self.rtl2832_source_0.set_auto_gain_mode(False) |
|
|
141 |
self.rtl2832_source_0.set_relative_gain(True) |
|
|
142 |
self.rtl2832_source_0.set_gain(tun_gain) |
|
|
143 |
|
|
|
144 |
self.qtgui_sink_x_0 = qtgui.sink_c( |
|
|
145 |
1024, #fftsize |
|
|
146 |
firdes.WIN_BLACKMAN_hARRIS, #wintype |
|
|
147 |
0, #fc |
|
|
148 |
samp_rate, #bw |
|
|
149 |
"QT GUI Plot", #name |
|
|
150 |
True, #plotfreq |
|
|
151 |
True, #plotwaterfall |
|
|
152 |
True, #plottime |
|
|
153 |
True, #plotconst |
|
|
154 |
) |
|
|
155 |
self._qtgui_sink_x_0_win = sip.wrapinstance(self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget) |
|
|
156 |
self.top_layout.addWidget(self._qtgui_sink_x_0_win) |
|
|
157 |
self.low_pass_filter_0 = gr.fir_filter_ccf(1, firdes.low_pass( |
|
|
158 |
1, samp_rate, 115e3, 30e3, firdes.WIN_HANN, 6.76)) |
|
|
159 |
self.gr_multiply_const_vxx = gr.multiply_const_vff((volume, )) |
|
|
160 |
self.blks2_wfm_rcv = blks2.wfm_rcv( |
|
|
161 |
quad_rate=samp_rate, |
|
|
162 |
audio_decimation=audio_decim, |
|
|
163 |
) |
|
|
164 |
self.audio_sink = audio.sink(int(samp_rate/audio_decim), audio_output, True) |
|
|
165 |
|
|
|
166 |
################################################## |
|
|
167 |
# Connections |
|
|
168 |
################################################## |
|
|
169 |
self.connect((self.gr_multiply_const_vxx, 0), (self.audio_sink, 0)) |
|
|
170 |
self.connect((self.blks2_wfm_rcv, 0), (self.gr_multiply_const_vxx, 0)) |
|
|
171 |
self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv, 0)) |
|
|
172 |
self.connect((self.rtl2832_source_0, 0), (self.low_pass_filter_0, 0)) |
|
|
173 |
self.connect((self.low_pass_filter_0, 0), (self.qtgui_sink_x_0, 0)) |
|
|
174 |
|
|
|
175 |
def get_audio_output(self): |
|
|
176 |
return self.audio_output |
|
|
177 |
|
|
|
178 |
def set_audio_output(self, audio_output): |
|
|
179 |
self.audio_output = audio_output |
|
|
180 |
|
|
|
181 |
def get_freq(self): |
|
|
182 |
return self.freq |
|
|
183 |
|
|
|
184 |
def set_freq(self, freq): |
|
|
185 |
self.freq = freq |
|
|
186 |
|
|
|
187 |
def get_gain(self): |
|
|
188 |
return self.gain |
|
|
189 |
|
|
|
190 |
def set_gain(self, gain): |
|
|
191 |
self.gain = gain |
|
|
192 |
self.set_tun_gain(self.gain) |
|
|
193 |
|
|
|
194 |
def get_address(self): |
|
|
195 |
return self.address |
|
|
196 |
|
|
|
197 |
def set_address(self, address): |
|
|
198 |
self.address = address |
|
|
199 |
|
|
|
200 |
def get_samp_rate(self): |
|
|
201 |
return self.samp_rate |
|
|
202 |
|
|
|
203 |
def set_samp_rate(self, samp_rate): |
|
|
204 |
self.samp_rate = samp_rate |
|
|
205 |
self.rtl2832_source_0.set_sample_rate(self.samp_rate) |
|
|
206 |
self.low_pass_filter_0.set_taps(firdes.low_pass(1, self.samp_rate, 115e3, 30e3, firdes.WIN_HANN, 6.76)) |
|
|
207 |
self.qtgui_sink_x_0.set_frequency_range(0, self.samp_rate) |
|
|
208 |
|
|
|
209 |
def get_volume(self): |
|
|
210 |
return self.volume |
|
|
211 |
|
|
|
212 |
def set_volume(self, volume): |
|
|
213 |
self.volume = volume |
|
|
214 |
self.gr_multiply_const_vxx.set_k((self.volume, )) |
|
|
215 |
self._volume_knob.setValue(self.volume) |
|
|
216 |
|
|
|
217 |
def get_tun_gain(self): |
|
|
218 |
return self.tun_gain |
|
|
219 |
|
|
|
220 |
def set_tun_gain(self, tun_gain): |
|
|
221 |
self.tun_gain = tun_gain |
|
|
222 |
self.rtl2832_source_0.set_gain(self.tun_gain) |
|
|
223 |
self._tun_gain_knob.setValue(self.tun_gain) |
|
|
224 |
|
|
|
225 |
def get_tun_freq(self): |
|
|
226 |
return self.tun_freq |
|
|
227 |
|
|
|
228 |
def set_tun_freq(self, tun_freq): |
|
|
229 |
self.tun_freq = tun_freq |
|
|
230 |
self.rtl2832_source_0.set_frequency(self.tun_freq+self.fine) |
|
|
231 |
self._tun_freq_counter.setValue(self.tun_freq) |
|
|
232 |
self._tun_freq_slider.setValue(self.tun_freq) |
|
|
233 |
|
|
|
234 |
def get_fine(self): |
|
|
235 |
return self.fine |
|
|
236 |
|
|
|
237 |
def set_fine(self, fine): |
|
|
238 |
self.fine = fine |
|
|
239 |
self.rtl2832_source_0.set_frequency(self.tun_freq+self.fine) |
|
|
240 |
self._fine_counter.setValue(self.fine) |
|
|
241 |
self._fine_slider.setValue(self.fine) |
|
|
242 |
|
|
|
243 |
def get_audio_decim(self): |
|
|
244 |
return self.audio_decim |
|
|
245 |
|
|
|
246 |
def set_audio_decim(self, audio_decim): |
|
|
247 |
self.audio_decim = audio_decim |
|
|
248 |
|
|
|
249 |
if __name__ == '__main__': |
|
|
250 |
parser = OptionParser(option_class=eng_option, usage="%prog: [options]") |
|
|
251 |
parser.add_option("-O", "--audio-output", dest="audio_output", type="string", default="", |
|
|
252 |
help="Set Audio Output Device [default=%default]") |
|
|
253 |
parser.add_option("-f", "--freq", dest="freq", type="eng_float", default=eng_notation.num_to_str(107.6e6), |
|
|
254 |
help="Set Default Frequency [default=%default]") |
|
|
255 |
parser.add_option("-g", "--gain", dest="gain", type="eng_float", default=eng_notation.num_to_str(10), |
|
|
256 |
help="Set Default Gain [default=%default]") |
|
|
257 |
parser.add_option("-a", "--address", dest="address", type="string", default="addr=192.168.10.2", |
|
|
258 |
help="Set IP Address [default=%default]") |
|
|
259 |
parser.add_option("-s", "--samp-rate", dest="samp_rate", type="eng_float", default=eng_notation.num_to_str(1056e3), |
|
|
260 |
help="Set Sample Rate [default=%default]") |
|
|
261 |
(options, args) = parser.parse_args() |
|
|
262 |
qapp = Qt.QApplication(sys.argv) |
|
|
263 |
tb = uhd_wbfm_receive(audio_output=options.audio_output, freq=options.freq, gain=options.gain, address=options.address, samp_rate=options.samp_rate) |
|
|
264 |
tb.start() |
|
|
265 |
tb.show() |
|
|
266 |
qapp.exec_() |
|
|
267 |
tb.stop() |
|
|
268 |
|