3 # Copyright 2005,2006,2007,2009 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, modulation_utils
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
36 #raw_input('Attach and press enter')
38 class my_top_block(gr.top_block):
39 def __init__(self, modulator, options):
40 gr.top_block.__init__(self)
41 self.txpath = transmit_path(modulator, options)
42 self.connect(self.txpath)
44 # /////////////////////////////////////////////////////////////////////////////
46 # /////////////////////////////////////////////////////////////////////////////
50 def send_pkt(payload='', eof=False):
51 return tb.txpath.send_pkt(payload, eof)
53 def rx_callback(ok, payload):
54 print "ok = %r, payload = '%s'" % (ok, payload)
56 mods = modulation_utils.type_1_mods()
58 parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
59 expert_grp = parser.add_option_group("Expert")
61 parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
63 help="Select modulation from: %s [default=%%default]"
64 % (', '.join(mods.keys()),))
66 parser.add_option("-s", "--size", type="eng_float", default=1500,
67 help="set packet size [default=%default]")
68 parser.add_option("-M", "--megabytes", type="eng_float", default=1.0,
69 help="set megabytes to transmit [default=%default]")
70 parser.add_option("","--discontinuous", action="store_true", default=False,
71 help="enable discontinous transmission (bursts of 5 packets)")
72 parser.add_option("","--from-file", default=None,
73 help="use file for packet contents")
75 transmit_path.add_options(parser, expert_grp)
77 for mod in mods.values():
78 mod.add_options(expert_grp)
80 (options, args) = parser.parse_args ()
86 if options.tx_freq is None:
87 sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
88 parser.print_help(sys.stderr)
91 if options.from_file is not None:
92 source_file = open(options.from_file, 'r')
95 tb = my_top_block(mods[options.modulation], options)
97 r = gr.enable_realtime_scheduling()
99 print "Warning: failed to enable realtime scheduling"
101 tb.start() # start flow graph
103 # generate and send packets
104 nbytes = int(1e6 * options.megabytes)
107 pkt_size = int(options.size)
110 if options.from_file is None:
111 data = (pkt_size - 2) * chr(pktno & 0xff)
113 data = source_file.read(pkt_size - 2)
117 payload = struct.pack('!H', pktno & 0xffff) + data
120 sys.stderr.write('.')
121 if options.discontinuous and pktno % 5 == 4:
127 tb.wait() # wait for it to finish
129 if __name__ == '__main__':
132 except KeyboardInterrupt: