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