Change default bandwidth to 25 MHz to match maximum USRP2 bandwidth
[debian/gnuradio] / usrp / limbo / inband / dump_packets.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2007 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
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)
10 # any later version.
11
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.
16
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #
21
22 import sys
23 import struct
24 from optparse import OptionParser
25
26 from usb_packet import *
27
28 def dump_packet(raw_pkt, outfile, dump_payload):
29     pkt = usb_packet(raw_pkt)
30     outfile.write(pkt.decoded_flags())
31     outfile.write(' chan= %2d  len= %3d timestamp= 0x%08x rssi= % 2d  tag= %2d\n' % (
32         pkt.chan(), pkt.payload_len(), pkt.timestamp(), pkt.rssi(), pkt.tag()))
33     if dump_payload:
34         assert pkt.payload_len() % 4 == 0
35         shorts = struct.unpack('<%dh' % (pkt.payload_len() // 2), pkt.payload())
36         for i in range(0, len(shorts), 2):
37             outfile.write('  %6d, %6d\n' % (shorts[i], shorts[i+1]))
38         
39
40 def dump_packets(infile, outfile, dump_payload):
41     raw_pkt = infile.read(512)
42     while raw_pkt:
43         if len(raw_pkt) != 512:
44             sys.stderr.write("File length is not a multiple of 512 bytes")
45             raise SystemExit, 1
46
47         dump_packet(raw_pkt, outfile, dump_payload)
48         raw_pkt = infile.read(512)
49
50
51 def main():
52     parser = OptionParser()
53     parser.add_option('-p', '--dump-payload', action='store_true', default=False,
54                       help='dump payload in decimal and hex')
55
56     (options, files) = parser.parse_args()
57     if len(files) == 0:
58         dump_packets(sys.stdin, sys.stdout, options.dump_payload)
59     else:
60         for f in files:
61             dump_packets(open(f, "r"), sys.stdout, options.dump_payload)
62
63
64 if __name__ == '__main__':
65     main()