4d341497a5f8a3c81603d98c7175457d86f683f4
[debian/gnuradio] / usrp2 / host / apps / streaming_fft.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2008 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 along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #
21
22 import os
23 import os.path
24 import sys
25 from gnuradio.eng_option import eng_option
26 from optparse import OptionParser
27
28 def main():
29     parser = OptionParser(option_class=eng_option)
30     parser.add_option("-d", "--decim", type="int", default=16,
31                       help="set fgpa decimation rate to DECIM [default=%default]")
32     parser.add_option("-f", "--freq", type="eng_float", default=0.0,
33                       help="set frequency to FREQ", metavar="FREQ")
34     parser.add_option("-g", "--gain", type="string", default=None,
35                       help="set gain to GAIN [default=%default]")
36     parser.add_option("-W", "--waterfall", action="store_true", default=False,
37                       help="Enable waterfall display")
38     parser.add_option("-S", "--oscilloscope", action="store_true", default=False,
39                       help="Enable oscilloscope display")
40     parser.add_option("-F", "--samples-per-frame", type="int", default=250,
41                       help="[default=%default]")
42     parser.add_option("-e", "--eth", default="eth0",
43                       help="specify ethernet interface [default=%default]")
44
45     (options, args) = parser.parse_args()
46     if len(args) != 0:
47         parser.print_help()
48         sys.exit(1)
49
50
51     path = os.path.dirname(sys.argv[0])
52     if path == '':
53         path = '.'
54     
55     
56     display_type = ''
57     if options.waterfall:
58         display_type = '-W'
59     if options.oscilloscope:
60         display_type = '-S'
61
62     gain_clause = ''
63     if options.gain:
64         gain_clause = '-g ' + options.gain
65
66     # FIXME: restore -F
67     cmd = "%s/rx_streaming_samples -s -e %s -f %g -d %d %s -o /proc/self/fd/1 | %s/stdin_int32_fft.py %s -f %g -d %d" % (
68         path, options.eth, options.freq, options.decim, gain_clause,
69         path, display_type, options.freq, options.decim)
70
71     print cmd
72     os.system(cmd)
73     
74
75 if __name__ == '__main__':
76     main()