Imported Upstream version 3.2.2
[debian/gnuradio] / gr-pager / src / usrp_flex_all.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2006,2007,2009 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, gru, usrp, optfir, eng_notation, blks2, pager
24 from gnuradio.eng_option import eng_option
25 from optparse import OptionParser
26 from string import split, join, printable
27 import time
28
29 class app_top_block(gr.top_block):
30     def __init__(self, options, queue):
31         gr.top_block.__init__(self, "usrp_flex_all")
32
33         if options.from_file is not None:
34             src = gr.file_source(gr.sizeof_gr_complex, options.from_file)
35             if options.verbose:
36                 print "Reading samples from file", options.from_file
37         else:
38             src = usrp.source_c()
39             if options.rx_subdev_spec is None:
40                 options.rx_subdev_spec = usrp.pick_rx_subdevice(src)
41             subdev = usrp.selected_subdev(src, options.rx_subdev_spec)
42             src.set_mux(usrp.determine_rx_mux_value(src, options.rx_subdev_spec))
43             src.set_decim_rate(20)
44             result = usrp.tune(src, 0, subdev, 930.5125e6+options.calibration)
45             if options.verbose:
46                 print "Using", subdev.name(), " for receiving."
47                 print "Tuned USRP to", 930.5125e6+options.calibration
48                 
49         taps = gr.firdes.low_pass(1.0,
50                                   1.0,
51                                   1.0/128.0*0.4,
52                                   1.0/128.0*0.1,
53                                   gr.firdes.WIN_HANN)
54
55         if options.verbose:
56             print "Channel filter has", len(taps), "taps"
57
58         bank = blks2.analysis_filterbank(128, taps)
59         self.connect(src, bank)
60
61         if options.log and options.from_file == None:
62             src_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat')
63             self.connect(src, src_sink)
64
65         for i in range(128):
66             if i < 64:
67                 freq = 930.5e6+i*25e3
68             else:
69                 freq = 928.9e6+(i-64)*25e3
70
71             if (freq < 929.0e6 or freq > 932.0e6):
72                 self.connect((bank, i), gr.null_sink(gr.sizeof_gr_complex))
73             else:
74                 self.connect((bank, i), pager.flex_demod(queue, freq, options.verbose, options.log))
75                 if options.log:
76                     self.connect((bank, i), gr.file_sink(gr.sizeof_gr_complex, 'chan_'+'%3.3f'%(freq/1e6)+'.dat'))
77
78 def main():
79     parser = OptionParser(option_class=eng_option)
80     parser.add_option("-R", "--rx-subdev-spec", type="subdev",
81                       help="select USRP Rx side A or B (default=first daughterboard found)")
82     parser.add_option("-c", "--calibration", type="eng_float", default=0.0,
83                       help="set frequency offset to Hz", metavar="Hz")
84     parser.add_option("-g", "--gain", type="int",
85                       help="set RF gain", metavar="dB")
86     parser.add_option("-F", "--from-file", default=None,
87                       help="Read from file instead of USRP")
88     parser.add_option("-l", "--log", action="store_true", default=False,
89                       help="log flowgraph to files (LOTS of data)")
90     parser.add_option("-v", "--verbose", action="store_true", default=False,
91                       help="display debug output")
92     (options, args) = parser.parse_args()
93
94     if options.verbose:
95         print options
96
97     queue = gr.msg_queue()
98     tb = app_top_block(options, queue)
99     runner = pager.queue_runner(queue)
100
101     try:
102         tb.run()
103     except KeyboardInterrupt:
104         pass
105
106     runner.end()
107     
108 if __name__ == "__main__":
109     main()