3 # Copyright 2005 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
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 2, or (at your option)
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.
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.
23 from gnuradio import gr, gru, blks
24 from gnuradio import usrp
25 from gnuradio import eng_notation
26 from gnuradio.eng_option import eng_option
27 from optparse import OptionParser
33 from receive_path import receive_path
38 #raw_input('Attach and press enter')
41 class my_graph(gr.flow_graph):
43 def __init__(self, demod_class, rx_subdev_spec,
44 bitrate, decim_rate, spb,
45 rx_callback, options, demod_kwargs):
46 gr.flow_graph.__init__(self)
47 self.rxpath = receive_path(self, demod_class, rx_subdev_spec,
48 bitrate, decim_rate, spb,
49 rx_callback, options, demod_kwargs)
51 # /////////////////////////////////////////////////////////////////////////////
53 # /////////////////////////////////////////////////////////////////////////////
55 global n_rcvd, n_right
58 global n_rcvd, n_right
63 def rx_callback(ok, payload):
64 global n_rcvd, n_right
65 (pktno,) = struct.unpack('!H', payload[0:2])
70 print "ok = %r pktno = %4d n_rcvd = %4d n_right = %4d" % (
71 ok, pktno, n_rcvd, n_right)
73 parser = OptionParser (option_class=eng_option)
74 parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
75 help="select USRP Rx side A or B")
76 parser.add_option("-f", "--freq", type="eng_float", default=423.1e6,
77 help="set Rx frequency to FREQ [default=%default]",
79 parser.add_option("-r", "--bitrate", type="eng_float", default=None,
80 help="specify bitrate. spb and interp will be derived.")
81 parser.add_option("-g", "--rx-gain", type="eng_float", default=27,
83 parser.add_option("-S", "--spb", type="int", default=None,
84 help="set samples/baud [default=%default]")
85 parser.add_option("-d", "--decim", type="intx", default=None,
86 help="set fpga decim rate to DECIM [default=%default]")
87 fusb_options.add_options(parser)
88 (options, args) = parser.parse_args ()
94 if options.freq < 1e6:
97 demod_kwargs = { } # placeholder
100 fg = my_graph(blks.gmsk2_demod,
101 options.rx_subdev_spec, options.bitrate,
102 options.decim, options.spb, rx_callback,
103 options, demod_kwargs)
105 print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.rxpath.bitrate()),)
106 print "spb: %3d" % (fg.rxpath.spb(),)
107 print "decim: %3d" % (fg.rxpath.decim(),)
109 ok = fg.rxpath.set_freq(options.freq)
111 print "Failed to set Rx frequency to %s" % (eng_notation.num_to_str(options.freq),)
114 fg.rxpath.set_gain(options.rx_gain)
115 print "Rx gain_range: ", fg.rxpath.subdev.gain_range(), " using", fg.rxpath.gain
117 r = gr.enable_realtime_scheduling()
119 print "Warning: Failed to enable realtime scheduling."
121 fg.start() # start flow graph
122 fg.wait() # wait for it to finish
124 if __name__ == '__main__':
127 except KeyboardInterrupt: