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
38 from transmit_path import transmit_path
42 #raw_input('Attach and press enter')
45 class my_graph(gr.flow_graph):
47 def __init__(self, tx_subdev_spec, bitrate, interp_rate, spb, bt):
48 gr.flow_graph.__init__(self)
49 self.txpath = transmit_path(self, tx_subdev_spec, bitrate, interp_rate, spb, bt)
53 src = audio.source(sample_rate, audio_input)
54 src_scale = gr.multiply_const_ff(32767)
55 f2s = gr.float_to_short()
56 voice_coder = gsm_full_rate.encode_sp()
57 self.packets_from_encoder = gr.msg_queue()
58 packet_sink = gr.message_sink(33, self.packets_from_encoder, False)
59 self.connect(src, src_scale, f2s, voice_coder, packet_sink)
63 # /////////////////////////////////////////////////////////////////////////////
65 # /////////////////////////////////////////////////////////////////////////////
69 def send_pkt(payload='', eof=False):
70 return fg.txpath.send_pkt(payload, eof)
72 def rx_callback(ok, payload):
73 print "ok = %r, payload = '%s'" % (ok, payload)
75 parser = OptionParser (option_class=eng_option)
76 parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
77 help="select USRP Tx side A or B")
78 parser.add_option("-f", "--freq", type="eng_float", default=423.1e6,
79 help="set Tx and Rx frequency to FREQ [default=%default]", metavar="FREQ")
80 parser.add_option("-r", "--bitrate", type="eng_float", default=100e3,
81 help="specify bitrate. spb and interp will be derived.")
82 parser.add_option("-S", "--spb", type="int", default=None, help="set samples/baud [default=%default]")
83 parser.add_option("-i", "--interp", type="intx", default=None,
84 help="set fpga interpolation rate to INTERP [default=%default]")
85 parser.add_option("-s", "--size", type="eng_float", default=1500,
86 help="set packet size [default=%default]")
87 parser.add_option("", "--bt", type="float", default=0.3, help="set bandwidth-time product [default=%default]")
88 parser.add_option("-M", "--megabytes", type="eng_float", default=1.0,
89 help="set megabytes to transmit [default=%default]")
90 parser.add_option("","--discontinuous", action="store_true", default=False,
91 help="enable discontinous transmission (bursts of 5 packets)")
92 (options, args) = parser.parse_args ()
98 if options.freq < 1e6:
101 pkt_size = int(options.size)
104 fg = my_graph(options.tx_subdev_spec, options.bitrate, options.interp,
105 options.spb, options.bt)
107 print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.txpath.bitrate()),)
108 print "spb: %3d" % (fg.txpath.spb(),)
109 print "interp: %3d" % (fg.txpath.interp(),)
111 fg.txpath.set_freq(options.freq)
113 fg.start() # start flow graph
115 # generate and send packets
116 nbytes = int(1e6 * options.megabytes)
121 packet = fg.packets_from_encoder.delete_head()
122 s = packet.to_string()
125 sys.stderr.write('.')
126 if options.discontinuous and pktno % 5 == 4:
131 fg.wait() # wait for it to finish
132 fg.txpath.set_auto_tr(False)
135 if __name__ == '__main__':
138 except KeyboardInterrupt: