commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10901 - gnuradio/branches/developers/jblum/digital


From: jblum
Subject: [Commit-gnuradio] r10901 - gnuradio/branches/developers/jblum/digital
Date: Thu, 23 Apr 2009 20:04:08 -0600 (MDT)

Author: jblum
Date: 2009-04-23 20:04:07 -0600 (Thu, 23 Apr 2009)
New Revision: 10901

Added:
   gnuradio/branches/developers/jblum/digital/generic_usrp.py
Modified:
   gnuradio/branches/developers/jblum/digital/receive_path.py
Log:
Work on generic usrp classes.
Implemented generic usrp in rx path.
Tested rx path on usrp2.



Added: gnuradio/branches/developers/jblum/digital/generic_usrp.py
===================================================================
--- gnuradio/branches/developers/jblum/digital/generic_usrp.py                  
        (rev 0)
+++ gnuradio/branches/developers/jblum/digital/generic_usrp.py  2009-04-24 
02:04:07 UTC (rev 10901)
@@ -0,0 +1,252 @@
+#
+# Copyright 2009 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.
+# 
+
+USRP_TYPE = 'usrp'
+USRP2_TYPE = 'usrp2'
+
+from gnuradio import gr, usrp, usrp2
+
+########################################################################
+# common usrp options
+########################################################################
+def add_options(normal, expert):
+    """
+    Add options to manually choose between usrp or usrp2.
+    Add options for usb. Add options common to source and sink.
+    @param parser: instance of OptionParser
+    """
+    if normal.has_option("usrp2"): return
+    #pick usrp or usrp2
+    normal.add_option("--usrp2", action="store_true", default=False,
+                      help="Use USRP2 [default=auto]")
+    normal.add_option("--usrp", action="store_true", default=False,
+                      help="Use USRP [default=auto]")
+    #fast usb options
+    expert.add_option("-B", "--fusb-block-size", type="int", default=0,
+                      help="specify fast usb block size [default=%default]")
+    expert.add_option("-N", "--fusb-nblocks", type="int", default=0,
+                      help="specify number of fast usb blocks 
[default=%default]")
+    #usrp options
+    normal.add_option("-w", "--which", type="int", default=0,
+                      help="select USRP board [default=%default]")
+    #usrp2 options
+    normal.add_option("-e", "--interface", type="string", default="eth0",
+                      help="Use specified Ethernet interface 
[default=%default]")
+    normal.add_option("-m", "--mac-addr", type="string", default="",
+                      help="Use USRP2 at specified MAC address [default=None]")
+
+########################################################################
+# generic usrp common stuff
+########################################################################
+class _generic_usrp_base(object):
+
+    def __str__(self):
+        if self._type == USRP_TYPE: return self._subdev.side_and_name()
+        elif self._type == USRP2_TYPE: return "D-Board ID 
0x%x\n"%self._u.daughterboard_id()
+
+    def gain(self): return self._gain
+
+    def set_gain(self, gain=None):
+        if gain is None:
+            r = self.gain_range()
+            gain = (r[0] + r[1])/2               # set gain to midpoint
+        self._gain = gain
+        return self._u.set_gain(gain)
+
+    def gain_range(self):
+        if self._type == USRP_TYPE: return self._subdev.gain_range()
+        elif self._type == USRP2_TYPE: return self._u.gain_range()
+
+########################################################################
+# generic usrp source
+########################################################################
+class generic_usrp_source_c(_generic_usrp_base, gr.hier_block2):
+    """
+    Create a generic usrp source that represents usrp and usrp2.
+    Take usrp and usrp2 constructor arguments and try to figure out usrp or 
usrp2.
+    Provide generic access methods so the API looks the same for both.
+    """
+
+    @staticmethod
+    def add_options(normal, expert):
+        normal.add_option("-R", "--rx-subdev-spec", type="subdev", 
default=None,
+                          help="select USRP Rx side A or B")
+        normal.add_option("--rx-gain", type="eng_float", default=None, 
metavar="GAIN",
+                          help="set receiver gain in dB [default=midpoint].  
See also --show-rx-gain-range")
+        normal.add_option("--show-rx-gain-range", action="store_true", 
default=False, 
+                          help="print min and max Rx gain available on 
selected daughterboard")
+        expert.add_option("-d", "--decim", type="intx", default=None,
+                          help="set fpga decimation rate to DECIM 
[default=%default]")
+        add_options(normal, expert)
+
+    def __init__(self, options):
+        gr.hier_block2.__init__(self, "generic_usrp_source",
+            gr.io_signature(0, 0, 0), # Input signature
+            gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
+
+        #usrp options
+        self._which = options.which
+        self._rx_subdev_spec = options.rx_subdev_spec
+        self._fusb_block_size = options.fusb_block_size
+        self._fusb_nblocks = options.fusb_nblocks
+        #usrp2 options
+        self._interface = options.interface
+        self._mac_addr = options.mac_addr
+        #generic options
+        self._rx_gain = options.rx_gain
+        self._show_rx_gain_range = options.show_rx_gain_range
+
+        #pick usrp or usrp2
+        if options.usrp or self._rx_subdev_spec:
+            self._setup_usrp_source()
+        elif options.usrp2 or self._mac_addr:
+            self._setup_usrp2_source()
+        else: #automatic
+            try: self._setup_usrp2_source()
+            except: self._setup_usrp_source()
+        self.connect(self._u, self)
+        if options.show_rx_gain_range:
+            print "Rx Gain Range: minimum = %g, maximum = %g, step size = 
%g"%tuple(self.gain_range())
+
+    ####################################################################
+    # generic access methods
+    ####################################################################
+    def set_decim(self, decim):
+        if self._type == USRP_TYPE: return self._u.set_decim_rate(decim)
+        elif self._type == USRP2_TYPE: return self._u.set_decim(decim)
+    
+    def adc_rate(self): return self._u.adc_rate()
+    
+    def set_center_freq(self, target_freq):
+        if self._type == USRP_TYPE:
+            return bool(self._u.tune(0, self._subdev, target_freq))
+        elif self._type == USRP2_TYPE:
+            return self._u.set_center_freq(target_freq) or True
+
+    ####################################################################
+    # setup usrp methods
+    ####################################################################
+    def _setup_usrp_source(self):
+        self._u = usrp.source_c (self._which,
+                                fusb_block_size=self._fusb_block_size,
+                                fusb_nblocks=self._fusb_nblocks)
+        # determine the daughterboard subdevice we're using
+        if self._rx_subdev_spec is None:
+            self._rx_subdev_spec = usrp.pick_rx_subdevice(self._u)
+        self._subdev = usrp.selected_subdev(self._u, self._rx_subdev_spec)
+        self._u.set_mux(usrp.determine_rx_mux_value(self._u, 
self._rx_subdev_spec))
+        self._type = USRP_TYPE
+    
+    def _setup_usrp2_source(self):
+        self._u = usrp2.source_32fc(self._interface, self._mac_addr)
+        self._type = USRP2_TYPE
+
+    def __del__(self):
+        # Avoid weak reference error
+        if self._type == USRP_TYPE: del self._subdev
+
+########################################################################
+# generic usrp sink
+########################################################################
+class generic_usrp_sink_c(_generic_usrp_base, gr.hier_block2):
+    """
+    Create a generic usrp sink that represents usrp and usrp2.
+    Take usrp and usrp2 constructor arguments and try to figure out usrp or 
usrp2.
+    Provide generic access methods so the API looks the same for both.
+    """
+
+    @staticmethod
+    def add_options(normal, expert):
+        normal.add_option("-T", "--tx-subdev-spec", type="subdev", 
default=None,
+                          help="select USRP Tx side A or B")
+        normal.add_option("--tx-gain", type="eng_float", default=None, 
metavar="GAIN",
+                          help="set receiver gain in dB [default=midpoint].  
See also --show-tx-gain-range")
+        normal.add_option("--show-tx-gain-range", action="store_true", 
default=False, 
+                          help="print min and max Tx gain available on 
selected daughterboard")
+        expert.add_option("-i", "--interp", type="intx", default=None,
+                          help="set fpga interpolation rate to INTERP 
[default=%default]")
+        add_options(normal, expert)
+
+    def __init__(self, options):
+        gr.hier_block2.__init__(self, "generic_usrp_sink",
+            gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
+            gr.io_signature(0, 0, 0)) # Output signature
+
+        #usrp options
+        self._which = options.which
+        self._tx_subdev_spec = options.tx_subdev_spec
+        self._fusb_block_size = options.fusb_block_size
+        self._fusb_nblocks = options.fusb_nblocks
+        #usrp2 options
+        self._interface = options.interface
+        self._mac_addr = options.mac_addr
+        #generic options
+        self._tx_gain = options.tx_gain
+        self._show_tx_gain_range = options.show_tx_gain_range
+
+        #pick usrp or usrp2
+        if options.usrp or self._tx_subdev_spec:
+            self._setup_usrp_source()
+        elif options.usrp2 or self._mac_addr:
+            self._setup_usrp2_source()
+        else: #automatic
+            try: self._setup_usrp2_source()
+            except: self._setup_usrp_source()
+        self.connect(self, self._u)
+        if options.show_tx_gain_range:
+            print "Tx Gain Range: minimum = %g, maximum = %g, step size = 
%g"%tuple(self.gain_range())
+
+    ####################################################################
+    # generic access methods
+    ####################################################################
+    def set_interp(self, interp):
+        if self._type == USRP_TYPE: return self._u.set_interp_rate(interp)
+        elif self._type == USRP2_TYPE: return self._u.set_interp(interp)
+    
+    def dac_rate(self): return self._u.dac_rate()
+    
+    def set_center_freq(self, target_freq):
+        if self._type == USRP_TYPE:
+            return bool(self._u.tune(self._subdev.which(), self._subdev, 
target_freq))
+        elif self._type == USRP2_TYPE:
+            return self._u.set_center_freq(target_freq)
+
+    ####################################################################
+    # setup usrp methods
+    ####################################################################
+    def _setup_usrp_source(self):
+        self._u = usrp.sink_c (self._which,
+                                fusb_block_size=self._fusb_block_size,
+                                fusb_nblocks=self._fusb_nblocks)
+        # determine the daughterboard subdevice we're using
+        if self._tx_subdev_spec is None:
+            self._tx_subdev_spec = usrp.pick_tx_subdevice(self._u)
+        self._subdev = usrp.selected_subdev(self._u, self._tx_subdev_spec)
+        self._u.set_mux(usrp.determine_tx_mux_value(self._u, 
self._tx_subdev_spec))
+        self._type = USRP_TYPE
+    
+    def _setup_usrp2_source(self):
+        self._u = usrp2.sink_32fc(self._interface, self._mac_addr)
+        self._type = USRP2_TYPE
+
+    def __del__(self):
+        # Avoid weak reference error
+        if self._type == USRP_TYPE: del self._subdev

Modified: gnuradio/branches/developers/jblum/digital/receive_path.py
===================================================================
--- gnuradio/branches/developers/jblum/digital/receive_path.py  2009-04-24 
01:55:56 UTC (rev 10900)
+++ gnuradio/branches/developers/jblum/digital/receive_path.py  2009-04-24 
02:04:07 UTC (rev 10901)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-# Copyright 2005,2006,2007 Free Software Foundation, Inc.
+# Copyright 2005,2006,2007,2009 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -28,6 +28,7 @@
 
 # from current dir
 from pick_bitrate import pick_rx_bitrate
+import generic_usrp
 
 # /////////////////////////////////////////////////////////////////////////////
 #                              receive path
@@ -61,16 +62,11 @@
             raise SystemExit
 
         # Set up USRP source; also adjusts decim, samples_per_symbol, and 
bitrate
-        self._setup_usrp_source()
+        self._setup_usrp_source(options)
 
-        g = self.subdev.gain_range()
-        if options.show_rx_gain_range:
-            print "Rx Gain Range: minimum = %g, maximum = %g, step size = %g" \
-                  % (g[0], g[1], g[2])
-
         self.set_gain(options.rx_gain)
 
-        self.set_auto_tr(True)                 # enable Auto Transmit/Receive 
switching
+        #TODO self.set_auto_tr(True)                 # enable Auto 
Transmit/Receive switching
 
         # Set RF frequency
         ok = self.set_freq(self._rx_freq)
@@ -124,10 +120,9 @@
             
         self.connect(self.u, self.chan_filt, self.packet_receiver)
 
-    def _setup_usrp_source(self):
-        self.u = usrp.source_c (self._which,
-                                fusb_block_size=self._fusb_block_size,
-                                fusb_nblocks=self._fusb_nblocks)
+    def _setup_usrp_source(self, options):
+
+        self.u = generic_usrp.generic_usrp_source_c(options)
         adc_rate = self.u.adc_rate()
 
         # derive values of bitrate, samples_per_symbol, and decim from desired 
info
@@ -135,15 +130,8 @@
             pick_rx_bitrate(self._bitrate, 
self._demod_class.bits_per_symbol(), \
                             self._samples_per_symbol, self._decim, adc_rate)
 
-        self.u.set_decim_rate(self._decim)
+        self.u.set_decim(self._decim)
 
-        # determine the daughterboard subdevice we're using
-        if self._rx_subdev_spec is None:
-            self._rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
-        self.subdev = usrp.selected_subdev(self.u, self._rx_subdev_spec)
-
-        self.u.set_mux(usrp.determine_rx_mux_value(self.u, 
self._rx_subdev_spec))
-
     def set_freq(self, target_freq):
         """
         Set the center frequency we're interested in.
@@ -156,24 +144,13 @@
         the result of that operation and our target_frequency to
         determine the value for the digital up converter.
         """
-        r = self.u.tune(0, self.subdev, target_freq)
-        if r:
-            return True
+        return self.u.set_center_freq(target_freq)
 
-        return False
-
     def set_gain(self, gain):
         """
         Sets the analog gain in the USRP
         """
-        if gain is None:
-            r = self.subdev.gain_range()
-            gain = (r[0] + r[1])/2               # set gain to midpoint
-        self.gain = gain
-        return self.subdev.set_gain(gain)
-
-    def set_auto_tr(self, enable):
-        return self.subdev.set_auto_tr(enable)
+        return self.u.set_gain(gain)
         
     def bitrate(self):
         return self._bitrate
@@ -206,7 +183,7 @@
         """
         self.probe.set_threshold(threshold_in_db)
     
-        
+    @staticmethod
     def add_options(normal, expert):
         """
         Adds receiver-specific options to the Options Parser
@@ -215,48 +192,30 @@
         if not normal.has_option("--bitrate"):
             normal.add_option("-r", "--bitrate", type="eng_float", 
default=None,
                               help="specify bitrate.  samples-per-symbol and 
interp/decim will be derived.")
-        normal.add_option("-w", "--which", type="int", default=0,
-                          help="select USRP board [default=%default]")
-        normal.add_option("-R", "--rx-subdev-spec", type="subdev", 
default=None,
-                          help="select USRP Rx side A or B")
-        normal.add_option("", "--rx-gain", type="eng_float", default=None, 
metavar="GAIN",
-                          help="set receiver gain in dB [default=midpoint].  
See also --show-rx-gain-range")
-        normal.add_option("", "--show-rx-gain-range", action="store_true", 
default=False, 
-                          help="print min and max Rx gain available on 
selected daughterboard")
+        generic_usrp.generic_usrp_source_c.add_options(normal, expert)
         normal.add_option("-v", "--verbose", action="store_true", 
default=False)
         expert.add_option("-S", "--samples-per-symbol", type="int", 
default=None,
                           help="set samples/symbol [default=%default]")
         expert.add_option("", "--rx-freq", type="eng_float", default=None,
                           help="set Rx frequency to FREQ [default=%default]", 
metavar="FREQ")
-        expert.add_option("-d", "--decim", type="intx", default=None,
-                          help="set fpga decimation rate to DECIM 
[default=%default]")
         expert.add_option("", "--log", action="store_true", default=False,
                           help="Log all parts of flow graph to files (CAUTION: 
lots of data)")
         expert.add_option("", "--log-rx-power", action="store_true", 
default=False,
                           help="Log receive signal power to file (CAUTION: 
lots of data)")
 
-    # Make a static method to call before instantiation
-    add_options = staticmethod(add_options)
-
-
     def _print_verbage(self):
         """
         Prints information about the receive path
         """
         print "\nReceive Path:"
-        print "Using RX d'board %s"    % (self.subdev.side_and_name(),)
-        print "Rx gain:         %g"    % (self.gain,)
+        print "USRP %s"    % (self.u,)
+        print "Rx gain:         %g"    % (self.u.gain(),)
         print "modulation:      %s"    % (self._demod_class.__name__)
         print "bitrate:         %sb/s" % 
(eng_notation.num_to_str(self._bitrate))
         print "samples/symbol:  %3d"   % (self._samples_per_symbol)
         print "decim:           %3d"   % (self._decim)
         print "Rx Frequency:    %s"    % 
(eng_notation.num_to_str(self._rx_freq))
-        # print "Rx Frequency:    %f"    % (self._rx_freq)
 
-    def __del__(self):
-        # Avoid weak reference error
-        del self.subdev
-            
 def add_freq_option(parser):
     """
     Hackery that has the -f / --freq option set both tx_freq and rx_freq





reply via email to

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