commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 01/10: fixing hfx.py for proper uhd support


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/10: fixing hfx.py for proper uhd support - tuning was negative of desired change, removed antenna tuner support
Date: Tue, 11 Feb 2014 21:11:22 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

trondeau pushed a commit to branch master
in repository gnuradio.

commit f7980ba9a05fdf47cbf1a2fe9ca4d76dbced2613
Author: Chuck Swiger <address@hidden>
Date:   Thu Jan 2 15:03:14 2014 -0500

    fixing hfx.py for proper uhd support - tuning was negative of desired 
change, removed  antenna tuner support
---
 gr-uhd/apps/hf_explorer/hfx.py | 160 ++++++++++-------------------------------
 1 file changed, 37 insertions(+), 123 deletions(-)

diff --git a/gr-uhd/apps/hf_explorer/hfx.py b/gr-uhd/apps/hf_explorer/hfx.py
index 93d34c0..0fe250a 100755
--- a/gr-uhd/apps/hf_explorer/hfx.py
+++ b/gr-uhd/apps/hf_explorer/hfx.py
@@ -1,3 +1,4 @@
+#!/usr/bin/python
 #!/usr/bin/env python
 # generated by wxGlade 0.4 on Tue Mar 14 10:16:06 2006
 #
@@ -59,24 +60,13 @@
 #
 #----------------------------------------------------------------------
 #
-# Versions 2.2.1 adds loop antenna automatic tuner
+# 3.0.1 - updated to support uhd correctly, old code for usrp had display 
negative, removed antenna tuner controls
 #
-# 2.3.1 adds web control, made AM Sync display optional,
-# added more comments.
-#
-# 2.4.1 updates usrp interface to support auto subdev
-#
-# 2.8.1 changed saved file format from 8-byte complex to
-# 4-byte short for obvious storage space savings.
 
 # Web server control disabled by default. Do not enable
 # until directory structure and scripts are in place.
 WEB_CONTROL = False
 
-# Controls display of AM Sync Carrier - turn off for smaller
-# window if not needed
-AM_SYNC_DISPLAY = False
-
 import os, wx, sys, math
 import wx.lib.evtmgr as em
 from gnuradio.wxgui import powermate, fftsink2
@@ -101,9 +91,6 @@ ID_BUTTON_8 = wx.NewId()     #  "                  Volume
 ID_BUTTON_9 = wx.NewId()       #  "                  Time
 ID_BUTTON_10 = wx.NewId()      # Time Seek Forwards
 ID_BUTTON_11 = wx.NewId()      # Time Seek Backwards
-ID_BUTTON_12 = wx.NewId()      # Automatic Antenna Tune (AT) enable
-ID_BUTTON_13 = wx.NewId()      # AT Calibrate point
-ID_BUTTON_14 = wx.NewId()      # AT Reset
 ID_TEXT_1 = wx.NewId()         # Band Center, USRP ddc Freq
 ID_SPIN_1 = wx.NewId()         # Frequency display and control
 ID_SLIDER_1 = wx.NewId()       # Upper audio freq cutoff
@@ -111,7 +98,6 @@ ID_SLIDER_2 = wx.NewId()     # Lower audio freq cutoff
 ID_SLIDER_3 = wx.NewId()       # Frequency
 ID_SLIDER_4 = wx.NewId()       # Volume
 ID_SLIDER_5 = wx.NewId()       # Programmable Gain Amp, PGA, RF gain
-ID_SLIDER_6 = wx.NewId()       # AM Sync carrier level
 ID_SLIDER_7 = wx.NewId()       # AT control voltage output
 ID_EXIT        = wx.NewId()            # Menu Exit
 
@@ -162,16 +148,7 @@ class MyFrame(wx.Frame):
         self.panel_4 = wx.Panel(self, -1)
         self.panel_8 = wx.Panel(self, -1)
         self.panel_9 = wx.Panel(self, -1)
-        self.label_3 = wx.StaticText(self, -1, "AM Sync\nCarrier")
-        self.slider_6 = wx.Slider(self, ID_SLIDER_6, 50, 0, 200,
-                                  style=wx.SL_HORIZONTAL|wx.SL_LABELS)
-        self.label_4 = wx.StaticText(self, -1, "Antenna Tune")
-        self.slider_7 = wx.Slider(self, ID_SLIDER_7, 1575, 950, 2200,
-                                  style=wx.SL_HORIZONTAL|wx.SL_LABELS)
         self.panel_10 = wx.Panel(self, -1)
-        self.button_12 = wx.ToggleButton(self, ID_BUTTON_12, "Auto Tune")
-        self.button_13 = wx.Button(self, ID_BUTTON_13, "Calibrate")
-        self.button_14 = wx.Button(self, ID_BUTTON_14, "Reset")
         self.panel_11 = wx.Panel(self, -1)
         self.panel_12 = wx.Panel(self, -1)
 
@@ -180,11 +157,13 @@ class MyFrame(wx.Frame):
         # end wxGlade
 
         parser = OptionParser (option_class=eng_option)
-        parser.add_option("", "--address", type="string", 
default="addr=192.168.10.2",
+        parser.add_option("", "--address", type="string", default="addr=''",
                           help="Address of UHD device, [default=%default]")
+        parser.add_option("", "--spec", type="string", default="A:A",
+                          help="UHD device subdev spec, [default=%default]")
         parser.add_option ("-c", "--ddc-freq", type="eng_float", default=3.9e6,
                            help="set Rx DDC frequency to FREQ", metavar="FREQ")
-        parser.add_option ("-s", "--samp-rate", type="eng_float", 
default=256e3,
+        parser.add_option ("-s", "--samp-rate", type="eng_float", 
default=256000,
                            help="set sample rate (bandwidth) 
[default=%default]")
         parser.add_option ("-a", "--audio_file", default="",
                            help="audio output file", metavar="FILE")
@@ -205,9 +184,13 @@ class MyFrame(wx.Frame):
        self.af_sample_rate = 32000
        fir_decim = long (input_rate / self.af_sample_rate)
 
-        # data point arrays for antenna tuner
-        self.xdata = []
-        self.ydata = []
+       print "usrp_center, ddc_freq: " + str(self.usrp_center)
+       print "input_rate: " + str(input_rate)
+       print "slider_range: " + str(self.slider_range)
+       print "f_lo: " + str(self.f_lo)
+       print "f_hi: " + str(self.f_hi)
+       print "af_sample_rate: " + str(self.af_sample_rate)
+       print "fir_decim: " + str(fir_decim)
 
        self.tb = gr.top_block()
 
@@ -215,12 +198,15 @@ class MyFrame(wx.Frame):
         self.frequency = self.usrp_center
         # these map the frequency slider (0-6000) to the actual range
         self.f_slider_offset = self.f_lo
-        self.f_slider_scale = 10000
+        self.f_slider_scale = 10000/250
         self.spin_ctrl_1.SetRange(self.f_lo,self.f_hi)
         self.text_ctrl_1.SetValue(str(int(self.usrp_center)))
         self.slider_5.SetValue(0)
        self.AM_mode = False
 
+       print "f_slider_offset: " + str(self.f_slider_offset)
+       print "f_slider_scale: " + str(self.f_slider_scale)
+
         
self.slider_3.SetValue((self.frequency-self.f_slider_offset)/self.f_slider_scale)
         self.spin_ctrl_1.SetValue(int(self.frequency))
 
@@ -245,13 +231,12 @@ class MyFrame(wx.Frame):
         else: self.PLAY_FROM_USRP = False
 
         if self.PLAY_FROM_USRP:
-            self.src = uhd.usrp_source(device_addr=options.address,
-                                       io_type=uhd.io_type.COMPLEX_FLOAT32,
-                                       num_channels=1)
+            self.src = uhd.usrp_source("",stream_args=uhd.stream_args('fc32'))
             self.src.set_samp_rate(input_rate)
+            self.src.set_subdev_spec(options.spec)
             input_rate = self.src.get_samp_rate()
 
-            self.src.set_center_freq(self.usrp_center, 0)
+            self.src.set_center_freq(self.usrp_center, 0)      
             self.tune_offset = 0
 
         else:
@@ -298,13 +283,6 @@ class MyFrame(wx.Frame):
                                        sample_rate=self.af_sample_rate,
                                        average=True, size=(640,240))
 
-       # AM Sync carrier
-       if AM_SYNC_DISPLAY:
-          self.fft2 = fftsink.fft_sink_c(self.tb, self.panel_9,
-                                          y_per_div=20, fft_size=512,
-                                          sample_rate=self.af_sample_rate,
-                                          average=True, size=(640,240))
-
         c2f = blocks.complex_to_float()
 
        # AM branch
@@ -312,7 +290,7 @@ class MyFrame(wx.Frame):
        # the following frequencies turn out to be in radians/sample
        # analog.pll_refout_cc(alpha,beta,min_freq,max_freq)
        # suggested alpha = X, beta = .25 * X * X
-       pll = 
analog.pll_refout_cc(.5,.0625,(2.*math.pi*7.5e3/self.af_sample_rate),
+       pll = analog.pll_refout_cc(.05,(2.*math.pi*7.5e3/self.af_sample_rate),
                                     (2.*math.pi*6.5e3/self.af_sample_rate))
        self.pll_carrier_scale = blocks.multiply_const_cc(complex(10,0))
        am_det = blocks.multiply_cc()
@@ -364,8 +342,6 @@ class MyFrame(wx.Frame):
        self.tb.connect(self.audio_filter,c2f,
                         self.sel_sb,(combine,1))
 
-       if AM_SYNC_DISPLAY:
-         self.tb.connect(self.pll_carrier_filter,self.fft2)
 
        self.tb.connect(combine,self.scale)
        self.tb.connect(self.scale,(sqr1,0))
@@ -398,8 +374,6 @@ class MyFrame(wx.Frame):
        wx.EVT_BUTTON(self,ID_BUTTON_4,self.set_cw)
        wx.EVT_BUTTON(self,ID_BUTTON_10,self.fwd)
        wx.EVT_BUTTON(self,ID_BUTTON_11,self.rew)
-        wx.EVT_BUTTON(self, ID_BUTTON_13, self.AT_calibrate)
-        wx.EVT_BUTTON(self, ID_BUTTON_14, self.AT_reset)
        wx.EVT_TOGGLEBUTTON(self,ID_BUTTON_5,self.on_button)
        wx.EVT_TOGGLEBUTTON(self,ID_BUTTON_6,self.on_button)
        wx.EVT_TOGGLEBUTTON(self,ID_BUTTON_7,self.on_button)
@@ -410,8 +384,6 @@ class MyFrame(wx.Frame):
         wx.EVT_SLIDER(self,ID_SLIDER_3,self.slide_tune)
         wx.EVT_SLIDER(self,ID_SLIDER_4,self.set_volume)
        wx.EVT_SLIDER(self,ID_SLIDER_5,self.set_pga)
-       wx.EVT_SLIDER(self,ID_SLIDER_6,self.am_carrier)
-        wx.EVT_SLIDER(self,ID_SLIDER_7,self.antenna_tune)
         wx.EVT_SPINCTRL(self,ID_SPIN_1,self.spin_tune)
 
         wx.EVT_MENU(self, ID_EXIT,  self.TimeToQuit)
@@ -421,15 +393,11 @@ class MyFrame(wx.Frame):
         self.SetTitle("HF Explorer")
         self.slider_fcutoff_hi.SetMinSize((450, 38))
         self.slider_fcutoff_lo.SetMinSize((450, 38))
-        self.panel_2.SetMinSize((640, 240))
+        self.panel_2.SetMinSize((640, 320))
         self.button_7.SetValue(1)
         self.slider_3.SetMinSize((450, 19))
         self.slider_4.SetMinSize((275, 19))
         self.slider_5.SetMinSize((275, 19))
-       if AM_SYNC_DISPLAY:
-           self.panel_9.SetMinSize((640, 240))
-        self.slider_6.SetMinSize((300, 38))
-        self.slider_7.SetMinSize((400, 38))
         # end wxGlade
 
     def __do_layout(self):
@@ -479,16 +447,7 @@ class MyFrame(wx.Frame):
         grid_sizer_1.Add(sizer_5, 1, wx.EXPAND, 0)
         grid_sizer_1.Add(self.panel_8, 1, wx.EXPAND, 0)
         grid_sizer_1.Add(self.panel_9, 1, wx.EXPAND, 0)
-        grid_sizer_1.Add(self.label_3, 0,
-                         
wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
-        grid_sizer_1.Add(self.slider_6, 0, wx.ADJUST_MINSIZE, 0)
-        grid_sizer_1.Add(self.label_4, 0,
-                         wx.ALIGN_BOTTOM|wx.ADJUST_MINSIZE, 0)
-        grid_sizer_1.Add(self.slider_7, 0, wx.ADJUST_MINSIZE, 0)
         grid_sizer_1.Add(self.panel_10, 1, wx.EXPAND, 0)
-        sizer_7.Add(self.button_12, 0, wx.ADJUST_MINSIZE, 0)
-        sizer_7.Add(self.button_13, 0, wx.ADJUST_MINSIZE, 0)
-        sizer_7.Add(self.button_14, 0, wx.ADJUST_MINSIZE, 0)
         sizer_7.Add(self.panel_11, 1, wx.EXPAND, 0)
         sizer_7.Add(self.panel_12, 1, wx.EXPAND, 0)
         grid_sizer_1.Add(sizer_7, 1, wx.EXPAND, 0)
@@ -523,11 +482,9 @@ class MyFrame(wx.Frame):
            self.frequency = (self.f_slider_scale * new) + self.f_slider_offset
            self.spin_ctrl_1.SetValue(self.frequency)
           if self.AM_mode == False:
-             self.xlate.set_center_freq( self.usrp_center - (self.frequency - 
self.tune_offset))
+             self.xlate.set_center_freq( (self.frequency - self.tune_offset) - 
self.usrp_center)
           else:
-            self.xlate.set_center_freq( self.usrp_center - (self.frequency - 
self.tune_offset - 7.5e3))
-          if self.button_12.GetValue():
-             self.auto_antenna_tune()
+            self.xlate.set_center_freq( (self.frequency - self.tune_offset - 
7.5e3) - self.usrp_center)
        if self.active_button == 8:
            new = max(0, min(500, self.slider_4.GetValue() + event.delta))
            self.slider_4.SetValue(new)
@@ -624,7 +581,7 @@ class MyFrame(wx.Frame):
 
     def set_lsb(self, event):
        self.AM_mode = False
-       self.xlate.set_center_freq( self.usrp_center - (self.frequency - 
self.tune_offset))
+       self.xlate.set_center_freq( (self.frequency - self.tune_offset) - 
self.usrp_center)
        self.sel_sb.set_k(1)
        self.sel_am.set_k(0)
        self.slider_fcutoff_hi.SetValue(0)
@@ -633,7 +590,7 @@ class MyFrame(wx.Frame):
 
     def set_usb(self, event):
        self.AM_mode = False
-       self.xlate.set_center_freq( self.usrp_center - (self.frequency - 
self.tune_offset))
+       self.xlate.set_center_freq( (self.frequency - self.tune_offset) - 
self.usrp_center)
        self.sel_sb.set_k(1)
        self.sel_am.set_k(0)
        self.slider_fcutoff_hi.SetValue(3000)
@@ -642,7 +599,7 @@ class MyFrame(wx.Frame):
 
     def set_am(self, event):
        self.AM_mode = True
-       self.xlate.set_center_freq( self.usrp_center - (self.frequency - 
self.tune_offset - 7.5e3))
+       self.xlate.set_center_freq( (self.frequency - self.tune_offset - 7.5e3) 
- self.usrp_center)
        self.sel_sb.set_k(0)
        self.sel_am.set_k(1)
        self.slider_fcutoff_hi.SetValue(12500)
@@ -651,7 +608,7 @@ class MyFrame(wx.Frame):
 
     def set_cw(self, event):
        self.AM_mode = False
-       self.xlate.set_center_freq( self.usrp_center - (self.frequency - 
self.tune_offset))
+       self.xlate.set_center_freq( (self.frequency - self.tune_offset) - 
self.usrp_center)
        self.AM_mode = False
        self.sel_sb.set_k(1)
        self.sel_am.set_k(0)
@@ -669,22 +626,18 @@ class MyFrame(wx.Frame):
     def slide_tune(self, event):
         self.frequency = (self.f_slider_scale * self.slider_3.GetValue()) + 
self.f_slider_offset
        if self.AM_mode == False:
-          self.xlate.set_center_freq( self.usrp_center - (self.frequency - 
self.tune_offset))
+          self.xlate.set_center_freq( (self.frequency - self.tune_offset) - 
self.usrp_center)
        else:
-         self.xlate.set_center_freq( self.usrp_center - (self.frequency - 
self.tune_offset - 7.5e3))
+         self.xlate.set_center_freq( (self.frequency - self.tune_offset - 
7.5e3) - self.usrp_center)
         self.spin_ctrl_1.SetValue(self.frequency)
-       if self.button_12.GetValue():
-          self.auto_antenna_tune()
 
     def spin_tune(self, event):
        self.frequency = self.spin_ctrl_1.GetValue()
        if self.AM_mode == False:
-           self.xlate.set_center_freq( self.usrp_center - (self.frequency - 
self.tune_offset))
+           self.xlate.set_center_freq( (self.frequency - self.tune_offset) - 
self.usrp_center)
        else:
-          self.xlate.set_center_freq( self.usrp_center - (self.frequency - 
self.tune_offset - 7.5e3))
+          self.xlate.set_center_freq( (self.frequency - self.tune_offset - 
7.5e3) - self.usrp_center)
         
self.slider_3.SetValue(int((self.frequency-self.f_slider_offset)/self.f_slider_scale))
-       if self.button_12.GetValue():
-          self.auto_antenna_tune()
 
     # Seek forwards in file
     def fwd(self, event):
@@ -714,47 +667,10 @@ class MyFrame(wx.Frame):
         self.spin_ctrl_1.SetValue(int(self.frequency))
         
self.slider_3.SetValue(int((self.frequency-self.f_slider_offset)/self.f_slider_scale))
         if self.AM_mode == False:
-          self.xlate.set_center_freq ( self.usrp_center - ( self.frequency - 
self.tune_offset ))
+          self.xlate.set_center_freq ( ( self.frequency - self.tune_offset ) - 
self.usrp_center)
        else:
-          self.xlate.set_center_freq( self.usrp_center - (self.frequency - 
self.tune_offset - 7.5e3))
-
-    # Set power of AM sync carrier
-    def am_carrier(self,event):
-       scale = math.pow(10,(self.slider_6.GetValue())/50.)
-       self.pll_carrier_scale.set_k(complex(scale,0))
-
-    # Reset AT data and start calibrate over
-    def AT_reset(self, event):
-        self.xdata = []
-        self.ydata = []
-
-    # Save AT setting for a particular frequency
-    def AT_calibrate(self, event):
-        self.xdata.append(float(self.frequency))
-        self.ydata.append(self.slider_7.GetValue())
-        if len(self.xdata) > 1:
-          self.m = []
-          self.b = []
-          for i in range(0,len(self.xdata)-1):
-            self.m.append( (self.ydata[i+1] - self.ydata[i]) / 
(self.xdata[i+1] - self.xdata[i]) )
-            self.b.append( self.ydata[i] - self.m[i] * self.xdata[i] )
-
-    # Lookup calibrated points and calculate interpolated antenna tune voltage.
-    # This is to automatically tune a narrowband loop antenna when the freq
-    # is changed, to keep signals peaked.
-    def auto_antenna_tune(self):
-        for i in range(0,len(self.xdata)-1):
-          if (self.frequency > self.xdata[i]) & (self.frequency < 
self.xdata[i+1]):
-            self.slider_7.SetValue(self.m[i]*self.frequency + self.b[i])
-        self.antenna_tune(0)
-
-    # Slider to set loop antenna capacitance
-    def antenna_tune(self, evt):
-        if self.PLAY_FROM_USRP:
-            dev = self.src.get_dboard_iface()
-            dev.write_aux_dac(uhd.dboard_iface.UNIT_RX,
-                              uhd.dboard_iface.AUX_DAC_C,
-                              float(self.slider_7.GetValue()))
+          self.xlate.set_center_freq( (self.frequency - self.tune_offset - 
7.5e3) - self.usrp_center)
+
 
     # Timer events - check for web commands
     def OnUpdate(self):
@@ -770,12 +686,10 @@ class MyFrame(wx.Frame):
                self.frequency = int(new)
                self.slider_3.SetValue(( self.frequency - self.f_slider_offset) 
/ self.f_slider_scale )
                self.spin_ctrl_1.SetValue(self.frequency)
-               if self.button_12.GetValue():
-                 self.auto_antenna_tune()
                if self.AM_mode:
-                 self.xlate.set_center_freq ( self.usrp_center - ( 
self.frequency - self.tune_offset - 7.5e3 ))
+                 self.xlate.set_center_freq ( ( self.frequency - 
self.tune_offset - 7.5e3 ) - self.usrp_center)
                else:
-                 self.xlate.set_center_freq ( self.usrp_center - ( 
self.frequency - self.tune_offset ))
+                 self.xlate.set_center_freq ( ( self.frequency - 
self.tune_offset ) - self.usrp_center)
 
         if cmds[0]=='chvolume':
           fd=open("/var/www/cgi-bin/commands/chvolume","r")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]