[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10942 - gnuradio/trunk/gnuradio-examples/python/digit
From: |
jblum |
Subject: |
[Commit-gnuradio] r10942 - gnuradio/trunk/gnuradio-examples/python/digital |
Date: |
Fri, 1 May 2009 14:33:09 -0600 (MDT) |
Author: jblum
Date: 2009-05-01 14:33:09 -0600 (Fri, 01 May 2009)
New Revision: 10942
Added:
gnuradio/trunk/gnuradio-examples/python/digital/generic_usrp.py
gnuradio/trunk/gnuradio-examples/python/digital/usrp_options.py
Removed:
gnuradio/trunk/gnuradio-examples/python/digital/fusb_options.py
Modified:
gnuradio/trunk/gnuradio-examples/python/digital/
gnuradio/trunk/gnuradio-examples/python/digital/Makefile.am
gnuradio/trunk/gnuradio-examples/python/digital/benchmark_loopback.py
gnuradio/trunk/gnuradio-examples/python/digital/benchmark_rx.py
gnuradio/trunk/gnuradio-examples/python/digital/benchmark_tx.py
gnuradio/trunk/gnuradio-examples/python/digital/pick_bitrate.py
gnuradio/trunk/gnuradio-examples/python/digital/receive_path.py
gnuradio/trunk/gnuradio-examples/python/digital/rx_voice.py
gnuradio/trunk/gnuradio-examples/python/digital/transmit_path.py
gnuradio/trunk/gnuradio-examples/python/digital/tunnel.py
gnuradio/trunk/gnuradio-examples/python/digital/tx_voice.py
Log:
Merged developer branch for digital r10900:10941
Creates generic usrp class abstraction for usrp and usrp2.
Common command line options for usrp devices.
Property changes on: gnuradio/trunk/gnuradio-examples/python/digital
___________________________________________________________________
Added: svn:mergeinfo
+
/gnuradio/branches/developers/eb/t348/gnuradio-examples/python/digital:10638-10648
/gnuradio/branches/developers/eb/t378/gnuradio-examples/python/digital:10683-10688
/gnuradio/branches/developers/jblum/digital:10901-10941
/gnuradio/branches/developers/jblum/grc/gnuradio-examples/python/digital:10680-10938
/gnuradio/branches/developers/jblum/gui_guts/gnuradio-examples/python/digital:10464-10658
/gnuradio/branches/developers/jblum/vlen/gnuradio-examples/python/digital:10667-10677
/gnuradio/branches/developers/jcorgan/cpphier/gnuradio-examples/python/digital:10818-10858
/gnuradio/branches/developers/jcorgan/fw-optimize/gnuradio-examples/python/digital:10428-10429
/gnuradio/branches/developers/jcorgan/gpio2/gnuradio-examples/python/digital:10713-10765
/gnuradio/branches/developers/jcorgan/iad2/gnuradio-examples/python/digital:10771-10887
/gnuradio/branches/developers/jcorgan/t161/gnuradio-examples/python/digital:10876-10880
/gnuradio/branches/developers/michaelld/am_swig_4/gnuradio-examples/python/digital:10555-10595
/gnuradio/branches/developers/michaelld/two_mods/gnuradio-examples/python/digital:10540-10546
Modified: gnuradio/trunk/gnuradio-examples/python/digital/Makefile.am
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/Makefile.am 2009-05-01
20:28:04 UTC (rev 10941)
+++ gnuradio/trunk/gnuradio-examples/python/digital/Makefile.am 2009-05-01
20:33:09 UTC (rev 10942)
@@ -30,7 +30,6 @@
benchmark_loopback.py \
benchmark_rx.py \
benchmark_tx.py \
- fusb_options.py \
gen_whitener.py \
pick_bitrate.py \
receive_path.py \
Modified: gnuradio/trunk/gnuradio-examples/python/digital/benchmark_loopback.py
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/benchmark_loopback.py
2009-05-01 20:28:04 UTC (rev 10941)
+++ gnuradio/trunk/gnuradio-examples/python/digital/benchmark_loopback.py
2009-05-01 20:33:09 UTC (rev 10942)
@@ -30,7 +30,6 @@
# from current dir
from transmit_path_lb import transmit_path
from receive_path_lb import receive_path
-import fusb_options
class my_top_block(gr.top_block):
def __init__(self, mod_class, demod_class, rx_callback, options):
Modified: gnuradio/trunk/gnuradio-examples/python/digital/benchmark_rx.py
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/benchmark_rx.py
2009-05-01 20:28:04 UTC (rev 10941)
+++ gnuradio/trunk/gnuradio-examples/python/digital/benchmark_rx.py
2009-05-01 20:33:09 UTC (rev 10942)
@@ -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
#
@@ -32,7 +32,6 @@
# from current dir
from receive_path import receive_path
-import fusb_options
#import os
#print os.getpid()
@@ -83,7 +82,6 @@
for mod in demods.values():
mod.add_options(expert_grp)
- fusb_options.add_options(expert_grp)
(options, args) = parser.parse_args ()
if len(args) != 0:
Modified: gnuradio/trunk/gnuradio-examples/python/digital/benchmark_tx.py
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/benchmark_tx.py
2009-05-01 20:28:04 UTC (rev 10941)
+++ gnuradio/trunk/gnuradio-examples/python/digital/benchmark_tx.py
2009-05-01 20:33:09 UTC (rev 10942)
@@ -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
#
@@ -30,7 +30,6 @@
# from current dir
from transmit_path import transmit_path
-import fusb_options
#import os
#print os.getpid()
@@ -78,7 +77,6 @@
for mod in mods.values():
mod.add_options(expert_grp)
- fusb_options.add_options(expert_grp)
(options, args) = parser.parse_args ()
if len(args) != 0:
Copied: gnuradio/trunk/gnuradio-examples/python/digital/generic_usrp.py (from
rev 10941, gnuradio/branches/developers/jblum/digital/generic_usrp.py)
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/generic_usrp.py
(rev 0)
+++ gnuradio/trunk/gnuradio-examples/python/digital/generic_usrp.py
2009-05-01 20:33:09 UTC (rev 10942)
@@ -0,0 +1,187 @@
+#
+# 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
+
+########################################################################
+# generic usrp common stuff
+########################################################################
+class _generic_usrp_base(object):
+
+ def __init__(self, which=0, subdev_spec=None, interface="", mac_addr="",
fusb_block_size=0, fusb_nblocks=0, usrpx=None):
+ self._gain = 0
+ self._usrpx = usrpx
+ #usrp options
+ self._which = which
+ self._subdev_spec = subdev_spec
+ #usrp2 options
+ self._interface = interface
+ self._mac_addr = mac_addr
+ #fusb options
+ self._fusb_block_size = fusb_block_size
+ 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()
+
+ 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
+ if self._type == USRP_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()
+ 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))
+ elif self._type == USRP2_TYPE:
+ return self._u.set_center_freq(target_freq)
+
+ def set_auto_tr(self, enable):
+ if self._type == USRP_TYPE: return self._subdev.set_auto_tr(enable)
+
+ def __del__(self):
+ # Avoid weak reference error
+ if self._type == USRP_TYPE: del self._subdev
+
+########################################################################
+# 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.
+ """
+
+ def __init__(self, **kwargs):
+ _generic_usrp_base.__init__(self, **kwargs)
+ 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
+ #pick usrp or usrp2
+ if self._usrpx == '1' or self._subdev_spec:
+ self._setup_usrp_source()
+ elif self._usrpx == '2' 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)
+ self.set_auto_tr(True)
+
+ ####################################################################
+ # 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()
+
+ ####################################################################
+ # 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._subdev_spec is None:
+ 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):
+ self._u = usrp2.source_32fc(self._interface, self._mac_addr)
+ self._type = USRP2_TYPE
+
+########################################################################
+# 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.
+ """
+
+ def __init__(self, **kwargs):
+ _generic_usrp_base.__init__(self, **kwargs)
+ 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
+
+ #pick usrp or usrp2
+ if self._usrpx == '1' or self._subdev_spec:
+ self._setup_usrp_source()
+ elif self._usrpx == '2' 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)
+ 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)
+ 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):
+ 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._subdev_spec is None:
+ 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):
+ self._u = usrp2.sink_32fc(self._interface, self._mac_addr)
+ self._type = USRP2_TYPE
Modified: gnuradio/trunk/gnuradio-examples/python/digital/pick_bitrate.py
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/pick_bitrate.py
2009-05-01 20:28:04 UTC (rev 10941)
+++ gnuradio/trunk/gnuradio-examples/python/digital/pick_bitrate.py
2009-05-01 20:33:09 UTC (rev 10942)
@@ -19,6 +19,8 @@
# Boston, MA 02110-1301, USA.
#
+from gnuradio import eng_notation
+
_default_bitrate = 500e3
_valid_samples_per_symbol = (2,3,4,5,6,7)
@@ -94,13 +96,15 @@
# now we have a target bitrate and possibly an xrate or
# samples_per_symbol constraint, but not both of them.
- return _pick_best(bitrate, bits_per_symbol,
+ ret = _pick_best(bitrate, bits_per_symbol,
_filter_info(gen_info(converter_rate),
samples_per_symbol, xrate))
+ print "Actual Bitrate:", eng_notation.num_to_str(ret[0])
+ return ret
#
---------------------------------------------------------------------------------------
def pick_tx_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
- interp_rate, converter_rate=128e6):
+ interp_rate, converter_rate):
"""
Given the 4 input parameters, return at configuration that matches
@@ -117,12 +121,13 @@
@returns tuple (bitrate, samples_per_symbol, interp_rate)
"""
+ print "Requested TX Bitrate:", bitrate and
eng_notation.num_to_str(bitrate) or 'Auto'
return _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
interp_rate, converter_rate, _gen_tx_info)
def pick_rx_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
- decim_rate, converter_rate=64e6):
+ decim_rate, converter_rate):
"""
Given the 4 input parameters, return at configuration that matches
@@ -139,5 +144,6 @@
@returns tuple (bitrate, samples_per_symbol, decim_rate)
"""
+ print "Requested RX Bitrate:", bitrate and
eng_notation.num_to_str(bitrate) or 'Auto'
return _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
decim_rate, converter_rate, _gen_rx_info)
Modified: gnuradio/trunk/gnuradio-examples/python/digital/receive_path.py
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/receive_path.py
2009-05-01 20:28:04 UTC (rev 10941)
+++ gnuradio/trunk/gnuradio-examples/python/digital/receive_path.py
2009-05-01 20:33:09 UTC (rev 10942)
@@ -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 usrp_options
# /////////////////////////////////////////////////////////////////////////////
# receive path
@@ -42,16 +43,12 @@
options = copy.copy(options) # make a copy so we can destructively
modify
- self._which = options.which # the USRP board
attached
self._verbose = options.verbose
self._rx_freq = options.rx_freq # receiver's center
frequency
self._rx_gain = options.rx_gain # receiver's gain
- self._rx_subdev_spec = options.rx_subdev_spec # daughterboard to
use
self._bitrate = options.bitrate # desired bit rate
self._decim = options.decim # Decimating rate
for the USRP (prelim)
self._samples_per_symbol = options.samples_per_symbol # desired
samples/symbol
- self._fusb_block_size = options.fusb_block_size # usb info for USRP
- self._fusb_nblocks = options.fusb_nblocks # usb info for USRP
self._rx_callback = rx_callback # this callback is fired when
there's a packet available
self._demod_class = demod_class # the demodulator_class we're
using
@@ -61,17 +58,13 @@
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])
+ print "Rx Gain Range: minimum = %g, maximum = %g, step size =
%g"%tuple(self.u.gain_range())
self.set_gain(options.rx_gain)
- self.set_auto_tr(True) # enable Auto Transmit/Receive
switching
-
# Set RF frequency
ok = self.set_freq(self._rx_freq)
if not ok:
@@ -124,10 +117,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 = usrp_options.create_usrp_source(options)
adc_rate = self.u.adc_rate()
# derive values of bitrate, samples_per_symbol, and decim from desired
info
@@ -135,15 +127,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 +141,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 +180,7 @@
"""
self.probe.set_threshold(threshold_in_db)
-
+ @staticmethod
def add_options(normal, expert):
"""
Adds receiver-specific options to the Options Parser
@@ -215,48 +189,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")
+ usrp_options.add_rx_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
Modified: gnuradio/trunk/gnuradio-examples/python/digital/rx_voice.py
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/rx_voice.py 2009-05-01
20:28:04 UTC (rev 10941)
+++ gnuradio/trunk/gnuradio-examples/python/digital/rx_voice.py 2009-05-01
20:33:09 UTC (rev 10942)
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2005,2006 Free Software Foundation, Inc.
+# Copyright 2005,2006,2009 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -35,7 +35,6 @@
# from current dir
from receive_path import receive_path
-import fusb_options
#import os
#print os.getpid()
@@ -108,8 +107,6 @@
for mod in demods.values():
mod.add_options(expert_grp)
- fusb_options.add_options(expert_grp)
-
parser.set_defaults(bitrate=50e3) # override default bitrate default
(options, args) = parser.parse_args ()
Modified: gnuradio/trunk/gnuradio-examples/python/digital/transmit_path.py
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/transmit_path.py
2009-05-01 20:28:04 UTC (rev 10941)
+++ gnuradio/trunk/gnuradio-examples/python/digital/transmit_path.py
2009-05-01 20:33:09 UTC (rev 10942)
@@ -1,5 +1,5 @@
#
-# 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_tx_bitrate
+import usrp_options
# /////////////////////////////////////////////////////////////////////////////
# transmit path
@@ -44,16 +45,12 @@
options = copy.copy(options) # make a copy so we can destructively
modify
- self._which = options.which # the USRP board
attached
self._verbose = options.verbose
self._tx_freq = options.tx_freq # tranmitter's
center frequency
self._tx_amplitude = options.tx_amplitude # digital amplitude
sent to USRP
- self._tx_subdev_spec = options.tx_subdev_spec # daughterboard to
use
self._bitrate = options.bitrate # desired bit rate
self._interp = options.interp # interpolating
rate for the USRP (prelim)
self._samples_per_symbol = options.samples_per_symbol # desired
samples/baud
- self._fusb_block_size = options.fusb_block_size # usb info for USRP
- self._fusb_nblocks = options.fusb_nblocks # usb info for USRP
self._use_whitener_offset = options.use_whitener_offset # increment
start of whitener XOR data
self._modulator_class = modulator_class # the modulator_class
we are using
@@ -63,8 +60,11 @@
raise SystemExit
# Set up USRP sink; also adjusts interp, samples_per_symbol, and
bitrate
- self._setup_usrp_sink()
+ 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
@@ -90,14 +90,11 @@
# Set the USRP for maximum transmit gain
# (Note that on the RFX cards this is a nop.)
- self.set_gain(self.subdev.gain_range()[1])
+ self.set_gain(self.u.gain_range()[1])
self.amp = gr.multiply_const_cc(1)
self.set_tx_amplitude(self._tx_amplitude)
- # enable Auto Transmit/Receive switching
- self.set_auto_tr(True)
-
# Display some information about the setup
if self._verbose:
self._print_verbage()
@@ -105,14 +102,12 @@
# Create and setup transmit path flow graph
self.connect(self.packet_transmitter, self.amp, self.u)
- def _setup_usrp_sink(self):
+ def _setup_usrp_sink(self, options):
"""
Creates a USRP sink, determines the settings for best bitrate,
and attaches to the transmitter's subdevice.
"""
- self.u = usrp.sink_c(self._which,
- fusb_block_size=self._fusb_block_size,
- fusb_nblocks=self._fusb_nblocks)
+ self.u = usrp_options.create_usrp_sink(options)
dac_rate = self.u.dac_rate();
# derive values of bitrate, samples_per_symbol, and interp from
desired info
@@ -120,15 +115,9 @@
pick_tx_bitrate(self._bitrate,
self._modulator_class.bits_per_symbol(),
self._samples_per_symbol, self._interp, dac_rate)
- self.u.set_interp_rate(self._interp)
+ self.u.set_interp(self._interp)
- # 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.u.set_mux(usrp.determine_tx_mux_value(self.u,
self._tx_subdev_spec))
- self.subdev = usrp.selected_subdev(self.u, self._tx_subdev_spec)
-
def set_freq(self, target_freq):
"""
Set the center frequency we're interested in.
@@ -141,33 +130,24 @@
the result of that operation and our target_frequency to
determine the value for the digital up converter.
"""
- r = self.u.tune(self.subdev.which(), self.subdev, target_freq)
- if r:
- return True
-
- return False
+ return self.u.set_center_freq(target_freq)
def set_gain(self, gain):
"""
Sets the analog gain in the USRP
"""
- self.gain = gain
- self.subdev.set_gain(gain)
+ return self.u.set_gain(gain)
def set_tx_amplitude(self, ampl):
"""
Sets the transmit amplitude sent to the USRP
- @param: ampl 0 <= ampl < 32768. Try 8000
+ @param ampl the amplitude or None for automatic
"""
- self._tx_amplitude = max(0.0, min(ampl, 32767.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.amp.set_k(self._tx_amplitude)
-
- def set_auto_tr(self, enable):
- """
- Turns on auto transmit/receive of USRP daughterboard (if exits; else
ignored)
- """
- return self.subdev.set_auto_tr(enable)
-
+
def send_pkt(self, payload='', eof=False):
"""
Calls the transmitter method to send a packet
@@ -191,20 +171,16 @@
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("-T", "--tx-subdev-spec", type="subdev",
default=None,
- help="select USRP Tx side A or B")
- normal.add_option("", "--tx-amplitude", type="eng_float",
default=12000, metavar="AMPL",
- help="set transmitter digital amplitude: 0 <= AMPL <
32768 [default=%default]")
+ 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("-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("", "--tx-freq", type="eng_float", default=None,
help="set transmit frequency to FREQ
[default=%default]", metavar="FREQ")
- expert.add_option("-i", "--interp", type="intx", default=None,
- help="set fpga interpolation rate to INTERP
[default=%default]")
expert.add_option("", "--log", action="store_true", default=False,
help="Log all parts of flow graph to file (CAUTION:
lots of data)")
expert.add_option("","--use-whitener-offset", action="store_true",
default=False,
@@ -217,7 +193,7 @@
"""
Prints information about the transmit path
"""
- print "Using TX d'board %s" % (self.subdev.side_and_name(),)
+ print "Using TX d'board %s" % (self.u,)
print "Tx amplitude %s" % (self._tx_amplitude)
print "modulation: %s" % (self._modulator_class.__name__)
print "bitrate: %sb/s" %
(eng_notation.num_to_str(self._bitrate))
Modified: gnuradio/trunk/gnuradio-examples/python/digital/tunnel.py
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/tunnel.py 2009-05-01
20:28:04 UTC (rev 10941)
+++ gnuradio/trunk/gnuradio-examples/python/digital/tunnel.py 2009-05-01
20:33:09 UTC (rev 10942)
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2005,2006 Free Software Foundation, Inc.
+# Copyright 2005,2006,2009 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -48,7 +48,6 @@
# from current dir
from transmit_path import transmit_path
from receive_path import receive_path
-import fusb_options
#print os.getpid()
#raw_input('Attach and press enter')
@@ -202,8 +201,6 @@
for demod in demods.values():
demod.add_options(expert_grp)
- fusb_options.add_options(expert_grp)
-
(options, args) = parser.parse_args ()
if len(args) != 0:
parser.print_help(sys.stderr)
Modified: gnuradio/trunk/gnuradio-examples/python/digital/tx_voice.py
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/tx_voice.py 2009-05-01
20:28:04 UTC (rev 10941)
+++ gnuradio/trunk/gnuradio-examples/python/digital/tx_voice.py 2009-05-01
20:33:09 UTC (rev 10942)
@@ -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
#
@@ -36,7 +36,6 @@
# from current dir
from transmit_path import transmit_path
-import fusb_options
#import os
#print os.getpid()
@@ -102,8 +101,6 @@
for mod in mods.values():
mod.add_options(expert_grp)
- fusb_options.add_options(expert_grp)
-
parser.set_defaults(bitrate=50e3) # override default bitrate default
(options, args) = parser.parse_args ()
@@ -142,11 +139,10 @@
send_pkt(eof=True)
tb.wait() # wait for it to finish
- tb.txpath.set_auto_tr(False)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
- pass
\ No newline at end of file
+ pass
Copied: gnuradio/trunk/gnuradio-examples/python/digital/usrp_options.py (from
rev 10941, gnuradio/branches/developers/jblum/digital/usrp_options.py)
===================================================================
--- gnuradio/trunk/gnuradio-examples/python/digital/usrp_options.py
(rev 0)
+++ gnuradio/trunk/gnuradio-examples/python/digital/usrp_options.py
2009-05-01 20:33:09 UTC (rev 10942)
@@ -0,0 +1,103 @@
+#
+# 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.
+#
+
+import generic_usrp
+
+def _add_options(parser, 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
+ """
+ #pick usrp or usrp2
+ 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,
+ 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
+ parser.add_option("-w", "--which", type="int", default=0,
+ help="select USRP board [default=%default]")
+ #usrp2 options
+ parser.add_option("-e", "--interface", type="string", default="eth0",
+ help="Use USRP2 at specified Ethernet interface
[default=%default]")
+ parser.add_option("-m", "--mac-addr", type="string", default="",
+ help="Use USRP2 at specified MAC address [default=None]")
+
+def add_rx_options(parser, expert=None):
+ """
+ Add receive specific usrp options.
+ @param parser: instance of OptionParser
+ """
+ parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
+ help="select USRP Rx side A or B")
+ parser.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")
+ parser.add_option("--show-rx-gain-range", action="store_true",
default=False,
+ help="print min and max Rx gain available on selected
daughterboard")
+ parser.add_option("-d", "--decim", type="intx", default=None,
+ help="set fpga decimation rate to DECIM
[default=%default]")
+ _add_options(parser, expert)
+
+def create_usrp_source(options):
+ u = generic_usrp.generic_usrp_source_c(
+ usrpx=options.usrpx,
+ which=options.which,
+ subdev_spec=options.rx_subdev_spec,
+ interface=options.interface,
+ mac_addr=options.mac_addr,
+ fusb_block_size=options.fusb_block_size,
+ fusb_nblocks=options.fusb_nblocks,
+ )
+ if options.show_rx_gain_range:
+ print "Rx Gain Range: minimum = %g, maximum = %g, step size =
%g"%tuple(u.gain_range())
+ return u
+
+def add_tx_options(parser, expert=None):
+ """
+ Add transmit specific usrp options.
+ @param parser: instance of OptionParser
+ """
+ parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
+ help="select USRP Rx side A or B")
+ parser.add_option("--tx-gain", type="eng_float", default=None,
metavar="GAIN",
+ help="set transmitter gain in dB [default=midpoint].
See also --show-tx-gain-range")
+ parser.add_option("--show-tx-gain-range", action="store_true",
default=False,
+ help="print min and max Tx gain available on selected
daughterboard")
+ parser.add_option("-i", "--interp", type="intx", default=None,
+ help="set fpga interpolation rate to INTERP
[default=%default]")
+ _add_options(parser, expert)
+
+def create_usrp_sink(options):
+ u = generic_usrp.generic_usrp_sink_c(
+ usrpx=options.usrpx,
+ which=options.which,
+ subdev_spec=options.tx_subdev_spec,
+ interface=options.interface,
+ mac_addr=options.mac_addr,
+ fusb_block_size=options.fusb_block_size,
+ fusb_nblocks=options.fusb_nblocks,
+ )
+ if options.show_tx_gain_range:
+ print "Tx Gain Range: minimum = %g, maximum = %g, step size =
%g"%tuple(u.gain_range())
+ return u
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10942 - gnuradio/trunk/gnuradio-examples/python/digital,
jblum <=