3 # Copyright 2005,2006,2007 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, gru, eng_notation
24 from gnuradio import msdd
25 from gnuradio import blks2
26 from gnuradio.eng_option import eng_option
27 from gnuradio.wxgui import slider, powermate
28 from gnuradio.wxgui import stdgui2, form
29 from gnuradio.wxgui import fftsink2
30 from optparse import OptionParser
31 #from usrpm import usrp_dbid
36 class wfm_rx_block (stdgui2.std_top_block):
37 def __init__(self,frame,panel,vbox,argv):
38 stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv)
40 parser=OptionParser(option_class=eng_option)
41 # parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
42 # help="select MSDD Rx side A or B (default=A)")
43 parser.add_option("-f", "--freq", type="eng_float", default=100.1e6,
44 help="set frequency to FREQ", metavar="FREQ")
45 parser.add_option("-g", "--gain", type="eng_float", default=40,
46 help="set gain in dB (default is midpoint)")
47 # parser.add_option("-V", "--volume", type="eng_float", default=None,
48 # help="set volume (default is midpoint)")
49 # parser.add_option("-O", "--audio-output", type="string", default="",
50 # help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp")
52 (options, args) = parser.parse_args()
61 self.gain_range = (10, 70, .5)
68 self.sample_rate = 200
69 self.u = msdd.source_c(0, 1, "10.45.4.44", 10000)
70 self.u.set_decim_rate(4)
71 self.u.set_desired_packet_size(0, 1460*100)
74 #self.u.set_decim_rate(msdd_decim)
75 # usrp_rate = adc_rate / msdd_decim # 320 kS/s
77 # demod_rate = usrp_rate / chanfilt_decim
78 # audio_decimation = 10
79 # audio_rate = demod_rate / audio_decimation # 32 kHz
81 # if options.rx_subdev_spec is None:
82 # options.rx_subdev_spec = pick_subdevice(self.u)
84 # self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
85 # self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
86 # print "Using RX d'board %s" % (self.subdev.side_and_name(),)
89 # chan_filt_coeffs = optfir.low_pass (1, # gain
90 # usrp_rate, # sampling rate
91 # 80e3, # passband cutoff
92 # 115e3, # stopband cutoff
93 # 0.1, # passband ripple
94 # 60) # stopband attenuation
95 # #print len(chan_filt_coeffs)
96 # chan_filt = gr.fir_filter_ccf (chanfilt_decim, chan_filt_coeffs)
98 # self.guts = blks2.wfm_rcv (demod_rate, audio_decimation)
100 # self.volume_control = gr.multiply_const_ff(self.vol)
102 # # sound card as final sink
103 # audio_sink = audio.sink (int (audio_rate),
104 # options.audio_output,
105 # False) # ok_to_block
107 # now wire it all together
108 #self.connect (self.u, chan_filt, self.guts, self.volume_control, audio_sink)
110 self._build_gui(vbox)
112 if options.gain is None:
113 # if no gain was specified, use the mid-point in dB
114 #g = self.subdev.gain_range()
116 options.gain = float(g[0]+g[1])/2
118 # if options.volume is None:
119 # g = self.volume_range()
120 # options.volume = float(g[0]+g[1])/2
122 # if abs(options.freq) < 1e6:
123 # options.freq *= 1e6
127 self.set_gain(options.gain)
128 # self.set_vol(options.volume)
129 if not(self.set_freq(options.freq)):
130 self._set_status_msg("Failed to set initial frequency")
131 print "Frequency: ", self.u.rx_freq(0)
134 def _set_status_msg(self, msg, which=0):
135 self.frame.GetStatusBar().SetStatusText(msg, which)
138 def _build_gui(self, vbox):
140 def _form_set_freq(kv):
141 return self.set_freq(kv['freq'])
145 self.src_fft = fftsink2.fft_sink_c(self.panel, title="Data from MSDD",
146 fft_size=512, sample_rate=512)
147 # self.s2f1 = gr.short_to_float()
148 # self.scope = scopesink2.scope_sink_f(self.panel, sample_rate=self.sample_rate*self.fft_size)
150 self.connect (self.u, self.src_fft)
151 #self.connect (self.s2f1, self.scope)
152 vbox.Add (self.src_fft.win, 4, wx.EXPAND)
155 # post_filt_fft = fftsink2.fft_sink_f(self.panel, title="Post Demod",
156 # fft_size=1024, sample_rate=usrp_rate,
157 # y_per_div=10, ref_level=0)
158 # self.connect (self.guts.fm_demod, post_filt_fft)
159 # vbox.Add (post_filt_fft.win, 4, wx.EXPAND)
162 # post_deemph_fft = fftsink2.fft_sink_f(self.panel, title="Post Deemph",
163 # fft_size=512, sample_rate=audio_rate,
164 # y_per_div=10, ref_level=-20)
165 # self.connect (self.guts.deemph, post_deemph_fft)
166 # vbox.Add (post_deemph_fft.win, 4, wx.EXPAND)
169 # control area form at bottom
170 self.myform = myform = form.form()
172 hbox = wx.BoxSizer(wx.HORIZONTAL)
174 myform['freq'] = form.float_field(
175 parent=self.panel, sizer=hbox, label="Freq", weight=1,
176 callback=myform.check_input_and_call(_form_set_freq, self._set_status_msg))
179 myform['freq_slider'] = \
180 form.quantized_slider_field(parent=self.panel, sizer=hbox, weight=3,
181 range=(30e6, 6e9, 1e6),
182 callback=self.set_freq)
184 vbox.Add(hbox, 0, wx.EXPAND)
186 hbox = wx.BoxSizer(wx.HORIZONTAL)
189 # myform['volume'] = \
190 # form.quantized_slider_field(parent=self.panel, sizer=hbox, label="Volume",
191 # weight=3, range=self.volume_range(),
192 # callback=self.set_vol)
196 form.quantized_slider_field(parent=self.panel, sizer=hbox, label="Gain",
197 weight=3, range=self.gain_range,
198 callback=self.set_gain)
200 vbox.Add(hbox, 0, wx.EXPAND)
203 # self.knob = powermate.powermate(self.frame)
205 # powermate.EVT_POWERMATE_ROTATE (self.frame, self.on_rotate)
206 # powermate.EVT_POWERMATE_BUTTON (self.frame, self.on_button)
208 # print "FYI: No Powermate or Contour Knob found"
211 def on_rotate (self, event):
212 self.rot += event.delta
213 if (self.state == "FREQ"):
215 self.set_freq(self.freq + .1e6)
218 self.set_freq(self.freq - .1e6)
221 step = self.volume_range()[2]
223 self.set_vol(self.vol + step)
226 self.set_vol(self.vol - step)
229 def on_button (self, event):
230 if event.value == 0: # button up
233 if self.state == "FREQ":
237 self.update_status_bar ()
240 # def set_vol (self, vol):
241 # g = self.volume_range()
242 # self.vol = max(g[0], min(g[1], vol))
243 # self.volume_control.set_k(10**(self.vol/10))
244 # self.myform['volume'].set_value(self.vol)
245 # self.update_status_bar ()
247 def set_freq(self, target_freq):
249 Set the center frequency we're interested in.
251 @param target_freq: frequency in Hz
254 Tuning is a two step process. First we ask the front-end to
255 tune as close to the desired frequency as it can. Then we use
256 the result of that operation and our target_frequency to
257 determine the value for the digital down converter.
259 r = self.u.set_rx_freq(0, target_freq);
262 self.freq = target_freq
263 self.myform['freq'].set_value(target_freq) # update displayed value
264 self.myform['freq_slider'].set_value(target_freq) # update displayed value
265 self.update_status_bar()
266 self._set_status_msg("OK", 0)
269 self._set_status_msg("Failed", 0)
272 def set_gain(self, gain):
273 self.myform['gain'].set_value(gain) # update displayed value
274 self.u.set_pga(0,gain)
276 def update_status_bar (self):
277 msg = "Volume:%r Setting:%s" % (self.vol, self.state)
278 self._set_status_msg(msg, 1)
279 #self.src_fft.set_baseband_freq(self.freq)
281 # def volume_range(self):
282 # return (-20.0, 0.0, 0.5)
285 if __name__ == '__main__':
286 app = stdgui2.stdapp (wfm_rx_block, "MSDD FFT RX")