From 9752270b6c70fe3ca3b009844a0ecfb99c7705ba Mon Sep 17 00:00:00 2001 From: James Woglom Date: Sat, 21 Sep 2024 17:16:40 -0400 Subject: [PATCH] eventparser: fix parsing --- tconnectsync/eventparser/build_events.py | 11 +- tconnectsync/eventparser/events.py | 918 ++++++++++++++++------- tconnectsync/eventparser/generic.py | 8 +- tconnectsync/eventparser/raw_event.py | 18 +- tconnectsync/eventparser/transforms.py | 17 +- 5 files changed, 702 insertions(+), 270 deletions(-) diff --git a/tconnectsync/eventparser/build_events.py b/tconnectsync/eventparser/build_events.py index 9927d52..1a492cd 100644 --- a/tconnectsync/eventparser/build_events.py +++ b/tconnectsync/eventparser/build_events.py @@ -35,8 +35,9 @@ TYPE_TO_PYOBJ = { 'float32': 'float', } +HEADER_SIZE = 10 def unpack_command_for(field_def): - return f'struct.unpack_from({field_def["type"].upper()}, raw[:EVENT_LEN], {field_def["offset"]})' + return f'struct.unpack_from({field_def["type"].upper()}, raw[:EVENT_LEN], {HEADER_SIZE + field_def["offset"]})' TEMPLATE = ''' @dataclass @@ -58,6 +59,14 @@ class {name}(BaseEvent): {build_p2} ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + ''' def firstLower(text): diff --git a/tconnectsync/eventparser/events.py b/tconnectsync/eventparser/events.py index a1ab44d..c8402de 100644 --- a/tconnectsync/eventparser/events.py +++ b/tconnectsync/eventparser/events.py @@ -59,11 +59,11 @@ class LidBasalRateChange(BaseEvent): @staticmethod def build(raw): - commandedbasalrate, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 0) - basebasalrate, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 4) - maxbasalrate, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 8) - IDP, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) - changetype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + commandedbasalrate, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 10) + basebasalrate, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 14) + maxbasalrate, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 18) + IDP, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 24) + changetype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 23) return LidBasalRateChange( raw = RawEvent.build(raw), @@ -74,6 +74,14 @@ class LidBasalRateChange(BaseEvent): changetypeRaw = changetype, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidAlertActivated(BaseEvent): @@ -224,10 +232,10 @@ class LidAlertActivated(BaseEvent): @staticmethod def build(raw): - alertid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - param1, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - param2, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 12) + alertid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + param1, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + param2, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 22) return LidAlertActivated( raw = RawEvent.build(raw), @@ -237,6 +245,14 @@ class LidAlertActivated(BaseEvent): param2 = param2, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidAlarmActivated(BaseEvent): @@ -389,10 +405,10 @@ class LidAlarmActivated(BaseEvent): @staticmethod def build(raw): - alarmid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - param1, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - param2, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 12) + alarmid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + param1, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + param2, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 22) return LidAlarmActivated( raw = RawEvent.build(raw), @@ -402,6 +418,14 @@ class LidAlarmActivated(BaseEvent): param2 = param2, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidMalfunctionActivated(BaseEvent): @@ -418,10 +442,10 @@ class LidMalfunctionActivated(BaseEvent): # Dictionary unknown: malfs @staticmethod def build(raw): - malfid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - param1, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - param2, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 12) + malfid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + param1, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + param2, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 22) return LidMalfunctionActivated( raw = RawEvent.build(raw), @@ -431,6 +455,14 @@ class LidMalfunctionActivated(BaseEvent): param2 = param2, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidPumpingSuspended(BaseEvent): @@ -463,10 +495,10 @@ class LidPumpingSuspended(BaseEvent): @staticmethod def build(raw): - presuspendstate, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - insulinamount, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 6) - suspendreason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 5) - rpatimeout, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 4) + presuspendstate, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + insulinamount, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 16) + suspendreason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 15) + rpatimeout, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 14) return LidPumpingSuspended( raw = RawEvent.build(raw), @@ -476,6 +508,14 @@ class LidPumpingSuspended(BaseEvent): rpatimeout = rpatimeout, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidPumpingResumed(BaseEvent): @@ -490,8 +530,8 @@ class LidPumpingResumed(BaseEvent): @staticmethod def build(raw): - preresumestate, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - insulinamount, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 6) + preresumestate, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + insulinamount, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 16) return LidPumpingResumed( raw = RawEvent.build(raw), @@ -499,6 +539,14 @@ class LidPumpingResumed(BaseEvent): insulinamount = insulinamount, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidTimeChanged(BaseEvent): @@ -514,9 +562,9 @@ class LidTimeChanged(BaseEvent): @staticmethod def build(raw): - timeprior, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - timeafter, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - rawrtctime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) + timeprior, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + timeafter, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + rawrtctime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) return LidTimeChanged( raw = RawEvent.build(raw), @@ -525,6 +573,14 @@ class LidTimeChanged(BaseEvent): rawrtctime = rawrtctime, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidDateChanged(BaseEvent): @@ -540,9 +596,9 @@ class LidDateChanged(BaseEvent): @staticmethod def build(raw): - dateprior, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - dateafter, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - rawrtctime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) + dateprior, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + dateafter, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + rawrtctime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) return LidDateChanged( raw = RawEvent.build(raw), @@ -551,6 +607,14 @@ class LidDateChanged(BaseEvent): rawrtctime = rawrtctime, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidBgReadingTaken(BaseEvent): @@ -622,14 +686,14 @@ class LidBgReadingTaken(BaseEvent): @staticmethod def build(raw): - selectediob, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 15) - BG, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - bgentrytype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 0) - IOB, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 4) - targetbg, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 10) - ISF, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 8) - bgsourcetype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 14) - cgmcalibration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 1) + selectediob, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 25) + BG, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + bgentrytype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 10) + IOB, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 14) + targetbg, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 20) + ISF, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 18) + bgsourcetype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 24) + cgmcalibration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) return LidBgReadingTaken( raw = RawEvent.build(raw), @@ -643,6 +707,14 @@ class LidBgReadingTaken(BaseEvent): cgmcalibrationRaw = cgmcalibration, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidBolusCompleted(BaseEvent): @@ -674,11 +746,8 @@ class LidBolusCompleted(BaseEvent): TerminatedByAlarm = 1 TerminatedByMalfunction = 2 Completed = 3 - Reserved = 4 BolusRejected = 5 AbortedByPlgs = 6 - Reserved = 7 - Reserved = 8 @property def completionstatus(self): @@ -686,11 +755,11 @@ class LidBolusCompleted(BaseEvent): @staticmethod def build(raw): - completionstatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 0) - insulindelivered, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 8) - insulinrequested, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 12) - IOB, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 4) + completionstatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 10) + insulindelivered, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 18) + insulinrequested, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 22) + IOB, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 14) return LidBolusCompleted( raw = RawEvent.build(raw), @@ -701,6 +770,14 @@ class LidBolusCompleted(BaseEvent): IOB = IOB, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidBolexCompleted(BaseEvent): @@ -732,11 +809,8 @@ class LidBolexCompleted(BaseEvent): TerminatedByAlarm = 1 TerminatedByMalfunction = 2 Completed = 3 - Reserved = 4 BolusRejected = 5 AbortedByPlgs = 6 - Reserved = 7 - Reserved = 8 @property def completionstatus(self): @@ -744,11 +818,11 @@ class LidBolexCompleted(BaseEvent): @staticmethod def build(raw): - completionstatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 0) - insulindelivered, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 8) - insulinrequested, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 12) - IOB, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 4) + completionstatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 10) + insulindelivered, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 18) + insulinrequested, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 22) + IOB, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 14) return LidBolexCompleted( raw = RawEvent.build(raw), @@ -759,6 +833,14 @@ class LidBolexCompleted(BaseEvent): IOB = IOB, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidAlertCleared(BaseEvent): @@ -907,8 +989,8 @@ class LidAlertCleared(BaseEvent): @staticmethod def build(raw): - alertid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) + alertid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) return LidAlertCleared( raw = RawEvent.build(raw), @@ -916,6 +998,14 @@ class LidAlertCleared(BaseEvent): faultlocatordata = faultlocatordata, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidAlarmCleared(BaseEvent): @@ -1065,13 +1155,21 @@ class LidAlarmCleared(BaseEvent): @staticmethod def build(raw): - alarmid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) + alarmid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) return LidAlarmCleared( raw = RawEvent.build(raw), alarmidRaw = alarmid, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCartridgeFilled(BaseEvent): @@ -1086,8 +1184,8 @@ class LidCartridgeFilled(BaseEvent): @staticmethod def build(raw): - insulinvolume, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - v2Volume, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 4) + insulinvolume, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + v2Volume, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 14) return LidCartridgeFilled( raw = RawEvent.build(raw), @@ -1095,6 +1193,14 @@ class LidCartridgeFilled(BaseEvent): v2Volume = v2Volume, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidShelfMode(BaseEvent): @@ -1113,12 +1219,12 @@ class LidShelfMode(BaseEvent): @staticmethod def build(raw): - msecsincereset, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - lipocurrent, = struct.unpack_from(INT16, raw[:EVENT_LEN], 6) - lipoAbc, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 5) - lipoIbc, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 4) - lipoRemcap, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - lipoMv, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 12) + msecsincereset, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + lipocurrent, = struct.unpack_from(INT16, raw[:EVENT_LEN], 16) + lipoAbc, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 15) + lipoIbc, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 14) + lipoRemcap, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + lipoMv, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 22) return LidShelfMode( raw = RawEvent.build(raw), @@ -1130,6 +1236,14 @@ class LidShelfMode(BaseEvent): lipoMv = lipoMv, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidBolusActivated(BaseEvent): @@ -1158,10 +1272,10 @@ class LidBolusActivated(BaseEvent): @staticmethod def build(raw): - selectediob, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 1) - bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - IOB, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 4) - bolussize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 8) + selectediob, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) + bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + IOB, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 14) + bolussize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 18) return LidBolusActivated( raw = RawEvent.build(raw), @@ -1171,6 +1285,14 @@ class LidBolusActivated(BaseEvent): bolussize = bolussize, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidBolexActivated(BaseEvent): @@ -1199,10 +1321,10 @@ class LidBolexActivated(BaseEvent): @staticmethod def build(raw): - selectediob, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 1) - bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - IOB, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 4) - bolexsize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 8) + selectediob, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) + bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + IOB, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 14) + bolexsize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 18) return LidBolexActivated( raw = RawEvent.build(raw), @@ -1212,6 +1334,14 @@ class LidBolexActivated(BaseEvent): bolexsize = bolexsize, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidDataLogCorruption(BaseEvent): @@ -1226,8 +1356,8 @@ class LidDataLogCorruption(BaseEvent): @staticmethod def build(raw): - block, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - reason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 7) + block, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + reason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 17) return LidDataLogCorruption( raw = RawEvent.build(raw), @@ -1235,6 +1365,14 @@ class LidDataLogCorruption(BaseEvent): reason = reason, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCannulaFilled(BaseEvent): @@ -1265,8 +1403,8 @@ class LidCannulaFilled(BaseEvent): @staticmethod def build(raw): - primesize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 0) - completionstatus, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) + primesize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 10) + completionstatus, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) return LidCannulaFilled( raw = RawEvent.build(raw), @@ -1274,6 +1412,14 @@ class LidCannulaFilled(BaseEvent): completionstatusRaw = completionstatus, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidTubingFilled(BaseEvent): @@ -1305,9 +1451,9 @@ class LidTubingFilled(BaseEvent): @staticmethod def build(raw): - primesize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 0) - completionstatus, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - position, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) + primesize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 10) + completionstatus, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + position, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) return LidTubingFilled( raw = RawEvent.build(raw), @@ -1316,6 +1462,14 @@ class LidTubingFilled(BaseEvent): position = position, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidBolusRequestedMsg1(BaseEvent): @@ -1368,13 +1522,13 @@ class LidBolusRequestedMsg1(BaseEvent): @staticmethod def build(raw): - bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - bolustype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 1) - correctionbolusincluded, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 0) - carbamount, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 6) - BG, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 4) - carbratio, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 12) - IOB, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 8) + bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + bolustype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) + correctionbolusincluded, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 10) + carbamount, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 16) + BG, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) + carbratio, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 22) + IOB, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 18) return LidBolusRequestedMsg1( raw = RawEvent.build(raw), @@ -1387,6 +1541,14 @@ class LidBolusRequestedMsg1(BaseEvent): IOB = IOB, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidBolusRequestedMsg2(BaseEvent): @@ -1471,15 +1633,15 @@ class LidBolusRequestedMsg2(BaseEvent): @staticmethod def build(raw): - selectediob, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) - bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - options, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 1) - standardpercent, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 0) - duration, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 6) - ISF, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 10) - targetbg, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 8) - useroverride, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 15) - declinedcorrection, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 14) + selectediob, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 23) + bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + options, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) + standardpercent, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 10) + duration, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 16) + ISF, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 20) + targetbg, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 18) + useroverride, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 25) + declinedcorrection, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 24) return LidBolusRequestedMsg2( raw = RawEvent.build(raw), @@ -1494,6 +1656,14 @@ class LidBolusRequestedMsg2(BaseEvent): declinedcorrectionRaw = declinedcorrection, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidBolusRequestedMsg3(BaseEvent): @@ -1510,10 +1680,10 @@ class LidBolusRequestedMsg3(BaseEvent): @staticmethod def build(raw): - bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - foodbolussize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 4) - correctionbolussize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 8) - totalbolussize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 12) + bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + foodbolussize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 14) + correctionbolussize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 18) + totalbolussize, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 22) return LidBolusRequestedMsg3( raw = RawEvent.build(raw), @@ -1523,6 +1693,14 @@ class LidBolusRequestedMsg3(BaseEvent): totalbolussize = totalbolussize, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidNewDay(BaseEvent): @@ -1538,9 +1716,9 @@ class LidNewDay(BaseEvent): @staticmethod def build(raw): - commandedbasalrate, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 0) - featuresbitmask, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - featurebitmaskindex, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) + commandedbasalrate, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 10) + featuresbitmask, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + featurebitmaskindex, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) return LidNewDay( raw = RawEvent.build(raw), @@ -1549,6 +1727,14 @@ class LidNewDay(BaseEvent): featurebitmaskindex = featurebitmaskindex, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidArmInit(BaseEvent): @@ -1565,10 +1751,10 @@ class LidArmInit(BaseEvent): @staticmethod def build(raw): - version, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - configabits, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - configbbits, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - numlogentries, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 12) + version, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + configabits, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + configbbits, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + numlogentries, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 22) return LidArmInit( raw = RawEvent.build(raw), @@ -1578,6 +1764,14 @@ class LidArmInit(BaseEvent): numlogentries = numlogentries, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidPlgsPeriodic(BaseEvent): @@ -1685,13 +1879,13 @@ class LidPlgsPeriodic(BaseEvent): SuspendCurrent = 2**1 ResumeEgvRise = 2**4 ResumeNadirLock = 2**6 - Unavailable = 2**7 - Unavailable = 2**8 - Unavailable = 2**9 - Unavailable = 2**10 - Unavailable = 2**11 - Unavailable = 2**12 - Unavailable = 2**13 + Unavailabletimesmall = 2**7 + Unavailablesuspendoverride = 2**8 + Unavailablecgmoff = 2**9 + Unavailablehighegv = 2**10 + Unavailablenottherapy = 2**11 + Unavailablebolusactive = 2**12 + Unavailablenocurrent = 2**13 @property def status(self): @@ -1699,14 +1893,14 @@ class LidPlgsPeriodic(BaseEvent): @staticmethod def build(raw): - timestamp, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - FMR, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 6) - PGV, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 4) - fmrstatus, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) - pgvvalid, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 10) - rulestate, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 9) - hominstate, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 8) - status, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 12) + timestamp, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + FMR, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 16) + PGV, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) + fmrstatus, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 21) + pgvvalid, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 20) + rulestate, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 19) + hominstate, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 18) + status, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 22) return LidPlgsPeriodic( raw = RawEvent.build(raw), @@ -1720,6 +1914,14 @@ class LidPlgsPeriodic(BaseEvent): statusRaw = status, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmAlertActivated(BaseEvent): @@ -1736,10 +1938,10 @@ class LidCgmAlertActivated(BaseEvent): # Dictionary unknown: dalerts @staticmethod def build(raw): - dalertid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - param1, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - param2, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 12) + dalertid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + param1, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + param2, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 22) return LidCgmAlertActivated( raw = RawEvent.build(raw), @@ -1749,6 +1951,14 @@ class LidCgmAlertActivated(BaseEvent): param2 = param2, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmAlertCleared(BaseEvent): @@ -1762,13 +1972,21 @@ class LidCgmAlertCleared(BaseEvent): # Dictionary unknown: dalerts @staticmethod def build(raw): - dalertid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) + dalertid, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) return LidCgmAlertCleared( raw = RawEvent.build(raw), dalertidRaw = dalertid, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidVersionInfo(BaseEvent): @@ -1785,10 +2003,10 @@ class LidVersionInfo(BaseEvent): @staticmethod def build(raw): - version, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - configabits, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - configbbits, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - armcrc, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) + version, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + configabits, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + configbbits, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + armcrc, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 24) return LidVersionInfo( raw = RawEvent.build(raw), @@ -1798,6 +2016,14 @@ class LidVersionInfo(BaseEvent): armcrc = armcrc, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidUpdateStatus(BaseEvent): @@ -1829,13 +2055,13 @@ class LidUpdateStatus(BaseEvent): @staticmethod def build(raw): - swupdatestatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - metadataandversionstatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 0) - fulldlandcrcstatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 6) - filedlandsideloadstatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 4) - externalflashstatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 10) - updatesuccessful, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 9) - swpartnum, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 12) + swupdatestatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + metadataandversionstatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 10) + fulldlandcrcstatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 16) + filedlandsideloadstatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) + externalflashstatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 20) + updatesuccessful, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 19) + swpartnum, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 22) return LidUpdateStatus( raw = RawEvent.build(raw), @@ -1848,6 +2074,14 @@ class LidUpdateStatus(BaseEvent): swpartnum = swpartnum, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmStartSessionGx(BaseEvent): @@ -1863,9 +2097,9 @@ class LidCgmStartSessionGx(BaseEvent): @staticmethod def build(raw): - currenttransmittertime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 15) + currenttransmittertime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 25) return LidCgmStartSessionGx( raw = RawEvent.build(raw), @@ -1874,6 +2108,14 @@ class LidCgmStartSessionGx(BaseEvent): sessionduration = sessionduration, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmJoinSessionGx(BaseEvent): @@ -1907,12 +2149,10 @@ class LidCgmJoinSessionGx(BaseEvent): class SessionjoinreasonEnum(Enum): DexblesReasonUser = 0 DexblesReasonUnknown = 1 - Reserved = 2 DexblesReasonTxEndOfLife = 3 DexblesReasonTransmitterError = 4 DexblesReasonSessionStopSuccess = 5 DexblesReasonTransmitterNotInSession = 6 - Reserved = 7 DexblesReasonNewSessionStartedSuccess = 8 DexblesReasonSessionStartedInProgress = 9 DexblesReasonTransmitterInSession = 10 @@ -1926,10 +2166,10 @@ class LidCgmJoinSessionGx(BaseEvent): @staticmethod def build(raw): - currenttransmittertime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 15) - sessionjoinreason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 14) + currenttransmittertime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 25) + sessionjoinreason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 24) return LidCgmJoinSessionGx( raw = RawEvent.build(raw), @@ -1939,6 +2179,14 @@ class LidCgmJoinSessionGx(BaseEvent): sessionjoinreasonRaw = sessionjoinreason, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmStopSessionGx(BaseEvent): @@ -1973,12 +2221,10 @@ class LidCgmStopSessionGx(BaseEvent): class SessionstopreasonEnum(Enum): DexblesReasonUser = 0 DexblesReasonUnknown = 1 - Reserved = 2 DexblesReasonTxEndOfLife = 3 DexblesReasonTransmitterError = 4 DexblesReasonSessionStopSuccess = 5 DexblesReasonTransmitterNotInSession = 6 - Reserved = 7 DexblesReasonNewSessionStartedSuccess = 8 DexblesReasonSessionStartedInProgress = 9 DexblesReasonTransmitterInSession = 10 @@ -1992,11 +2238,11 @@ class LidCgmStopSessionGx(BaseEvent): @staticmethod def build(raw): - currenttransmittertime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - sessionstoptime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 15) - sessionstopreason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 14) + currenttransmittertime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + sessionstoptime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 25) + sessionstopreason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 24) return LidCgmStopSessionGx( raw = RawEvent.build(raw), @@ -2007,6 +2253,14 @@ class LidCgmStopSessionGx(BaseEvent): sessionstopreasonRaw = sessionstopreason, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidAaUserModeChange(BaseEvent): @@ -2155,15 +2409,15 @@ class LidAaUserModeChange(BaseEvent): @staticmethod def build(raw): - exercisechoice, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 10) - exercisetime, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 8) - currentusermode, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 3) - previoususermode, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 2) - requestedaction, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 1) - sleepstartedbygui, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 7) - exercisestoppedbytimer, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) - activesleepschedule, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 6) - eatingsoonstoppedbytimer, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 15) + exercisechoice, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 20) + exercisetime, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 18) + currentusermode, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + previoususermode, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 12) + requestedaction, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) + sleepstartedbygui, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 17) + exercisestoppedbytimer, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 21) + activesleepschedule, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 16) + eatingsoonstoppedbytimer, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 25) return LidAaUserModeChange( raw = RawEvent.build(raw), @@ -2178,6 +2432,14 @@ class LidAaUserModeChange(BaseEvent): eatingsoonstoppedbytimerRaw = eatingsoonstoppedbytimer, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidAaPcmChange(BaseEvent): @@ -2295,13 +2557,13 @@ class LidAaPcmChange(BaseEvent): @staticmethod def build(raw): - currentpcm, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 3) - previouspcm, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 2) - pumpsuspended, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 1) - calculationavailable, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 0) - cgmavailable, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 7) - closedlooppreferred, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 6) - sufficientclosedloopparams, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 5) + currentpcm, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + previouspcm, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 12) + pumpsuspended, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) + calculationavailable, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 10) + cgmavailable, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 17) + closedlooppreferred, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 16) + sufficientclosedloopparams, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 15) return LidAaPcmChange( raw = RawEvent.build(raw), @@ -2314,6 +2576,14 @@ class LidAaPcmChange(BaseEvent): sufficientclosedloopparamsRaw = sufficientclosedloopparams, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmDataGxb(BaseEvent): @@ -2399,15 +2669,15 @@ class LidCgmDataGxb(BaseEvent): @staticmethod def build(raw): - glucosevaluestatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - cgmDataType, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 1) - rate, = struct.unpack_from(INT8, raw[:EVENT_LEN], 0) - algorithmstate, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 7) - RSSI, = struct.unpack_from(INT8, raw[:EVENT_LEN], 6) - currentglucosedisplayvalue, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 4) - egvTimestamp, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - egvInfoBitmask, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) - interval, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + glucosevaluestatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + cgmDataType, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) + rate, = struct.unpack_from(INT8, raw[:EVENT_LEN], 10) + algorithmstate, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 17) + RSSI, = struct.unpack_from(INT8, raw[:EVENT_LEN], 16) + currentglucosedisplayvalue, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) + egvTimestamp, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + egvInfoBitmask, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 24) + interval, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 23) return LidCgmDataGxb( raw = RawEvent.build(raw), @@ -2422,6 +2692,14 @@ class LidCgmDataGxb(BaseEvent): interval = interval, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidBasalDelivery(BaseEvent): @@ -2457,11 +2735,11 @@ class LidBasalDelivery(BaseEvent): @staticmethod def build(raw): - commandedRateSource, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - commandedRate, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 6) - profileBasalRate, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 4) - algorithmRate, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 10) - tempRate, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 8) + commandedRateSource, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + commandedRate, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 16) + profileBasalRate, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) + algorithmRate, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 20) + tempRate, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 18) return LidBasalDelivery( raw = RawEvent.build(raw), @@ -2472,6 +2750,14 @@ class LidBasalDelivery(BaseEvent): tempRate = tempRate, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidBolusDelivery(BaseEvent): @@ -2541,11 +2827,7 @@ class LidBolusDelivery(BaseEvent): class BolussourceEnum(Enum): PumpButton = 0 PumpGui = 1 - Reserved = 2 - Reserved = 3 - Reserved = 4 Remote = 5 - Reserved = 6 Algorithm = 7 Ble = 8 EatingSoonBolus = 9 @@ -2556,16 +2838,16 @@ class LidBolusDelivery(BaseEvent): @staticmethod def build(raw): - bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - bolusDeliveryStatus, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 1) - bolusType, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 0) - bolusSource, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 7) - remoteId, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 6) - requestedNow, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 4) - requestedLater, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 10) - extendedDurationRequested, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) - deliveredTotal, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) - correction, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 8) + bolusid, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + bolusDeliveryStatus, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) + bolusType, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 10) + bolusSource, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 17) + remoteId, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 16) + requestedNow, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) + requestedLater, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 20) + extendedDurationRequested, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 24) + deliveredTotal, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 22) + correction, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 18) return LidBolusDelivery( raw = RawEvent.build(raw), @@ -2581,6 +2863,14 @@ class LidBolusDelivery(BaseEvent): correction = correction, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidVersionsA(BaseEvent): @@ -2597,10 +2887,10 @@ class LidVersionsA(BaseEvent): @staticmethod def build(raw): - armpartnumber, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - armswversion, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - blepartnumber, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - bleswversion, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 12) + armpartnumber, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + armswversion, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + blepartnumber, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + bleswversion, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 22) return LidVersionsA( raw = RawEvent.build(raw), @@ -2610,6 +2900,14 @@ class LidVersionsA(BaseEvent): bleswversion = bleswversion, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidAaDailyStatus(BaseEvent): @@ -2673,9 +2971,9 @@ class LidAaDailyStatus(BaseEvent): @staticmethod def build(raw): - pumpcontrolstate, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 3) - usermode, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 2) - sensortype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 1) + pumpcontrolstate, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + usermode, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 12) + sensortype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) return LidAaDailyStatus( raw = RawEvent.build(raw), @@ -2684,6 +2982,14 @@ class LidAaDailyStatus(BaseEvent): sensortypeRaw = sensortype, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmAlertActivatedDex(BaseEvent): @@ -2716,11 +3022,11 @@ class LidCgmAlertActivatedDex(BaseEvent): @staticmethod def build(raw): - dalertid, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 3) - sensortype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 2) - faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - param1, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - param2, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 12) + dalertid, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + sensortype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 12) + faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + param1, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + param2, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 22) return LidCgmAlertActivatedDex( raw = RawEvent.build(raw), @@ -2731,6 +3037,14 @@ class LidCgmAlertActivatedDex(BaseEvent): param2 = param2, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmAlertClearedDex(BaseEvent): @@ -2760,8 +3074,8 @@ class LidCgmAlertClearedDex(BaseEvent): @staticmethod def build(raw): - dalertid, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 3) - sensortype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 2) + dalertid, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + sensortype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 12) return LidCgmAlertClearedDex( raw = RawEvent.build(raw), @@ -2769,6 +3083,14 @@ class LidCgmAlertClearedDex(BaseEvent): sensortypeRaw = sensortype, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmAlertAckDex(BaseEvent): @@ -2812,9 +3134,9 @@ class LidCgmAlertAckDex(BaseEvent): @staticmethod def build(raw): - dalertid, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 3) - sensortype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 2) - acksource, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) + dalertid, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + sensortype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 12) + acksource, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) return LidCgmAlertAckDex( raw = RawEvent.build(raw), @@ -2823,6 +3145,14 @@ class LidCgmAlertAckDex(BaseEvent): acksourceRaw = acksource, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmDataFsl2(BaseEvent): @@ -2937,15 +3267,15 @@ class LidCgmDataFsl2(BaseEvent): @staticmethod def build(raw): - glucosevaluestatus, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 3) - cgmDataType, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 2) - rate, = struct.unpack_from(INT16, raw[:EVENT_LEN], 0) - algorithmstate, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 7) - RSSI, = struct.unpack_from(INT8, raw[:EVENT_LEN], 6) - currentglucosedisplayvalue, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 4) - egvTimestamp, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - egvInfoBitmask, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) - interval, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + glucosevaluestatus, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + cgmDataType, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 12) + rate, = struct.unpack_from(INT16, raw[:EVENT_LEN], 10) + algorithmstate, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 17) + RSSI, = struct.unpack_from(INT8, raw[:EVENT_LEN], 16) + currentglucosedisplayvalue, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) + egvTimestamp, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + egvInfoBitmask, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 24) + interval, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 23) return LidCgmDataFsl2( raw = RawEvent.build(raw), @@ -2960,6 +3290,14 @@ class LidCgmDataFsl2(BaseEvent): interval = interval, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmJoinSessionG7(BaseEvent): @@ -2974,8 +3312,8 @@ class LidCgmJoinSessionG7(BaseEvent): @staticmethod def build(raw): - cgmtimestamp, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - sessionsignature, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) + cgmtimestamp, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + sessionsignature, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) return LidCgmJoinSessionG7( raw = RawEvent.build(raw), @@ -2983,6 +3321,14 @@ class LidCgmJoinSessionG7(BaseEvent): sessionsignature = sessionsignature, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmDataG7(BaseEvent): @@ -3096,8 +3442,6 @@ class LidCgmDataG7(BaseEvent): ValidEgvValidRange = 2**6 ValidAlgstateAlgstateIs32 = 2**7 EgvWasSuccessfullyAddedToCgmSubsystemArrayE = 2**8 - Reserved = 2**9 - Reserved = 2**10 @property def egvInfoBitmask(self): @@ -3105,15 +3449,15 @@ class LidCgmDataG7(BaseEvent): @staticmethod def build(raw): - glucosevaluestatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 2) - cgmDataType, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 1) - rate, = struct.unpack_from(INT8, raw[:EVENT_LEN], 0) - algorithmstate, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 7) - RSSI, = struct.unpack_from(INT8, raw[:EVENT_LEN], 6) - currentglucosedisplayvalue, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 4) - egvTimestamp, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - egvInfoBitmask, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) - interval, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + glucosevaluestatus, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 12) + cgmDataType, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) + rate, = struct.unpack_from(INT8, raw[:EVENT_LEN], 10) + algorithmstate, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 17) + RSSI, = struct.unpack_from(INT8, raw[:EVENT_LEN], 16) + currentglucosedisplayvalue, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 14) + egvTimestamp, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + egvInfoBitmask, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 24) + interval, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 23) return LidCgmDataG7( raw = RawEvent.build(raw), @@ -3128,6 +3472,14 @@ class LidCgmDataG7(BaseEvent): interval = interval, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmStartSessionFsl2(BaseEvent): @@ -3142,8 +3494,8 @@ class LidCgmStartSessionFsl2(BaseEvent): @staticmethod def build(raw): - sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 7) + sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 17) return LidCgmStartSessionFsl2( raw = RawEvent.build(raw), @@ -3151,6 +3503,14 @@ class LidCgmStartSessionFsl2(BaseEvent): sessionduration = sessionduration, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmStopSessionFsl2(BaseEvent): @@ -3167,10 +3527,10 @@ class LidCgmStopSessionFsl2(BaseEvent): @staticmethod def build(raw): - sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - sessionstoptime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) - sessionstopreason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 10) + sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + sessionstoptime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 21) + sessionstopreason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 20) return LidCgmStopSessionFsl2( raw = RawEvent.build(raw), @@ -3180,6 +3540,14 @@ class LidCgmStopSessionFsl2(BaseEvent): sessionstopreason = sessionstopreason, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmJoinSessionFsl2(BaseEvent): @@ -3196,10 +3564,10 @@ class LidCgmJoinSessionFsl2(BaseEvent): @staticmethod def build(raw): - sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - sessionjointime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 11) - sessionjoinreason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 10) + sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + sessionjointime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 21) + sessionjoinreason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 20) return LidCgmJoinSessionFsl2( raw = RawEvent.build(raw), @@ -3209,6 +3577,14 @@ class LidCgmJoinSessionFsl2(BaseEvent): sessionjoinreason = sessionjoinreason, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmStopSessionG7(BaseEvent): @@ -3227,12 +3603,12 @@ class LidCgmStopSessionG7(BaseEvent): @staticmethod def build(raw): - currenttransmittertime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 0) - sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - sessionstoptime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 15) - sessionstopreason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 14) - stopsessioncode, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + currenttransmittertime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10) + sessionstarttime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + sessionstoptime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + sessionduration, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 25) + sessionstopreason, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 24) + stopsessioncode, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 23) return LidCgmStopSessionG7( raw = RawEvent.build(raw), @@ -3244,6 +3620,14 @@ class LidCgmStopSessionG7(BaseEvent): stopsessioncode = stopsessioncode, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmAlertActivatedFsl2(BaseEvent): @@ -3274,11 +3658,11 @@ class LidCgmAlertActivatedFsl2(BaseEvent): @staticmethod def build(raw): - dalertid, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 3) - sensortype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 2) - faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 4) - param1, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 8) - param2, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 12) + dalertid, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + sensortype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 12) + faultlocatordata, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14) + param1, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18) + param2, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 22) return LidCgmAlertActivatedFsl2( raw = RawEvent.build(raw), @@ -3289,6 +3673,14 @@ class LidCgmAlertActivatedFsl2(BaseEvent): param2 = param2, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + @dataclass class LidCgmAlertClearedFsl2(BaseEvent): @@ -3316,8 +3708,8 @@ class LidCgmAlertClearedFsl2(BaseEvent): @staticmethod def build(raw): - dalertid, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 3) - sensortype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 2) + dalertid, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 13) + sensortype, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 12) return LidCgmAlertClearedFsl2( raw = RawEvent.build(raw), @@ -3325,6 +3717,14 @@ class LidCgmAlertClearedFsl2(BaseEvent): sensortypeRaw = sensortype, ) + @property + def eventTimestamp(self): + return self.raw.timestamp + + @property + def eventId(self): + return self.raw.id + EVENT_IDS = { 3: LidBasalRateChange, 4: LidAlertActivated, diff --git a/tconnectsync/eventparser/generic.py b/tconnectsync/eventparser/generic.py index bb093c9..7149faf 100644 --- a/tconnectsync/eventparser/generic.py +++ b/tconnectsync/eventparser/generic.py @@ -1,11 +1,15 @@ import struct +import base64 from dataclasses import dataclass from .raw_event import RawEvent, EVENT_LEN -from .codegen import EVENT_IDS +from .events import EVENT_IDS from .utils import batched Event = lambda x: EVENT_IDS[RawEvent.build(x).id].build(x) -Events = lambda x: (Event(bytearray(e)) for e in batched(x, EVENT_LEN)) \ No newline at end of file +Events = lambda x: (Event(bytearray(e)) for e in batched(x, EVENT_LEN)) + +def decode_raw_events(raw): + return base64.b64decode(raw) \ No newline at end of file diff --git a/tconnectsync/eventparser/raw_event.py b/tconnectsync/eventparser/raw_event.py index dfbc36d..18d3f59 100644 --- a/tconnectsync/eventparser/raw_event.py +++ b/tconnectsync/eventparser/raw_event.py @@ -1,27 +1,35 @@ import struct +import arrow from dataclasses import dataclass EVENT_LEN = 26 UINT16 = '>H' UINT32 = '>I' +TANDEM_EPOCH = 1199145600 @dataclass class RawEvent: source: int id: int - timestamp: int + timestampRaw: int seqNum: int + raw: bytearray @staticmethod def build(raw): source_and_id, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 0) - timestamp, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 2) + timestampRaw, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 2) seqNum, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 6) return RawEvent( source = (source_and_id & 0xF000) >> 12, id = source_and_id & 0x0FFF, - timestamp = timestamp, - seqNum = seqNum - ) \ No newline at end of file + timestampRaw = timestampRaw, + seqNum = seqNum, + raw = raw + ) + + @property + def timestamp(self): + return arrow.get(TANDEM_EPOCH + self.timestampRaw) diff --git a/tconnectsync/eventparser/transforms.py b/tconnectsync/eventparser/transforms.py index a87ff3e..958fb9b 100644 --- a/tconnectsync/eventparser/transforms.py +++ b/tconnectsync/eventparser/transforms.py @@ -13,8 +13,12 @@ def enumNameFormat(text): if t.startswith('yes,'): return 'Yes' + rem = None for i in '-,.': - t = t.split(i)[0] + spl = t.split(i) + t = spl[0] + if len(spl) > 1: + rem = rem or spl[1] for i in '()/"\u201c\u201d': t = t.replace(i, '') @@ -25,6 +29,13 @@ def enumNameFormat(text): return 'TrueVal' if t.lower() == 'none': return 'NoneVal' + if t.lower() == 'reserved': + return None + if t.lower() == 'unused': + return None + if t.lower() == 'unavailable' and rem: + suffix = enumNameFormat(rem) + t += f'{suffix[0].lower()}{suffix[1:]}' return f'{t[0].upper()}{t[1:]}' @@ -36,7 +47,7 @@ def transform_enum(event_def, name, name_fmt, field, tx): out += [''] out += [f'class {enumNameFormat(name_fmt)}Enum(Enum):'] out += [ - f' {enumNameFormat(v)} = {k}' for k, v in tx.items() + f' {enumNameFormat(v)} = {k}' for k, v in tx.items() if enumNameFormat(v) ] out += [''] out += [ @@ -64,7 +75,7 @@ def transform_bitmask(event_def, name, name_fmt, field, tx): out += [''] out += [f'class {enumNameFormat(name_fmt)}Bitmask(IntFlag):',] out += [ - f' {enumNameFormat(v)} = 2**{k}' for k, v in tx.items() if 'unused' not in v.lower() + f' {enumNameFormat(v)} = 2**{k}' for k, v in tx.items() if enumNameFormat(v) ] out += [''] out += [