2 # Copyright 2007 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 FL_OVERRUN = 0x80000000
25 FL_UNDERRUN = 0x40000000
26 FL_DROPPED = 0x20000000
27 FL_END_OF_BURST = 0x10000000
28 FL_START_OF_BURST = 0x08000000
30 FL_ALL_FLAGS = 0xf8000000
33 FL_UNDERRUN_SHIFT = 30
35 FL_END_OF_BURST_SHIFT = 28
36 FL_START_OF_BURST_SHIFT = 27
47 PAYLOAD_LEN_MASK = 0x1ff
50 def make_header(flags, chan, payload_len, timestamp, rssi=0, tag=0):
51 word0 = ((flags & FL_ALL_FLAGS)
52 | ((rssi & RSSI_MASK) << RSSI_SHIFT)
53 | ((chan & CHAN_MASK) << CHAN_SHIFT)
54 | ((tag & TAG_MASK) << TAG_SHIFT)
55 | ((payload_len & PAYLOAD_LEN_MASK) << PAYLOAD_LEN_SHIFT))
57 return struct.pack('<2I', word0, word1)
60 def _decode(pred, indicator):
67 class usb_packet(object):
68 def __init__(self, raw_pkt):
69 assert isinstance(raw_pkt, str) and len(raw_pkt) == 512
70 self._raw_pkt = raw_pkt;
71 (self._word0, self._word1) = struct.unpack('<2I', self._raw_pkt[0:8])
77 return (self._word0 >> RSSI_SHIFT) & RSSI_MASK
80 return (self._word0 >> CHAN_SHIFT) & CHAN_MASK
83 return (self._word0 >> TAG_SHIFT) & TAG_MASK
85 def payload_len(self):
86 return (self._word0 >> PAYLOAD_LEN_SHIFT) & PAYLOAD_LEN_MASK
89 return self._word0 & FL_ALL_FLAGS
92 return (self._word0 >> FL_OVERRUN_SHIFT) & 0x1
95 return (self._word0 >> FL_UNDERRUN_SHIFT) & 0x1
97 def start_of_burst(self):
98 return (self._word0 >> FL_START_OF_BURST_SHIFT) & 0x1
100 def end_of_burst(self):
101 return (self._word0 >> FL_END_OF_BURST_SHIFT) & 0x1
104 return (self._word0 >> FL_DROPPED_SHIFT) & 0x1
107 return self._raw_pkt[8:8+self.payload_len()]
109 def decoded_flags(self):
110 s = (_decode(self.overrun(), 'O')
111 + _decode(self.underrun(), 'U')
112 + _decode(self.dropped(), 'D')
113 + _decode(self.end_of_burst(), 'E')
114 + _decode(self.start_of_burst(), 'S'))