Files
seismo-relay/tests/test_minimate_monitor_status.py
T
serversdownandClaude Opus 5.5 d990466407 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
2026-10-26 18:53:11 -04:00

64 lines
2.7 KiB
Python

"""SUB 0x1C monitor status, decoded from BE9441's own replies (2026-10-26).
Recorded by the bridge (bridges/captures/10-26-26 - BE9441 blastware histogram/):
* 16:24:54, idle, before the histogram run: flag 0x00.
* 18:47:41, during a histogram run Brian confirmed at the unit: flag **0x0B**. Only
0x10 had ever been measured as "monitoring" (BE11529, 2026-04-08), so the status
read "not monitoring" and the change path refused the state as unknown.
* The same 18:47 reply's free memory, 0x000D0E04, holds a 04. The unit escapes it
(10 04) and the parser keeps both bytes, so the fields counted from the end came
out one byte off: 419.84 V and 251,655,168 bytes, against 6.76 V and 983,028.
"""
from __future__ import annotations
import os
import sys
import pytest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from minimateplus.client import _decode_monitor_status # noqa: E402
from minimateplus.framing import S3FrameParser # noqa: E402
from sfm.device_access.s3 import s3_run_state # noqa: E402
IDLE_1624 = bytes.fromhex(
"1002001010e300002c0000000000000000000000001a0a07ea0010101836000000000000010107cb00070000010107cb0013000000001002a4000efff4000e0de4fa03")
MONITORING_1847 = bytes.fromhex(
"1002001010e300002c00000000000000000000000b1a0a07ea00122f29000000000000010107cb00070000010107cb0013000000001002a4000efff4000d0e10043103")
def _status(wire: bytes):
frames = S3FrameParser().feed(wire)
assert len(frames) == 1 and frames[0].sub == 0xE3
return _decode_monitor_status(frames[0].data)
def test_idle_reply():
st = _status(IDLE_1624)
assert (st.state_flag, st.is_monitoring, s3_run_state(st)) == (0x00, False, "idle")
assert (st.battery_v, st.memory_total, st.memory_free) == (6.76, 983028, 921060)
def test_a_histogram_run_reads_monitoring():
st = _status(MONITORING_1847)
assert (st.state_flag, st.is_monitoring, s3_run_state(st)) == (0x0B, True, "monitoring")
def test_an_escaped_byte_in_the_memory_field_does_not_shift_the_fields():
st = _status(MONITORING_1847)
assert (st.battery_v, st.memory_total, st.memory_free) == (6.76, 983028, 855556)
@pytest.mark.parametrize("value", [0x02, 0x03, 0x04, 0x10])
def test_every_escaped_value_in_the_last_ten_bytes_decodes(value):
# free memory ending in each escaped value, encoded as the unit does
st0 = _status(IDLE_1624)
# the reply's last data byte (free memory's low byte, 0xE4) swapped for `value`
assert IDLE_1624[-3] == 0xE4
frames = S3FrameParser().feed(IDLE_1624[:-3] + bytes([0x10, value]) + IDLE_1624[-2:])
st = _decode_monitor_status(frames[0].data)
assert st.memory_free == (st0.memory_free & ~0xFF) | value
assert (st.battery_v, st.memory_total) == (6.76, 983028)