From 1397f8486fb4724bf84abfb871c0fd5cb3e1cadc Mon Sep 17 00:00:00 2001 From: Brian Harrison Date: Mon, 6 Apr 2026 17:32:49 -0400 Subject: [PATCH] diag: per-chunk WARNING logging in 5A bulk stream loop Wraps each recv_one call in a try/except TimeoutError, logging: - On timeout: chunk_num, counter, raw bytes_fed (distinguishes "device silent" from "device sent unparseable bytes") - On success: chunk_num, page_key, data_len, contains_Project flag Parser is explicitly reset before each chunk recv so bytes_fed is accurate per-chunk rather than cumulative. Helps identify exactly which chunk fails and whether the device is responding at all. Co-Authored-By: Claude Sonnet 4.6 --- minimateplus/protocol.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/minimateplus/protocol.py b/minimateplus/protocol.py index c6aa338..f6c5f13 100644 --- a/minimateplus/protocol.py +++ b/minimateplus/protocol.py @@ -518,7 +518,20 @@ class MiniMateProtocol: params = bulk_waveform_params(key4, counter) log.debug("5A chunk %d counter=0x%04X", chunk_num, counter) self._send(build_5a_frame(_BULK_CHUNK_OFFSET, params)) - rsp = self._recv_one(expected_sub=rsp_sub) + self._parser.reset() # reset bytes_fed for accurate per-chunk count + try: + rsp = self._recv_one(expected_sub=rsp_sub, reset_parser=False) + except TimeoutError: + log.warning( + "5A TIMEOUT chunk=%d counter=0x%04X raw_bytes=%d", + chunk_num, counter, self._parser.bytes_fed, + ) + raise + + log.warning( + "5A RX chunk=%d page_key=0x%04X data_len=%d contains_Project=%s", + chunk_num, rsp.page_key, len(rsp.data), b"Project:" in rsp.data, + ) if rsp.page_key == 0x0000: # Device unexpectedly terminated mid-stream (no termination needed). @@ -526,10 +539,6 @@ class MiniMateProtocol: return frames_data frames_data.append(rsp.data) - log.debug( - "5A A5[%d] page_key=0x%04X %d bytes", - chunk_num, rsp.page_key, len(rsp.data), - ) if stop_after_metadata and b"Project:" in rsp.data: log.debug("5A A5[%d] metadata found — stopping early", chunk_num)