[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5200 - gnuradio/branches/developers/eb/ibu/usrp/host/
From: |
eb |
Subject: |
[Commit-gnuradio] r5200 - gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband |
Date: |
Mon, 30 Apr 2007 23:29:55 -0600 (MDT) |
Author: eb
Date: 2007-04-30 23:29:55 -0600 (Mon, 30 Apr 2007)
New Revision: 5200
Added:
gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/dump_packets.py
gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/gen_test_packets.py
gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/usb_packet.py
Modified:
gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/Makefile.am
Log:
Added code to generate test packets for exercising fpga Tx testbench.
Also includes a packet dumper.
Modified: gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/Makefile.am
2007-04-30 23:49:40 UTC (rev 5199)
+++ gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/Makefile.am
2007-05-01 05:29:55 UTC (rev 5200)
@@ -26,7 +26,10 @@
EXTRA_DIST = \
- usrp_server.mbh
+ usrp_server.mbh \
+ dump_packets.py \
+ usb_packet.py \
+ gen_test_packets.py
noinst_LTLIBRARIES = libinband.la
Added: gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/dump_packets.py
===================================================================
--- gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/dump_packets.py
(rev 0)
+++ gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/dump_packets.py
2007-05-01 05:29:55 UTC (rev 5200)
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+import sys
+import struct
+from optparse import OptionParser
+
+from usb_packet import *
+
+def dump_packet(raw_pkt, outfile, dump_payload):
+ pkt = usb_packet(raw_pkt)
+ outfile.write(pkt.decoded_flags())
+ outfile.write(' chan= %2d len= %3d timestamp= 0x%08x rssi= % 2d tag=
%2d\n' % (
+ pkt.chan(), pkt.payload_len(), pkt.timestamp(), pkt.rssi(), pkt.tag()))
+ if dump_payload:
+ assert pkt.payload_len() % 4 == 0
+ shorts = struct.unpack('<%dh' % (pkt.payload_len() // 2),
pkt.payload())
+ for i in range(0, len(shorts), 2):
+ outfile.write(' %6d, %6d\n' % (shorts[i], shorts[i+1]))
+
+
+def dump_packets(infile, outfile, dump_payload):
+ raw_pkt = infile.read(512)
+ while raw_pkt:
+ if len(raw_pkt) != 512:
+ sys.stderr.write("File length is not a multiple of 512 bytes")
+ raise SystemExit, 1
+
+ dump_packet(raw_pkt, outfile, dump_payload)
+ raw_pkt = infile.read(512)
+
+
+def main():
+ parser = OptionParser()
+ parser.add_option('-p', '--dump-payload', action='store_true',
default=False,
+ help='dump payload in decimal and hex')
+
+ (options, files) = parser.parse_args()
+ if len(files) == 0:
+ dump_packets(sys.stdin, sys.stdout, options.dump_payload)
+ else:
+ for f in files:
+ dump_packets(open(f, "r"), sys.stdout, options.dump_payload)
+
+
+if __name__ == '__main__':
+ main()
Property changes on:
gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/dump_packets.py
___________________________________________________________________
Name: svn:executable
+ *
Added:
gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/gen_test_packets.py
===================================================================
---
gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/gen_test_packets.py
(rev 0)
+++
gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/gen_test_packets.py
2007-05-01 05:29:55 UTC (rev 5200)
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+
+import random
+import struct
+from pprint import pprint
+from usb_packet import *
+
+MAX_PAYLOAD = 504
+TIME_NOW = 0xffffffff
+
+
+class sequence_generator(object):
+ def __init__(self):
+ self.i = 0
+
+ def __call__(self):
+ t = self.i
+ self.i += 1
+ return t
+
+def gen_shuffled_lengths():
+ valid_lengths = range(0, MAX_PAYLOAD+1, 4) # [0, 4, 8, ... 504]
+ random.shuffle(valid_lengths)
+ return valid_lengths
+
+
+class packet_sequence_generator(object):
+ def __init__(self, channel, lengths):
+ self.next = sequence_generator()
+ self.channel = channel
+ self.lengths = lengths
+
+ def __call__(self, output_file):
+ gen_packet(output_file, self.channel, self.next, self.lengths[0])
+ del self.lengths[0]
+
+
+def gen_packet(output_file, channel, content_generator, payload_len):
+ assert (payload_len % 4) == 0
+ payload = []
+ n_iq = payload_len // 4
+ for n in range(n_iq):
+ payload.append(content_generator()) # I
+ payload.append(content_generator()) # Q
+ for n in range(MAX_PAYLOAD // 4 - n_iq):
+ payload.append(0x0000)
+ payload.append(0xffff)
+
+ assert (len(payload) == MAX_PAYLOAD // 2)
+
+ #print "\npayload_len =", payload_len
+ #pprint(payload)
+
+ output_file.write(make_header(FL_START_OF_BURST|FL_END_OF_BURST,
+ channel, payload_len, TIME_NOW))
+ output_file.write(struct.pack('<252h', *payload))
+
+
+def gen_all_valid_packet_lengths_1_channel(output_file):
+ lengths = gen_shuffled_lengths()
+ npkts = len(lengths) # number of packets we'll generator on
each stream
+ pkt_gen_0 = packet_sequence_generator(0, lengths)
+ for i in range(npkts):
+ pkt_gen_0(output_file)
+
+ assert pkt_gen_0.next() == 16002 # 2*sum(1, 2, ..., 126) == 126 * 127
+
+
+def gen_all_valid_packet_lengths_2_channels(output_file):
+ lengths = gen_shuffled_lengths()
+ npkts = len(lengths) # number of packets we'll generator on
each stream
+ pkt_gen_0 = packet_sequence_generator(0, lengths)
+ pkt_gen_1 = packet_sequence_generator(1, gen_shuffled_lengths())
+ pkt_gen = (pkt_gen_0, pkt_gen_1)
+
+ which_gen = (npkts * [0]) + (npkts * [1])
+ random.shuffle(which_gen)
+
+ for i in which_gen:
+ pkt_gen[i](output_file)
+
+ assert pkt_gen_0.next() == 16002 # 2*sum(1, 2, ..., 126) == 126 * 127
+ assert pkt_gen_1.next() == 16002 # 2*sum(1, 2, ..., 126) == 126 * 127
+
+if __name__ == '__main__':
+
gen_all_valid_packet_lengths_1_channel(open("all_valid_packet_lengths_1_channel.dat",
"w"))
+
gen_all_valid_packet_lengths_2_channels(open("all_valid_packet_lengths_2_channels.dat",
"w"))
Property changes on:
gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/gen_test_packets.py
___________________________________________________________________
Name: svn:executable
+ *
Added: gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/usb_packet.py
===================================================================
--- gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/usb_packet.py
(rev 0)
+++ gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband/usb_packet.py
2007-05-01 05:29:55 UTC (rev 5200)
@@ -0,0 +1,115 @@
+#
+# Copyright 2007 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+import struct
+
+
+FL_OVERRUN = 0x80000000
+FL_UNDERRUN = 0x40000000
+FL_DROPPED = 0x20000000
+FL_END_OF_BURST = 0x10000000
+FL_START_OF_BURST = 0x08000000
+
+FL_ALL_FLAGS = 0xf8000000
+
+FL_OVERRUN_SHIFT = 31
+FL_UNDERRUN_SHIFT = 30
+FL_DROPPED_SHIFT = 29
+FL_END_OF_BURST_SHIFT = 28
+FL_START_OF_BURST_SHIFT = 27
+
+RSSI_MASK = 0x3f
+RSSI_SHIFT = 21
+
+CHAN_MASK = 0x1f
+CHAN_SHIFT = 16
+
+TAG_MASK = 0xf
+TAG_SHIFT = 9
+
+PAYLOAD_LEN_MASK = 0x1ff
+PAYLOAD_LEN_SHIFT = 0
+
+def make_header(flags, chan, payload_len, timestamp, rssi=0, tag=0):
+ word0 = ((flags & FL_ALL_FLAGS)
+ | ((rssi & RSSI_MASK) << RSSI_SHIFT)
+ | ((chan & CHAN_MASK) << CHAN_SHIFT)
+ | ((tag & TAG_MASK) << TAG_SHIFT)
+ | ((payload_len & PAYLOAD_LEN_MASK) << PAYLOAD_LEN_SHIFT))
+ word1 = timestamp
+ return struct.pack('<2I', word0, word1)
+
+
+def _decode(pred, indicator):
+ if pred:
+ return indicator
+ else:
+ return '-'
+
+
+class usb_packet(object):
+ def __init__(self, raw_pkt):
+ assert isinstance(raw_pkt, str) and len(raw_pkt) == 512
+ self._raw_pkt = raw_pkt;
+ (self._word0, self._word1) = struct.unpack('<2I', self._raw_pkt[0:8])
+
+ def timestamp(self):
+ return self._word1
+
+ def rssi(self):
+ return (self._word0 >> RSSI_SHIFT) & RSSI_MASK
+
+ def chan(self):
+ return (self._word0 >> CHAN_SHIFT) & CHAN_MASK
+
+ def tag(self):
+ return (self._word0 >> TAG_SHIFT) & TAG_MASK
+
+ def payload_len(self):
+ return (self._word0 >> PAYLOAD_LEN_SHIFT) & PAYLOAD_LEN_MASK
+
+ def flags(self):
+ return self._word0 & FL_ALL_FLAGS
+
+ def overrun(self):
+ return (self._word0 >> FL_OVERRUN_SHIFT) & 0x1
+
+ def underrun(self):
+ return (self._word0 >> FL_UNDERRUN_SHIFT) & 0x1
+
+ def start_of_burst(self):
+ return (self._word0 >> FL_START_OF_BURST_SHIFT) & 0x1
+
+ def end_of_burst(self):
+ return (self._word0 >> FL_END_OF_BURST_SHIFT) & 0x1
+
+ def dropped(self):
+ return (self._word0 >> FL_DROPPED_SHIFT) & 0x1
+
+ def payload(self):
+ return self._raw_pkt[8:8+self.payload_len()]
+
+ def decoded_flags(self):
+ s = (_decode(self.overrun(), 'O')
+ + _decode(self.underrun(), 'U')
+ + _decode(self.dropped(), 'D')
+ + _decode(self.end_of_burst(), 'E')
+ + _decode(self.start_of_burst(), 'S'))
+ return s
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5200 - gnuradio/branches/developers/eb/ibu/usrp/host/lib/inband,
eb <=