fix: add addition recv after loop to make up for modem TCP/IP lag

This commit is contained in:
Brian Harrison
2026-04-02 17:13:12 -04:00
parent 66967e036c
commit 0363425d83

View File

@@ -623,8 +623,7 @@ class MiniMateProtocol:
("D", 0x002A, _DATA_PARAMS), # _DATA_PARAMS built above ("D", 0x002A, _DATA_PARAMS), # _DATA_PARAMS built above
] ]
config = bytearray() config = bytearray()
seen_bytes: set[bytes] = set() # exact-content dedup (not page_key+len)
for step_name, step_offset, step_params in _STEPS: for step_name, step_offset, step_params in _STEPS:
log.debug( log.debug(
@@ -637,32 +636,36 @@ class MiniMateProtocol:
data_rsp = self._recv_one(expected_sub=rsp_sub) data_rsp = self._recv_one(expected_sub=rsp_sub)
except TimeoutError: except TimeoutError:
log.warning( log.warning(
"read_compliance_config: frame %s — no E5 response (timeout); " "read_compliance_config: frame %s — no E5 response (timeout)",
"device may return all data on a later request",
step_name, step_name,
) )
continue continue
chunk = data_rsp.data[11:] chunk = data_rsp.data[11:]
page = data_rsp.page_key
if chunk in seen_bytes:
log.warning(
"read_compliance_config: frame %s page=0x%04X data=%d "
"cfg_chunk=%d BYTE-IDENTICAL DUPLICATE — skipping",
step_name, page, len(data_rsp.data), len(chunk),
)
continue
seen_bytes.add(bytes(chunk))
log.warning( log.warning(
"read_compliance_config: frame %s page=0x%04X data=%d " "read_compliance_config: frame %s page=0x%04X data=%d cfg_chunk=%d running_total=%d",
"cfg_chunk=%d running_total=%d", step_name, data_rsp.page_key, len(data_rsp.data),
step_name, page, len(data_rsp.data),
len(chunk), len(config) + len(chunk), len(chunk), len(config) + len(chunk),
) )
config.extend(chunk) 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.
try:
tail_rsp = self._recv_one(expected_sub=rsp_sub, timeout=3.0)
tail_chunk = tail_rsp.data[11:]
log.warning(
"read_compliance_config: tail drain page=0x%04X data=%d "
"cfg_chunk=%d running_total=%d",
tail_rsp.page_key, len(tail_rsp.data),
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)")
log.warning( log.warning(
"read_compliance_config: done — %d cfg bytes total", "read_compliance_config: done — %d cfg bytes total",
len(config), len(config),