fix(minimateplus): the 0x1C status reads a histogram run as monitoring, and unescapes before counting from the end

Measured on BE9441 tonight, through the recording bridge:

- Monitoring flag 0x0B while recording a histogram (confirmed at the unit), 0x00
  idle.  Only 0x10 had been measured as monitoring (BE11529, 2026-04-08), so the
  status showed 'not monitoring' and the change path refused the state as
  unknown(0x0B) -- refused, not skipped, which is the design working.  0x0B joins
  S3_RUN_STATES and S3_MONITORING_FLAGS as measured.  The shared status's
  'monitoring' now follows the change path's reading: None for an unmeasured
  flag, never a guessed False.
- Free memory 0x000D0E04 arrived as 0d 0e 10 04.  The parser keeps the 10 of a
  10 02/03/04 escape, so every field counted from the end read one byte off:
  419.84 V and 251,655,168 bytes for 6.76 V and 983,028.  New
  framing.unescape_reply() (also used by parse_strt_end_key) runs first.

Tests: the two recorded replies (idle 16:24, monitoring 18:47) decode to the
unit's own values; each escaped value in the last ten bytes decodes; the status
mapping for 00 / 10 / 0B / unmeasured.  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:
serversdownandClaude Opus 5.5 committed 2026-10-26 18:53:11 -04:00
1 parent 8acb9512a9
commit d990466407
5 files changed
+114 -16

No files matched your search

+15 -2
View File
@@ -34,7 +34,7 @@ import re
import struct
from typing import Optional
from .framing import S3Frame
from .framing import S3Frame, unescape_reply
from .models import (
CallHomeConfig,
ComplianceConfig,
@@ -60,6 +60,11 @@ from .transport import SerialTransport, BaseTransport
log = logging.getLogger(__name__)
# SUB 0x1C state-flag values measured while a unit was monitoring: 0x10 (BE11529,
# 2026-04-08, 98 frames) and 0x0B (BE9441 recording a histogram, 2026-10-26).
# Idle is 0x00 on both.
S3_MONITORING_FLAGS = frozenset({0x10, 0x0B})
# ── Module-level constants ────────────────────────────────────────────────────
# Trigger config payload hardcoded from 3-11-26 BW TX capture (BW frame 108).
@@ -2682,6 +2687,10 @@ def _decode_monitor_status(data: bytes) -> MonitorStatus:
mem_total 0x000EFFF2 = 983026 bytes ≈ 960 KB
mem_free 0x000E9E52 = 958034 bytes ≈ 935 KB
"""
# Unescape first (2026-10-26): BE9441's free memory 0x000D0E04 arrived as
# `0d 0e 10 04`, and with the parser's kept 10 every field counted from the
# end read one byte off -- 419.84 V and 251,655,168 bytes for 6.76 V and 983,028.
data = unescape_reply(data)
# The data section starts at offset 11 (after the S3 section header).
section = data[11:] if len(data) > 11 else data
@@ -2694,7 +2703,11 @@ def _decode_monitor_status(data: bytes) -> MonitorStatus:
# Confirmed from byte diff of all 144 0xE3 data frames in 4-8-26/2ndtry capture:
# section[1] = 0x00 in all IDLE frames, 0x10 in all MONITORING frames.
# (section[6] also changes but has non-binary values 0xea/0x07 — device-specific.)
is_monitoring = len(section) > 1 and section[1] == 0x10
#
# 2026-10-26: 0x0B on BE9441 recording a HISTOGRAM (confirmed at the unit);
# 0x00 on the same unit idle. Only measured values count as monitoring --
# sfm.device_access.s3.S3_RUN_STATES refuses any other for a change.
is_monitoring = len(section) > 1 and section[1] in S3_MONITORING_FLAGS
# The same byte, raw -- but only from a real section: for data of 11 bytes
# or fewer, `section` above falls back to the header itself.
state_flag = data[12] if len(data) > 12 else None
+21 -10
View File
@@ -600,20 +600,31 @@ def bulk_waveform_term_v2(
STRT_MARKER = b"STRT"
def unescape_reply(data: bytes) -> bytes:
"""A reply's data with each kept escape removed: `10 02/03/04` → `02/03/04`.
The unit escapes 02, 03, 04 and 10 in its replies exactly as requests do
(748/748 replies, 2026-10-26). S3FrameParser collapses `10 10` but keeps the
`10` of `10 02/03/04` (inner-frame markers to it), so its `.data` carries an
extra byte before each 02/03/04 value -- harmless for fields read before the
escape, one byte off for any read after it, or counted from the end."""
out, i = bytearray(), 0
while i < len(data):
if data[i] == DLE and i + 1 < len(data) and data[i + 1] in (STX, ETX, 0x04):
i += 1
continue
out.append(data[i])
i += 1
return bytes(out)
def parse_strt_end_key(a5_data: bytes) -> Optional[int]:
"""The event's FULL 32-bit end key from the STRT record in an A5 reply's
data, or None. The page byte is part of it: an event that ends in the next
64 KB page reads e.g. 0x011216C4 here, where `parse_strt_end_offset` gave
0x16C4. Read after removing the reply's inner DLE pairs (10 02 / 10 03 /
10 04 → 02 / 03 / 04), which the parser keeps as two bytes."""
out, i = bytearray(), 0
while i < len(a5_data):
if a5_data[i] == DLE and i + 1 < len(a5_data) and a5_data[i + 1] in (STX, ETX, 0x04):
i += 1
continue
out.append(a5_data[i])
i += 1
pos = bytes(out).find(STRT_MARKER)
0x16C4. Read after `unescape_reply`."""
out = unescape_reply(a5_data)
pos = out.find(STRT_MARKER)
if pos < 0 or pos + 10 > len(out):
return None
return int.from_bytes(out[pos + 6:pos + 10], "big")