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
30 n2s = eng_notation.num_to_str
33 parser = OptionParser(option_class=eng_option)
34 parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
35 help="select USRP Rx side A or B")
36 parser.add_option("-f", "--frequency", type="eng_float", default=0.0,
37 help="set frequency to FREQ in Hz, default is %default", metavar="FREQ")
38 parser.add_option("-d", "--degree", type="int", default=12,
39 help="set sounding sequence degree (2-12), default is %default,")
40 parser.add_option("-t", "--transmit", action="store_true", default=False,
41 help="enable sounding transmitter")
42 parser.add_option("-r", "--receive", action="store_true", default=False,
43 help="enable sounding receiver")
44 parser.add_option("-l", "--loopback", action="store_true", default=False,
45 help="enable digital loopback, default is disabled")
46 parser.add_option("-v", "--verbose", action="store_true", default=False,
47 help="enable verbose output, default is disabled")
48 parser.add_option("-D", "--debug", action="store_true", default=False,
49 help="enable debugging output, default is disabled")
50 parser.add_option("-F", "--filename", default=None,
51 help="log received impulse responses to file")
53 (options, args) = parser.parse_args()
55 if len(args) != 0 or not (options.transmit | options.receive):
59 if options.receive and (options.filename == None):
60 print "Must supply filename when receiving."
63 if options.degree > 12 or options.degree < 2:
64 print "PN code degree must be between 2 and 12"
67 length = int(2**options.degree-1)
69 print "Using PN code degree of", options.degree, "length", length
70 if options.loopback == False:
71 print "Sounding frequency range is", n2s(options.frequency-16e6), "to", n2s(options.frequency+16e6)
72 if options.filename != None:
73 print "Logging impulse records to file: ", options.filename
76 s = sounder(transmit=options.transmit,receive=options.receive,loopback=options.loopback,
77 rx_subdev_spec=options.rx_subdev_spec,frequency=options.frequency,degree=options.degree,
78 length=length,msgq=msgq,verbose=options.verbose,debug=options.debug)
82 f = open(options.filename, "wb")
83 print "Enter CTRL-C to stop."
86 msg = msgq.delete_head()
89 rec = msg.to_string()[:length*gr.sizeof_gr_complex]
91 print "Received impulse vector of length", len(rec)
94 except KeyboardInterrupt:
98 raw_input("Press return to exit.")
100 if __name__ == "__main__":