3 # Copyright 2007 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
24 from gnuradio.eng_option import eng_option
25 from optparse import OptionParser
26 from usrp_sink import usrp_sink_c
27 from sounder_tx import sounder_tx
29 n2s = eng_notation.num_to_str
31 class usrp_sounder_tx(gr.top_block):
32 def __init__(self, subdev_spec, freq, cal, verbose, degree, chip_rate, amplitude):
34 # Call hierarchical block constructor
35 # Top-level blocks have no inputs or outputs
36 gr.top_block.__init__(self, "usrp_sounder_tx")
39 self._verbose = verbose
41 self._length = 2**degree-1
42 self._amplitude = amplitude
44 self._u = usrp_sink_c(0, subdev_spec, chip_rate, self._freq, self._cal, self._verbose)
45 self._chip_rate = self._u._if_rate
46 self._max_time = float(self._length)/self._chip_rate
47 self._pn = sounder_tx(self._degree, self._chip_rate, self._verbose)
48 self._gain = gr.multiply_const_ff(amplitude)
49 self._f2c = gr.float_to_complex()
50 self.connect(self._pn, self._gain, self._f2c, self._u)
53 print "Chip rate is", n2s(self._chip_rate), "chips/sec"
54 print "Resolution is", n2s(1.0/self._chip_rate), "sec"
55 print "Using PN code of degree", self._degree, "length", 2**self._degree-1
56 print "Maximum measurable impulse response is", n2s(self._max_time), "sec"
57 print "Output amplitude is", amplitude
61 parser = OptionParser(option_class=eng_option)
63 # Transmit path options
64 parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
65 help="select USRP Rx side A or B (default=first found)")
66 parser.add_option("-f", "--freq", type="eng_float", default=0.0,
67 help="set center frequency (default=%default)")
68 parser.add_option("-c", "--cal", type="eng_float", default=0.0,
69 help="set frequency calibration offset (default=%default)")
70 parser.add_option("-v", "--verbose", action="store_true", default=False,
71 help="print extra debugging info")
72 parser.add_option("-d", "--degree", type="int", default=10,
73 help="set PN code degree (length=2**degree-1, default=%default)")
74 parser.add_option("-r", "--chip-rate", type="eng_float", default=8e6,
75 help="set sounder chip rate (default=%default)")
76 parser.add_option("-g", "--amplitude", type="eng_float", default=8000.0,
77 help="set output amplitude (default=%default)")
78 parser.add_option("", "--real-time", action="store_true", default=False,
79 help="Attempt to enable real-time scheduling")
80 (options, args) = parser.parse_args()
86 if not options.real_time:
89 # Attempt to enable realtime scheduling
90 r = gr.enable_realtime_scheduling()
95 print "Note: failed to enable realtime scheduling"
97 # Create an instance of a hierarchical block
98 top_block = usrp_sounder_tx(options.tx_subdev_spec, options.freq, options.cal,
99 options.verbose, options.degree, options.chip_rate,
102 # Create an instance of a runtime, passing it the top block
104 runtime = gr.runtime(top_block)
109 except KeyboardInterrupt:
113 if __name__ == '__main__':