3 # Copyright 2005,2006,2007,2009 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
38 import usrp_transmit_path
42 #raw_input('Attach and press enter')
45 class audio_rx(gr.hier_block2):
46 def __init__(self, audio_input_dev):
47 gr.hier_block2.__init__(self, "audio_rx",
48 gr.io_signature(0, 0, 0), # Input signature
49 gr.io_signature(0, 0, 0)) # Output signature
51 src = audio.source(sample_rate, audio_input_dev)
52 src_scale = gr.multiply_const_ff(32767)
53 f2s = gr.float_to_short()
54 voice_coder = gsm_full_rate.encode_sp()
55 self.packets_from_encoder = gr.msg_queue()
56 packet_sink = gr.message_sink(33, self.packets_from_encoder, False)
57 self.connect(src, src_scale, f2s, voice_coder, packet_sink)
59 def get_encoded_voice_packet(self):
60 return self.packets_from_encoder.delete_head()
63 class my_top_block(gr.top_block):
65 def __init__(self, modulator_class, options):
66 gr.top_block.__init__(self)
67 self.txpath = usrp_transmit_path.usrp_transmit_path(modulator_class, options)
68 self.audio_rx = audio_rx(options.audio_input)
69 self.connect(self.txpath)
70 self.connect(self.audio_rx)
73 # /////////////////////////////////////////////////////////////////////////////
75 # /////////////////////////////////////////////////////////////////////////////
79 def send_pkt(payload='', eof=False):
80 return tb.txpath.send_pkt(payload, eof)
82 def rx_callback(ok, payload):
83 print "ok = %r, payload = '%s'" % (ok, payload)
85 mods = modulation_utils.type_1_mods()
87 parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
88 expert_grp = parser.add_option_group("Expert")
90 parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
92 help="Select modulation from: %s [default=%%default]"
93 % (', '.join(mods.keys()),))
94 parser.add_option("-M", "--megabytes", type="eng_float", default=0,
95 help="set megabytes to transmit [default=inf]")
96 parser.add_option("-I", "--audio-input", type="string", default="",
97 help="pcm input device name. E.g., hw:0,0 or /dev/dsp")
98 usrp_transmit_path.add_options(parser, expert_grp)
100 for mod in mods.values():
101 mod.add_options(expert_grp)
103 parser.set_defaults(bitrate=50e3) # override default bitrate default
104 (options, args) = parser.parse_args ()
110 if options.tx_freq is None:
111 sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
112 parser.print_help(sys.stderr)
117 tb = my_top_block(mods[options.modulation], options)
119 r = gr.enable_realtime_scheduling()
121 print "Warning: failed to enable realtime scheduling"
124 tb.start() # start flow graph
126 # generate and send packets
127 nbytes = int(1e6 * options.megabytes)
131 while nbytes == 0 or n < nbytes:
132 packet = tb.audio_rx.get_encoded_voice_packet()
133 s = packet.to_string()
136 sys.stderr.write('.')
140 tb.wait() # wait for it to finish
143 if __name__ == '__main__':
146 except KeyboardInterrupt: