fix: update compliance config read logic to handle buffered responses on slow links

This commit is contained in:
Brian Harrison
2026-04-02 17:18:48 -04:00
parent 0363425d83
commit 3b04d4683b

View File

@@ -589,10 +589,8 @@ class MiniMateProtocol:
self._send(build_bw_frame(SUB_COMPLIANCE, 0, _PROBE_PARAMS)) self._send(build_bw_frame(SUB_COMPLIANCE, 0, _PROBE_PARAMS))
self._recv_one(expected_sub=rsp_sub) 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]) _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 ──────────────────────────────────────── # ── Multi-request accumulation ────────────────────────────────────────
# #
@@ -649,22 +647,18 @@ class MiniMateProtocol:
) )
config.extend(chunk) config.extend(chunk)
# Over TCP/modem the device responses are buffered one step behind: # Safety drain: catch any extra frame the device may buffer on slow links.
# 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.
try: 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:] tail_chunk = tail_rsp.data[11:]
log.warning( 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", "cfg_chunk=%d running_total=%d",
tail_rsp.page_key, len(tail_rsp.data), tail_rsp.page_key, len(tail_chunk), len(config) + len(tail_chunk),
len(tail_chunk), len(config) + len(tail_chunk),
) )
config.extend(tail_chunk) config.extend(tail_chunk)
except TimeoutError: except TimeoutError:
log.debug("read_compliance_config: no tail frame (direct serial or already complete)") pass
log.warning( log.warning(
"read_compliance_config: done — %d cfg bytes total", "read_compliance_config: done — %d cfg bytes total",