diff --git a/minimateplus/client.py b/minimateplus/client.py index 471a266..767d104 100644 --- a/minimateplus/client.py +++ b/minimateplus/client.py @@ -895,14 +895,14 @@ class MiniMateClient: Write payloads: event_index_data : 88 bytes — read live via SUB 08 - compliance_data : 2128 bytes — read live via SUB 1A (2126 bytes) + \\x00\\x00 footer + compliance_data : ~2128 bytes — read live via SUB 1A (~2126 bytes, varies ±1-2) + \\x00\\x00 footer trigger_data : 29 bytes — hardcoded from 3-11-26 capture waveform_data : 204 bytes — read live via SUB 09 Raises: RuntimeError: if not connected. ProtocolError: if any read or write step fails. - ValueError: if compliance buffer is not the expected 2126 bytes. + ValueError: if compliance buffer is shorter than the 2082-byte write minimum. """ proto = self._require_proto() @@ -911,7 +911,7 @@ class MiniMateClient: event_index_data = proto.read_event_index() log.info("apply_config: reading compliance config (SUB 1A)") - compliance_raw = proto.read_compliance_config() # 2126 bytes + compliance_raw = proto.read_compliance_config() # ~2126 bytes (varies ±1-2 by DLE jitter) log.info("apply_config: reading waveform data (SUB 09)") waveform_data = proto.read_waveform_data_raw() # 204 bytes @@ -1806,10 +1806,26 @@ def _encode_compliance_config( by the device in POC test 2026-04-07.) Raises: - ValueError: if raw is not exactly 2126 bytes. + ValueError: if raw is shorter than the minimum needed for the 3-chunk write. """ - if len(raw) != 2126: - raise ValueError(f"_encode_compliance_config: expected 2126 bytes, got {len(raw)}") + # Total size is nominally ~2126 bytes but varies by ±1-2 bytes depending on + # DLE jitter in the E5 read response (0x10 bytes in the config data cause + # 1-byte expansions per occurrence during DLE stuffing/unstuffing). The + # anchor-based field access and the chunk splitter (fixed chunk1=1027, + # chunk2=1055, chunk3=remainder) both handle variable length correctly. + # Only enforce a minimum — must have at least chunk1+chunk2 bytes of content. + _MIN_COMPLIANCE_LEN = 1027 + 1055 # = 2082 + if len(raw) < _MIN_COMPLIANCE_LEN: + raise ValueError( + f"_encode_compliance_config: compliance buffer too short " + f"({len(raw)} bytes, need at least {_MIN_COMPLIANCE_LEN})" + ) + if len(raw) not in range(2124, 2132): + log.warning( + "_encode_compliance_config: unusual compliance buffer length %d " + "(expected ~2126); proceeding with anchor-based access", + len(raw), + ) buf = bytearray(raw)