commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8142 - in grc/branches/grc_reloaded: notes scripts sr


From: jblum
Subject: [Commit-gnuradio] r8142 - in grc/branches/grc_reloaded: notes scripts src/grc_gnuradio/blks2 src/grc_gnuradio/blocks/usrp src/grc_gnuradio/data src/grc_gnuradio/usrp src/grc_gnuradio/wxgui
Date: Mon, 31 Mar 2008 12:22:14 -0600 (MDT)

Author: jblum
Date: 2008-03-31 12:22:13 -0600 (Mon, 31 Mar 2008)
New Revision: 8142

Added:
   grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/callback_controls.py
Removed:
   grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/Controls.py
Modified:
   grc/branches/grc_reloaded/notes/todo.txt
   grc/branches/grc_reloaded/scripts/usrp_diagnostics
   grc/branches/grc_reloaded/src/grc_gnuradio/blks2/__init__.py
   grc/branches/grc_reloaded/src/grc_gnuradio/blks2/packet.py
   grc/branches/grc_reloaded/src/grc_gnuradio/blks2/selector.py
   grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_dual_sink_x.xml
   grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_dual_source_x.xml
   grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_simple_sink_x.xml
   
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_simple_source_x.xml
   grc/branches/grc_reloaded/src/grc_gnuradio/data/block_tree.xml
   grc/branches/grc_reloaded/src/grc_gnuradio/data/wx_gui.tmpl
   grc/branches/grc_reloaded/src/grc_gnuradio/usrp/__init__.py
   grc/branches/grc_reloaded/src/grc_gnuradio/usrp/simple_usrp.py
   grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/__init__.py
Log:
simple usrp tested + fixed, license stuff in external blocks

Modified: grc/branches/grc_reloaded/notes/todo.txt
===================================================================
--- grc/branches/grc_reloaded/notes/todo.txt    2008-03-31 04:53:12 UTC (rev 
8141)
+++ grc/branches/grc_reloaded/notes/todo.txt    2008-03-31 18:22:13 UTC (rev 
8142)
@@ -1,7 +1,6 @@
 ############ GRC Reloaded: #############
 -html documentation/tutorial
 -default platform for preferences block
--usrp simple needs testing
 
 ############   Blocks to Add:  ####################
 -see checklist

Modified: grc/branches/grc_reloaded/scripts/usrp_diagnostics
===================================================================
--- grc/branches/grc_reloaded/scripts/usrp_diagnostics  2008-03-31 04:53:12 UTC 
(rev 8141)
+++ grc/branches/grc_reloaded/scripts/usrp_diagnostics  2008-03-31 18:22:13 UTC 
(rev 8142)
@@ -92,12 +92,12 @@
                        get_mux = usrp.determine_tx_mux_value
                try:            
                        u = make(usrp_number_param.evaluate())
-                       subdev_spec = side_subdev_param.evaluate()      
+                       subdev_spec = eval(side_subdev_param.evaluate())
                        subdev = usrp.selected_subdev(u, subdev_spec)#get the 
subdev
                        msg = ">>> USRP Query\n"
-                       msg = "%s\nName:\n\t%s\n"%(msg,str(subdev.name()))
+                       msg = "%s\nName:\n\t%s\n"%(msg, str(subdev.name()))
                        msg = "%s\nAutomated Mux:\n\t0x%08x\n"%(msg, 
0xFFFFFFFFL & long(get_mux(u, subdev_spec))) #ensure that the value is 
displayed as: 8 nibbles, unsigned, hex
-                       msg = "%s\nConverter 
Rate:\n\t%s\n"%(msg,u.converter_rate())
+                       msg = "%s\nConverter Rate:\n\t%s\n"%(msg, 
u.converter_rate())
                        msg = "%s\nUses Quadrature:\n\t%s\n"%(msg, 
str(subdev.is_quadrature()))
                        gain_min, gain_max, gain_step = subdev.gain_range()
                        msg = "%s\nGain Range (min, max, step 
size):\n\t%s\n\t%s\n\t%s\n"%(msg, gain_min, gain_max, gain_step)

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/blks2/__init__.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/blks2/__init__.py        
2008-03-31 04:53:12 UTC (rev 8141)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/blks2/__init__.py        
2008-03-31 18:22:13 UTC (rev 8142)
@@ -1,25 +1,5 @@
-"""
-Copyright 2008 Free Software Foundation, Inc.
-This file is part of GNU Radio
+# make this directory a package
 
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
-"""
address@hidden grc_gnuradio.blks2
-#Package for external gnuradio blocks.
address@hidden Josh Blum
-
 from selector import selector, valve
 from packet import packet_mod, packet_demod
 

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/blks2/packet.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/blks2/packet.py  2008-03-31 
04:53:12 UTC (rev 8141)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/blks2/packet.py  2008-03-31 
18:22:13 UTC (rev 8142)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-# Copyright 2003,2004,2006,2007 Free Software Foundation, Inc.
+# Copyright 2008 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/blks2/selector.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/blks2/selector.py        
2008-03-31 04:53:12 UTC (rev 8141)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/blks2/selector.py        
2008-03-31 18:22:13 UTC (rev 8142)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-# Copyright 2003,2004,2006,2007 Free Software Foundation, Inc.
+# Copyright 2008 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 

Modified: 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_dual_sink_x.xml
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_dual_sink_x.xml 
2008-03-31 04:53:12 UTC (rev 8141)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_dual_sink_x.xml 
2008-03-31 18:22:13 UTC (rev 8142)
@@ -59,7 +59,7 @@
        <param>
                <name>Interpolation</name>
                <key>interpolation</key>
-               <type>real</type>               
+               <type>int</type>                
        </param>
        <param>
                <name>Gain A</name>

Modified: 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_dual_source_x.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_dual_source_x.xml   
    2008-03-31 04:53:12 UTC (rev 8141)
+++ 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_dual_source_x.xml   
    2008-03-31 18:22:13 UTC (rev 8142)
@@ -59,7 +59,7 @@
        <param>
                <name>Decimation</name>
                <key>decimation</key>
-               <type>real</type>               
+               <type>int</type>                
        </param>
        <param>
                <name>Gain A</name>

Modified: 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_simple_sink_x.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_simple_sink_x.xml   
    2008-03-31 04:53:12 UTC (rev 8141)
+++ 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_simple_sink_x.xml   
    2008-03-31 18:22:13 UTC (rev 8142)
@@ -80,7 +80,7 @@
        <param>
                <name>Interpolation</name>
                <key>interpolation</key>
-               <type>real</type>               
+               <type>int</type>                
        </param>
        <param>
                <name>Gain</name>

Modified: 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_simple_source_x.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_simple_source_x.xml 
    2008-03-31 04:53:12 UTC (rev 8141)
+++ 
grc/branches/grc_reloaded/src/grc_gnuradio/blocks/usrp/usrp_simple_source_x.xml 
    2008-03-31 18:22:13 UTC (rev 8142)
@@ -80,7 +80,7 @@
        <param>
                <name>Decimation</name>
                <key>decimation</key>
-               <type>real</type>               
+               <type>int</type>                
        </param>
        <param>
                <name>Gain</name>

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/data/block_tree.xml
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/data/block_tree.xml      
2008-03-31 04:53:12 UTC (rev 8141)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/data/block_tree.xml      
2008-03-31 18:22:13 UTC (rev 8142)
@@ -194,8 +194,8 @@
        <cat>
                <name>USRP</name>
                <block>usrp_simple_source_x</block>
+               <block>usrp_simple_sink_x</block>
                <block>usrp_dual_source_x</block>
-               <block>usrp_simple_sink_x</block>
                <block>usrp_dual_sink_x</block>
        </cat>
        <cat>

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/data/wx_gui.tmpl
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/data/wx_gui.tmpl 2008-03-31 
04:53:12 UTC (rev 8141)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/data/wx_gui.tmpl 2008-03-31 
18:22:13 UTC (rev 8142)
@@ -104,7 +104,7 @@
 ########################################################
 #for $slider in $sliders
 $make_callback($slider.get_id())
-slider = grc_wxgui.Slider(
+slider = grc_wxgui.slider_control(
        window=_frame, 
        callback=_callback,
 #if $slider.get_param('label').evaluate() 
@@ -125,7 +125,7 @@
 ########################################################               
 #for $chooser in $choosers
 $make_callback($chooser.get_id())
-chooser = grc_wxgui.Chooser(
+chooser = grc_wxgui.chooser_control(
        window=_frame, 
        callback=_callback, 
 #if $chooser.get_param('label').evaluate() 

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/usrp/__init__.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/usrp/__init__.py 2008-03-31 
04:53:12 UTC (rev 8141)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/usrp/__init__.py 2008-03-31 
18:22:13 UTC (rev 8142)
@@ -1,25 +1,5 @@
-"""
-Copyright 2008 Free Software Foundation, Inc.
-This file is part of GNU Radio
+# make this directory a package
 
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
-"""
address@hidden grc_gnuradio.usrp
-#Package for external gnuradio blocks.
address@hidden Josh Blum
-
 from simple_usrp import simple_source_c, simple_source_s
 from simple_usrp import dual_source_c, dual_source_s
 from simple_usrp import simple_sink_c, simple_sink_s

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/usrp/simple_usrp.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/usrp/simple_usrp.py      
2008-03-31 04:53:12 UTC (rev 8141)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/usrp/simple_usrp.py      
2008-03-31 18:22:13 UTC (rev 8142)
@@ -1,27 +1,32 @@
-"""
-Copyright 2008 Free Software Foundation, Inc.
-This file is part of GNU Radio
+#!/usr/bin/env python
+#
+# Copyright 2008 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+# 
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
 
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
+import sys
+from gnuradio import usrp, gr
 
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+####################################################################
+#      Helper Functions
+####################################################################
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
-"""
address@hidden grc_gnuradio.usrp.usrp
-#USRP convenience contructors.
address@hidden Josh Blum
-
-from gnuradio import usrp, gr
-
 def _set_frequency(u, which, subdev, frequency, verbose=False):
        """!
        Set the carrier frequency for the given subdevice.      
@@ -31,13 +36,14 @@
        @param verbose if true, print usrp tuning information
        """
        r = u.tune(which, subdev, frequency)
-       if verbose and r:       
-               print subdev.side_and_name()
-               print "  r.baseband_frequency =", r.baseband_frequency
-               print "  r.dxc_frequency      =", r.dxc_frequency
-               print "  r.residual_frequency =", r.residual_frequency
+       if not verbose: return
+       print subdev.side_and_name()
+       if r:
+               print "  r.baseband_frequency =", r.baseband_freq
+               print "  r.dxc_frequency      =", r.dxc_freq
+               print "  r.residual_frequency =", r.residual_freq
                print "  r.inverted      =", r.inverted
-       elif not r: raise ValueError, '"%s" is not a valid frequency for this 
sub-device\n'%frequency
+       else: print >> sys.stderr, 'Error calling tune on subdevice.'
                
 def _setup_rx_subdev(u, subdev_spec, ddc, gain, frequency, auto_tr=None, 
rx_ant=None):
        """!
@@ -89,9 +95,57 @@
 }
 
 ####################################################################
+####################################################################
+#      Simple USRP Base Classes
+####################################################################
+####################################################################
+
+class _simple_usrp(object):
+       """A single usrp source/sink base class."""
+       
+       def __init__(self, u, subdev, which):
+               """!
+               Create a simple usrp base class.
+               @param u the usrp object
+               @param subdev the subdevice object
+               @param which specifies the DDC/DUC number when tuning
+               """
+               self._u = u
+               self._subdev = subdev
+               self._which = which
+       
+       def get_u(self):
+               """!
+               Get the underlying usrp object.
+               @return the usrp source/sink object.
+               """
+               return self._u
+       
+       def get_subdev(self):
+               """!
+               Get the underlying subdevice.
+               @return the subdev object.
+               """
+               return self._subdev
+       
+       def set_frequency(self, frequency):
+               """!
+               Set the frequency of the subdevice.
+               @param frequency the frequency to tune
+               """
+               _set_frequency(self.get_u(), self._which, self.get_subdev(), 
frequency)
+               
+       def set_gain(self, gain):
+               """!
+               Set the gain of the subdevice.
+               @param gain the gain to set
+               """
+               self.get_subdev().set_gain(gain)
+               
+####################################################################
 #      Single USRP Source
 ####################################################################
-class _simple_source(gr.hier_block2):
+class _simple_source(gr.hier_block2, _simple_usrp):
        """A single usrp source of IO type short or complex."""
        
        def __init__(self, number, subdev_spec, frequency, decimation, gain, 
mux=None, auto_tr=None, rx_ant=None):
@@ -113,155 +167,175 @@
                        gr.io_signature(1, 1, 
constructor_to_size[self.constructor]),
                )
                #create usrp object
-               self.u = u = self.constructor(number, nchan=1)
+               u = self.constructor(number, nchan=1)
                if subdev_spec is None: subdev_spec = subdev_spec = 
usrp.pick_rx_subdevice(u)
                u.set_decim_rate(decimation)
                if mux is None: mux = usrp.determine_rx_mux_value(u, 
subdev_spec)
                u.set_mux(mux)                  
-               self.subdev = _setup_rx_subdev(u, subdev_spec, 0, gain, 
frequency, auto_tr, rx_ant)                     
+               subdev = _setup_rx_subdev(u, subdev_spec, 0, gain, frequency, 
auto_tr, rx_ant)
+               _simple_usrp.__init__(self, u, subdev, 0)       
                #connect
                self.connect(u, self)
        
-       def set_frequency(self, frequency):
-               """!
-               Set the frequency of the subdevice.
-               @param frequency the frequency to tune
-               """
-               _set_frequency(self.u, 0, self.subdev, frequency)
-               
-       def set_gain(self, gain):
-               """!
-               Set the gain of the subdevice.
-               @param gain the gain to set
-               """
-               self.subdev.set_gain(gain)
-
 class simple_source_c(_simple_source): constructor = usrp.source_c
 class simple_source_s(_simple_source): constructor = usrp.source_s
 
 ####################################################################
-#      Dual USRP Source
+#      Single USRP Sink
 ####################################################################
-class _dual_source(gr.hier_block2):
-       """A dual usrp source of IO type short or complex."""
+class _simple_sink(gr.hier_block2, _simple_usrp):
+       """A single usrp sink of IO type short or complex."""
        
-       def __init__(self, number, frequency_a, frequency_b, decimation, 
gain_a, gain_b, mux=0x3210, auto_tr=None, rx_ant_a=None, rx_ant_b=None):
+       def __init__(self, number, subdev_spec, frequency, interpolation, gain, 
mux=None, auto_tr=None, tx_enb=None):
                """!
-               USRP dual source contructor.
+               USRP simple sink contructor.
                @param number the unit number
-               @param frequency_a the frequency to tune side a
-               @param frequency_b the frequency to tune side b
-               @param decimation the device decimation
-               @param gain_a the gain to set side a
-               @param gain_b the gain to set side b
-               @param mux the mux in hex
+               @param subdev_spec the sub-device specification tuple
+               @param frequency the frequency to tune
+               @param interpolation the device interpolation
+               @param gain the gain to set
+               @param mux the mux in hex or None
                @param auto_tr auto transmit/receive True, False, or None
-               @param rx_ant_a the receive antenna side a: 'TX/RX', 'RX2', or 
None
-               @param rx_ant_b the receive antenna side b: 'TX/RX', 'RX2', or 
None
+               @param tx_enb the transmit enable: True, False, or None
                """
                #initialize hier2 block
                gr.hier_block2.__init__(
-                       self, 'usrp_dual_source', 
+                       self, 'usrp_simple_sink', 
+                       gr.io_signature(1, 1, 
constructor_to_size[self.constructor]),
                        gr.io_signature(0, 0, 0), 
-                       gr.io_signature(2, 2, 
constructor_to_size[self.constructor]),
                )
                #create usrp object
-               self.u = u = self.constructor(number, nchan=2)
-               u.set_decim_rate(decimation)
+               u = self.constructor(number, nchan=1)
+               if subdev_spec is None: subdev_spec = subdev_spec = 
usrp.pick_tx_subdevice(u)
+               u.set_interp_rate(interpolation)
+               if mux is None: mux = usrp.determine_tx_mux_value(u, 
subdev_spec)
                u.set_mux(mux)                  
-               self.subdev_a = _setup_rx_subdev(u, (0, 0), 0, gain_a, 
frequency_a, auto_tr, rx_ant_a)          
-               self.subdev_b = _setup_rx_subdev(u, (1, 0), 1, gain_b, 
frequency_b, auto_tr, rx_ant_b)                  
+               subdev = _setup_tx_subdev(u, subdev_spec, gain, frequency, 
auto_tr, tx_enb)
+               _simple_usrp.__init__(self, u, subdev, subdev._which)   
                #connect
-               deinter = gr.deinterleave(constructor_to_size[self.constructor])
-               self.connect(u, deinter)
-               for i in range(2): self.connect((deinter, i), (self, i))
+               self.connect(self, u)
+
+class simple_sink_c(_simple_sink): constructor = usrp.sink_c
+class simple_sink_s(_simple_sink): constructor = usrp.sink_s
+
+####################################################################           
+####################################################################
+#      Dual USRP Base Classes
+####################################################################
+####################################################################
+
+class _dual_usrp(object):
+       """A dual usrp source/sink base class."""
        
+       def __init__(self, u, subdev_a, subdev_b, which_a, which_b):
+               """!
+               Create a dual usrp base class.
+               @param u the usrp object
+               @param subdev_a the subdevice object side a
+               @param subdev_b the subdevice object side b
+               @param which_a specifies the DDC/DUC number when tuning side a
+               @param which_b specifies the DDC/DUC number when tuning side b
+               """
+               self._u = u
+               self._subdev_a = subdev_a
+               self._subdev_b = subdev_b
+               self._which_a = which_a
+               self._which_b = which_b
+       
+       def get_u(self):
+               """!
+               Get the underlying usrp object.
+               @return the usrp source/sink object.
+               """
+               return self._u
+       
+       def get_subdev_a(self):
+               """!
+               Get the underlying subdevice.
+               @return the subdev object.
+               """
+               return self._subdev_a
+               
+       def get_subdev_b(self):
+               """!
+               Get the underlying subdevice.
+               @return the subdev object.
+               """
+               return self._subdev_b
+       
        def set_frequency_a(self, frequency):
                """!
                Set the frequency of the subdevice.
                @param frequency the frequency to tune
                """
-               _set_frequency(self.u, 0, self.subdev_a, frequency)
+               _set_frequency(self.get_u(), self._which_a, 
self.get_subdev_a(), frequency)
                
+       def set_frequency_b(self, frequency):
+               """!
+               Set the frequency of the subdevice.
+               @param frequency the frequency to tune
+               """
+               _set_frequency(self.get_u(), self._which_b, 
self.get_subdev_b(), frequency)
+               
        def set_gain_a(self, gain):
                """!
                Set the gain of the subdevice.
                @param gain the gain to set
                """
-               self.subdev_a.set_gain(gain)
+               self.get_subdev_a().set_gain(gain)              
                
-       def set_frequency_b(self, frequency):
-               """!
-               Set the frequency of the subdevice.
-               @param frequency the frequency to tune
-               """
-               _set_frequency(self.u, 0, self.subdev_b, frequency)
-               
        def set_gain_b(self, gain):
                """!
                Set the gain of the subdevice.
                @param gain the gain to set
                """
-               self.subdev_b.set_gain(gain)
+               self.get_subdev_b().set_gain(gain)              
 
-class dual_source_c(_dual_source): constructor = usrp.source_c
-class dual_source_s(_dual_source): constructor = usrp.source_s
-
 ####################################################################
-#      Single USRP Sink
+#      Dual USRP Source
 ####################################################################
-class _simple_sink(gr.hier_block2):
-       """A single usrp sink of IO type short or complex."""
+class _dual_source(gr.hier_block2, _dual_usrp):
+       """A dual usrp source of IO type short or complex."""
        
-       def __init__(self, number, subdev_spec, frequency, interpolation, gain, 
mux=None, auto_tr=None, tx_enb=None):
+       def __init__(self, number, frequency_a, frequency_b, decimation, 
gain_a, gain_b, mux=0x3210, auto_tr=None, rx_ant_a=None, rx_ant_b=None):
                """!
-               USRP simple sink contructor.
+               USRP dual source contructor.
                @param number the unit number
-               @param subdev_spec the sub-device specification tuple
-               @param frequency the frequency to tune
-               @param interpolation the device interpolation
-               @param gain the gain to set
-               @param mux the mux in hex or None
+               @param frequency_a the frequency to tune side a
+               @param frequency_b the frequency to tune side b
+               @param decimation the device decimation
+               @param gain_a the gain to set side a
+               @param gain_b the gain to set side b
+               @param mux the mux in hex
                @param auto_tr auto transmit/receive True, False, or None
-               @param tx_enb the transmit enable: True, False, or None
+               @param rx_ant_a the receive antenna side a: 'TX/RX', 'RX2', or 
None
+               @param rx_ant_b the receive antenna side b: 'TX/RX', 'RX2', or 
None
                """
                #initialize hier2 block
                gr.hier_block2.__init__(
-                       self, 'usrp_simple_sink', 
-                       gr.io_signature(1, 1, 
constructor_to_size[self.constructor]),
+                       self, 'usrp_dual_source', 
                        gr.io_signature(0, 0, 0), 
+                       gr.io_signature(2, 2, 
constructor_to_size[self.constructor]),
                )
                #create usrp object
-               self.u = u = self.constructor(number, nchan=1)
-               if subdev_spec is None: subdev_spec = subdev_spec = 
usrp.pick_tx_subdevice(u)
-               u.set_interp_rate(interpolation)
-               if mux is None: mux = usrp.determine_tx_mux_value(u, 
subdev_spec)
+               u = self.constructor(number, nchan=2)
+               u.set_decim_rate(decimation)
                u.set_mux(mux)                  
-               self.subdev = _setup_tx_subdev(u, subdev_spec, gain, frequency, 
auto_tr, tx_enb)                        
+               subdev_a = _setup_rx_subdev(u, (0, 0), 0, gain_a, frequency_a, 
auto_tr, rx_ant_a)               
+               subdev_b = _setup_rx_subdev(u, (1, 0), 1, gain_b, frequency_b, 
auto_tr, rx_ant_b)                       
+               _dual_usrp.__init__(self, u, subdev_a, subdev_b, 0, 1)
                #connect
-               self.connect(self, u)
-       
-       def set_frequency(self, frequency):
-               """!
-               Set the frequency of the subdevice.
-               @param frequency the frequency to tune
-               """
-               _set_frequency(self.u, 0, self.subdev, frequency)
-               
-       def set_gain(self, gain):
-               """!
-               Set the gain of the subdevice.
-               @param gain the gain to set
-               """
-               self.subdev.set_gain(gain)
+               deinter = gr.deinterleave(constructor_to_size[self.constructor])
+               self.connect(u, deinter)
+               for i in range(2): self.connect((deinter, i), (self, i))
 
-class simple_sink_c(_simple_sink): constructor = usrp.sink_c
-class simple_sink_s(_simple_sink): constructor = usrp.sink_s
+class dual_source_c(_dual_source): constructor = usrp.source_c
+class dual_source_s(_dual_source): constructor = usrp.source_s
 
 ####################################################################
 #      Dual USRP Sink
 ####################################################################
-class _dual_sink(gr.hier_block2):
+class _dual_sink(gr.hier_block2, _dual_usrp):
        """A dual usrp sink of IO type short or complex."""
        
        def __init__(self, number, frequency_a, frequency_b, interpolation, 
gain_a, gain_b, mux=0xba98, auto_tr=None, tx_enb_a=None, tx_enb_b=None):
@@ -283,43 +357,17 @@
                        gr.io_signature(0, 0, 0), 
                )
                #create usrp object
-               self.u = u = self.constructor(number, nchan=2)
+               u = self.constructor(number, nchan=2)
                u.set_interp_rate(interpolation)
                u.set_mux(mux)                  
-               self.subdev_a = _setup_tx_subdev(u, (0, 0), gain_a, 
frequency_a, auto_tr, tx_enb_a)
-               self.subdev_b = _setup_tx_subdev(u, (0, 0), gain_b, 
frequency_b, auto_tr, tx_enb_b)                     
+               subdev_a = _setup_tx_subdev(u, (0, 0), gain_a, frequency_a, 
auto_tr, tx_enb_a)
+               subdev_b = _setup_tx_subdev(u, (0, 0), gain_b, frequency_b, 
auto_tr, tx_enb_b)
+               _dual_usrp.__init__(self, u, subdev_a, subdev_b, 
subdev_a._which, subdev_b._which)
                #connect
-               inter = gr.interleaver(constructor_to_size[self.constructor])
+               inter = gr.interleave(constructor_to_size[self.constructor])
                self.connect(inter, u)
                for i in range(2): self.connect((self, i), (inter, i))
-       
-       def set_frequency_a(self, frequency):
-               """!
-               Set the frequency of the subdevice.
-               @param frequency the frequency to tune
-               """
-               _set_frequency(self.u, 0, self.subdev_a, frequency)
-               
-       def set_gain_a(self, gain):
-               """!
-               Set the gain of the subdevice.
-               @param gain the gain to set
-               """
-               self.subdev.set_gain_a(gain)
-               
-       def set_frequency_b(self, frequency):
-               """!
-               Set the frequency of the subdevice.
-               @param frequency the frequency to tune
-               """
-               _set_frequency(self.u, 0, self.subdev_b, frequency)
-               
-       def set_gain_b(self, gain):
-               """!
-               Set the gain of the subdevice.
-               @param gain the gain to set
-               """
-               self.subdev.set_gain_b(gain)
 
 class dual_sink_c(_dual_sink): constructor = usrp.sink_c
 class dual_sink_s(_dual_sink): constructor = usrp.sink_s
+

Deleted: grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/Controls.py

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/__init__.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/__init__.py        
2008-03-31 04:53:12 UTC (rev 8141)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/__init__.py        
2008-03-31 18:22:13 UTC (rev 8142)
@@ -1,24 +1,4 @@
-"""
-Copyright 2008 Free Software Foundation, Inc.
-This file is part of GNU Radio
+# make this directory a package
 
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
+from callback_controls import chooser_control, slider_control 
 
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
-"""
address@hidden grc_gnuradio.wxgui
-#Package for external gnuradio wxgui objects.
address@hidden Josh Blum
-
-from Controls import Chooser, Slider 
-

Copied: grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/callback_controls.py 
(from rev 8122, grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/Controls.py)
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/callback_controls.py       
                        (rev 0)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/callback_controls.py       
2008-03-31 18:22:13 UTC (rev 8142)
@@ -0,0 +1,215 @@
+#!/usr/bin/env python
+#
+# Copyright 2008 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+# 
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
+
+import wx
+import sys
+
+class _control_base(wx.BoxSizer):
+       """Control base class"""
+       
+       def __init__(self, window, callback, orientation=wx.VERTICAL):
+               self.window = window
+               self.callback = callback
+               wx.BoxSizer.__init__(self, orientation)                 
+               
+       def get_window(self): return self.window
+       
+       def call(self): return self.callback(self.get_value())
+       
+       def get_value(self): raise NotImplementedError
+       
+class LabelText(wx.StaticText):
+       """Label text class for uniform labels among all controls."""
+       
+       def __init__(self, window, label):
+               wx.StaticText.__init__(self, window, -1, str(label))
+               font = self.GetFont()
+               font.SetWeight(wx.FONTWEIGHT_BOLD)
+               self.SetFont(font)      
+       
+##############################################################################################
+#      Chooser Control
+##############################################################################################
+class chooser_control(_control_base):
+       """House a drop down or radio buttons for variable control."""
+
+       def __init__(self, window, callback, label='Label', index=0, 
choices=[0], labels=[], type='drop_down'):
+               """!
+               Chooser contructor.
+               Create the slider, text box, and label.
+               @param window the wx parent window
+               @param callback call the callback on changes
+               @param title the label title
+               @param index the default choice index
+               @param choices a list of choices
+               @param radio true for radio buttons
+               """
+               #initialize
+               _control_base.__init__(self, window, callback, wx.VERTICAL)
+               label_text = LabelText(self.get_window(), label)
+               self.Add(label_text, 0, wx.ALIGN_CENTER)
+               self.choices = choices
+               self.labels = labels = map(str, labels or choices)
+               ########### Drop Down ###########
+               if type == 'drop_down':
+                       self.drop_down = wx.Choice(self.get_window(), -1, 
choices=labels)
+                       self.Add(self.drop_down, 0, wx.ALIGN_CENTER)
+                       self.drop_down.Bind(wx.EVT_CHOICE, 
self._handle_changed)                
+                       self.drop_down.SetSelection(index)
+               ########### Radio Buttons ###########
+               elif type in ('radio_buttons_horizontal', 
'radio_buttons_vertical'):
+                       #determine gui parameters
+                       if type == 'radio_buttons_horizontal': 
+                               radio_box_orientation = wx.HORIZONTAL
+                               radio_button_align = wx.ALIGN_CENTER
+                       elif type == 'radio_buttons_vertical': 
+                               radio_box_orientation = wx.VERTICAL
+                               radio_button_align = wx.ALIGN_LEFT
+                       #create box for radio buttons
+                       radio_box = wx.BoxSizer(radio_box_orientation)
+                       panel = wx.Panel(self.get_window(), -1)
+                       panel.SetSizer(radio_box)
+                       self.Add(panel, 0, wx.ALIGN_CENTER)
+                       #create radio buttons
+                       self.radio_buttons = list()
+                       for label in labels:
+                               radio_button = wx.RadioButton(panel, -1, label)
+                               radio_button.SetValue(False)
+                               self.radio_buttons.append(radio_button)
+                               radio_box.Add(radio_button, 0, 
radio_button_align)
+                               radio_button.Bind(wx.EVT_RADIOBUTTON, 
self._handle_changed)
+                       #set one radio button active
+                       self.radio_buttons[index].SetValue(True)
+               ########### Button ###########
+               elif type == 'button':
+                       self.button = wx.Button(self.get_window(), -1, 
labels[index])
+                       self.button.Bind(wx.EVT_BUTTON, self._handle_changed)
+                       self.Add(self.button, 0, wx.ALIGN_CENTER)
+               self.index = index              
+  
+       def _handle_changed(self, event=None):
+               """!
+               A change is detected. Call the callback.
+               """
+               try: self.call()
+               except Exception, e: print >> sys.stderr, 'Error in handle 
change: "%s".'%e             
+
+       def get_value(self):
+               """!
+               Get the value from the drop down.
+               Read the selected index and parse the choice.
+               @return one of the possible choices
+               """
+               ########### Drop Down ###########
+               if hasattr(self, 'drop_down'):  
+                       index = self.drop_down.GetSelection()
+               ########### Radio Buttons ###########
+               elif hasattr(self, 'radio_buttons'):
+                       selected_radio_button = filter(lambda rb: 
rb.GetValue(), self.radio_buttons)[0]                         
+                       index = self.radio_buttons.index(selected_radio_button)
+               ########### Button ###########
+               elif hasattr(self, 'button'):
+                       index = (self.index + 1)%len(self.choices) #circularly 
increment index
+                       self.button.SetLabel(self.labels[index])
+               #store new index        
+               self.index = index
+               return self.choices[index]
+
+##############################################################################################
+#      Slider Control
+##############################################################################################
+class slider_control(_control_base):
+       """House a Slider and a Text Box for variable control."""
+       
+       def __init__(self, window, callback, label='Label', value=50, min=0, 
max=100, num_steps=100):
+               """!
+               Slider contructor.
+               Create the slider, text box, and label.
+               @param window the wx parent window
+               @param callback call the callback on changes
+               @param title the label title
+               @param value the default value
+               @param min the min
+               @param max the max
+               @param num_steps the number of steps
+               """
+               #initialize
+               _control_base.__init__(self, window, callback, wx.VERTICAL)
+               self.min = float(min)
+               self.max = float(max)
+               self.num_steps = int(num_steps)
+               #create gui elements
+               label_text_sizer = wx.BoxSizer(wx.HORIZONTAL) #label and text 
box container 
+               label_text = LabelText(self.get_window(), '%s -> '%str(label))
+               self.text_box = text_box = wx.TextCtrl(self.get_window(), -1, 
str(value), style=wx.TE_PROCESS_ENTER)
+               text_box.Bind(wx.EVT_TEXT_ENTER, self._handle_enter)    #bind 
this special enter hotkey event
+               for obj in (label_text, text_box):      #fill the container 
with label and text entry box
+                       label_text_sizer.Add(obj, 0, 
wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL)
+               self.Add(label_text_sizer, 0, wx.ALIGN_CENTER)
+               #make the slider
+               self.slider = slider = wx.Slider(self.get_window(), -1, 
size=wx.Size(200, 20), style=wx.SL_HORIZONTAL)                          
+               try: slider.SetRange(0, num_steps)
+               except Exception, e:
+                       print >> sys.stderr, 'Error in set slider range: 
"%s".'%e
+                       sys.exit(-1)
+               slider.Bind(wx.EVT_SCROLL, self._handle_scroll) #bind the 
scrolling event               
+               self.Add(slider, 0, wx.ALIGN_CENTER)
+               self._set_slider_value(value)#sets the slider's value
+                       
+       def get_value(self):
+               """!
+               Read the value from the slider and,  
+               translate the slider value into a real numerical value.
+               @return the numeric representation of the slider
+               """
+               slider_value = self.slider.GetValue()                   
+               return slider_value*(self.max - self.min)/self.num_steps + 
self.min
+               
+       def _set_slider_value(self, real_value):
+               """!
+               Translate the real numerical value into a slider value and,  
+               write the value to the slider.
+               @param real_value the numeric value the slider should represent
+               """             
+               slider_value = (float(real_value) - 
self.min)*self.num_steps/(self.max - self.min)
+               self.slider.SetValue(slider_value)
+       
+       def _handle_scroll(self, event=None):
+               """!
+               A scroll event is detected. Read the slider, call the callback.
+               """
+               new_value = str(self.get_value())       #the new value must be 
a string!
+               self._set_slider_value(new_value)
+               self.text_box.SetValue(new_value)
+               try: self.call()
+               except Exception, e: print >> sys.stderr, 'Error in handle 
scroll: "%s".'%e 
+               
+       def _handle_enter(self, event=None):
+               """!
+               An enter key was pressed. Read the text box, call the callback.
+               """     
+               new_value = str(self.text_box.GetValue())       #the new value 
must be a string!                
+               self._set_slider_value(new_value)
+               self.text_box.SetValue(new_value)
+               try: self.call()
+               except Exception, e: print >> sys.stderr, 'Error in handle 
enter: "%s".'%e 
+       





reply via email to

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