3 # Copyright 2008 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
23 from gnuradio import gr, eng_notation, usrp
24 from gnuradio.eng_option import eng_option
25 from optparse import OptionParser
26 from transmit_path import transmit_path
31 n2s = eng_notation.num_to_str
33 class tx_bpsk_block(gr.top_block):
34 def __init__(self, options):
35 gr.top_block.__init__(self, "tx_mpsk")
37 self._transmitter = transmit_path(options.sps,
41 if_rate = options.rate*options.sps
42 interp = int(_dac_rate/if_rate)
44 print "Modulation:", n2s(options.rate), "bits/sec"
45 print "TX IF rate:", n2s(if_rate), "samples/sec"
46 print "USRP interpolation:", interp
47 print "DAC amplitude:", options.amplitude
49 self._setup_usrp(options.which,
51 options.tx_subdev_spec,
54 self.connect(self._transmitter, self._usrp)
57 def _setup_usrp(self, which, interp, subdev_spec, freq):
58 self._usrp = usrp.sink_c(which=which, interp_rate=interp)
59 if subdev_spec is None:
60 subdev_spec = usrp.pick_tx_subdevice(self._usrp)
61 self._usrp.set_mux(usrp.determine_tx_mux_value(self._usrp, subdev_spec))
62 self._subdev = usrp.selected_subdev(self._usrp, subdev_spec)
63 tr = usrp.tune(self._usrp, self._subdev.which(), self._subdev, freq)
65 print "Failed to tune to center frequency!"
67 print "Center frequency:", n2s(freq)
68 gain = float(self._subdev.gain_range()[1]) # Max TX gain
69 self._subdev.set_gain(gain)
70 self._subdev.set_enable(True)
71 print "TX d'board:", self._subdev.side_and_name()
75 parser = OptionParser(option_class=eng_option)
76 parser.add_option("-w", "--which", type="int", default=0,
77 help="select which USRP (0, 1, ...) default is %default",
79 parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
80 help="select USRP Tx side A or B (default=first one with a daughterboard)")
81 parser.add_option("-f", "--freq", type="eng_float", default=None,
82 help="set frequency to FREQ", metavar="FREQ")
83 parser.add_option("-a", "--amplitude", type="eng_float", default=2000,
84 help="set Tx amplitude (0-32767) (default=%default)")
85 parser.add_option("-r", "--rate", type="eng_float", default=250e3,
86 help="Select modulation symbol rate (default=%default)")
87 parser.add_option("", "--sps", type="int", default=2,
88 help="Select samples per symbol (default=%default)")
89 parser.add_option("", "--excess-bw", type="eng_float", default=0.35,
90 help="Select RRC excess bandwidth (default=%default)")
92 (options, args) = parser.parse_args()
97 if options.freq == None:
98 print "Must supply frequency as -f or --freq"
101 return (options, args)
103 if __name__ == "__main__":
104 (options, args) = get_options()
106 tb = tx_bpsk_block(options)
110 except KeyboardInterrupt: