def _decode_event_mix_changed(self) -> EventMixChangeRecord: return EventMixChangeRecord( when=self.bit_array.get_int(4, 21), record_type=self.record_type, event_type=EventRecordType.Mix_Changed, o2=ByteConverter.to_uint8(self.record_data[2:3]), he=ByteConverter.to_uint8(self.record_data[3:4]), )
def _decode_event_key(self) -> EventKeyRecord: return EventKeyRecord( when=self.bit_array.get_int(4, 21), record_type=self.record_type, event_type=EventRecordType.Key_Down, key1=ByteConverter.to_bool(self.record_data[2:3]), key2=ByteConverter.to_bool(self.record_data[3:4]), )
def _decode_event_user_mark(self) -> EventUserMarkRecord: return EventUserMarkRecord( when=self.bit_array.get_int(4, 21), record_type=self.record_type, event_type=EventRecordType.User_Mark, order=ByteConverter.to_uint16(self.record_data[2:4]), category=ByteConverter.to_uint8(self.record_data[4:5]), )
def decode(self) -> PointRecord: bit_array_2 = BitArray(self.record_data[4:8]) return PointRecord( when=self.bit_array.get_int(4, 21), record_type=self.record_type, depth=ByteConverter.to_uint16(self.record_data[0:2]) / 100.00, ppo2=ByteConverter.to_uint16(self.record_data[2:4]) / 10000.00, no_deco_time=bit_array_2.get_int(0, 10) * 60, ascent_time=bit_array_2.get_int(10, 20) * 60, temperature=bit_array_2.get_int(20, 30) / 10.0, ceiling=ByteConverter.to_uint16(self.record_data[8:10]) / 100.0, he=self.record_data[10], )
def _decode_event_mode_change(self) -> Optional[EventChangeModeRecord]: try: dive_mode = DiveMode(ByteConverter.to_uint8(self.record_data[4:5])) except ValueError as e: logger.error(f"Unknown dive mode: {e}") return return EventChangeModeRecord( when=self.bit_array.get_int(4, 21), record_type=self.record_type, event_type=EventRecordType.Change_Mode, o2=ByteConverter.to_uint8(self.record_data[2:3]), he=ByteConverter.to_uint8(self.record_data[3:4]), measured=ByteConverter.to_bool(self.record_data[5:6]), mode=dive_mode, )
def _decode_event_cns(self) -> EventCnsRecord: return EventCnsRecord( when=self.bit_array.get_int(4, 21), record_type=self.record_type, event_type=EventRecordType.CNS, cns=ByteConverter.to_uint8(self.record_data[2:3]), )
def _decode_battery_measurement( self) -> Optional[MeasurementBatteryRecord]: volt, percentage, status = None, None, None if self.record_data[0] != 255: volt = ByteConverter.to_uint16(self.record_data[0:2]) / 1000.00 percentage = self.record_data[2] try: status = BatteryStats( ByteConverter.to_uint8(self.record_data[3:4])) except ValueError as e: logger.warning(f"Unknown battery status {e}") return return MeasurementBatteryRecord( when=self.bit_array.get_int(4, 21), record_type=self.record_type, measurement_type=MeasurementType.Battery, volt=volt, percentage=percentage, status=status, )
def _decode_version(self) -> ConfigurationVersionRecord: return ConfigurationVersionRecord( when=self.bit_array.get_int(4, 21), record_type=self.record_type, configuration_type=ConfigurationType.Version, device=ByteConverter.to_uint8(self.record_data[0:1]), hardware_major=ByteConverter.to_uint8(self.record_data[1:2]), hardware_minor=ByteConverter.to_uint8(self.record_data[2:3]), software_major=ByteConverter.to_uint8(self.record_data[3:4]), software_minor=ByteConverter.to_uint8(self.record_data[4:5]), software_patch=ByteConverter.to_uint8(self.record_data[5:6]), software_flags=ByteConverter.to_uint16(self.record_data[6:8]), software_build=ByteConverter.to_int16(self.record_data[8:10]), )
def _decode_event_start(self) -> Optional[EventStartRecord]: try: reason = DiveStartReason(ByteConverter.to_uint8(self.record_data[1:2])) except ValueError as e: logger.error(f"Unknown start reason {e}") return return EventStartRecord( when=self.bit_array.get_int(4, 21), record_type=self.record_type, event_type=EventRecordType.Start, reason=reason, )
def decode(self) -> Union[None, EventMixChangeRecord, EventStartRecord, EventKeyRecord, EventUserMarkRecord, EventCnsRecord, EventOccurrenceRecord, EventChangeModeRecord]: try: event_type = EventRecordType(ByteConverter.to_uint16(self.record_data[0:2])) except ValueError: logger.warning(f'Skipping decoding of event record ({self.record_data.hex()})') return if event_type == EventRecordType.Mix_Changed: return self._decode_event_mix_changed() elif event_type == EventRecordType.Start: return self._decode_event_start() elif event_type in [ EventRecordType.Too_Fast, EventRecordType.Above_Ceiling, EventRecordType.Toxic, EventRecordType.Above_Stop, EventRecordType.Safety_Miss, ]: return self._decode_event_occurrence(event_type) elif event_type == EventRecordType.Key_Down: return self._decode_event_key() elif event_type == EventRecordType.Change_Mode: return self._decode_event_mode_change() elif event_type == EventRecordType.User_Mark: return self._decode_event_user_mark() elif event_type == EventRecordType.CNS: return self._decode_event_cns() else: logger.error(f"Unknown event type: {event_type}")