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 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, 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 from transmit_path import transmit_path
43 #raw_input('Attach and press enter')
46 class audio_rx(gr.hier_block):
47 def __init__(self, fg, audio_input_dev):
49 src = audio.source(sample_rate, audio_input_dev)
50 src_scale = gr.multiply_const_ff(32767)
51 f2s = gr.float_to_short()
52 voice_coder = gsm_full_rate.encode_sp()
53 self.packets_from_encoder = gr.msg_queue()
54 packet_sink = gr.message_sink(33, self.packets_from_encoder, False)
55 fg.connect(src, src_scale, f2s, voice_coder, packet_sink)
56 gr.hier_block.__init__(self, fg, src, packet_sink)
58 def get_encoded_voice_packet(self):
59 return self.packets_from_encoder.delete_head()
62 class my_graph(gr.flow_graph):
64 def __init__(self, modulator_class, options):
65 gr.flow_graph.__init__(self)
66 self.txpath = transmit_path(self, modulator_class, options)
67 self.audio_rx = audio_rx(self, options.audio_input)
71 # /////////////////////////////////////////////////////////////////////////////
73 # /////////////////////////////////////////////////////////////////////////////
77 def send_pkt(payload='', eof=False):
78 return fg.txpath.send_pkt(payload, eof)
80 def rx_callback(ok, payload):
81 print "ok = %r, payload = '%s'" % (ok, payload)
83 mods = modulation_utils.type_1_mods()
85 parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
86 expert_grp = parser.add_option_group("Expert")
88 parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
90 help="Select modulation from: %s [default=%%default]"
91 % (', '.join(mods.keys()),))
92 parser.add_option("-M", "--megabytes", type="eng_float", default=0,
93 help="set megabytes to transmit [default=inf]")
94 parser.add_option("-I", "--audio-input", type="string", default="",
95 help="pcm input device name. E.g., hw:0,0 or /dev/dsp")
97 transmit_path.add_options(parser, expert_grp)
99 for mod in mods.values():
100 mod.add_options(expert_grp)
102 fusb_options.add_options(expert_grp)
104 parser.set_defaults(bitrate=50e3) # override default bitrate default
105 (options, args) = parser.parse_args ()
111 if options.tx_freq is None:
112 sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
113 parser.print_help(sys.stderr)
118 fg = my_graph(mods[options.modulation], options)
120 r = gr.enable_realtime_scheduling()
122 print "Warning: failed to enable realtime scheduling"
125 fg.start() # start flow graph
127 # generate and send packets
128 nbytes = int(1e6 * options.megabytes)
132 while nbytes == 0 or n < nbytes:
133 packet = fg.audio_rx.get_encoded_voice_packet()
134 s = packet.to_string()
137 sys.stderr.write('.')
141 fg.wait() # wait for it to finish
142 fg.txpath.set_auto_tr(False)
145 if __name__ == '__main__':
148 except KeyboardInterrupt: