~ubuntu-branches/ubuntu/precise/gnuradio/precise

« back to all changes in this revision

Viewing changes to gnuradio-examples/python/digital/benchmark_tx.py

  • Committer: Bazaar Package Importer
  • Author(s): Kamal Mostafa
  • Date: 2010-03-13 07:46:01 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100313074601-zjsa893a87bozyh7
Tags: 3.2.2.dfsg-1ubuntu1
* Fix build for Ubuntu lucid (LP: #260406)
  - add binary package dep for libusrp0, libusrp2-0: adduser
  - debian/rules clean: remove pre-built Qt moc files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
#
3
 
# Copyright 2005, 2006 Free Software Foundation, Inc.
 
3
# Copyright 2005,2006,2007,2009 Free Software Foundation, Inc.
4
4
5
5
# This file is part of GNU Radio
6
6
29
29
import random, time, struct, sys
30
30
 
31
31
# from current dir
32
 
from transmit_path import transmit_path
33
 
import fusb_options
 
32
import usrp_transmit_path
34
33
 
35
34
#import os 
36
35
#print os.getpid()
37
36
#raw_input('Attach and press enter')
38
37
 
39
 
 
40
 
class my_graph(gr.flow_graph):
41
 
    def __init__(self, modulator_class, options):
42
 
        gr.flow_graph.__init__(self)
43
 
        self.txpath = transmit_path(self, modulator_class, options)
44
 
 
 
38
class my_top_block(gr.top_block):
 
39
    def __init__(self, modulator, options):
 
40
        gr.top_block.__init__(self)
 
41
 
 
42
        self.txpath = usrp_transmit_path.usrp_transmit_path(modulator, options)
 
43
 
 
44
        self.connect(self.txpath)
45
45
 
46
46
# /////////////////////////////////////////////////////////////////////////////
47
47
#                                   main
50
50
def main():
51
51
 
52
52
    def send_pkt(payload='', eof=False):
53
 
        return fg.txpath.send_pkt(payload, eof)
 
53
        return tb.txpath.send_pkt(payload, eof)
54
54
 
55
55
    def rx_callback(ok, payload):
56
56
        print "ok = %r, payload = '%s'" % (ok, payload)
71
71
                      help="set megabytes to transmit [default=%default]")
72
72
    parser.add_option("","--discontinuous", action="store_true", default=False,
73
73
                      help="enable discontinous transmission (bursts of 5 packets)")
 
74
    parser.add_option("","--from-file", default=None,
 
75
                      help="use file for packet contents")
74
76
 
75
 
    transmit_path.add_options(parser, expert_grp)
 
77
    usrp_transmit_path.add_options(parser, expert_grp)
76
78
 
77
79
    for mod in mods.values():
78
80
        mod.add_options(expert_grp)
79
81
 
80
 
    fusb_options.add_options(expert_grp)
81
82
    (options, args) = parser.parse_args ()
82
83
 
83
84
    if len(args) != 0:
89
90
        parser.print_help(sys.stderr)
90
91
        sys.exit(1)
91
92
 
 
93
    if options.from_file is not None:
 
94
        source_file = open(options.from_file, 'r')
 
95
 
92
96
    # build the graph
93
 
    fg = my_graph(mods[options.modulation], options)
 
97
    tb = my_top_block(mods[options.modulation], options)
94
98
 
95
99
    r = gr.enable_realtime_scheduling()
96
100
    if r != gr.RT_OK:
97
101
        print "Warning: failed to enable realtime scheduling"
98
102
 
99
 
    fg.start()                       # start flow graph
100
 
 
101
 
 
 
103
    tb.start()                       # start flow graph
 
104
        
102
105
    # generate and send packets
103
106
    nbytes = int(1e6 * options.megabytes)
104
107
    n = 0
106
109
    pkt_size = int(options.size)
107
110
 
108
111
    while n < nbytes:
109
 
        send_pkt(struct.pack('!H', pktno) + (pkt_size - 2) * chr(pktno & 0xff))
110
 
        n += pkt_size
 
112
        if options.from_file is None:
 
113
            data = (pkt_size - 2) * chr(pktno & 0xff) 
 
114
        else:
 
115
            data = source_file.read(pkt_size - 2)
 
116
            if data == '':
 
117
                break;
 
118
 
 
119
        payload = struct.pack('!H', pktno & 0xffff) + data
 
120
        send_pkt(payload)
 
121
        n += len(payload)
111
122
        sys.stderr.write('.')
112
123
        if options.discontinuous and pktno % 5 == 4:
113
124
            time.sleep(1)
114
125
        pktno += 1
115
126
        
116
127
    send_pkt(eof=True)
117
 
    fg.wait()                       # wait for it to finish
 
128
 
 
129
    tb.wait()                       # wait for it to finish
118
130
 
119
131
if __name__ == '__main__':
120
132
    try: