3 # Copyright 2007 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 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.
24 from optparse import OptionParser
26 from usb_packet import *
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()))
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]))
40 def dump_packets(infile, outfile, dump_payload):
41 raw_pkt = infile.read(512)
43 if len(raw_pkt) != 512:
44 sys.stderr.write("File length is not a multiple of 512 bytes")
47 dump_packet(raw_pkt, outfile, dump_payload)
48 raw_pkt = infile.read(512)
52 parser = OptionParser()
53 parser.add_option('-p', '--dump-payload', action='store_true', default=False,
54 help='dump payload in decimal and hex')
56 (options, files) = parser.parse_args()
58 dump_packets(sys.stdin, sys.stdout, options.dump_payload)
61 dump_packets(open(f, "r"), sys.stdout, options.dump_payload)
64 if __name__ == '__main__':