2 # Copyright 2010 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
22 from gnuradio import gr
23 from gnuradio import usrp_options
25 from pick_bitrate2 import pick_tx_bitrate
26 from gnuradio import eng_notation
28 def add_freq_option(parser):
30 Hackery that has the -f / --freq option set both tx_freq and rx_freq
32 def freq_callback(option, opt_str, value, parser):
33 parser.values.rx_freq = value
34 parser.values.tx_freq = value
36 if not parser.has_option('--freq'):
37 parser.add_option('-f', '--freq', type="eng_float",
38 action="callback", callback=freq_callback,
39 help="set Tx and/or Rx frequency to FREQ [default=%default]",
42 def add_options(parser, expert):
43 add_freq_option(parser)
44 usrp_options.add_tx_options(parser)
45 transmit_path.transmit_path.add_options(parser, expert)
46 expert.add_option("", "--tx-freq", type="eng_float", default=None,
47 help="set transmit frequency to FREQ [default=%default]", metavar="FREQ")
48 parser.add_option("-v", "--verbose", action="store_true", default=False)
50 class usrp_transmit_path(gr.hier_block2):
51 def __init__(self, modulator_class, options):
53 See below for what options should hold
55 gr.hier_block2.__init__(self, "usrp_transmit_path",
56 gr.io_signature(0, 0, 0), # Input signature
57 gr.io_signature(0, 0, 0)) # Output signature
58 if options.tx_freq is None:
59 sys.stderr.write("-f FREQ or --freq FREQ or --tx-freq FREQ must be specified\n")
63 self._modulator_class = modulator_class
64 self._setup_usrp_sink(options)
66 tx_path = transmit_path.transmit_path(modulator_class, options)
67 for attr in dir(tx_path): #forward the methods
68 if not attr.startswith('_') and not hasattr(self, attr):
69 setattr(self, attr, getattr(tx_path, attr))
72 self.connect(tx_path, self.u)
74 def _setup_usrp_sink(self, options):
76 Creates a USRP sink, determines the settings for best bitrate,
77 and attaches to the transmitter's subdevice.
79 self.u = usrp_options.create_usrp_sink(options)
80 dac_rate = self.u.dac_rate()
81 self.rs_rate = options.bitrate # Store requested bit rate
83 (self._bitrate, self._samples_per_symbol, self._interp) = \
84 pick_tx_bitrate(options.bitrate, self._modulator_class.bits_per_symbol(),
85 options.samples_per_symbol, options.interp,
86 dac_rate, self.u.get_interp_rates())
88 options.interp = self._interp
89 options.samples_per_symbol = self._samples_per_symbol
90 options.bitrate = self._bitrate
93 print 'USRP Sink:', self.u
94 print "Interpolation Rate: ", self._interp
96 self.u.set_interp(self._interp)
97 self.u.set_auto_tr(True)
99 if not self.u.set_center_freq(options.tx_freq):
100 print "Failed to set Rx frequency to %s" % (eng_notation.num_to_str(options.tx_freq))
101 raise ValueError, eng_notation.num_to_str(options.tx_freq)