commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10758 - in gnuradio/branches/features/experimental-gu


From: jblum
Subject: [Commit-gnuradio] r10758 - in gnuradio/branches/features/experimental-gui: . forms
Date: Fri, 3 Apr 2009 15:37:28 -0600 (MDT)

Author: jblum
Date: 2009-04-03 15:37:27 -0600 (Fri, 03 Apr 2009)
New Revision: 10758

Modified:
   gnuradio/branches/features/experimental-gui/forms/__init__.py
   gnuradio/branches/features/experimental-gui/forms/forms.py
   gnuradio/branches/features/experimental-gui/usrp2_siggen.py
   gnuradio/branches/features/experimental-gui/usrp2_siggen_gui.py
Log:
pubsubbed the usrp2 siggen and gui.
using new forms in usrp2 siggen gui.
incomplete, needs testing and further dev



Modified: gnuradio/branches/features/experimental-gui/forms/__init__.py
===================================================================
--- gnuradio/branches/features/experimental-gui/forms/__init__.py       
2009-04-03 13:04:04 UTC (rev 10757)
+++ gnuradio/branches/features/experimental-gui/forms/__init__.py       
2009-04-03 21:37:27 UTC (rev 10758)
@@ -38,3 +38,17 @@
        button, toggle_button, single_button, \
        check_box, text_box, static_text, \
        slider, log_slider
+
+########################################################################
+# Helpful widgets
+########################################################################
+import wx
+
+class static_box_sizer(wx.StaticBoxSizer):
+       def __init__(self, parent, label='', bold=False, orient=wx.VERTICAL):
+               box = wx.StaticBox(parent=parent, label=label)
+               if bold:
+                       font = box.GetFont()
+                       font.SetWeight(wx.FONTWEIGHT_BOLD)
+                       box.SetFont(font)
+               wx.StaticBoxSizer.__init__(self, box=box, orient=orient)

Modified: gnuradio/branches/features/experimental-gui/forms/forms.py
===================================================================
--- gnuradio/branches/features/experimental-gui/forms/forms.py  2009-04-03 
13:04:04 UTC (rev 10757)
+++ gnuradio/branches/features/experimental-gui/forms/forms.py  2009-04-03 
21:37:27 UTC (rev 10758)
@@ -73,7 +73,7 @@
                self.subscribe(EXT_KEY, self._translate_external_to_internal)
                if self._callback: self.subscribe(EXT_KEY, self._callback)
 
-       def _add_widget(self, widget, label='', proportion=0, 
label_proportion=1, style=wx.HORIZONTAL):
+       def _add_widget(self, widget, label='', proportion=1, 
label_proportion=0, style=wx.HORIZONTAL):
                """
                Add the main widget to this object sizer.
                If label is passed, add a label as well.
@@ -138,8 +138,8 @@
 # Static Text Form
 ########################################################################
 class static_text(_form_base):
-       def __init__(self, label='', width=-1, bold=False, **kwargs):
-               _form_base.__init__(self, converter=converters.str_converter(), 
**kwargs)
+       def __init__(self, label='', width=-1, bold=False, 
converter=converters.str_converter(), **kwargs):
+               _form_base.__init__(self, converter=converter, **kwargs)
                self._static_text = wx.StaticText(self._parent, 
size=wx.Size(width, -1))
                if bold:
                        font = self._static_text.GetFont()
@@ -172,9 +172,10 @@
        @param length the length of the slider in px
        @param style wx.SL_HORIZONTAL or wx.SL_VERTICAL
        """
-       def __init__(self, label='', length=-1, minimum=-100, maximum=100, 
num_steps=100, cast=float, style=wx.SL_HORIZONTAL, converter=None, **kwargs):
-               if not converter:
-                       converter = 
converters.slider_converter(minimum=minimum, maximum=maximum, 
num_steps=num_steps, cast=cast)
+       def __init__(self, label='', length=-1, minimum=-100, maximum=100, 
num_steps=100, step_size=None, cast=float, style=wx.SL_HORIZONTAL, 
converter=None, **kwargs):
+               assert step_size or num_steps
+               if step_size is not None: num_steps = (maximum - 
minimum)/step_size
+               if not converter: converter = 
converters.slider_converter(minimum=minimum, maximum=maximum, 
num_steps=num_steps, cast=cast)
                _form_base.__init__(self, converter=converter, style=style, 
**kwargs)
                if style & wx.SL_HORIZONTAL:
                        slider_size = wx.Size(length, -1)
@@ -301,19 +302,16 @@
 #  A page must be added to the notebook for each choice.
 ########################################################################
 class notebook(_chooser_base):
-       def __init__(self, pages, **kwargs):
+       def __init__(self, pages, notebook, **kwargs):
                _chooser_base.__init__(self, **kwargs)
                assert len(pages) == len(self._choices)
-               self._notebook = wx.Notebook(self._parent)
+               self._notebook = notebook
                self._notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self._handle)
                #add pages, setting the label on each tab
                for i, page in enumerate(pages):
                        self._notebook.AddPage(page, self._labels[i])
                self._add_widget(self._notebook)
 
-       #get at the real notebook object for adding pages and such
-       def get_notebook(self): return self._notebook
-
        def _handle(self, event): self[INT_KEY] = self._notebook.GetSelection()
        def _update(self, i): self._notebook.SetSelection(i)
 

Modified: gnuradio/branches/features/experimental-gui/usrp2_siggen.py
===================================================================
--- gnuradio/branches/features/experimental-gui/usrp2_siggen.py 2009-04-03 
13:04:04 UTC (rev 10757)
+++ gnuradio/branches/features/experimental-gui/usrp2_siggen.py 2009-04-03 
21:37:27 UTC (rev 10758)
@@ -22,13 +22,21 @@
 
 INTERFACE_KEY = 'interface'
 MAC_ADDR_KEY = 'mac_addr'
+DBOARD_ID_KEY = 'dboard_id'
+ETH_RATE_KEY = 'eth_rate'
+DAC_RATE_KEY = 'dac_rate'
 INTERP_KEY = 'interp'
 GAIN_KEY = 'gain'
 TX_FREQ_KEY = 'tx_freq'
+DDC_FREQ_KEY = 'ddc_freq'
+BB_FREQ_KEY = 'bb_freq'
 LO_OFFSET_KEY = 'lo_offset'
 AMPLITUDE_KEY = 'amplitude'
-WAVEFROM_FREQ_KEY = 'waveform_freq'
-WAVEFROM2_FREQ_KEY = 'waveform2_freq'
+WAVEFORM_FREQ_KEY = 'waveform_freq'
+WAVEFORM_OFFSET_KEY = 'waveform_offset'
+WAVEFORM2_FREQ_KEY = 'waveform2_freq'
+FREQ_RANGE_KEY = 'freq_range'
+GAIN_RANGE_KEY = 'gain_range'
 TYPE_KEY = 'type'
 
 from gnuradio import gr, eng_notation, usrp2
@@ -48,9 +56,9 @@
        def daughterboard_id(self): return -1
        def set_center_freq(self, *args, **kwargs): pass
        def set_interp(self, *args, **kwargs): return True
-       def gain_range(self, *args, **kwargs): return (0., 1.)
+       def gain_range(self, *args, **kwargs): return (0., 1., .1)
        def set_gain(self, *args, **kwargs): return True
-       def freq_range(self, *args, **kwargs): return (-100e6, 1, 100e6)
+       def freq_range(self, *args, **kwargs): return (-100e6, 100e6)
        def interface_name(self, *args, **kwargs): return 'eth-x'
 usrp2.sink_32fc = dummy_usrp2
 
@@ -72,33 +80,45 @@
         gr.top_block.__init__(self)
         pubsub.__init__(self)
         self._verbose = options.verbose
+        #initialize values from options
+        self.set_usrp2(options)
+        self[INTERP_KEY] = options.interp
+        self[GAIN_KEY] = options.gain
+        self[TX_FREQ_KEY] = options.tx_freq
+        self[LO_OFFSET_KEY] = options.lo_offset
+        self[AMPLITUDE_KEY] = options.amplitude
+        self[WAVEFORM_FREQ_KEY] = options.waveform_freq
+        self[WAVEFORM_OFFSET_KEY] = options.offset
+        self[WAVEFORM2_FREQ_KEY] = options.waveform2_freq
+        self[BB_FREQ_KEY] = 0
+        self[DDC_FREQ_KEY] = 0
+        #subscribe set methods
+        self.subscribe(INTERP_KEY, self.set_interp)
+        self.subscribe(GAIN_KEY, self.set_gain)
+        self.subscribe(TX_FREQ_KEY, self.set_freq)
+        self.subscribe(LO_OFFSET_KEY, self.set_lo_offset)
+        self.subscribe(AMPLITUDE_KEY, self.set_amplitude)
+        self.subscribe(WAVEFORM_FREQ_KEY, self.set_waveform_freq)
+        self.subscribe(WAVEFORM2_FREQ_KEY, self.set_waveform2_freq)
+        self.subscribe(TYPE_KEY, self.set_waveform)
+        #force update on pubsub keys
+        for key in (INTERP_KEY, GAIN_KEY, TX_FREQ_KEY, LO_OFFSET_KEY,
+            AMPLITUDE_KEY, WAVEFORM_FREQ_KEY, WAVEFORM_OFFSET_KEY, 
WAVEFORM2_FREQ_KEY):
+            self[key] = self[key]
+        self[TYPE_KEY] = options.type #set type last
 
-        self._interp = 0 
-        self._gain = 0
-        self._freq = None       # Indicates frequency hasn't been successfully 
set yet
-        self._bb_freq = 0
-        self._ddc_freq = 0
-        self._amplitude = 0
-        self._type = None       # Indicates waveform flowgraph not created yet
-        self._offset = options.offset
-
-        self.set_usrp2(options.interface, options.mac_addr)
-        self.set_interp(options.interp)
-        self.set_gain(options.gain)
-        self.set_freq(options.tx_freq, options.lo_offset)
-        self.set_amplitude(options.amplitude)
-
-        self.set_waveform_freq(options.waveform_freq)
-        self.set_waveform2_freq(options.waveform2_freq)
-        self.set_waveform(options.type)
-
-    def set_usrp2(self, interface, mac_addr):
-        self._u = usrp2.sink_32fc(interface, mac_addr)
-        self._dac_rate = self._u.dac_rate()
+    def set_usrp2(self, options):
+        self._u = usrp2.sink_32fc(options.interface, options.mac_addr)
+        self.publish(INTERFACE_KEY, self._u.interface_name)
+        self.publish(MAC_ADDR_KEY, self._u.mac_addr)
+        self.publish(DBOARD_ID_KEY, self._u.daughterboard_id)
+        self.publish(DAC_RATE_KEY, self._u.dac_rate)
+        self.publish(FREQ_RANGE_KEY, self._u.freq_range)
+        self.publish(GAIN_RANGE_KEY, self._u.gain_range)
         if self._verbose:
-            print "Network interface:", interface
-            print "Network address:", self._u.mac_addr()
-            print "Daughterboard ID:", hex(self._u.daughterboard_id())
+            print "Network interface:", self[INTERFACE_KEY]
+            print "Network address:", self[MAC_ADDR_KEY]
+            print "Daughterboard ID:", hex(self[DBOARD_ID_KEY])
 
     def set_interp(self, interp):
         if interp < 4 or interp > 512: # FIXME get from flowgraph
@@ -108,113 +128,82 @@
         if not self._u.set_interp(interp):
             raise RuntimeError("Failed to set interpolation rate %i" % 
(interp,))
 
-        self._interp = interp
-        self._eth_rate = self._dac_rate/self._interp
+        self.publish(ETH_RATE_KEY, lambda: self[DAC_RATE_KEY]/self[INTERP_KEY])
         if self._verbose:
-            print "USRP2 interpolation rate:", self._interp
-            print "USRP2 IF bandwidth: %sHz" % (n2s(self._eth_rate),)
+            print "USRP2 interpolation rate:", self[INTERP_KEY]
+            print "USRP2 IF bandwidth: %sHz" % (n2s(self[ETH_RATE_KEY]),)
 
-        if (self._type == gr.GR_SIN_WAVE or 
-            self._type == gr.GR_CONST_WAVE):
-            self._src.set_sampling_freq(self._eth_rate)
-        elif self._type == "2tone":
-            self._src1.set_sampling_freq(self._eth_rate)
-            self._src1.set_sampling_freq(self._eth_rate)
-        elif self._type == "sweep":
-            self._src1.set_sampling_freq(self._eth_rate)
-            
self._src1.set_sampling_freq(self._waveform_freq*2*math.pi/self._eth_rate)
+        if (self[TYPE_KEY] == gr.GR_SIN_WAVE or 
+            self[TYPE_KEY] == gr.GR_CONST_WAVE):
+            self._src.set_sampling_freq(self[ETH_RATE_KEY])
+        elif self[TYPE_KEY] == "2tone":
+            self._src1.set_sampling_freq(self[ETH_RATE_KEY])
+            self._src1.set_sampling_freq(self[ETH_RATE_KEY])
+        elif self[TYPE_KEY] == "sweep":
+            self._src1.set_sampling_freq(self[ETH_RATE_KEY])
+            
self._src1.set_sampling_freq(self[WAVEFORM_FREQ_KEY]*2*math.pi/self[ETH_RATE_KEY])
         else:
             return True # Waveform not yet set
         
         if self._verbose: print "Set interpolation rate to:", interp
         return True
 
-    def set_gain(self, gain):
-        if gain is None:
-            g = self._u.gain_range()
-            gain = float(g[0]+g[1])/2
-            if self._verbose:
-                print "Using auto-calculated mid-point TX gain"
-        self._u.set_gain(gain)
-        self._gain = gain
+    def set_lo_offset(self, lo_offset):
+        if lo_offset is None: return
+        self._u.set_lo_offset(lo_offset)
         if self._verbose:
-            print "Set TX gain to:", self._gain
+            print "Set LO offset frequency to: %sHz" % (n2s(lo_offset),)
 
-    def set_freq(self, target_freq, lo_offset=None):
-        if lo_offset is not None:
-            self._lo_offset = lo_offset
-            self._u.set_lo_offset(self._lo_offset)
-            if self._verbose:
-                print "Set LO offset frequency to: %sHz" % (n2s(lo_offset),)
-
-        if target_freq is None:
-            f = self._u.freq_range()
-            target_freq = float(f[0]+f[1])/2.0
-            if self._verbose:
-                print "Using auto-calculated mid-point frequency"
-
-        tr = self._u.set_center_freq(target_freq)
-        fs = "%sHz" % (n2s(target_freq),)
-        if tr is not None:
-            self._freq = target_freq
-
-        else:
-            return True # Waveform not yet set
-        
-        if self._verbose: print "Set amplitude to:", amplitude
-        return True
-
     def set_gain(self, gain):
         if gain is None:
-            g = self._u.gain_range()
+            g = self[GAIN_RANGE_KEY]
             gain = float(g[0]+g[1])/2
             if self._verbose:
                 print "Using auto-calculated mid-point TX gain"
+            self[GAIN_KEY] = gain
+            return
         self._u.set_gain(gain)
-        self._gain = gain
         if self._verbose:
-            print "Set TX gain to:", self._gain
+            print "Set TX gain to:", gain
 
-    def set_freq(self, target_freq, lo_offset=None):
-        if lo_offset is not None:
-            self._lo_offset = lo_offset
-            self._u.set_lo_offset(self._lo_offset)
-            if self._verbose:
-                print "Set LO offset frequency to: %sHz" % (n2s(lo_offset),)
+    def set_freq(self, target_freq):
 
         if target_freq is None:
-            f = self._u.freq_range()
+            f = self[FREQ_RANGE_KEY]
             target_freq = float(f[0]+f[1])/2.0
             if self._verbose:
                 print "Using auto-calculated mid-point frequency"
+            self[TX_FREQ_KEY] = target_freq
+            return
 
         tr = self._u.set_center_freq(target_freq)
         fs = "%sHz" % (n2s(target_freq),)
         if tr is not None:
             self._freq = target_freq
-            self._ddc_freq = tr.dxc_freq
-            self._bb_freq = tr.baseband_freq
+            self[DDC_FREQ_KEY] = tr.dxc_freq
+            self[BB_FREQ_KEY] = tr.baseband_freq
             if self._verbose:
                 print "Set center frequency to", fs
                 print "Tx baseband frequency: %sHz" % (n2s(tr.baseband_freq),)
                 print "Tx DDC frequency: %sHz" % (n2s(tr.dxc_freq),)
                 print "Tx residual frequency: %sHz" % (n2s(tr.residual_freq),)
-                
+        elif self._verbose: print "Failed to set freq." 
         return tr
 
     def set_waveform_freq(self, freq):
-        self._waveform_freq = freq
-        if self._type == gr.GR_SIN_WAVE:
+        if self[TYPE_KEY] == gr.GR_SIN_WAVE:
             self._src.set_frequency(freq)
-        elif self._type == "2tone" or self._type == "sweep":
+        elif self[TYPE_KEY] == "2tone" or self[TYPE_KEY] == "sweep":
             self._src1.set_frequency(freq)
         return True
 
     def set_waveform2_freq(self, freq):
-        self._waveform2_freq = freq
-        if self._type == "2tone":
+        if freq is None:
+            self[WAVEFORM2_FREQ_KEY] = -self[WAVEFORM_FREQ_KEY]
+            return
+        if self[TYPE_KEY] == "2tone":
             self._src2.set_frequency(freq)
-        elif self._type == "sweep":
+        elif self[TYPE_KEY] == "sweep":
             self._src1.set_frequency(freq)
         return True
 
@@ -223,26 +212,26 @@
         self.disconnect_all()
 
         if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE:
-            self._src = gr.sig_source_c(self._eth_rate,      # Sample rate
+            self._src = gr.sig_source_c(self[ETH_RATE_KEY],      # Sample rate
                                         type,                # Waveform type
-                                        self._waveform_freq, # Waveform 
frequency
-                                        self._amplitude,     # Waveform 
amplitude
-                                        self._offset)        # Waveform offset
+                                        self[WAVEFORM_FREQ_KEY], # Waveform 
frequency
+                                        self[AMPLITUDE_KEY],     # Waveform 
amplitude
+                                        self[WAVEFORM_OFFSET_KEY])        # 
Waveform offset
         elif type == gr.GR_GAUSSIAN or type == gr.GR_UNIFORM:
-            self._src = gr.noise_source_c(type, self._amplitude)
+            self._src = gr.noise_source_c(type, self[AMPLITUDE_KEY])
         elif type == "2tone":
-            self._src1 = gr.sig_source_c(self._eth_rate,
+            self._src1 = gr.sig_source_c(self[ETH_RATE_KEY],
                                          gr.GR_SIN_WAVE,
-                                         self._waveform_freq,
-                                         self._amplitude/2.0,
+                                         self[WAVEFORM_FREQ_KEY],
+                                         self[AMPLITUDE_KEY]/2.0,
                                          0)
-            if(self._waveform2_freq is None):
-                self._waveform2_freq = -self._waveform_freq
+            if(self[WAVEFORM2_FREQ_KEY] is None):
+                self[WAVEFORM2_FREQ_KEY] = -self[WAVEFORM_FREQ_KEY]
 
-            self._src2 = gr.sig_source_c(self._eth_rate,
+            self._src2 = gr.sig_source_c(self[ETH_RATE_KEY],
                                          gr.GR_SIN_WAVE,
-                                         self._waveform2_freq,
-                                         self._amplitude/2.0,
+                                         self[WAVEFORM2_FREQ_KEY],
+                                         self[AMPLITUDE_KEY]/2.0,
                                          0)
             self._src = gr.add_cc()
             self.connect(self._src1,(self._src,0))
@@ -252,36 +241,35 @@
             # waveform_freq is total swept width
             # waveform2_freq is sweep rate
             # will sweep from (rf_freq-waveform_freq/2) to 
(rf_freq+waveform_freq/2)
-            if self._waveform2_freq is None:
-                self._waveform2_freq = 0.1
+            if self[WAVEFORM2_FREQ_KEY] is None:
+                self[WAVEFORM2_FREQ_KEY] = 0.1
 
-            self._src1 = gr.sig_source_f(self._eth_rate,
+            self._src1 = gr.sig_source_f(self[ETH_RATE_KEY],
                                          gr.GR_TRI_WAVE,
-                                         self._waveform2_freq,
+                                         self[WAVEFORM2_FREQ_KEY],
                                          1.0,
                                          -0.5)
-            self._src2 = 
gr.frequency_modulator_fc(self._waveform_freq*2*math.pi/self._eth_rate)
-            self._src = gr.multiply_const_cc(self._amplitude)
+            self._src2 = 
gr.frequency_modulator_fc(self[WAVEFORM_FREQ_KEY]*2*math.pi/self[ETH_RATE_KEY])
+            self._src = gr.multiply_const_cc(self[AMPLITUDE_KEY])
             self.connect(self._src1,self._src2,self._src)
         else:
             raise RuntimeError("Unknown waveform type")
 
         self.connect(self._src, self._u)
-        self._type = type
         self.unlock()
 
         if self._verbose:
-            print "Set baseband modulation to:", waveforms[self._type]
+            print "Set baseband modulation to:", waveforms[type]
             if type == gr.GR_SIN_WAVE:
-                print "Modulation frequency: %sHz" % 
(n2s(self._waveform_freq),)
-                print "Initial phase:", self._offset
+                print "Modulation frequency: %sHz" % 
(n2s(self[WAVEFORM_FREQ_KEY]),)
+                print "Initial phase:", self[WAVEFORM_OFFSET_KEY]
             elif type == "2tone":
-                print "Tone 1: %sHz" % (n2s(self._waveform_freq),)
-                print "Tone 2: %sHz" % (n2s(self._waveform2_freq),)
+                print "Tone 1: %sHz" % (n2s(self[WAVEFORM_FREQ_KEY]),)
+                print "Tone 2: %sHz" % (n2s(self[WAVEFORM2_FREQ_KEY]),)
             elif type == "sweep":
-                print "Sweeping across %sHz to %sHz" % 
(n2s(-self._waveform_freq/2.0),n2s(self._waveform_freq/2.0))
-                print "Sweep rate: %sHz" % (n2s(self._waveform2_freq),)
-            print "TX amplitude:", self._amplitude
+                print "Sweeping across %sHz to %sHz" % 
(n2s(-self[WAVEFORM_FREQ_KEY]/2.0),n2s(self[WAVEFORM_FREQ_KEY]/2.0))
+                print "Sweep rate: %sHz" % (n2s(self[WAVEFORM2_FREQ_KEY]),)
+            print "TX amplitude:", self[AMPLITUDE_KEY]
 
 
     def set_amplitude(self, amplitude):
@@ -289,17 +277,15 @@
             if self._verbose: print "Amplitude out of range:", amplitude
             return False
 
-        self._amplitude = amplitude
-
-        if (self._type == gr.GR_SIN_WAVE or 
-            self._type == gr.GR_CONST_WAVE or
-            self._type == gr.GR_GAUSSIAN or
-            self._type == gr.GR_UNIFORM):
+        if (self[TYPE_KEY] == gr.GR_SIN_WAVE or 
+            self[TYPE_KEY] == gr.GR_CONST_WAVE or
+            self[TYPE_KEY] == gr.GR_GAUSSIAN or
+            self[TYPE_KEY] == gr.GR_UNIFORM):
             self._src.set_amplitude(amplitude)
-        elif self._type == "2tone":
+        elif self[TYPE_KEY] == "2tone":
             self._src1.set_amplitude(amplitude/2.0)
             self._src2.set_amplitude(amplitude/2.0)
-        elif self._type == "sweep":
+        elif self[TYPE_KEY] == "sweep":
             self._src.set_k(amplitude)
         else:
             return True # Waveform not yet set
@@ -307,51 +293,6 @@
         if self._verbose: print "Set amplitude to:", amplitude
         return True
 
-
-    # Property getters
-
-    def mac_addr(self):
-        return self._u.mac_addr()
-
-    def interface_name(self):
-        return self._u.interface_name()
-
-    def daughterboard_id(self):
-        return self._u.daughterboard_id()
-
-    def interp_rate(self):
-        return self._interp
-
-    def eth_rate(self):
-        return self._eth_rate
-
-    def freq(self):
-        return self._freq
-
-    def freq_range(self):
-        return self._u.freq_range()
-
-    def ddc_freq(self):
-        return self._ddc_freq
-
-    def baseband_freq(self):
-        return self._bb_freq
-
-    def amplitude(self):
-        return self._amplitude
-
-    def waveform_type(self):
-        return self._type
-
-    def waveform_freq(self):
-        return self._waveform_freq
-
-    def waveform2_freq(self):
-        if self._waveform2_freq is None:
-            return -self._waveform_freq
-        else:
-            return self._waveform2_freq
-
 def get_options():
     usage="%prog: [options]"
 
@@ -389,7 +330,7 @@
                       help="Generate a swept sine wave")
     parser.add_option("-a", "--amplitude", type="eng_float", default=0.1,
                       help="Set output amplitude to AMPL (0.0-1.0) 
[default=%default]", metavar="AMPL")
-    parser.add_option("-v", "--verbose", action="store_true", default=False,
+    parser.add_option("-v", "--verbose", action="store_true", default=True,
                       help="Use verbose console output [default=%default]")
 
     (options, args) = parser.parse_args()

Modified: gnuradio/branches/features/experimental-gui/usrp2_siggen_gui.py
===================================================================
--- gnuradio/branches/features/experimental-gui/usrp2_siggen_gui.py     
2009-04-03 13:04:04 UTC (rev 10757)
+++ gnuradio/branches/features/experimental-gui/usrp2_siggen_gui.py     
2009-04-03 21:37:27 UTC (rev 10758)
@@ -21,9 +21,11 @@
 # 
 
 import wx
+from gnuradio import gr
 from gnuradio.wxgui import form, slider, gui
 import usrp2_siggen
 import sys, math
+import forms
 
 class app_gui(object):
     def __init__(self, frame, panel, vbox, top_block, options, args):
@@ -33,221 +35,261 @@
         self.tb = top_block     # GUI-unaware flowgraph class
         self.options = options  # Supplied command-line options
         self.args = args        # Supplied command-line arguments
-
-        freq_range = self.tb.freq_range()
-        self.min_freq = freq_range[0]
-        self.max_freq = freq_range[1]
-        self.freq_step = (self.max_freq-self.min_freq)/100.0
-        self._types = dict([v, k] for k, v in usrp2_siggen.waveforms.items())
-
         self.build_gui()
 
-        # TODO: turn these into listeners
-        self.myform['ifc'].set_value(self.tb.interface_name())
-        self.myform['mac'].set_value(self.tb.mac_addr())
-        dbid = self.tb.daughterboard_id()
-        self.myform['dbid'].set_value("%04x" % (dbid,))
-
-        w = usrp2_siggen.waveforms[self.tb.waveform_type()]
-        self.myform['type'].set_value(w)
-        self.myform['w1freq'].set_value(self.tb.waveform_freq())
-        self.myform['w2freq'].set_value(self.tb.waveform2_freq())
-
-        freq = self.tb.freq()
-        if freq is None:
-            self.evt_set_status_msg("Failed to set initial frequency")
-        else:
-            self.myform['freq'].set_value(freq)
-            self.myform['freq_slider'].set_value(self.tb.freq())
-
-        amp = self.tb.amplitude()
-        if (amp > 0.0):
-            db = 20*math.log10(amp)
-        else:
-            db = -100.0
-        self.myform['amp'].set_value(amp)
-        self.myform['amp_slider'].set_value(db)
-        self.myform['eth'].set_value(self.tb.eth_rate())
-        self.myform['gbe'].set_value(self.tb.eth_rate()*32)
-        self.myform['interp'].set_value(self.tb.interp_rate())
-        self.myform['DDC'].set_value(self.tb.ddc_freq())
-        self.myform['analog'].set_value(self.tb.baseband_freq())
-
     # Event response handlers
     def evt_set_status_msg(self, msg):
         self.frame.SetStatusText(msg, 0)
 
-    def evt_set_freq1(self, kv):
-        return self.tb.set_waveform_freq(kv['w1freq'])
-
-    def evt_set_freq2(self, kv):
-        return self.tb.set_waveform2_freq(kv['w2freq'])
-
-    def evt_set_freq(self, kv):
-        if type(kv) == type(0.0):              # Set from slider
-            tr = self.tb.set_freq(kv)
-            if tr is not None:
-                self.myform['freq'].set_value(kv)
-        else:                                  # Set from edit box
-            f = kv['freq']
-            tr = self.tb.set_freq(f)
-            if tr is not None:
-                self.myform['freq_slider'].set_value(f)
-
-        if tr is not None:
-            self.myform['DDC'].set_value(tr.dxc_freq)
-            self.myform['analog'].set_value(tr.baseband_freq)
-
-        return (tr is not None)
-
-    def evt_set_amplitude(self, kv):
-        if type(kv) == type(0.0):              # Set from slider
-            amp = math.pow(10, kv/20.0)
-            self.myform['amp'].set_value(amp)
-            return self.tb.set_amplitude(amp)
-        else:                                  # Set from edit box
-            amp = kv['amp']
-            if amp < 0.0 or amp > 1.0:
-                return False
-            if amp == 0.0:
-                db = -100.0
-            else:
-                db = 20*math.log10(amp)
-            self.myform['amp_slider'].set_value(db)
-            return self.tb.set_amplitude(amp)
-
-    def evt_set_interp(self):
-        interp = self.myform['interp'].get_value()
-        if self.tb.set_interp(interp):
-            eth_rate = self.tb.eth_rate()
-            self.myform['eth'].set_value(eth_rate)
-            self.myform['gbe'].set_value(eth_rate*32)
-            return True
-        return False
-
-    def evt_set_waveform_type(self, type):
-        # TODO: update frequency labels
-        return self.tb.set_waveform(self._types[type])
-
     # GUI construction
     def build_gui(self):
-        self.myform = myform = form.form()
-
+        self.vbox.AddSpacer(5)
+        self.vbox.AddStretchSpacer()
+        ##################################################
         # Baseband controls
-        bb_sbox = wx.StaticBox(parent=self.panel, label="Baseband Modulation")
-        bb_vbox = wx.StaticBoxSizer(bb_sbox, wx.VERTICAL) # Holds all baseband 
controls as unit
-
-        # First row of baseband controls (modulation type)
-        mod_hbox = wx.BoxSizer(wx.HORIZONTAL)
-        mod_hbox.Add((10,0), 0, 0)
-        myform['type'] = form.radiobox_field(
-            parent=self.panel, label="Type", sizer=mod_hbox, value=None,
-            callback=self.evt_set_waveform_type, weight=1, major_dimension=0,
-            choices=usrp2_siggen.waveforms.values() )
-        bb_vbox.Add((0,10), 0, 0)
-        bb_vbox.Add(mod_hbox, 0, wx.EXPAND)
-
-        # Second row of baseband controls (frequencies)
-        bbf_hbox = wx.BoxSizer(wx.HORIZONTAL)
-        bbf_hbox.Add((10,0), 0, 0)
-        myform['w1freq'] = form.float_field(
-            parent=self.panel, sizer=bbf_hbox, label="Frequency 1 (Hz)", 
weight=1,
-            callback=myform.check_input_and_call(self.evt_set_freq1, 
self.evt_set_status_msg) )
-        bbf_hbox.Add((10,0), 0, 0)
-        myform['w2freq'] = form.float_field(
-            parent=self.panel, sizer=bbf_hbox, label="Frequency 2 (Hz)", 
weight=1,
-            callback=myform.check_input_and_call(self.evt_set_freq2, 
self.evt_set_status_msg) )
-        bbf_hbox.Add((10,0), 0, 0)
-        
-        bb_vbox.Add((0,10), 0, 0)
-        bb_vbox.Add(bbf_hbox, 0, wx.EXPAND)
-
+        ##################################################
+        bb_vbox = forms.static_box_sizer(parent=self.panel, label="Baseband 
Modulation", orient=wx.VERTICAL, bold=True)
+        self.vbox.Add(bb_vbox, 0, wx.EXPAND)
         # Add baseband controls to top window sizer
-        self.vbox.Add((0,10), 0, 0)
-        self.vbox.Add(bb_vbox, 0, wx.EXPAND)
-
+        self.vbox.AddSpacer(10)
+        self.vbox.AddStretchSpacer()
+        type_notebook = wx.Notebook(self.panel)
+        type_pages = list()
+        for i, wfm  in enumerate(usrp2_siggen.waveforms.keys()):
+            panel = wx.Panel(type_notebook)
+            type_pages.append(panel)
+            box = wx.BoxSizer(wx.HORIZONTAL)
+            panel.SetSizer(box)
+            if wfm == gr.GR_SIN_WAVE:
+                forms.text_box(
+                    parent=panel, sizer=box,
+                    label='Frequency (Hz)',
+                    ps=self.tb,
+                    key=usrp2_siggen.WAVEFORM_FREQ_KEY,
+                    converter=forms.float_converter(),
+                )
+            elif wfm == 'sweep':
+                forms.text_box(
+                    parent=panel, sizer=box,
+                    label='Frequency (Hz)',
+                    ps=self.tb,
+                    key=usrp2_siggen.WAVEFORM_FREQ_KEY,
+                    converter=forms.float_converter(),
+                )
+                forms.text_box(
+                    parent=panel, sizer=box,
+                    label='Sweep Rate (Hz)',
+                    ps=self.tb,
+                    key=usrp2_siggen.WAVEFORM2_FREQ_KEY,
+                    converter=forms.float_converter(),
+                )
+            elif wfm == '2tone':
+                forms.text_box(
+                    parent=panel, sizer=box,
+                    label='Frequency 1 (Hz)',
+                    ps=self.tb,
+                    key=usrp2_siggen.WAVEFORM_FREQ_KEY,
+                    converter=forms.float_converter(),
+                )
+                forms.text_box(
+                    parent=panel, sizer=box,
+                    label='Frequency 2 (Hz)',
+                    ps=self.tb,
+                    key=usrp2_siggen.WAVEFORM2_FREQ_KEY,
+                    converter=forms.float_converter(),
+                )
+        forms.notebook(
+            parent=self.panel, sizer=bb_vbox,
+            choices=usrp2_siggen.waveforms.keys(),
+            labels=usrp2_siggen.waveforms.values(),
+            notebook=type_notebook,
+            pages=type_pages,
+            ps=self.tb,
+            key=usrp2_siggen.TYPE_KEY,
+        )
+        ##################################################
         # Frequency controls
-        fc_sbox = wx.StaticBox(parent=self.panel, label="Center Frequency")
-        fc_vbox = wx.StaticBoxSizer(fc_sbox, wx.VERTICAL) # Holds all 
frequency controls as unit
-
+        ##################################################
+        fc_vbox = forms.static_box_sizer(parent=self.panel, label="Center 
Frequency", orient=wx.VERTICAL, bold=True)
+        fc_vbox.AddSpacer(5)
         # First row of frequency controls (center frequency)
         freq_hbox = wx.BoxSizer(wx.HORIZONTAL)
-        freq_hbox.Add((10,0), 0, 0)
-        myform['freq'] = form.float_field(
-            parent=self.panel, sizer=freq_hbox, label=None, weight=1,
-            callback=myform.check_input_and_call(self.evt_set_freq, 
self.evt_set_status_msg) )
-        freq_hbox.Add((10,0), 0, 0)
-        myform['freq_slider'] = form.quantized_slider_field(
-            parent=self.panel, sizer=freq_hbox, label="Min-Max", weight=4,
-            range = (self.min_freq, self.max_freq, self.freq_step),
-            callback=self.evt_set_freq)
-        freq_hbox.Add((10,0), 0, 0)
-
-        fc_vbox.Add((10,0), 0, 0)
         fc_vbox.Add(freq_hbox, 0, wx.EXPAND)
-
+        fc_vbox.AddSpacer(10)
         # Second row of frequency controls (results)
         tr_hbox = wx.BoxSizer(wx.HORIZONTAL)
-        tr_hbox.Add((10,0), 0, 0)
-        myform['analog'] = form.static_float_field(
-            parent=self.panel, sizer=tr_hbox, label="Daughterboard: (Hz)", 
weight=1)
-        tr_hbox.Add((10,0), 0, 0)
-        myform['DDC'] = form.static_float_field(
-            parent=self.panel, sizer=tr_hbox, label="USRP2 DDC (Hz)", weight=1)
-        tr_hbox.Add((10,0), 0, 0)
         fc_vbox.Add(tr_hbox, 0, wx.EXPAND)
-
+        fc_vbox.AddSpacer(5)
         # Add frequency controls to top window sizer
-        self.vbox.Add((0,10), 0, 0)
         self.vbox.Add(fc_vbox, 0, wx.EXPAND)
-
-        # Amplitude row
-        amp_sbox = wx.StaticBox(parent=self.panel, label="Amplitude")
-        amp_hbox = wx.StaticBoxSizer(amp_sbox, wx.HORIZONTAL)
-        amp_hbox.Add((10,0), 0, 0)
-        myform['amp'] = form.float_field(
-            parent=self.panel, sizer=amp_hbox, label="Linear\n(0.0-1.0)", 
weight=1,
-            callback=myform.check_input_and_call(self.evt_set_amplitude, 
self.evt_set_status_msg) )
-        amp_hbox.Add((10,0), 0, 0)
-        myform['amp_slider'] = form.quantized_slider_field(
-            parent=self.panel, sizer=amp_hbox, label="dB Full 
Scale\n(-100-0)", weight=4,
-            range=(-100.0, 0.0, 1), callback=self.evt_set_amplitude)
-        amp_hbox.Add((10,0), 0, 0)
-        self.vbox.Add((0,10), 0, 0)
+        self.vbox.AddSpacer(10)
+        self.vbox.AddStretchSpacer()
+        freq_hbox.AddSpacer(5)
+        forms.text_box(
+            parent=self.panel, sizer=freq_hbox,
+            proportion=1,
+            converter=forms.float_converter(),
+            ps=self.tb,
+            key=usrp2_siggen.TX_FREQ_KEY,
+        )
+        freq_hbox.AddSpacer(10)
+        forms.slider(
+            parent=self.panel, sizer=freq_hbox,
+            proportion=2,
+            ps=self.tb,
+            key=usrp2_siggen.TX_FREQ_KEY,
+            minimum=self.tb[usrp2_siggen.FREQ_RANGE_KEY][0],
+            maximum=self.tb[usrp2_siggen.FREQ_RANGE_KEY][1],
+            num_steps=100,
+        )
+        freq_hbox.AddSpacer(5)
+        tr_hbox.AddSpacer(5)
+        forms.static_text(
+            parent=self.panel, sizer=tr_hbox,
+            label='Daughterboard (Hz)',
+            ps=self.tb,
+            key=usrp2_siggen.BB_FREQ_KEY,
+            converter=forms.float_converter(),
+            proportion=1,
+        )
+        tr_hbox.AddSpacer(10)
+        forms.static_text(
+            parent=self.panel, sizer=tr_hbox,
+            label='USRP2 DDC (Hz)',
+            ps=self.tb,
+            key=usrp2_siggen.DDC_FREQ_KEY,
+            converter=forms.float_converter(),
+            proportion=1,
+        )
+        tr_hbox.AddSpacer(5)
+        ##################################################
+        # Amplitude controls
+        ##################################################
+        amp_hbox = forms.static_box_sizer(parent=self.panel, 
label="Amplitude", orient=wx.VERTICAL, bold=True)
+        amp_hbox.AddSpacer(5)
+        # First row of amp controls (ampl)
+        lvl_hbox = wx.BoxSizer(wx.HORIZONTAL)
+        amp_hbox.Add(lvl_hbox, 0, wx.EXPAND)
+        amp_hbox.AddSpacer(10)
+        # Second row of amp controls (tx gain)
+        gain_hbox = wx.BoxSizer(wx.HORIZONTAL)
+        amp_hbox.Add(gain_hbox, 0, wx.EXPAND)
+        amp_hbox.AddSpacer(5)
         self.vbox.Add(amp_hbox, 0, wx.EXPAND)
-
-        # Sample rate row
-        sam_sbox = wx.StaticBox(parent=self.panel, label="Sample Rate")
-        sam_hbox = wx.StaticBoxSizer(sam_sbox, wx.HORIZONTAL)
-        sam_hbox.Add((10,0), 0, 0)
-        myform['interp'] = form.int_field(
-            parent=self.panel, sizer=sam_hbox, label="Interpolation", weight=1,
-            callback=self.evt_set_interp)
-        sam_hbox.Add((10,0), 0, 0)
-        myform['eth'] = form.static_float_field(
-            parent=self.panel, sizer=sam_hbox, label="Sample Rate (sps)", 
weight=1)
-        sam_hbox.Add((10,0), 0, 0)
-        myform['gbe'] = form.static_float_field(
-            parent=self.panel, sizer=sam_hbox, label="GbE Rate (bits/sec)", 
weight=1)
-        sam_hbox.Add((10,0), 0, 0)
-        self.vbox.Add((0,10), 0, 0)
+        self.vbox.AddSpacer(10)
+        self.vbox.AddStretchSpacer()
+        lvl_hbox.AddSpacer(5)
+        forms.text_box(
+            parent=self.panel, sizer=lvl_hbox,
+            proportion=1,
+            converter=forms.float_converter(),
+            ps=self.tb,
+            key=usrp2_siggen.AMPLITUDE_KEY,
+            label="Level (0.0-1.0)",
+        )
+        lvl_hbox.AddSpacer(10)
+        forms.slider(
+            parent=self.panel, sizer=lvl_hbox,
+            proportion=2,
+            ps=self.tb,
+            key=usrp2_siggen.AMPLITUDE_KEY,
+            minimum=0,
+            maximum=1,
+            num_steps=100,
+        )
+        lvl_hbox.AddSpacer(5)
+        gain_hbox.AddSpacer(5)
+        forms.text_box(
+            parent=self.panel, sizer=gain_hbox,
+            proportion=1,
+            converter=forms.float_converter(),
+            ps=self.tb,
+            key=usrp2_siggen.GAIN_KEY,
+            label="TX Gain (dB)",
+        )
+        gain_hbox.AddSpacer(10)
+        forms.slider(
+            parent=self.panel, sizer=gain_hbox,
+            proportion=2,
+            ps=self.tb,
+            key=usrp2_siggen.GAIN_KEY,
+            minimum=self.tb[usrp2_siggen.GAIN_RANGE_KEY][0],
+            maximum=self.tb[usrp2_siggen.GAIN_RANGE_KEY][1],
+            step_size=self.tb[usrp2_siggen.GAIN_RANGE_KEY][2],
+        )
+        gain_hbox.AddSpacer(5)
+        ##################################################
+        # Sample Rate controls
+        ##################################################
+        sam_hbox = forms.static_box_sizer(parent=self.panel, label="Sample 
Rate", orient=wx.HORIZONTAL, bold=True)
         self.vbox.Add(sam_hbox, 0, wx.EXPAND)
-
-        # USRP2 row
-        u2_sbox = wx.StaticBox(parent=self.panel, label="USRP2 Hardware")
-        u2_hbox = wx.StaticBoxSizer(u2_sbox, wx.HORIZONTAL)
-        u2_hbox.Add((10,0), 0, 0)
-        myform['ifc'] = form.static_text_field(parent=self.panel, 
sizer=u2_hbox, 
-                                               label="Interface", weight=2)
-        u2_hbox.Add((10,0), 0, 0)
-        myform['mac'] = form.static_text_field(parent=self.panel, 
sizer=u2_hbox, 
-                                               label="MAC Address", weight=2)
-        u2_hbox.Add((10,0), 0, 0)
-        myform['dbid'] = form.static_text_field(parent=self.panel, 
sizer=u2_hbox, 
-                                                label="Daughterboard ID", 
weight=1)
-        self.vbox.Add((0,10), 0, 0)
+        self.vbox.AddSpacer(10)
+        self.vbox.AddStretchSpacer()
+        sam_hbox.AddSpacer(5)
+        forms.text_box(
+            parent=self.panel, sizer=sam_hbox,
+            proportion=1,
+            converter=forms.int_converter(),
+            ps=self.tb,
+            key=usrp2_siggen.INTERP_KEY,
+            label="Interpolation",
+        )
+        sam_hbox.AddSpacer(10)
+        forms.static_text(
+            parent=self.panel, sizer=sam_hbox,
+            label='Sample Rate (sps)',
+            ps=self.tb,
+            key=usrp2_siggen.ETH_RATE_KEY,
+            converter=forms.float_converter(),
+            proportion=1,
+        )
+        sam_hbox.AddSpacer(10)
+        forms.static_text(
+            parent=self.panel, sizer=sam_hbox,
+            label='GbE Rate (bits/sec)',
+            ps=self.tb,
+            key=usrp2_siggen.ETH_RATE_KEY,
+            converter=forms.float_converter(),
+            proportion=2,
+        )
+        sam_hbox.AddSpacer(5)
+        ##################################################
+        # USRP2 controls
+        ##################################################
+        u2_hbox = forms.static_box_sizer(parent=self.panel, label="USRP2 
Hardware", orient=wx.HORIZONTAL, bold=True)
         self.vbox.Add(u2_hbox, 0, wx.EXPAND)
-        self.vbox.Add((0,20), 0, 0)
+        self.vbox.AddSpacer(10)
+        self.vbox.AddStretchSpacer()
+        u2_hbox.AddSpacer(5)
+        forms.static_text(
+            parent=self.panel, sizer=u2_hbox,
+            label='Interface',
+            ps=self.tb,
+            key=usrp2_siggen.INTERFACE_KEY,
+            converter=forms.str_converter(),
+            proportion=2,
+        )
+        u2_hbox.AddSpacer(10)
+        forms.static_text(
+            parent=self.panel, sizer=u2_hbox,
+            label='MAC Address',
+            ps=self.tb,
+            key=usrp2_siggen.MAC_ADDR_KEY,
+            converter=forms.str_converter(),
+            proportion=2,
+        )
+        u2_hbox.AddSpacer(10)
+        forms.static_text(
+            parent=self.panel, sizer=u2_hbox,
+            label='Daughterboard ID',
+            ps=self.tb,
+            key=usrp2_siggen.DBOARD_ID_KEY,
+            converter=forms.int_converter(),
+            proportion=2,
+        )
+        u2_hbox.AddSpacer(5)
+        self.vbox.AddSpacer(5)
+        self.vbox.AddStretchSpacer()
 
 if __name__ == "__main__":
     try:





reply via email to

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