3 # Copyright 2005,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 3, 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, modulation_utils
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
41 #raw_input('Attach and press enter')
44 class audio_tx(gr.hier_block):
45 def __init__(self, fg, audio_output_dev):
46 self.packet_src = gr.message_source(33)
47 voice_decoder = gsm_full_rate.decode_ps()
48 s2f = gr.short_to_float ()
49 sink_scale = gr.multiply_const_ff(1.0/32767.)
50 audio_sink = audio.sink(8000, audio_output_dev)
51 fg.connect(self.packet_src, voice_decoder, s2f, sink_scale, audio_sink)
52 gr.hier_block.__init__(self, fg, self.packet_src, audio_sink)
55 return self.packet_src.msgq()
58 class my_graph(gr.flow_graph):
60 def __init__(self, demod_class, rx_callback, options):
61 gr.flow_graph.__init__(self)
62 self.rxpath = receive_path(self, demod_class, rx_callback, options)
63 self.audio_tx = audio_tx(self, options.audio_output)
66 # /////////////////////////////////////////////////////////////////////////////
68 # /////////////////////////////////////////////////////////////////////////////
70 global n_rcvd, n_right
73 global n_rcvd, n_right
78 def rx_callback(ok, payload):
79 global n_rcvd, n_right
84 fg.audio_tx.msgq().insert_tail(gr.message_from_string(payload))
86 print "ok = %r n_rcvd = %4d n_right = %4d" % (
89 demods = modulation_utils.type_1_demods()
91 # Create Options Parser:
92 parser = OptionParser (option_class=eng_option, conflict_handler="resolve")
93 expert_grp = parser.add_option_group("Expert")
95 parser.add_option("-m", "--modulation", type="choice", choices=demods.keys(),
97 help="Select modulation from: %s [default=%%default]"
98 % (', '.join(demods.keys()),))
99 parser.add_option("-O", "--audio-output", type="string", default="",
100 help="pcm output device name. E.g., hw:0,0 or /dev/dsp")
102 receive_path.add_options(parser, expert_grp)
104 for mod in demods.values():
105 mod.add_options(expert_grp)
107 fusb_options.add_options(expert_grp)
109 parser.set_defaults(bitrate=50e3) # override default bitrate default
110 (options, args) = parser.parse_args ()
113 parser.print_help(sys.stderr)
116 if options.rx_freq is None:
117 sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
118 parser.print_help(sys.stderr)
123 fg = my_graph(demods[options.modulation], rx_callback, options)
125 r = gr.enable_realtime_scheduling()
127 print "Warning: Failed to enable realtime scheduling."
129 fg.start() # start flow graph
130 fg.wait() # wait for it to finish
132 if __name__ == '__main__':
135 except KeyboardInterrupt: