diff --git a/minimateplus/protocol.py b/minimateplus/protocol.py index 01c21fd..ad5fdff 100644 --- a/minimateplus/protocol.py +++ b/minimateplus/protocol.py @@ -240,6 +240,41 @@ class MiniMateProtocol: # ── Event download API ──────────────────────────────────────────────────── + def read_event_index(self) -> bytes: + """ + Send the SUB 08 (EVENT_INDEX) two-step read and return the raw 88-byte + (0x58) index block. + + The index block contains: + +0x00 (3 bytes): total index size or record count — purpose partially + decoded; byte [3] may be a high byte of event count. + +0x03 (4 bytes): stored event count as uint32 BE ❓ (inferred from + captures; see §7.4 in protocol reference) + +0x07 onwards: 6-byte event timestamps (see §8), one per event + + Caller is responsible for parsing the returned bytes. + + Returns: + Raw 88-byte data section (data[11:11+0x58]). + + Raises: + ProtocolError: on timeout, bad checksum, or wrong response SUB. + """ + rsp_sub = _expected_rsp_sub(SUB_EVENT_INDEX) + length = DATA_LENGTHS[SUB_EVENT_INDEX] # 0x58 + + log.debug("read_event_index: 08 probe") + self._send(build_bw_frame(SUB_EVENT_INDEX, 0)) + self._recv_one(expected_sub=rsp_sub) + + log.debug("read_event_index: 08 data request offset=0x%02X", length) + self._send(build_bw_frame(SUB_EVENT_INDEX, length)) + data_rsp = self._recv_one(expected_sub=rsp_sub) + + raw = data_rsp.data[11 : 11 + length] + log.debug("read_event_index: got %d bytes", len(raw)) + return raw + def read_event_first(self) -> tuple[bytes, bytes]: """ Send the SUB 1E (EVENT_HEADER) two-step read and return the first