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 ------ ####
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):
# 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
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))