fix(s3): a settings read takes exactly what each frame was asked for
Bench 2026-11-04, BE9441 live: frame B of a 1A read arrived one byte long, ending in a lone 0x10. When a frame's checksum byte is itself escaped (02 / 03 / 04, about one frame in 85) the parser keeps the escape's 0x10 and strips only the byte after it. The 12 recorded reads never hit it, so the assembled block was 2,091 bytes and SFM refused it as 'monitoring'. read_compliance_content now passes the lengths it asked for (1024, 1024, 42) and that one stray byte is dropped; any other leftover still fails is_compliance_content. The trimmed read decodes exactly as the old decoder read the same reply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
2d237be5ef
commit
9992b25fde
2 files changed
+39
-5
No files matched your search
@@ -185,14 +185,26 @@ class ImageRefused(ValueError):
|
||||
# tests/test_s3_settings_read.py.
|
||||
|
||||
COMPLIANCE_CONTENT_LEN = 2090
|
||||
# SFM's 1A read: (offset = the content length asked for, page) per data frame.
|
||||
_COMPLIANCE_READ_STEPS = ((0x0400, 0x00), (0x0400, 0x04), (0x002A, 0x08))
|
||||
|
||||
|
||||
def assemble_compliance_content(frames: "list[bytes]") -> bytes:
|
||||
def assemble_compliance_content(frames: "list[bytes]", lengths: "Optional[tuple]" = None) -> bytes:
|
||||
"""Join a 1A read's data frames (each S3Frame.data, kept escapes and all, in
|
||||
order) into the logical settings block. Judges nothing: a monitoring unit's
|
||||
device-info answer assembles too -- `is_compliance_content` tells them apart."""
|
||||
device-info answer assembles too -- `is_compliance_content` tells them apart.
|
||||
|
||||
`lengths`: the content each frame was asked for (SFM's read: 1024, 1024, 42).
|
||||
Each frame then gives exactly that. Measured at the bench 2026-11-04 (BE9441):
|
||||
when a frame's checksum byte is itself escaped (02 / 03 / 04), the parser keeps
|
||||
the escape's 0x10 and strips only the byte after it, so the frame arrives one
|
||||
byte long, ending in a lone 0x10. That one byte is dropped; any other leftover
|
||||
is kept, and the block then fails is_compliance_content."""
|
||||
parts = [unescape_reply(bytes(f))[11:] for f in frames]
|
||||
return b"".join(p[1:] for p in parts[:-1]) + (parts[-1] if parts else b"")
|
||||
parts = [p[1:] for p in parts[:-1]] + parts[-1:]
|
||||
if lengths is not None and len(lengths) == len(parts):
|
||||
parts = [p[:n] if p[n:] == b"\x10" else p for p, n in zip(parts, lengths)]
|
||||
return b"".join(parts)
|
||||
|
||||
|
||||
def is_compliance_content(block: bytes) -> bool:
|
||||
@@ -1074,11 +1086,11 @@ class MiniMateProtocol:
|
||||
self._send(build_bw_frame(SUB_COMPLIANCE, 0, bytes([0, 0, 0, 0, 0, 0, 0, 0x64, 0, 0])))
|
||||
self._recv_one(expected_sub=rsp_sub)
|
||||
frames = []
|
||||
for offset, page in ((0x0400, 0x00), (0x0400, 0x04), (0x002A, 0x08)):
|
||||
for offset, page in _COMPLIANCE_READ_STEPS:
|
||||
self._send(build_bw_frame(SUB_COMPLIANCE, offset,
|
||||
bytes([0, 0, page, 0, 0, 0, 0, 0x64, 0, 0])))
|
||||
frames.append(self._recv_one(expected_sub=rsp_sub).data)
|
||||
return assemble_compliance_content(frames)
|
||||
return assemble_compliance_content(frames, lengths=tuple(o for o, _ in _COMPLIANCE_READ_STEPS))
|
||||
|
||||
# ── Write commands (SUBs 68–83) ───────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in new issue
Block a user