fix(minimateplus): SUB 0x15's serial is a C string -- cut at the first NUL
BE9441 (MiniMate bench, 2026-10-25) answers b"BE9441\x00?": six characters, the terminator, a leftover byte. rstrip(b"\x00") kept the "?", so the serial read "BE9441\x00?" and the serial-named path refused every request as the wrong unit (409). Seven-character serials fill the field to the terminator, which is why no earlier unit showed it. The legacy /device/info output is cleaned too. No codec, store or DB change. 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
5527fcd91f
commit
a8cc516601
2 files changed
+35
-2
No files matched your search
@@ -1305,12 +1305,15 @@ def _decode_serial_number(data: bytes) -> DeviceInfo:
|
|||||||
# Actual serial payload starts at data[11].
|
# Actual serial payload starts at data[11].
|
||||||
actual = data[11:] if len(data) > 11 else data
|
actual = data[11:] if len(data) > 11 else data
|
||||||
|
|
||||||
|
# The serial is a C string: cut at the first NUL. A short serial leaves a
|
||||||
|
# stray byte after its terminator (BE9441 sends b"BE9441\x00?"), so
|
||||||
|
# stripping trailing NULs alone is not enough.
|
||||||
if len(actual) < 9:
|
if len(actual) < 9:
|
||||||
# Short payload — gracefully degrade
|
# Short payload — gracefully degrade
|
||||||
serial = actual.rstrip(b"\x00").decode("ascii", errors="replace")
|
serial = actual.split(b"\x00", 1)[0].decode("ascii", errors="replace")
|
||||||
return DeviceInfo(serial=serial, firmware_minor=0)
|
return DeviceInfo(serial=serial, firmware_minor=0)
|
||||||
|
|
||||||
serial = actual[:8].rstrip(b"\x00").decode("ascii", errors="replace")
|
serial = actual[:8].split(b"\x00", 1)[0].decode("ascii", errors="replace")
|
||||||
trail_0 = actual[8] if len(actual) > 8 else None
|
trail_0 = actual[8] if len(actual) > 8 else None
|
||||||
fw_minor = actual[9] if len(actual) > 9 else 0
|
fw_minor = actual[9] if len(actual) > 9 else 0
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
"""SUB 0x15's serial is a C string in an 8-byte field: cut at the first NUL.
|
||||||
|
|
||||||
|
BE9441 (bench, 2026-10-25) answers `BE9441\\x00?` -- six characters, the
|
||||||
|
terminator, then a leftover byte. Stripping only trailing NULs kept the `?`, so
|
||||||
|
the serial read as "BE9441\\x00?" and every serial-named request was refused as
|
||||||
|
the wrong unit. Seven-character serials (BE11529, BE18189) fill the field up to
|
||||||
|
the terminator, which is why this never showed before.
|
||||||
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from minimateplus.client import _decode_serial_number
|
||||||
|
|
||||||
|
_HEADER = bytes(11) # data[0:11]: the section header
|
||||||
|
|
||||||
|
|
||||||
|
def _reply(field8: bytes, trail: int = 0x00, fw_minor: int = 0x11) -> bytes:
|
||||||
|
return _HEADER + field8 + bytes([trail, fw_minor])
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_six_character_serial_stops_at_its_terminator():
|
||||||
|
assert _decode_serial_number(_reply(b"BE9441\x00?")).serial == "BE9441"
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_seven_character_serial_is_unchanged():
|
||||||
|
info = _decode_serial_number(_reply(b"BE18189\x00", trail=0x2A, fw_minor=0x11))
|
||||||
|
assert (info.serial, info.firmware_minor) == ("BE18189", 0x11)
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_short_payload_also_stops_at_the_terminator():
|
||||||
|
assert _decode_serial_number(_HEADER + b"BE9441\x00?").serial == "BE9441"
|
||||||
Reference in new issue
Block a user