From 3b04d4683bc8d947599d1637aeea72a9d082fd33 Mon Sep 17 00:00:00 2001 From: Brian Harrison Date: Thu, 2 Apr 2026 17:18:48 -0400 Subject: [PATCH] fix: update compliance config read logic to handle buffered responses on slow links --- minimateplus/protocol.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/minimateplus/protocol.py b/minimateplus/protocol.py index c5f79c2..7103624 100644 --- a/minimateplus/protocol.py +++ b/minimateplus/protocol.py @@ -589,10 +589,8 @@ class MiniMateProtocol: self._send(build_bw_frame(SUB_COMPLIANCE, 0, _PROBE_PARAMS)) self._recv_one(expected_sub=rsp_sub) - # Data request — 0x082A encoded as: byte[5]=0x2A, params[2]=0x08, params[7]=0x64 + # Frame D params — offset=0x002A, params[2]=0x08, params[7]=0x64 _DATA_PARAMS = bytes([0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00]) - log.debug("read_compliance_config: 1A data request offset=0x2A params[2]=0x08") - self._send(build_bw_frame(SUB_COMPLIANCE, 0x2A, _DATA_PARAMS)) # ── Multi-request accumulation ──────────────────────────────────────── # @@ -649,22 +647,18 @@ class MiniMateProtocol: ) config.extend(chunk) - # Over TCP/modem the device responses are buffered one step behind: - # each recv() above collected the PREVIOUS send's response, so Frame D's - # real data is still sitting in the buffer. Drain it with a short-timeout - # recv — this is a no-op on direct serial where responses are synchronous. + # Safety drain: catch any extra frame the device may buffer on slow links. try: - tail_rsp = self._recv_one(expected_sub=rsp_sub, timeout=3.0) + tail_rsp = self._recv_one(expected_sub=rsp_sub, timeout=2.0) tail_chunk = tail_rsp.data[11:] log.warning( - "read_compliance_config: tail drain page=0x%04X data=%d " + "read_compliance_config: unexpected tail frame page=0x%04X " "cfg_chunk=%d running_total=%d", - tail_rsp.page_key, len(tail_rsp.data), - len(tail_chunk), len(config) + len(tail_chunk), + tail_rsp.page_key, len(tail_chunk), len(config) + len(tail_chunk), ) config.extend(tail_chunk) except TimeoutError: - log.debug("read_compliance_config: no tail frame (direct serial or already complete)") + pass log.warning( "read_compliance_config: done — %d cfg bytes total",