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 audio
26 from gnuradio import eng_notation
27 from gnuradio.eng_option import eng_option
28 from optparse import OptionParser
30 from gnuradio.vocoder import gsm_full_rate
36 from receive_path import receive_path
40 #raw_input('Attach and press enter')
43 class audio_tx(gr.hier_block):
44 def __init__(self, fg):
45 self.packet_src = gr.message_source(33)
46 voice_decoder = gsm_full_rate.decode_ps()
47 s2f = gr.short_to_float ()
48 sink_scale = gr.multiply_const_ff(1.0/32767.)
49 audio_sink = audio.sink(8000)
50 fg.connect(self.packet_src, voice_decoder, s2f, sink_scale, audio_sink)
51 gr.hier_block.__init__(self, fg, self.packet_src, audio_sink)
54 return self.packet_src.msgq()
57 class my_graph(gr.flow_graph):
59 def __init__(self, rx_subdev_spec, bitrate, decim_rate, spb, rx_callback, log):
60 gr.flow_graph.__init__(self)
61 self.rxpath = receive_path(self, rx_subdev_spec, bitrate, decim_rate,
62 spb, rx_callback, log)
64 self.audio_tx = audio_tx(self)
67 # /////////////////////////////////////////////////////////////////////////////
69 # /////////////////////////////////////////////////////////////////////////////
71 global n_rcvd, n_right
74 global n_rcvd, n_right
79 def rx_callback(ok, payload):
80 global n_rcvd, n_right
85 fg.audio_tx.msgq().insert_tail(gr.message_from_string(payload))
87 print "ok = %r n_rcvd = %4d n_right = %4d" % (
90 parser = OptionParser (option_class=eng_option)
91 parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
92 help="select USRP Rx side A or B")
93 parser.add_option("-f", "--freq", type="eng_float", default=423.1e6,
94 help="set Rx frequency to FREQ [default=%default]", metavar="FREQ")
95 parser.add_option("-r", "--bitrate", type="eng_float", default=100e3,
96 help="specify bitrate. spb and interp will be derived.")
97 parser.add_option("-S", "--spb", type="int", default=None, help="set samples/baud [default=%default]")
98 parser.add_option("-d", "--decim", type="intx", default=None,
99 help="set fpga decim rate to DECIM [default=%default]")
100 parser.add_option("-g", "--gain", type="eng_float", default=27,
102 parser.add_option("","--log", action="store_true", default=False,
103 help="enable diagnostic logging")
104 (options, args) = parser.parse_args ()
110 if options.freq < 1e6:
114 fg = my_graph(options.rx_subdev_spec, options.bitrate,
115 options.decim, options.spb, rx_callback, options.log)
117 print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.rxpath.bitrate()),)
118 print "spb: %3d" % (fg.rxpath.spb(),)
119 print "decim: %3d" % (fg.rxpath.decim(),)
121 fg.rxpath.set_freq(options.freq)
122 fg.rxpath.set_gain(options.gain)
123 print "Rx gain_range: ", fg.rxpath.subdev.gain_range(), " using", fg.rxpath.gain
125 fg.start() # start flow graph
126 fg.wait() # wait for it to finish
128 if __name__ == '__main__':
131 except KeyboardInterrupt: