commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: jblum
Subject: [Commit-gnuradio] r10965 - gnuradio/branches/developers/jblum/digital
Date: Tue, 5 May 2009 16:15:05 -0600 (MDT)

Author: jblum
Date: 2009-05-05 16:15:05 -0600 (Tue, 05 May 2009)
New Revision: 10965

Modified:
   gnuradio/branches/developers/jblum/digital/generic_usrp.py
   gnuradio/branches/developers/jblum/digital/transmit_path.py
   gnuradio/branches/developers/jblum/digital/usrp_options.py
Log:
Changes to usrp options and generic usrp. Modified tx path for unity amplitude.

Modified: gnuradio/branches/developers/jblum/digital/generic_usrp.py
===================================================================
--- gnuradio/branches/developers/jblum/digital/generic_usrp.py  2009-05-05 
21:47:46 UTC (rev 10964)
+++ gnuradio/branches/developers/jblum/digital/generic_usrp.py  2009-05-05 
22:15:05 UTC (rev 10965)
@@ -19,7 +19,7 @@
 # Boston, MA 02110-1301, USA.
 #
 
-USRP_TYPE = 'usrp'
+USRP1_TYPE = 'usrp1'
 USRP2_TYPE = 'usrp2'
 
 from gnuradio import gr, usrp, usrp2
@@ -43,8 +43,10 @@
         self._fusb_nblocks = fusb_nblocks
 
     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()
+        if self._type == USRP1_TYPE: return self._subdev.side_and_name()
+        elif self._type == USRP2_TYPE:
+            return 'Interface: %s    MAC Address: %s    D-Board ID: 0x%.2x\n'%(
+                self._u.interface_name(), self._u.mac_addr(), 
self._u.daughterboard_id())
 
     def gain(self): return self._gain
 
@@ -53,25 +55,29 @@
             r = self.gain_range()
             gain = (r[0] + r[1])/2               # set gain to midpoint
         self._gain = gain
-        if self._type == USRP_TYPE: return self._subdev.set_gain(gain)
+        if self._type == USRP1_TYPE: return self._subdev.set_gain(gain)
         elif self._type == USRP2_TYPE: return self._u.set_gain(gain)
 
     def gain_range(self):
-        if self._type == USRP_TYPE: return self._subdev.gain_range()
+        if self._type == USRP1_TYPE: return self._subdev.gain_range()
         elif self._type == USRP2_TYPE: return self._u.gain_range()
 
     def set_center_freq(self, target_freq):
-        if self._type == USRP_TYPE:
-            return bool(self._u.tune(self._dxc, self._subdev, target_freq))
+        if self._type == USRP1_TYPE:
+            return self._u.tune(self._dxc, self._subdev, target_freq)
         elif self._type == USRP2_TYPE:
             return self._u.set_center_freq(target_freq)
 
+    def freq_range(self):
+        if self._type == USRP1_TYPE: return self._subdev.freq_range()
+        elif self._type == USRP2_TYPE: return self._u.freq_range()
+
     def set_auto_tr(self, enable):
-        if self._type == USRP_TYPE: return self._subdev.set_auto_tr(enable)
+        if self._type == USRP1_TYPE: return self._subdev.set_auto_tr(enable)
 
     def __del__(self):
         # Avoid weak reference error
-        if self._type == USRP_TYPE: del self._subdev
+        if self._type == USRP1_TYPE: del self._subdev
 
 ########################################################################
 # generic usrp source
@@ -90,12 +96,12 @@
             gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
         #pick usrp or usrp2
         if self._usrpx == '1' or self._subdev_spec:
-            self._setup_usrp_source()
+            self._setup_usrp1()
         elif self._usrpx == '2' or self._mac_addr:
-            self._setup_usrp2_source()
+            self._setup_usrp2()
         else: #automatic
-            try: self._setup_usrp2_source()
-            except: self._setup_usrp_source()
+            try: self._setup_usrp2()
+            except: self._setup_usrp1()
         self.connect(self._u, self)
         self.set_auto_tr(True)
 
@@ -103,7 +109,7 @@
     # generic access methods
     ####################################################################
     def set_decim(self, decim):
-        if self._type == USRP_TYPE: return self._u.set_decim_rate(decim)
+        if self._type == USRP1_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()
@@ -111,7 +117,8 @@
     ####################################################################
     # setup usrp methods
     ####################################################################
-    def _setup_usrp_source(self):
+    def _setup_usrp1(self):
+        self._type = USRP1_TYPE
         self._u = usrp.source_c (self._which,
                                 fusb_block_size=self._fusb_block_size,
                                 fusb_nblocks=self._fusb_nblocks)
@@ -120,12 +127,11 @@
             self._subdev_spec = usrp.pick_rx_subdevice(self._u)
         self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)
         self._u.set_mux(usrp.determine_rx_mux_value(self._u, 
self._subdev_spec))
-        self._type = USRP_TYPE
         self._dxc = 0
 
-    def _setup_usrp2_source(self):
+    def _setup_usrp2(self):
+        self._type = USRP2_TYPE
         self._u = usrp2.source_32fc(self._interface, self._mac_addr)
-        self._type = USRP2_TYPE
 
 ########################################################################
 # generic usrp sink
@@ -145,32 +151,31 @@
 
         #pick usrp or usrp2
         if self._usrpx == '1' or self._subdev_spec:
-            self._setup_usrp_source()
+            self._setup_usrp1()
         elif self._usrpx == '2' or self._mac_addr:
-            self._setup_usrp2_source()
+            self._setup_usrp2()
         else: #automatic
-            try: self._setup_usrp2_source()
-            except: self._setup_usrp_source()
-        self.connect(self, self._u)
+            try: self._setup_usrp2()
+            except: self._setup_usrp1()
+        if self._type == USRP1_TYPE: #scale 0.0 to 1.0 input for usrp1
+            self.connect(self, gr.multiply_const_cc((2**15)-1), self._u)
+        elif self._type == USRP2_TYPE: self.connect(self, self._u)
         self.set_auto_tr(True)
 
     ####################################################################
     # generic access methods
     ####################################################################
     def set_interp(self, interp):
-        if self._type == USRP_TYPE: return self._u.set_interp_rate(interp)
+        if self._type == USRP1_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 ampl_range(self):
-        if self._type == USRP_TYPE: return (0.0, 2.**15-1)
-        elif self._type == USRP2_TYPE: return (0.0, 1.0)
-
     ####################################################################
     # setup usrp methods
     ####################################################################
-    def _setup_usrp_source(self):
+    def _setup_usrp1(self):
+        self._type = USRP1_TYPE
         self._u = usrp.sink_c (self._which,
                                 fusb_block_size=self._fusb_block_size,
                                 fusb_nblocks=self._fusb_nblocks)
@@ -179,9 +184,8 @@
             self._subdev_spec = usrp.pick_tx_subdevice(self._u)
         self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)
         self._u.set_mux(usrp.determine_tx_mux_value(self._u, 
self._subdev_spec))
-        self._type = USRP_TYPE
         self._dxc = self._subdev.which()
 
-    def _setup_usrp2_source(self):
+    def _setup_usrp2(self):
+        self._type = USRP2_TYPE
         self._u = usrp2.sink_32fc(self._interface, self._mac_addr)
-        self._type = USRP2_TYPE

Modified: gnuradio/branches/developers/jblum/digital/transmit_path.py
===================================================================
--- gnuradio/branches/developers/jblum/digital/transmit_path.py 2009-05-05 
21:47:46 UTC (rev 10964)
+++ gnuradio/branches/developers/jblum/digital/transmit_path.py 2009-05-05 
22:15:05 UTC (rev 10965)
@@ -62,9 +62,6 @@
         # Set up USRP sink; also adjusts interp, samples_per_symbol, and 
bitrate
         self._setup_usrp_sink(options)
 
-        if options.show_tx_ampl_range:
-            print "Tx Amplitude Range: minimum = %g, maximum = 
%g"%tuple(self.u.ampl_range())
-
         # copy the final answers back into options for use by modulator
         options.samples_per_symbol = self._samples_per_symbol
         options.bitrate = self._bitrate
@@ -141,11 +138,9 @@
     def set_tx_amplitude(self, ampl):
         """
         Sets the transmit amplitude sent to the USRP
-        @param ampl the amplitude or None for automatic
+        @param ampl the amplitude between 0.0 and 1.0
         """
-        ampl_range = self.u.ampl_range()
-        if ampl is None: ampl = (ampl_range[1] - ampl_range[0])*0.15 + 
ampl_range[0]
-        self._tx_amplitude = max(ampl_range[0], min(ampl, ampl_range[1]))
+        self._tx_amplitude = max(0.0, min(ampl, 1.0))
         self.amp.set_k(self._tx_amplitude)
 
     def send_pkt(self, payload='', eof=False):
@@ -172,10 +167,8 @@
             normal.add_option("-r", "--bitrate", type="eng_float", 
default=None,
                               help="specify bitrate.  samples-per-symbol and 
interp/decim will be derived.")
         usrp_options.add_tx_options(normal, expert)
-        normal.add_option("--tx-amplitude", type="eng_float", default=None, 
metavar="AMPL",
-                          help="set transmitter digital amplitude 
[default=midpoint].  See also --show-tx-ampl-range")
-        normal.add_option("--show-tx-ampl-range", action="store_true", 
default=False, 
-                          help="print min and max Tx amplitude available")
+        normal.add_option("--tx-amplitude", type="eng_float", default=0.15, 
metavar="AMPL",
+                          help="set transmitter digital amplitude (0.0-1.0) 
[default=%default].")
         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]")

Modified: gnuradio/branches/developers/jblum/digital/usrp_options.py
===================================================================
--- gnuradio/branches/developers/jblum/digital/usrp_options.py  2009-05-05 
21:47:46 UTC (rev 10964)
+++ gnuradio/branches/developers/jblum/digital/usrp_options.py  2009-05-05 
22:15:05 UTC (rev 10965)
@@ -31,9 +31,9 @@
     parser.add_option("-u", "--usrpx", type="string", default=None,
                       help="specify which usrp model: 1 for USRP, 2 for USRP2 
[default=auto]")
     #fast usb options
-    expert.add_option("-B", "--fusb-block-size", type="int", default=0,
+    if expert: 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,
+    if expert: expert.add_option("-N", "--fusb-nblocks", type="int", default=0,
                       help="specify number of fast usb blocks 
[default=%default]")
     #usrp options
     parser.add_option("-w", "--which", type="int", default=0,
@@ -44,6 +44,14 @@
     parser.add_option("-m", "--mac-addr", type="string", default="",
                       help="Use USRP2 at specified MAC address [default=None]")
 
+def _ensure_values(options):
+    """
+    Ensure that expert options exist even if they did not get added to the 
parser.
+    @param options the parsed options
+    """
+    options.ensure_value('fusb_block_size', 0)
+    options.ensure_value('fusb_nblocks', 0)
+
 def add_rx_options(parser, expert=None):
     """
     Add receive specific usrp options.
@@ -60,6 +68,7 @@
     _add_options(parser, expert)
 
 def create_usrp_source(options):
+    _ensure_values(options)
     u = generic_usrp.generic_usrp_source_c(
         usrpx=options.usrpx,
         which=options.which,
@@ -89,6 +98,7 @@
     _add_options(parser, expert)
 
 def create_usrp_sink(options):
+    _ensure_values(options)
     u = generic_usrp.generic_usrp_sink_c(
         usrpx=options.usrpx,
         which=options.which,





reply via email to

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