diff options
Diffstat (limited to 'gnuradio-examples/python')
-rw-r--r-- | gnuradio-examples/python/digital/Makefile.am | 1 | ||||
-rwxr-xr-x | gnuradio-examples/python/digital/benchmark_loopback.py | 1 | ||||
-rwxr-xr-x | gnuradio-examples/python/digital/benchmark_rx.py | 4 | ||||
-rwxr-xr-x | gnuradio-examples/python/digital/benchmark_tx.py | 4 | ||||
-rw-r--r-- | gnuradio-examples/python/digital/fusb_options.py | 31 | ||||
-rw-r--r-- | gnuradio-examples/python/digital/generic_usrp.py | 187 | ||||
-rw-r--r-- | gnuradio-examples/python/digital/pick_bitrate.py | 12 | ||||
-rw-r--r-- | gnuradio-examples/python/digital/receive_path.py | 72 | ||||
-rwxr-xr-x | gnuradio-examples/python/digital/rx_voice.py | 5 | ||||
-rw-r--r-- | gnuradio-examples/python/digital/transmit_path.py | 70 | ||||
-rwxr-xr-x | gnuradio-examples/python/digital/tunnel.py | 5 | ||||
-rwxr-xr-x | gnuradio-examples/python/digital/tx_voice.py | 8 | ||||
-rw-r--r-- | gnuradio-examples/python/digital/usrp_options.py | 103 |
13 files changed, 342 insertions, 161 deletions
diff --git a/gnuradio-examples/python/digital/Makefile.am b/gnuradio-examples/python/digital/Makefile.am index f151c4329..20f27a5bc 100644 --- a/gnuradio-examples/python/digital/Makefile.am +++ b/gnuradio-examples/python/digital/Makefile.am @@ -30,7 +30,6 @@ dist_ourdata_SCRIPTS = \ benchmark_loopback.py \ benchmark_rx.py \ benchmark_tx.py \ - fusb_options.py \ gen_whitener.py \ pick_bitrate.py \ receive_path.py \ diff --git a/gnuradio-examples/python/digital/benchmark_loopback.py b/gnuradio-examples/python/digital/benchmark_loopback.py index 51deba44c..e62c12eac 100755 --- a/gnuradio-examples/python/digital/benchmark_loopback.py +++ b/gnuradio-examples/python/digital/benchmark_loopback.py @@ -30,7 +30,6 @@ import random, time, struct, sys, math # 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): diff --git a/gnuradio-examples/python/digital/benchmark_rx.py b/gnuradio-examples/python/digital/benchmark_rx.py index be1839577..b0b99ecff 100755 --- a/gnuradio-examples/python/digital/benchmark_rx.py +++ b/gnuradio-examples/python/digital/benchmark_rx.py @@ -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 @@ import sys # from current dir from receive_path import receive_path -import fusb_options #import os #print os.getpid() @@ -83,7 +82,6 @@ def main(): 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: diff --git a/gnuradio-examples/python/digital/benchmark_tx.py b/gnuradio-examples/python/digital/benchmark_tx.py index 9644ffb33..5115d764c 100755 --- a/gnuradio-examples/python/digital/benchmark_tx.py +++ b/gnuradio-examples/python/digital/benchmark_tx.py @@ -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 @@ import random, time, struct, sys # from current dir from transmit_path import transmit_path -import fusb_options #import os #print os.getpid() @@ -78,7 +77,6 @@ def main(): 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: diff --git a/gnuradio-examples/python/digital/fusb_options.py b/gnuradio-examples/python/digital/fusb_options.py deleted file mode 100644 index 153e06bea..000000000 --- a/gnuradio-examples/python/digital/fusb_options.py +++ /dev/null @@ -1,31 +0,0 @@ -# -# Copyright 2006 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. -# - -def add_options(parser): - """ - Add Fast USB specifc options to command line parser. - - @param parser: instance of OptionParser - """ - parser.add_option("-B", "--fusb-block-size", type="int", default=0, - help="specify fast usb block size [default=%default]") - parser.add_option("-N", "--fusb-nblocks", type="int", default=0, - help="specify number of fast usb blocks [default=%default]") diff --git a/gnuradio-examples/python/digital/generic_usrp.py b/gnuradio-examples/python/digital/generic_usrp.py new file mode 100644 index 000000000..ac5b13c81 --- /dev/null +++ b/gnuradio-examples/python/digital/generic_usrp.py @@ -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 diff --git a/gnuradio-examples/python/digital/pick_bitrate.py b/gnuradio-examples/python/digital/pick_bitrate.py index 82a476888..73957421b 100644 --- a/gnuradio-examples/python/digital/pick_bitrate.py +++ b/gnuradio-examples/python/digital/pick_bitrate.py @@ -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 @@ def _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol, # 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 @@ def pick_tx_bitrate(bitrate, bits_per_symbol, samples_per_symbol, @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 @@ def pick_rx_bitrate(bitrate, bits_per_symbol, samples_per_symbol, @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) diff --git a/gnuradio-examples/python/digital/receive_path.py b/gnuradio-examples/python/digital/receive_path.py index 32d02e4d0..7d9a08ca9 100644 --- a/gnuradio-examples/python/digital/receive_path.py +++ b/gnuradio-examples/python/digital/receive_path.py @@ -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 @@ import sys # from current dir from pick_bitrate import pick_rx_bitrate +import usrp_options # ///////////////////////////////////////////////////////////////////////////// # receive path @@ -42,16 +43,12 @@ class receive_path(gr.hier_block2): 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 @@ class receive_path(gr.hier_block2): 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 @@ class receive_path(gr.hier_block2): 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,14 +127,7 @@ class receive_path(gr.hier_block2): 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) - - # 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.u.set_decim(self._decim) def set_freq(self, target_freq): """ @@ -156,24 +141,13 @@ class receive_path(gr.hier_block2): 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 False + return self.u.set_center_freq(target_freq) 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 @@ class receive_path(gr.hier_block2): """ 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 @@ class receive_path(gr.hier_block2): 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 diff --git a/gnuradio-examples/python/digital/rx_voice.py b/gnuradio-examples/python/digital/rx_voice.py index 729265282..fa9e50b8e 100755 --- a/gnuradio-examples/python/digital/rx_voice.py +++ b/gnuradio-examples/python/digital/rx_voice.py @@ -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 @@ import sys # from current dir from receive_path import receive_path -import fusb_options #import os #print os.getpid() @@ -108,8 +107,6 @@ def main(): 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 () diff --git a/gnuradio-examples/python/digital/transmit_path.py b/gnuradio-examples/python/digital/transmit_path.py index 250c3f048..9486d795f 100644 --- a/gnuradio-examples/python/digital/transmit_path.py +++ b/gnuradio-examples/python/digital/transmit_path.py @@ -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 @@ import sys # from current dir from pick_bitrate import pick_tx_bitrate +import usrp_options # ///////////////////////////////////////////////////////////////////////////// # transmit path @@ -44,16 +45,12 @@ class transmit_path(gr.hier_block2): 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,7 +60,10 @@ class transmit_path(gr.hier_block2): 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 @@ -90,14 +90,11 @@ class transmit_path(gr.hier_block2): # 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 @@ class transmit_path(gr.hier_block2): # 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,13 +115,7 @@ class transmit_path(gr.hier_block2): 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) - - # 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) + self.u.set_interp(self._interp) def set_freq(self, target_freq): @@ -141,33 +130,24 @@ class transmit_path(gr.hier_block2): 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 @@ class transmit_path(gr.hier_block2): 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 @@ class transmit_path(gr.hier_block2): """ 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)) diff --git a/gnuradio-examples/python/digital/tunnel.py b/gnuradio-examples/python/digital/tunnel.py index 09bcd75dd..dd4bd3df6 100755 --- a/gnuradio-examples/python/digital/tunnel.py +++ b/gnuradio-examples/python/digital/tunnel.py @@ -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 @@ import os # 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 @@ def main(): 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) diff --git a/gnuradio-examples/python/digital/tx_voice.py b/gnuradio-examples/python/digital/tx_voice.py index c97e2f084..146f6e7e2 100755 --- a/gnuradio-examples/python/digital/tx_voice.py +++ b/gnuradio-examples/python/digital/tx_voice.py @@ -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 @@ import sys # from current dir from transmit_path import transmit_path -import fusb_options #import os #print os.getpid() @@ -102,8 +101,6 @@ def main(): 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 @@ def main(): 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 diff --git a/gnuradio-examples/python/digital/usrp_options.py b/gnuradio-examples/python/digital/usrp_options.py new file mode 100644 index 000000000..5408d2f3d --- /dev/null +++ b/gnuradio-examples/python/digital/usrp_options.py @@ -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 |