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, blks
24 from gnuradio import usrp
25 from gnuradio import eng_notation
26 from gnuradio.eng_option import eng_option
27 from optparse import OptionParser
35 from transmit_path import transmit_path
40 #raw_input('Attach and press enter')
42 class my_graph(gr.flow_graph):
44 def __init__(self, options, mod_kwargs):
45 gr.flow_graph.__init__(self)
46 self.txpath = transmit_path(self, options, mod_kwargs)
49 # /////////////////////////////////////////////////////////////////////////////
51 # /////////////////////////////////////////////////////////////////////////////
55 def send_pkt(payload='', eof=False):
56 return fg.txpath.send_pkt(payload, eof)
58 def rx_callback(ok, payload):
59 print "ok = %r, payload = '%s'" % (ok, payload)
61 parser = OptionParser (option_class=eng_option)
62 parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
63 help="select USRP Tx side A or B")
64 parser.add_option("-f", "--freq", type="eng_float", default=423.1e6,
65 help="set Tx and Rx frequency to FREQ [default=%default]",
67 parser.add_option("-r", "--bitrate", type="eng_float", default=None,
68 help="specify bitrate. spb and interp will be derived.")
69 parser.add_option("-S", "--spb", type="int", default=2,
70 help="set samples/baud [default=%default]")
71 parser.add_option("-i", "--interp", type="intx", default=None,
72 help="set fpga interpolation rate to INTERP [default=%default]")
73 parser.add_option("-s", "--size", type="eng_float", default=1500,
74 help="set packet size [default=%default]")
75 parser.add_option("", "--bt", type="float", default=0.3,
76 help="set bandwidth-time product [default=%default]")
77 parser.add_option("-g", "--gain", type="eng_float", default=100.0,
78 help="transmitter gain [default=%default]")
79 parser.add_option("-M", "--megabytes", type="eng_float", default=1.0,
80 help="set megabytes to transmit [default=%default]")
81 parser.add_option("","--discontinuous", action="store_true", default=False,
82 help="enable discontinous transmission (bursts of 5 packets)")
83 fusb_options.add_options(parser)
84 (options, args) = parser.parse_args ()
90 if options.freq < 1e6:
93 pkt_size = int(options.size)
95 # Add gmsk_mod modulator class to options list
96 options.modulation = getattr(blks, "gmsk_mod")
98 # Add GMSK modulator's properties
107 fg = my_graph(options, mod_kwargs)
109 print "bitrate: %sbps" % (eng_notation.num_to_str(fg.txpath.bitrate()),)
110 print "spb: %3d" % (fg.txpath.spb(),)
111 print "interp: %3d" % (fg.txpath.interp(),)
113 ok = fg.txpath.set_freq(options.freq)
115 print "Failed to set Tx frequency to %s" % (eng_notation.num_to_str(options.freq),)
118 print "Transmitting on frequency %s" % (eng_notation.num_to_str(options.freq))
120 r = gr.enable_realtime_scheduling()
122 print "Warning: failed to enable realtime scheduling"
124 print "Started realtime scheduling"
126 fg.start() # start flow graph
128 # generate and send packets
129 nbytes = int(1e6 * options.megabytes)
134 send_pkt(struct.pack('!H', pktno) + (pkt_size - 2) * chr(pktno & 0xff))
136 sys.stderr.write('.')
137 if options.discontinuous and pktno % 5 == 4:
142 fg.wait() # wait for it to finish
143 fg.txpath.set_auto_tr(False)
146 if __name__ == '__main__':
149 except KeyboardInterrupt: