e372ec9f04ce792448df9af7ca7403abff0c8066
[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
29
30 n2s = eng_notation.num_to_str
31
32 def main():
33     parser = OptionParser(option_class=eng_option)
34     parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
35                       help="use transmitter board side A or B (default is first found)")
36     parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
37                       help="use receiver board side A or B (default is first found)")
38     parser.add_option("-g", "--gain", type="eng_float", default=None,
39                       help="set gain in dB (default is midpoint)")
40     parser.add_option("-f", "--frequency", type="eng_float", default=0.0,
41                       help="set transmitter center frequency to FREQ in Hz, default is %default", metavar="FREQ")
42     parser.add_option("-w", "--chirp-width", type="eng_float", default=32e6,
43                       help="set LFM chirp bandwidth in Hz, default is %default", metavar="FREQ")
44     parser.add_option("-a", "--amplitude", type="eng_float", default=15,
45                       help="set waveform amplitude in % full scale, default is %default,")
46     parser.add_option("",   "--ton", type="eng_float", default=5e-6,
47                       help="set pulse on period in seconds, default is %default,")
48     parser.add_option("",   "--tsw", type="eng_float", default=406.25e-9,
49                       help="set transmitter switching period in seconds, default is %default,")
50     parser.add_option("",   "--tlook", type="eng_float", default=5e-6,
51                       help="set receiver look time in seconds, default is %default,")
52     parser.add_option("",   "--prf", type="eng_float", default=10e3,
53                       help="set pulse repetition frequency in Hz, default is %default,")
54     parser.add_option("-v", "--verbose", action="store_true", default=False,
55                       help="enable verbose output, default is disabled")
56     parser.add_option("-D", "--debug", action="store_true", default=False,
57                       help="enable debugging output, default is disabled")
58
59     # NOT IMPLEMENTED
60     #parser.add_option("-l", "--loopback", action="store_true", default=False,
61     #                  help="enable digital loopback, default is disabled")
62     #parser.add_option("-F", "--filename", default=None,
63     #                  help="log received echos to file")
64                       
65     (options, args) = parser.parse_args()
66
67     if len(args) != 0:
68         parser.print_help()
69         sys.exit(1)
70
71     """
72     if options.filename == None:
73         print "Must supply filename for logging received data."
74         sys.exit(1)
75     else:
76         if options.verbose:
77             print "Logging echo records to file: ", options.filename
78     """
79         
80     msgq = gr.msg_queue()
81     s = radar(msgq=msgq, tx_subdev_spec=options.tx_subdev_spec,
82               rx_subdev_spec=options.rx_subdev_spec,gain=options.gain,
83               verbose=options.verbose, debug=options.debug)
84
85     s.set_ton(options.ton)
86     s.set_tsw(options.tsw)
87     s.set_tlook(options.tlook)
88     s.set_prf(options.prf)
89     s.set_amplitude(options.amplitude)
90     s.set_freq(options.frequency, options.chirp_width)
91
92     s.start()
93
94     #f = open(options.filename, "wb")
95     print "Enter CTRL-C to stop."
96     try:
97         while 1:
98             if not msgq.empty_p():
99                 msg = msgq.delete_head()
100                 if msg.type() == 1:
101                     break
102                 echo = msg.to_string()
103                 if options.debug:
104                     print "Received echo vector of length", len(echo)
105                 #f.write(rec)
106                 
107     except KeyboardInterrupt:
108         pass
109
110     s.stop()
111         
112 if __name__ == "__main__":
113     main()