class Event(object):
- # the event header consists of 8 words
+ # the Event header consists of 8 words
HEADERSIZE = WORDSIZE * 8
+ HEADER_FMT = '>8I'
def __init__(self, header_bytes, payload_bytes):
self.header_bytes = header_bytes
self.payload_bytes = payload_bytes
- struct_fmt = '<{:d}I'.format(Event.HEADERSIZE//WORDSIZE)
- self.header_words = struct.unpack(struct_fmt, header_bytes)
+ self.header_words = struct.unpack(self.HEADER_FMT, header_bytes)
self._set_properties(*self.header_words)
self.subevents = list(read_subevents(io.BytesIO(self.payload_bytes)))
class SubEvent(object):
- # the event header consists of 8 words
+ # the SubEvent header consists of 4 words
HEADERSIZE = WORDSIZE * 4
+ HEADER_FMT = '>4I'
def __init__(self, header_bytes, payload_bytes):
self.header_bytes = header_bytes
self.payload_bytes = payload_bytes
- struct_fmt = '>{:d}I'.format(SubEvent.HEADERSIZE//WORDSIZE)
- self.header_words = struct.unpack(struct_fmt, header_bytes)
+ self.header_words = struct.unpack(self.HEADER_FMT, header_bytes)
self._set_properties(*self.header_words)
+ self.subsubevents = list(read_subsubevents(io.BytesIO(self.payload_bytes)))
def _set_properties(self, size, decoding, id, trignr):
self.size = size
self.trignr = trignr
def __str__(self):
- fmt = "size: 0x{:08x} decoding: 0x{:08x} id: 0x{:08x} trignr: 0x{:08x}\n"
+ fmt = " |-> size: 0x{:08x} decoding: 0x{:08x} id: 0x{:08x} trignr: 0x{:08x}\n"
out = fmt.format(self.size, self.decoding, self.id, self.trignr)
+ #out += "\n"
+ #out += str_32bit_chunks(self.payload_bytes)
+ #out += "\n"
+ for subsubevent in self.subsubevents:
+ out += str(subsubevent)
+ return out
+
+class SubSubEvent(object):
+
+ # The SubSubEvent header consists of a single words
+ HEADERSIZE = WORDSIZE * 1
+ HEADER_FMT = '>HH'
+
+ def __init__(self, header_bytes, payload_bytes):
+ self.header_bytes = header_bytes
+ self.payload_bytes = payload_bytes
+ self.header_words = struct.unpack(self.HEADER_FMT, header_bytes)
+ self._set_properties(*self.header_words)
+
+ def _set_properties(self, size, address):
+ self.size = size
+ self.address = address
+
+ def __str__(self):
+ fmt = " |-> size: 0x{:04x} address: 0x{:04x}\n"
+ out = fmt.format(self.size, self.address)
out += "\n"
out += str_32bit_chunks(self.payload_bytes)
return out
while True:
header_bytes = subevents_stream.read(SubEvent.HEADERSIZE)
if len(header_bytes) < SubEvent.HEADERSIZE: break
- # The size of the event in bytes is given in the first data word of the event:
+ # The size of the subevent in bytes is given in the first data word:
size = struct.unpack('>I', header_bytes[:WORDSIZE])[0]
# We read already all bytes belonging to the header, so we need to subtract them
actual_num_bytes = size - SubEvent.HEADERSIZE
#pdb.set_trace()
yield SubEvent(header_bytes, data_bytes)
+def read_subsubevents(subsubevents_stream):
+ while True:
+ header_bytes = subsubevents_stream.read(SubSubEvent.HEADERSIZE)
+ if len(header_bytes) < SubSubEvent.HEADERSIZE: break
+ # The remaining size of the subsubevent in four-byte/32-bit words is given in the first two bytes:
+ size = struct.unpack('>HH', header_bytes[:WORDSIZE])[0]
+ data_bytes = subsubevents_stream.read(size*WORDSIZE)
+ #pdb.set_trace()
+ yield SubSubEvent(header_bytes, data_bytes)