commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8837 - gnuradio/branches/features/experimental-gui


From: jcorgan
Subject: [Commit-gnuradio] r8837 - gnuradio/branches/features/experimental-gui
Date: Wed, 9 Jul 2008 10:37:12 -0600 (MDT)

Author: jcorgan
Date: 2008-07-09 10:37:12 -0600 (Wed, 09 Jul 2008)
New Revision: 8837

Modified:
   gnuradio/branches/features/experimental-gui/fft_controller.py
   gnuradio/branches/features/experimental-gui/fft_top_block.py
   gnuradio/branches/features/experimental-gui/usrp_fft.py
Log:
Have controller object create top block rather than having it passed.

Modified: gnuradio/branches/features/experimental-gui/fft_controller.py
===================================================================
--- gnuradio/branches/features/experimental-gui/fft_controller.py       
2008-07-09 16:36:46 UTC (rev 8836)
+++ gnuradio/branches/features/experimental-gui/fft_controller.py       
2008-07-09 16:37:12 UTC (rev 8837)
@@ -24,45 +24,79 @@
 above fft_top_block.
 """
 
+# Import the top block object.  Top blocks should be written not to know
+# anything about the controller or GUI layers
+from fft_top_block import fft_top_block
+
 from prop_val import prop_val_interface
 import threading
 
+"""!
+The FFT controller implements a property/value interface
+that controls all aspects of application operation.  It
+creates an underlying GNU Radio top block that it both
+manipulates in response to property updates and extracts
+from to update properties that external users will listen
+to.
+"""
 class fft_controller(prop_val_interface, threading.Thread):
-    def __init__(self, tb):
+    def __init__(self,
+                 fft_size=512,
+                 frame_rate=30,
+                 ref_scale=50,
+                 which=0,
+                 decim=16,
+                 width_8=False,
+                 no_hb=False,
+                 subdev_spec=None,
+                 gain=None,
+                 freq=None,
+                 antenna=None,
+                 avg_alpha=0.1,
+                 average=False):
+        
        prop_val_interface.__init__(self)
        threading.Thread.__init__(self)
-       self._tb = tb
+
+        # Create the top block with the initial parameters
+       self._tb = fft_top_block(fft_size=fft_size,
+                                 frame_rate=frame_rate,
+                                 ref_scale=ref_scale,
+                                 which=which,
+                                 decim=decim,
+                                 width_8=width_8,
+                                 no_hb=no_hb,
+                                 subdev_spec=subdev_spec,
+                                 gain=gain,
+                                 freq=freq,
+                                 antenna=antenna,
+                                 avg_alpha=avg_alpha,
+                                 average=average)
        
        # External control interface.  These properties, when set by an external
        # caller, result in the correct top block methods being invoked.
-       # These could be expanded to member functions to implement more advanced
-       # application logic, but here lambdas do the trick.
-
        self.add_listener('decim',     self.set_decim)
        self.add_listener('gain',      lambda x: self._tb.set_gain(x))
        self.add_listener('freq',      lambda x: self._tb.set_freq(x))
        self.add_listener('avg_alpha', lambda x: self._tb.set_avg_alpha(x))
        self.add_listener('average',   lambda x: self._tb.set_average(x))
 
-       # TODO: set providers for various properties an external caller might
-       # like to know about here.  Can be member functions or lambdas, and
-       # would make calls on the top block to retrieve info.
-       #
-       # self.set_provider('foo', lambda: 'bar')
-       # self.set_provider('decim', lambda: self._tb.decim())
+       # Set providers for application properties
+       self.set_provider('sample_rate', lambda: self._tb.sample_rate())
+       self.set_provider('average', lambda: self._tb.average())
+       self.set_provider('avg_alpha', lambda: self._tb.avg_alpha())
        
-       #!!! extreme badness below !!!
-       self.set_provider('sample_rate', lambda: self._tb._u.sample_rate())
-       self.set_provider('average', lambda: self._tb._fft._average)
-       self.set_provider('avg_alpha', lambda: self._tb._fft._avg_alpha)
-       
-       # The controller is a thread
+       # The controller is a thread.  This is not required but convenient here.
        self.setDaemon(1)
        self._keep_running = True
        
-    def set_decim(self, decim): #an update in decim will cause the sample_rate 
listeners to be called
-               self._tb.set_decim(decim)
-               self['sample_rate'] = self['sample_rate']
+    def set_decim(self, decim):
+        """!
+        Listens to property 'decim'. Changes decimation rate and updates 
'sample_rate'
+        property (which triggers listeners on that property).
+        """
+        self._tb.set_decim(decim)
+       self['sample_rate'] = self._tb.sample_rate()
 
     def on_init(self):
        """

Modified: gnuradio/branches/features/experimental-gui/fft_top_block.py
===================================================================
--- gnuradio/branches/features/experimental-gui/fft_top_block.py        
2008-07-09 16:36:46 UTC (rev 8836)
+++ gnuradio/branches/features/experimental-gui/fft_top_block.py        
2008-07-09 16:37:12 UTC (rev 8837)
@@ -106,3 +106,13 @@
     # Getters, which are called externally to get information about the 
flowgraph
     def queue(self):
        return self._msgq
+
+    def sample_rate(self):
+        return self._u.sample_rate()
+
+    def average(self):
+        return self._fft.average()
+
+    def avg_alpha(self):
+        return self._fft.avg_alpha()
+

Modified: gnuradio/branches/features/experimental-gui/usrp_fft.py
===================================================================
--- gnuradio/branches/features/experimental-gui/usrp_fft.py     2008-07-09 
16:36:46 UTC (rev 8836)
+++ gnuradio/branches/features/experimental-gui/usrp_fft.py     2008-07-09 
16:37:12 UTC (rev 8837)
@@ -24,9 +24,6 @@
 from gnuradio.eng_option import eng_option
 import sys
 
-# Import the top_block
-from fft_top_block import fft_top_block
-
 # Import the controller object
 from fft_controller import fft_controller
 
@@ -67,32 +64,27 @@
 if __name__ == "__main__":
     (options, args) = get_options()
 
-    # Applications have a 3-step initialization
+    # Applications have a 2-step initialization
     
-    # Step 1: Create the GNU Radio top block.  This top block knows
-    # nothing of the GUI, and is manipulated by a GUI independent
-    # controller.
-    tb = fft_top_block(fft_size=512,
-                       frame_rate=10,
-                      ref_scale=50,
-                      which=options.which,
-                      decim=options.decim,
-                      width_8=options.width_8,
-                      no_hb=options.no_hb,
-                      subdev_spec=options.rx_subdev_spec,
-                      gain=options.gain,
-                      freq=options.freq,
-                      antenna=options.antenna,
-                      avg_alpha=options.avg_alpha,
-                      average=False)
-
-    # Step 2: Create the application controller and pass it 
+    # Step 1: Create the application controller.  It will create
     # the top block it manipulates.  The controller implements
     # a property/value interface to allow setting, getting, and
     # listening properties that affect the application operation.
-    controller = fft_controller(tb)
+    controller = fft_controller(fft_size=512,
+                                frame_rate=10,
+                                ref_scale=50,
+                                which=options.which,
+                                decim=options.decim,
+                                width_8=options.width_8,
+                                no_hb=options.no_hb,
+                                subdev_spec=options.rx_subdev_spec,
+                                gain=options.gain,
+                                freq=options.freq,
+                                antenna=options.antenna,
+                                avg_alpha=options.avg_alpha,
+                                average=False)
 
-    # Step 3: Create the GUI and pass it the controller
+    # Step 2: Create the GUI and pass it the controller
     # to manipulate.  The GUI code doesn't know anything about GNU
     # Radio proper; it simply gets, sets, or listens to properties
     # on the controller.  The 'GUI' can actually be a CLI batch





reply via email to

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