2 # Copyright 2009 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")
61 tx_path = transmit_path.transmit_path(modulator_class, options)
62 for attr in dir(tx_path): #forward the methods
63 if not attr.startswith('_') and not hasattr(self, attr):
64 setattr(self, attr, getattr(tx_path, attr))
67 self._modulator_class = modulator_class
68 self._setup_usrp_sink(options)
70 # Set up resampler based on rate determined by _setup_usrp_sink
71 rs_taps = gr.firdes.low_pass_2(32, 32, 0.45, 0.1, 60)
72 self.resampler = gr.pfb_arb_resampler_ccf(self.rs_rate, rs_taps)
75 self.connect(tx_path, self.resampler, self.u)
77 def _setup_usrp_sink(self, options):
79 Creates a USRP sink, determines the settings for best bitrate,
80 and attaches to the transmitter's subdevice.
82 self.u = usrp_options.create_usrp_sink(options)
83 dac_rate = self.u.dac_rate()
84 self.rs_rate = options.bitrate # Store requested bit rate
86 print 'USRP Sink:', self.u
87 #(self._bitrate, self._samples_per_symbol, self._interp) = \
88 # pick_tx_bitrate(options.bitrate, self._modulator_class.bits_per_symbol(), \
89 # options.samples_per_symbol, options.interp, dac_rate, \
90 # self.u.get_interp_rates())
91 (self._bitrate, self._samples_per_symbol, self._interp) = \
92 pick_tx_bitrate(options.bitrate, self._modulator_class.bits_per_symbol(), \
93 dac_rate, self.u.get_interp_rates())
95 print "USRP Interpolation: ", self._interp
96 print "Samples Per Symbol: ", self._samples_per_symbol
98 self.u.set_interp(self._interp)
99 self.u.set_auto_tr(True)
101 if not self.u.set_center_freq(options.tx_freq):
102 print "Failed to set Rx frequency to %s" % (eng_notation.num_to_str(options.tx_freq))
103 raise ValueError, eng_notation.num_to_str(options.tx_freq)