Merged -r6379:6451 from jcorgan/radar into trunk. Adds working receiver implementati...
[debian/gnuradio] / gr-radar-mono / src / python / usrp_radar_mono.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2007 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
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)
10 # any later version.
11
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.
16
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.
21
22
23 from gnuradio import gr
24 from gnuradio.radar_mono import radar
25 from gnuradio import eng_notation
26 from gnuradio.eng_option import eng_option
27 from optparse import OptionParser
28 import sys, time
29
30 n2s = eng_notation.num_to_str
31 logfile = None
32
33 def process_echo(echo):
34     global logfile
35     #sys.stdout.write('.')
36     logfile.write(echo)
37         
38 def main():
39     global logfile
40     parser = OptionParser(option_class=eng_option)
41     parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
42                       help="use transmitter board side A or B (default is first found)")
43     parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
44                       help="use receiver board side A or B (default is first found)")
45     parser.add_option("-g", "--gain", type="eng_float", default=None,
46                       help="set gain in dB (default is midpoint)")
47     parser.add_option("-f", "--frequency", type="eng_float", default=0.0,
48                       help="set transmitter center frequency to FREQ in Hz, default is %default", metavar="FREQ")
49     parser.add_option("-w", "--chirp-width", type="eng_float", default=32e6,
50                       help="set LFM chirp bandwidth in Hz, default is %default", metavar="FREQ")
51     parser.add_option("-a", "--amplitude", type="eng_float", default=15,
52                       help="set waveform amplitude in % full scale, default is %default,")
53     parser.add_option("",   "--ton", type="eng_float", default=5e-6,
54                       help="set pulse on period in seconds, default is %default,")
55     parser.add_option("",   "--tsw", type="eng_float", default=406.25e-9,
56                       help="set transmitter switching period in seconds, default is %default,")
57     parser.add_option("",   "--tlook", type="eng_float", default=5e-6,
58                       help="set receiver look time in seconds, default is %default,")
59     parser.add_option("",   "--prf", type="eng_float", default=10e3,
60                       help="set pulse repetition frequency in Hz, default is %default,")
61     parser.add_option("-v", "--verbose", action="store_true", default=False,
62                       help="enable verbose output, default is disabled")
63     parser.add_option("-D", "--debug", action="store_true", default=False,
64                       help="enable debugging output, default is disabled")
65     parser.add_option("-F", "--filename", default=None,
66                       help="log received echos to file")
67
68     (options, args) = parser.parse_args()
69
70     if len(args) != 0:
71         parser.print_help()
72         sys.exit(1)
73
74     if options.filename == None:
75         print "Must supply filename for logging received data."
76         sys.exit(1)
77     else:
78         if options.verbose:
79             print "Logging echo records to file: ", options.filename
80
81     logfile = open(options.filename, 'wb')
82         
83     r = radar(options, process_echo)
84
85     r.set_ton(options.ton)
86     r.set_tsw(options.tsw)
87     r.set_tlook(options.tlook)
88     r.set_prf(options.prf)
89     r.set_amplitude(options.amplitude)
90     r.set_freq(options.frequency, options.chirp_width)
91
92     r.start()
93     raw_input("Press ENTER to stop.")
94     r.stop()
95     logfile.close()
96             
97 if __name__ == "__main__":
98     main()