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
29 import random, time, struct, sys
32 from bpsk import bpsk_mod
33 from dbpsk import dbpsk_mod
34 from dqpsk import dqpsk_mod
35 from transmit_path import transmit_path
40 #raw_input('Attach and press enter')
43 class my_graph(gr.flow_graph):
45 def __init__(self, mod_class, tx_subdev_spec,
46 bitrate, interp_rate, spb, gain,
48 gr.flow_graph.__init__(self)
49 self.txpath = transmit_path(self, mod_class, tx_subdev_spec,
50 bitrate, interp_rate, spb, gain,
54 # /////////////////////////////////////////////////////////////////////////////
56 # /////////////////////////////////////////////////////////////////////////////
60 def send_pkt(payload='', eof=False):
61 return fg.txpath.send_pkt(payload, eof)
63 def rx_callback(ok, payload):
64 print "ok = %r, payload = '%s'" % (ok, payload)
66 parser = OptionParser (option_class=eng_option)
67 parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
68 help="select USRP Tx side A or B")
69 parser.add_option("-f", "--freq", type="eng_float", default=423.1e6,
70 help="set Tx and Rx frequency to FREQ [default=%default]",
72 parser.add_option("-r", "--bitrate", type="eng_float", default=None,
73 help="specify bitrate. spb and interp will be derived.")
74 parser.add_option("-S", "--spb", type="int", default=None,
75 help="set samples/baud [default=%default]")
76 parser.add_option("-i", "--interp", type="intx", default=None,
77 help="set fpga interpolation rate to INTERP [default=%default]")
78 parser.add_option("-s", "--size", type="eng_float", default=1500,
79 help="set packet size [default=%default]")
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("-g", "--gain", type="eng_float", default=100.0,
85 help="transmitter gain [default=%default]")
86 parser.add_option("-M", "--megabytes", type="eng_float", default=1.0,
87 help="set megabytes to transmit [default=%default]")
88 parser.add_option("","--discontinuous", action="store_true", default=False,
89 help="enable discontinous transmission (bursts of 5 packets)")
90 fusb_options.add_options(parser)
91 (options, args) = parser.parse_args ()
97 if options.freq < 1e6:
100 pkt_size = int(options.size)
103 'excess_bw' : options.excess_bw,
106 #FIXME: rework when static class defintions are ready for the modulation types
107 if(options.modulation=='bpsk'):
109 elif( options.modulation=='dbpsk'):
115 fg = my_graph(modulation,
116 options.tx_subdev_spec, options.bitrate, options.interp,
117 options.spb, options.gain,
120 print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.txpath.bitrate()),)
121 print "spb: %3d" % (fg.txpath.spb(),)
122 print "interp: %3d" % (fg.txpath.interp(),)
124 ok = fg.txpath.set_freq(options.freq)
126 print "Failed to set Tx frequency to %s" % (eng_notation.num_to_str(options.freq),)
129 r = gr.enable_realtime_scheduling()
131 print "Warning: failed to enable realtime scheduling"
133 fg.start() # start flow graph
135 # generate and send packets
136 nbytes = int(1e6 * options.megabytes)
141 send_pkt(struct.pack('!H', pktno) + (pkt_size - 2) * chr(pktno & 0xff))
143 sys.stderr.write('.')
144 if options.discontinuous and pktno % 5 == 4:
149 fg.wait() # wait for it to finish
150 fg.txpath.set_auto_tr(False)
153 if __name__ == '__main__':
156 except KeyboardInterrupt: