From cfb8769ab38859ab2cbc3dc1655a4f26024a3a4c Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Wed, 29 Oct 2014 17:15:38 +0100 Subject: [PATCH] unpack_mvd: better integration of scurve frames --- .../mvd_unpacker/unpacker.py | 32 +++++++++++++------ .../python_mvd_unpacker/mvd_unpacker/utils.py | 14 ++++++++ tools/python_mvd_unpacker/scripts/unpack_mvd | 7 ++-- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/tools/python_mvd_unpacker/mvd_unpacker/unpacker.py b/tools/python_mvd_unpacker/mvd_unpacker/unpacker.py index 1a94c66..0ad8187 100644 --- a/tools/python_mvd_unpacker/mvd_unpacker/unpacker.py +++ b/tools/python_mvd_unpacker/mvd_unpacker/unpacker.py @@ -10,7 +10,7 @@ import struct import pdb import io -from .utils import split_by_n, str_32bit_chunks +from .utils import split_by_n, str_32bit_chunks, bits_set_count #### ------ Definitions for M-26 data ------ #### @@ -82,10 +82,14 @@ class FrameMessage(object): self.data_type = data_type self.data_bytes = data_bytes self._interpret() + self._check() def _interpret(self): pass + def _check(self): + pass + class Frame_Message_01(FrameMessage): def _interpret(self): @@ -119,17 +123,25 @@ class Frame_Message_C0(FrameMessage): # everything else is testmode data self.sensor_data = self.data_bytes[2*4:] + def _check(self): + if self.occupancy > 1.0: pdb.set_trace() + + @property + def occupancy(self): + try: + return self._occupancy + except: + self._occupancy = bits_set_count(self.sensor_data) / (len(self.sensor_data) * 8.0) * 4.0 + return self._occupancy + def __str__(self): - fmt = "static init: 0x{:08x} format version: 0x{:04x} testmode: 0x{:04x}\n" - out = fmt.format(self.init, self.format_version, self.testmode) - fmt = "id: 0x{:08x} status: 0x{:08x} h5: 0x{:08x}\n" - out += fmt.format(self.id, self.status, self.h5) - #fmt = "h6: 0x{:08x} external: 0x{:08x} frame_num: 0x{:08x}\n" - #out += fmt.format(self.h6, self.external, self.frame_num) - fmt = "h6: 0x{:08x} threshold: 0x{:04x} run: 0x{:04x} row: 0x{:04x}\n" - out += fmt.format(self.h6, self.threshold, self.run, self.row) + fmt = "frame length: 0x{:04x} sensor id: 0x{:02x}\n" + out = fmt.format(self.frame_length, self.sensor_id) + fmt = "bank: {} row: {} threshold: {} run: {}\n" + out += fmt.format(self.bank, self.row, self.threshold, self.run) out += "\n" - out += str_32bit_chunks(self.payload_bytes) + out += "Occupancy: {:.2f}".format(self.occupancy) + #out += str_32bit_chunks(self.sensor_data) out += "\n" return out diff --git a/tools/python_mvd_unpacker/mvd_unpacker/utils.py b/tools/python_mvd_unpacker/mvd_unpacker/utils.py index 93057fb..8682cfd 100644 --- a/tools/python_mvd_unpacker/mvd_unpacker/utils.py +++ b/tools/python_mvd_unpacker/mvd_unpacker/utils.py @@ -28,3 +28,17 @@ def str_32bit_chunks(data): i += int(wordlength/2) * words_per_line return out +def bits_set_count(x): + """ + Accepts bytes as input and returns the number of bits set in the bytes. + """ + if type(x) == bytes: + sum = 0 + for b in x: + sum += bin(b).count('1') + return sum + if type(x) == int: + return bin(x).count('1') + else: + raise TypeError() + diff --git a/tools/python_mvd_unpacker/scripts/unpack_mvd b/tools/python_mvd_unpacker/scripts/unpack_mvd index a1fac8f..b6e0315 100644 --- a/tools/python_mvd_unpacker/scripts/unpack_mvd +++ b/tools/python_mvd_unpacker/scripts/unpack_mvd @@ -15,16 +15,19 @@ def main(): help='HLD file with M26 data to unpack') args = parser.parse_args() + frame_count = 0 for event in read(args.hldfile): for subevent in event.subevents: for subsubevent in subevent.subsubevents: if not len(subsubevent.payload_bytes): continue if subsubevent.address == 0x5555: continue roc_message = read_ROC_Message(subsubevent.payload_bytes) - print(roc_message.payload_bytes) try: roc_message = read_ROC_Message(subsubevent.payload_bytes) - print(roc_message.frames) + for frame in roc_message.frames: + if not (frame_count % 10000): + print(frame) + frame_count += 1 except: print("Not a ROC message (?):") print(str_32bit_chunks(subsubevent.payload_bytes)) -- 2.43.0