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, 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
29 import random, time, struct, sys
32 from transmit_path import transmit_path
37 #raw_input('Attach and press enter')
40 class my_graph(gr.flow_graph):
42 def __init__(self, options, mod_kwargs):
43 gr.flow_graph.__init__(self)
44 self.txpath = transmit_path(self, options, mod_kwargs)
47 # /////////////////////////////////////////////////////////////////////////////
49 # /////////////////////////////////////////////////////////////////////////////
53 def send_pkt(payload='', eof=False):
54 return fg.txpath.send_pkt(payload, eof)
56 def rx_callback(ok, payload):
57 print "ok = %r, payload = '%s'" % (ok, payload)
59 parser = OptionParser (option_class=eng_option)
60 parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
61 help="select USRP Tx side A or B")
62 parser.add_option("-f", "--freq", type="eng_float", default=423.1e6,
63 help="set Tx and Rx frequency to FREQ [default=%default]",
65 parser.add_option("-r", "--bitrate", type="eng_float", default=None,
66 help="specify bitrate. spb and interp will be derived.")
67 parser.add_option("-S", "--spb", type="int", default=2,
68 help="set samples/baud [default=%default]")
69 parser.add_option("-i", "--interp", type="intx", default=None,
70 help="set fpga interpolation rate to INTERP [default=%default]")
71 parser.add_option("-s", "--size", type="eng_float", default=1500,
72 help="set packet size [default=%default]")
73 parser.add_option("-g", "--gain", type="eng_float", default=100.0,
74 help="transmitter gain [default=%default]")
75 parser.add_option("-M", "--megabytes", type="eng_float", default=1.0,
76 help="set megabytes to transmit [default=%default]")
77 parser.add_option("","--discontinuous", action="store_true", default=False,
78 help="enable discontinous transmission (bursts of 5 packets)")
80 parser.add_option("-m", "--modulation", type="string", default='dbpsk',
81 help="modulation type (bpsk, dbpsk, dqpsk) [default=%default]")
82 parser.add_option("", "--excess-bw", type="float", default=0.3,
83 help="set RRC excess bandwith factor [default=%default]")
84 parser.add_option("", "--no-gray-code", action="store_false", default=True,
85 help="Don't use gray coding on modulated bits [default=%default]")
87 fusb_options.add_options(parser)
88 (options, args) = parser.parse_args ()
94 if options.freq < 1e6:
97 pkt_size = int(options.size)
99 # Add PSK modulator class to options list
100 options.modulation = getattr(blks, options.modulation + "_mod")
102 # Add PSK modulator's properties
105 'excess_bw' : options.excess_bw,
106 'gray_code' : options.no_gray_code,
112 fg = my_graph(options, mod_kwargs)
114 print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.txpath.bitrate()),)
115 print "spb: %3d" % (fg.txpath.spb(),)
116 print "interp: %3d" % (fg.txpath.interp(),)
118 ok = fg.txpath.set_freq(options.freq)
120 print "Failed to set Tx frequency to %s" % (eng_notation.num_to_str(options.freq),)
123 r = gr.enable_realtime_scheduling()
125 print "Warning: failed to enable realtime scheduling"
127 fg.start() # start flow graph
129 # generate and send packets
130 nbytes = int(1e6 * options.megabytes)
135 send_pkt(struct.pack('!H', pktno) + (pkt_size - 2) * chr(pktno & 0xff))
137 sys.stderr.write('.')
138 if options.discontinuous and pktno % 5 == 4:
143 fg.wait() # wait for it to finish
144 fg.txpath.set_auto_tr(False)
147 if __name__ == '__main__':
150 except KeyboardInterrupt: