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 2, 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
24 from gnuradio.sounder import sounder
25 from gnuradio import eng_notation
26 from gnuradio.eng_option import eng_option
27 from optparse import OptionParser
31 n2s = eng_notation.num_to_str
34 parser = OptionParser(option_class=eng_option)
35 parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
36 help="select USRP Rx side A or B")
37 parser.add_option("-g", "--gain", type="eng_float", default=None,
38 help="set gain in dB (default is midpoint)")
39 parser.add_option("-f", "--frequency", type="eng_float", default=0.0,
40 help="set frequency to FREQ in Hz, default is %default", metavar="FREQ")
41 parser.add_option("-d", "--degree", type="int", default=12,
42 help="set sounding sequence degree (2-12), default is %default,")
43 parser.add_option("-a", "--amplitude", type="int", default=4096,
44 help="set waveform amplitude, default is %default,")
45 parser.add_option("-t", "--transmit", action="store_true", default=False,
46 help="enable sounding transmitter")
47 parser.add_option("-r", "--receive", action="store_true", default=False,
48 help="enable sounding receiver")
49 parser.add_option("-l", "--loopback", action="store_true", default=False,
50 help="enable digital loopback, default is disabled")
51 parser.add_option("-v", "--verbose", action="store_true", default=False,
52 help="enable verbose output, default is disabled")
53 parser.add_option("-D", "--debug", action="store_true", default=False,
54 help="enable debugging output, default is disabled")
55 parser.add_option("-F", "--filename", default=None,
56 help="log received impulse responses to file")
58 (options, args) = parser.parse_args()
60 if len(args) != 0 or not (options.transmit | options.receive):
64 if options.receive and (options.filename == None):
65 print "Must supply filename when receiving."
68 if options.degree > 12 or options.degree < 2:
69 print "PN code degree must be between 2 and 12"
72 length = int(2**options.degree-1)
74 print "Using PN code degree of", options.degree, "length", length
75 if options.loopback == False:
76 print "Sounding frequency range is", n2s(options.frequency-16e6), "to", n2s(options.frequency+16e6)
77 if options.filename != None:
78 print "Logging impulse records to file: ", options.filename
81 s = sounder(transmit=options.transmit,receive=options.receive,loopback=options.loopback,
82 rx_subdev_spec=options.rx_subdev_spec,frequency=options.frequency,rx_gain=options.gain,
83 degree=options.degree,length=length,msgq=msgq,verbose=options.verbose,ampl=options.amplitude,
88 f = open(options.filename, "wb")
89 print "Enter CTRL-C to stop."
92 msg = msgq.delete_head()
95 rec = msg.to_string()[:length*gr.sizeof_gr_complex]
97 print "Received impulse vector of length", len(rec)
98 recarray = numpy.fromstring(rec, dtype=numpy.complex64)
99 imparray = recarray[::-1]
100 data = imparray.tostring()
103 except KeyboardInterrupt:
107 raw_input("Press return to exit.")
109 if __name__ == "__main__":