3 # GUI interactions and high level connections handled here.
5 # Interacts with classes defined by wxGlade in ui.py.
7 # The usual gnuradio copyright boilerplate incorperated here by reference.
11 from threading import *
13 import wx.lib.evtmgr as em
16 from gnuradio import gr, gru, eng_notation, optfir
17 from gnuradio import audio
18 from gnuradio import usrp
19 from gnuradio import blks
20 from gnuradio.wxgui import fftsink
21 from gnuradio.wxgui import waterfallsink
22 from gnuradio.wxgui import scopesink
26 from ssbdemod import *
29 from math import log10
31 class graph( gr.hier_block ):
32 def __init__( self, fg ):
35 self.src = input( self.fe_decim )
36 self.adc_rate = self.src.adc_rate
37 self.fe_rate = self.adc_rate / self.fe_decim
40 self.demod_rate = self.fe_rate / self.filter_decim
41 self.audio_rate = self.demod_rate / self.audio_decim
43 self.demod = ssb_demod( fg, self.demod_rate, self.audio_rate )
45 #self.agc = gr.agc_ff()
46 self.out = output( fg, self.audio_rate )
48 fg.connect( self.src.src,
53 gr.hier_block.__init__( self, fg, None, None )
55 def tune( self, freq ):
57 self.src.set_freq( fe_target )
58 fe_freq = self.src.src.rx_freq( 0 )
59 demod_cf = fe_target - fe_freq
60 self.demod.tune( demod_cf )
62 class radio_frame( ui_frame ):
63 def __init__( self, block, *args, **kwds ):
64 ui_frame.__init__( self, *args, **kwds )
66 self.freq_disp.SetRange(0, 30e6)
67 f = self.block.src.freq
68 self.freq_disp.SetValue( -f )
69 self.volume.SetRange( 0, 20 )
70 self.pga.SetRange( 0, 20 )
72 self.rssi.SetRange( self.rssi_range )
73 self.agc_max.SetValue( str( self.rssi_range ) )
74 self.spin_e0.SetValue( 50 )
75 self.spin_e1.SetValue( 50 )
76 self.spin_e2.SetValue( 50 )
77 self.spin_e3.SetValue( 50 )
78 self.spin_e4.SetValue( 50 )
79 self.spin_e5.SetValue( 50 )
80 self.spin_e6.SetValue( 50 )
82 self.bandwidth.SetValue( str( bw ) )
83 self.block.demod.set_bw( bw )
84 self.bw_spin.SetValue( 5 )
85 agc_gain = self.block.agc.gain.k()
86 self.agc_gain_s.SetValue( 5 )
87 self.agc_gain.SetValue( str( agc_gain ) )
88 agc_ref = self.block.agc.offs.k()
89 self.agc_ref.SetValue( str( agc_ref ) )
90 self.agc_ref_s.SetValue( 5 )
92 self.fespectrum = fftsink.fft_sink_c(
96 sample_rate = block.fe_rate,
101 self.ifspectrum = fftsink.fft_sink_c(
105 sample_rate = block.audio_rate,
108 size = ( 680, 140 ) )
110 em.eventManager.Register( self.fe_mouse,
112 self.fespectrum.win )
114 em.eventManager.Register( self.fe_click,
116 self.fespectrum.win )
118 block.graph.connect( block.src.src, self.fespectrum )
119 block.graph.connect( block.demod.xlate, self.ifspectrum )
121 def agc_ref_up( self, event ):
122 self.agc_ref_s.SetValue( 5 )
123 r = float( self.agc_ref.GetValue() )
125 self.agc_ref.SetValue( str( r ) )
126 self.block.agc.offs.set_k( r )
128 def agc_ref_down( self, event ):
129 self.agc_ref_s.SetValue( 5 )
130 r = float( self.agc_ref.GetValue() )
132 self.agc_ref.SetValue( str( r ) )
133 self.block.agc.offs.set_k( r )
135 def agc_gain_up( self, event ):
136 self.agc_gain_s.SetValue( 5 )
137 g = float(self.agc_gain.GetValue())
139 self.agc_gain.SetValue( str( g ) )
140 self.block.agc.gain.set_k( g )
142 def agc_gain_down( self, event ):
143 self.agc_gain_s.SetValue( 5 )
144 g = float(self.agc_gain.GetValue())
146 self.agc_gain.SetValue( str( g ) )
147 self.block.agc.gain.set_k( g )
149 def fe_mouse( self, event ):
150 f = int(self.freq_disp.GetValue())
151 f = f+((event.GetX()-346.)*(400./610.))*1000
152 self.fespectrum.win.SetToolTip(
153 wx.ToolTip( eng_notation.num_to_str(f)))
155 def fe_click( self, event ):
156 f = int(self.freq_disp.GetValue())
157 f = f+((event.GetX()-346.)*(400./610.))*1000
160 def setrssi( self, level ):
163 if level > self.rssi_range:
164 self.rssi_range = level
165 self.rssi.SetRange( level )
166 self.agc_max.SetValue( str( level ))
167 self.rssi.SetValue( level )
168 self.agc_level.SetValue( str( level ))
170 def tune_evt( self, event ):
171 f = self.freq_disp.GetValue()
174 def tune( self, frequency ):
175 self.freq_disp.SetValue( frequency )
176 self.block.tune( frequency )
178 def up_e0( self, event ):
179 self.spin_e0.SetValue( 50 )
180 self.tune( self.freq_disp.GetValue() + 1e0 )
182 def down_e0( self, event ):
183 self.spin_e0.SetValue( 50 )
184 self.tune( self.freq_disp.GetValue() - 1e0 )
186 def up_e1( self, event ):
187 self.spin_e1.SetValue( 50 )
188 self.tune( self.freq_disp.GetValue() + 1e1 )
190 def down_e1( self, event ):
191 self.spin_e1.SetValue( 50 )
192 self.tune( self.freq_disp.GetValue() - 1e1 )
194 def up_e2( self, event ):
195 self.spin_e2.SetValue( 50 )
196 self.tune( self.freq_disp.GetValue() + 1e2 )
198 def down_e2( self, event ):
199 self.spin_e2.SetValue( 50 )
200 self.tune( self.freq_disp.GetValue() - 1e2 )
202 def up_e3( self, event ):
203 self.spin_e3.SetValue( 50 )
204 self.tune( self.freq_disp.GetValue() + 1e3 )
206 def down_e3( self, event ):
207 self.spin_e3.SetValue( 50 )
208 self.tune( self.freq_disp.GetValue() - 1e3 )
210 def up_e4( self, event ):
211 self.spin_e4.SetValue( 50 )
212 self.tune( self.freq_disp.GetValue() + 1e4 )
214 def down_e4( self, event ):
215 self.spin_e4.SetValue( 50 )
216 self.tune( self.freq_disp.GetValue() - 1e4 )
218 def up_e5( self, event ):
219 self.spin_e5.SetValue( 50 )
220 self.tune( self.freq_disp.GetValue() + 1e5 )
222 def down_e5( self, event ):
223 self.spin_e5.SetValue( 50 )
224 self.tune( self.freq_disp.GetValue() - 1e5 )
226 def up_e6( self, event ):
227 self.spin_e6.SetValue( 50 )
228 self.tune( self.freq_disp.GetValue() + 1e6 )
230 def down_e6( self, event ):
231 self.spin_e6.SetValue( 50 )
232 self.tune( self.freq_disp.GetValue() - 1e6 )
234 def event_pga( self, event ):
235 self.block.src.src.set_pga( 0, self.pga.GetValue())
237 def event_vol( self, event ):
238 self.block.out.set( self.volume.GetValue()/20.0 )
240 def set_usb( self, event ):
241 self.block.demod.upper_sb()
243 def set_lsb( self, event ):
244 self.block.demod.lower_sb()
246 def set_am( self, event ):
247 self.block.demod.set_am()
249 def bw_up( self, event ):
250 self.bw_spin.SetValue( 5 )
251 bw = float(self.bandwidth.GetValue())
255 self.bandwidth.SetValue( str( bw ) )
256 self.block.demod.set_bw( bw )
258 def bw_down( self, event ):
259 self.bw_spin.SetValue( 5 )
260 bw = float(self.bandwidth.GetValue())
264 self.bandwidth.SetValue( str( bw ) )
265 self.block.demod.set_bw( bw )
268 class radio( wx.App ):
270 self.graph = gr.flow_graph()
271 self.block = graph( self.graph )
272 self.frame = radio_frame( self.block, None, -1, "Title" )
273 self.frame.Show( True )
274 self.SetTopWindow( self.frame )
279 l=gr.probe_signal_f()
280 #l=gr.probe_avg_mag_sqrd_f(1,.001)
281 a.graph.connect(a.block.agc.offs,l )
282 #a.graph.connect(a.block.demod,l)
294 wx.CallAfter( a.frame.setrssi, level )
297 thread1 = Thread( target = main_function )
298 thread2 = Thread( target = rssi_function )