3 # Copyright 2006 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 bpsk import bpsk_demod
34 from dbpsk import dbpsk_demod
35 from dqpsk import dqpsk_demod
36 from receive_path import receive_path
42 raw_input('Attach and press enter')
45 class my_graph(gr.flow_graph):
47 def __init__(self, demod_class, rx_subdev_spec,
48 bitrate, decim_rate, spb,
49 rx_callback, options, demod_kwargs):
50 gr.flow_graph.__init__(self)
51 self.rxpath = receive_path(self, demod_class, rx_subdev_spec,
52 bitrate, decim_rate, spb,
53 rx_callback, options, demod_kwargs)
55 # /////////////////////////////////////////////////////////////////////////////
57 # /////////////////////////////////////////////////////////////////////////////
59 global n_rcvd, n_right
62 global n_rcvd, n_right
67 def rx_callback(ok, payload):
68 global n_rcvd, n_right
69 (pktno,) = struct.unpack('!H', payload[0:2])
74 print "ok = %r pktno = %4d n_rcvd = %4d n_right = %4d" % (
75 ok, pktno, n_rcvd, n_right)
77 parser = OptionParser (option_class=eng_option)
78 parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
79 help="select USRP Rx side A or B")
80 parser.add_option("-f", "--freq", type="eng_float", default=423.1e6,
81 help="set Rx frequency to FREQ [default=%default]",
83 parser.add_option("-r", "--bitrate", type="eng_float", default=None,
84 help="specify bitrate. spb and interp will be derived.")
85 parser.add_option("-S", "--spb", type="int", default=None,
86 help="set samples/baud [default=%default]")
87 parser.add_option("-d", "--decim", type="intx", default=None,
88 help="set fpga decim rate to DECIM [default=%default]")
89 parser.add_option("-m", "--modulation", type="string", default='dbpsk',
90 help="modulation type (bpsk, dbpsk, dqpsk) [default=%default]")
91 parser.add_option("", "--excess-bw", type="float", default=0.3,
92 help="set RRC excess bandwith factor [default=%default]")
93 parser.add_option("-g", "--gain", type="eng_float", default=27,
95 parser.add_option("","--log", action="store_true", default=False,
96 help="enable diagnostic logging")
97 fusb_options.add_options(parser)
98 (options, args) = parser.parse_args ()
104 if options.freq < 1e6:
108 'excess_bw' : options.excess_bw,
111 #FIXME: Needs to be worked in to overall structure; this will be fixed
112 # once static class definitions for modulations are defined
113 if(options.modulation=='bpsk'):
114 modulation=bpsk_demod
115 elif(options.modulation=='dbpsk'):
116 modulation=dbpsk_demod
118 modulation=dqpsk_demod
121 fg = my_graph(modulation,
122 options.rx_subdev_spec, options.bitrate,
123 options.decim, options.spb,
124 rx_callback, options, demod_kwargs)
126 print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.rxpath.bitrate()),)
127 print "spb: %3d" % (fg.rxpath.spb(),)
128 print "decim: %3d" % (fg.rxpath.decim(),)
130 ok = fg.rxpath.set_freq(options.freq)
132 print "Failed to set Rx frequency to %s" % (eng_notation.num_to_str(options.freq),)
135 fg.rxpath.set_gain(options.gain)
136 print "Rx gain_range: ", fg.rxpath.subdev.gain_range(), " using", fg.rxpath.gain
138 r = gr.enable_realtime_scheduling()
140 print "Warning: Failed to enable realtime scheduling."
142 fg.start() # start flow graph
143 fg.wait() # wait for it to finish
145 if __name__ == '__main__':
148 except KeyboardInterrupt: