summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gr-uhd/apps/hf_radio/input.py88
-rw-r--r--gr-uhd/apps/hf_radio/output.py14
-rwxr-xr-xgr-uhd/apps/hf_radio/radio.py145
-rw-r--r--gr-uhd/apps/hf_radio/ssbagc.py30
-rw-r--r--gr-uhd/apps/hf_radio/ssbdemod.py39
5 files changed, 167 insertions, 149 deletions
diff --git a/gr-uhd/apps/hf_radio/input.py b/gr-uhd/apps/hf_radio/input.py
index 5984d8254..7a802f5bf 100644
--- a/gr-uhd/apps/hf_radio/input.py
+++ b/gr-uhd/apps/hf_radio/input.py
@@ -5,42 +5,54 @@
#
# M. Revnell 2005-Dec
-from gnuradio import gr, gru, optfir
-from gnuradio import usrp
-from usrpm import usrp_dbid
-import math
-
-# Put special knowlege of usrp here.
-
-class input:
- def __init__( self, decim ):
- self.freq = -2.5e6
- self.src = usrp.source_c( )
- self.subdev = usrp.pick_subdev( self.src,
- (usrp_dbid.BASIC_RX,
- usrp_dbid.TV_RX,
- usrp_dbid.TV_RX_REV_2,
- usrp_dbid.TV_RX_REV_3,
- usrp_dbid.TV_RX_MIMO,
- usrp_dbid.TV_RX_REV_2_MIMO,
- usrp_dbid.TV_RX_REV_3_MIMO))
-
- print self.subdev
-
- self.subdevice = usrp.selected_subdev( self.src,
- self.subdev )
-
- self.mux = usrp.determine_rx_mux_value( self.src,
- self.subdev )
- self.decim = decim
-
- self.adc_rate = self.src.adc_rate()
- self.usrp_rate = self.adc_rate / self.decim
- self.src.set_decim_rate( self.decim )
- self.src.set_mux( self.mux )
- usrp.tune( self.src, 0, self.subdevice, self.freq )
-
- def set_freq( self, x ):
- r = usrp.tune( self.src, 0, self.subdevice, -x )
+from gnuradio import gr
+from gnuradio import uhd
+
+class uhd_input(gr.hier_block2):
+ def __init__( self, address, samp_rate):
+ gr.hier_block2.__init__(self, "uhd_input",
+ gr.io_signature(0,0,0),
+ gr.io_signature(1,1,gr.sizeof_gr_complex))
+
+ self.src = uhd.usrp_source(device_addr=address,
+ io_type=uhd.io_type.COMPLEX_FLOAT32,
+ num_channels=1)
+
+ self.src.set_samp_rate(samp_rate)
+ self.usrp_rate = self.src.get_samp_rate()
+
+ self.connect(self.src, self)
+
+ def set_freq(self, target_freq):
+ """
+ Set the center frequency.
+
+ @param target_freq: frequency in Hz
+ @type: bool
+ """
+ r = self.src.set_center_freq(target_freq, 0)
+
if r:
- self.freq = -x
+ self.freq = target_freq
+ return True
+ else:
+ return False
+
+ def get_freq(self):
+ return self.src.get_center_freq(0)
+
+ def set_gain(self, gain):
+ self.gain = gain
+ self.src.set_gain(gain, 0)
+
+ def add_options(parser):
+ parser.add_option("-a", "--address", type="string",
+ default="addr=192.168.10.2",
+ help="Address of UHD device, [default=%default]")
+ parser.add_option("-A", "--antenna", type="string", default=None,
+ help="select Rx Antenna where appropriate")
+ parser.add_option("-f", "--freq", type="eng_float", default=None,
+ help="set frequency to FREQ", metavar="FREQ")
+ parser.add_option("-g", "--gain", type="eng_float", default=None,
+ help="set gain in dB (default is midpoint)")
+ add_options = staticmethod(add_options)
diff --git a/gr-uhd/apps/hf_radio/output.py b/gr-uhd/apps/hf_radio/output.py
index dc9caf528..251d863bc 100644
--- a/gr-uhd/apps/hf_radio/output.py
+++ b/gr-uhd/apps/hf_radio/output.py
@@ -5,12 +5,16 @@
from gnuradio import gr, gru
from gnuradio import audio
-class output( gr.hier_block ):
- def __init__( self, fg, rate ):
- self.out = audio.sink( rate )
+class output( gr.hier_block2 ):
+ def __init__( self, rate, device ):
+ gr.hier_block2.__init__(self, "output",
+ gr.io_signature(1,1,gr.sizeof_float),
+ gr.io_signature(0,0,0))
+
self.vol = gr.multiply_const_ff( 0.1 )
- fg.connect( self.vol, self.out )
- gr.hier_block.__init__(self, fg, self.vol, None )
+ self.out = audio.sink( int(rate), device )
+
+ self.connect( self, self.vol, self.out )
def set( self, val ):
self.vol.set_k( val )
diff --git a/gr-uhd/apps/hf_radio/radio.py b/gr-uhd/apps/hf_radio/radio.py
index 9f444b916..2b6f6ee13 100755
--- a/gr-uhd/apps/hf_radio/radio.py
+++ b/gr-uhd/apps/hf_radio/radio.py
@@ -15,11 +15,11 @@ import time
from gnuradio import gr, gru, eng_notation, optfir
from gnuradio import audio
-from gnuradio import usrp
-from gnuradio import blks
-from gnuradio.wxgui import fftsink
-from gnuradio.wxgui import waterfallsink
-from gnuradio.wxgui import scopesink
+from gnuradio import uhd
+from gnuradio import blks2
+from gnuradio.wxgui import fftsink2
+from gnuradio.wxgui import waterfallsink2
+from gnuradio.wxgui import scopesink2
from input import *
from output import *
@@ -28,35 +28,36 @@ from ssbagc import *
from ui import *
from math import log10
-class graph( gr.hier_block ):
- def __init__( self, fg ):
- self.graph = fg
- self.fe_decim = 250
- self.src = input( self.fe_decim )
- self.adc_rate = self.src.adc_rate
- self.fe_rate = self.adc_rate / self.fe_decim
+class radio_top_block( gr.top_block ):
+ def __init__( self ):
+ gr.top_block.__init__(self, "radio_top_block")
+
+ self.address = "addr=192.168.11.2"
+ self.samp_rate = 256e3
+ self.freq = -2.5e6
+ self.gain = 0
+ self.src = uhd_input( self.address,
+ self.samp_rate)
+ self.src.set_freq(self.freq)
+ self.src.set_gain(self.gain)
+
+ self.fe_rate = self.src.usrp_rate
self.filter_decim = 1
self.audio_decim = 16
self.demod_rate = self.fe_rate / self.filter_decim
self.audio_rate = self.demod_rate / self.audio_decim
+ self.audio_dev = "pulse"
- self.demod = ssb_demod( fg, self.demod_rate, self.audio_rate )
- self.agc = agc( fg )
- #self.agc = gr.agc_ff()
- self.out = output( fg, self.audio_rate )
+ self.demod = ssb_demod( self.demod_rate, self.audio_rate )
+ self.agc = agc()
+ self.out = output( self.audio_rate, self.audio_dev )
- fg.connect( self.src.src,
- self.demod,
- self.agc,
- self.out )
-
- gr.hier_block.__init__( self, fg, None, None )
+ self.connect( self.src, self.demod, self.agc, self.out )
def tune( self, freq ):
fe_target = -freq
self.src.set_freq( fe_target )
- fe_freq = self.src.src.rx_freq( 0 )
- demod_cf = fe_target - fe_freq
+ demod_cf = fe_target - self.src.get_freq()
self.demod.tune( demod_cf )
class radio_frame( ui_frame ):
@@ -88,35 +89,30 @@ class radio_frame( ui_frame ):
agc_ref = self.block.agc.offs.k()
self.agc_ref.SetValue( str( agc_ref ) )
self.agc_ref_s.SetValue( 5 )
-
- self.fespectrum = fftsink.fft_sink_c(
- self.block.graph,
+
+ self.fespectrum = fftsink2.fft_sink_c(
self.fe_panel,
fft_size=512,
sample_rate = block.fe_rate,
- baseband_freq = 0,
- average = False,
- size = ( 680, 140 ) )
+ ref_scale = 1.0,
+ ref_level = 20.0,
+ y_divs = 12,
+ avg_alpha = 0.1)
- self.ifspectrum = fftsink.fft_sink_c(
- self.block.graph,
+ self.ifspectrum = fftsink2.fft_sink_c(
self.if_panel,
fft_size=512,
sample_rate = block.audio_rate,
- baseband_freq = 0,
- average = False,
- size = ( 680, 140 ) )
-
- em.eventManager.Register( self.fe_mouse,
- wx.EVT_MOTION,
- self.fespectrum.win )
+ ref_scale = 1.0,
+ ref_level = 20.0,
+ y_divs = 12,
+ avg_alpha = 0.1)
- em.eventManager.Register( self.fe_click,
- wx.EVT_LEFT_DOWN,
- self.fespectrum.win )
+ self.fespectrum.win.Bind( wx.EVT_MOTION, self.fe_mouse)
+ self.fespectrum.win.Bind( wx.EVT_LEFT_DOWN, self.fe_click)
- block.graph.connect( block.src.src, self.fespectrum )
- block.graph.connect( block.demod.xlate, self.ifspectrum )
+ block.connect( block.src.src, self.fespectrum )
+ block.connect( block.demod.xlate, self.ifspectrum )
def agc_ref_up( self, event ):
self.agc_ref_s.SetValue( 5 )
@@ -232,7 +228,7 @@ class radio_frame( ui_frame ):
self.tune( self.freq_disp.GetValue() - 1e6 )
def event_pga( self, event ):
- self.block.src.src.set_pga( 0, self.pga.GetValue())
+ self.block.src.set_gain(self.pga.GetValue())
def event_vol( self, event ):
self.block.out.set( self.volume.GetValue()/20.0 )
@@ -267,38 +263,39 @@ class radio_frame( ui_frame ):
class radio( wx.App ):
def OnInit( self ):
- self.graph = gr.flow_graph()
- self.block = graph( self.graph )
- self.frame = radio_frame( self.block, None, -1, "Title" )
+ self.block = radio_top_block()
+ self.frame = radio_frame( self.block, None, -1, "HF Receiver" )
self.frame.Show( True )
self.SetTopWindow( self.frame )
+ self.block.start()
return True
-a=radio( 0 )
-
-l=gr.probe_signal_f()
-#l=gr.probe_avg_mag_sqrd_f(1,.001)
-a.graph.connect(a.block.agc.offs,l )
-#a.graph.connect(a.block.demod,l)
-
-def main_function():
- global a
- a.MainLoop()
-
-
def rssi_function():
- global a
- global l
- while 1:
- level = l.level()
- wx.CallAfter( a.frame.setrssi, level )
- time.sleep( .1 )
-
-thread1 = Thread( target = main_function )
-thread2 = Thread( target = rssi_function )
-
-thread1.start()
-thread2.start()
-
-a.graph.start()
+ global radio_obj
+ global sig_probe
+
+ go = True
+ while go:
+ try:
+ level = sig_probe.level()
+ wx.CallAfter( radio_obj.frame.setrssi, level )
+ time.sleep( .1 )
+ except:
+ go = False
+
+def main():
+ global radio_obj, sig_probe
+
+ radio_obj = radio( 0 )
+ sig_probe = gr.probe_signal_f()
+ radio_obj.block.connect(radio_obj.block.agc.offs, sig_probe)
+
+ thread2 = Thread( target = rssi_function )
+ thread2.start()
+
+ radio_obj.MainLoop()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/gr-uhd/apps/hf_radio/ssbagc.py b/gr-uhd/apps/hf_radio/ssbagc.py
index fdf40bc6b..51e5f0248 100644
--- a/gr-uhd/apps/hf_radio/ssbagc.py
+++ b/gr-uhd/apps/hf_radio/ssbagc.py
@@ -24,10 +24,14 @@
#
# M. Revnell 2006-Jan
-from gnuradio import gr, gru
+from gnuradio import gr
+
+class agc( gr.hier_block2 ):
+ def __init__( self ):
+ gr.hier_block2.__init__(self, "agc",
+ gr.io_signature(1,1,gr.sizeof_float),
+ gr.io_signature(1,1,gr.sizeof_float))
-class agc( gr.hier_block ):
- def __init__( self, fg ):
self.split = gr.multiply_const_ff( 1 )
self.sqr = gr.multiply_ff( )
self.int0 = gr.iir_filter_ffd( [.004, 0], [0, .999] )
@@ -36,13 +40,13 @@ class agc( gr.hier_block ):
self.log = gr.nlog10_ff( 10, 1 )
self.agc = gr.divide_ff( )
- fg.connect( self.split, ( self.agc, 0 ) )
- fg.connect( self.split, ( self.sqr, 0 ) )
- fg.connect( self.split, ( self.sqr, 1 ) )
- fg.connect( self.sqr, self.int0 )
- fg.connect( self.int0, self.log )
- fg.connect( self.log, self.offs )
- fg.connect( self.offs, self.gain )
- fg.connect( self.gain, ( self.agc, 1 ) )
-
- gr.hier_block.__init__( self, fg, self.split, self.agc )
+ self.connect(self, self.split)
+ self.connect(self.split, (self.agc, 0))
+ self.connect(self.split, (self.sqr, 0))
+ self.connect(self.split, (self.sqr, 1))
+ self.connect(self.sqr, self.int0)
+ self.connect(self.int0, self.log)
+ self.connect(self.log, self.offs)
+ self.connect(self.offs, self.gain)
+ self.connect(self.gain, (self.agc, 1))
+ self.connect(self.agc, self)
diff --git a/gr-uhd/apps/hf_radio/ssbdemod.py b/gr-uhd/apps/hf_radio/ssbdemod.py
index c73567b66..9c43a2c82 100644
--- a/gr-uhd/apps/hf_radio/ssbdemod.py
+++ b/gr-uhd/apps/hf_radio/ssbdemod.py
@@ -13,16 +13,17 @@
# They were generated using Scilab which I am already familiar with.
# M. Revnell Jan 06
-from gnuradio import gr, gru
-from gnuradio import audio
-from gnuradio import usrp
+from gnuradio import gr
-class ssb_demod( gr.hier_block ):
- def __init__( self, fg, if_rate, af_rate ):
+class ssb_demod( gr.hier_block2 ):
+ def __init__( self, if_rate, af_rate ):
+ gr.hier_block2.__init__(self, "ssb_demod",
+ gr.io_signature(1,1,gr.sizeof_gr_complex),
+ gr.io_signature(1,1,gr.sizeof_float))
- self.if_rate = if_rate
- self.af_rate = af_rate
- self.if_decim = if_rate / af_rate
+ self.if_rate = int(if_rate)
+ self.af_rate = int(af_rate)
+ self.if_decim = int(if_rate / af_rate)
self.sideband = 1
self.xlate_taps = ([complex(v) for v in file('ssb_taps').readlines()])
@@ -51,17 +52,17 @@ class ssb_demod( gr.hier_block ):
self.mixer = gr.add_ff()
self.am_det = gr.complex_to_mag()
- fg.connect( self.xlate, self.split )
- fg.connect( ( self.split,0 ), ( self.sum,0 ) )
- fg.connect( ( self.split,1 ), ( self.sum,1 ) )
- fg.connect( self.sum, self.sb_sel )
- fg.connect( self.xlate, self.am_det )
- fg.connect( self.sb_sel, ( self.mixer, 0 ) )
- fg.connect( self.am_det, self.am_sel )
- fg.connect( self.am_sel, ( self.mixer, 1 ) )
- fg.connect( self.mixer, self.lpf )
-
- gr.hier_block.__init__( self, fg, self.xlate, self.lpf )
+ self.connect(self, self.xlate)
+ self.connect(self.xlate, self.split)
+ self.connect((self.split, 0), (self.sum, 0))
+ self.connect((self.split, 1), (self.sum, 1))
+ self.connect(self.sum, self.sb_sel)
+ self.connect(self.xlate, self.am_det)
+ self.connect(self.sb_sel, (self.mixer, 0))
+ self.connect(self.am_det, self.am_sel)
+ self.connect(self.am_sel, (self.mixer, 1))
+ self.connect(self.mixer, self.lpf)
+ self.connect(self.lpf, self)
def upper_sb( self ):
self.xlate.set_taps([v.conjugate() for v in self.xlate_taps])