fix: improve monitoring functionality with session-reset signal and payload adjustments
This commit is contained in:
+16
-9
@@ -1767,25 +1767,32 @@ def _decode_monitor_status(data: bytes) -> MonitorStatus:
|
||||
# The data section starts at offset 11 (after the S3 section header).
|
||||
section = data[11:] if len(data) > 11 else data
|
||||
|
||||
# Log the raw payload at WARNING level so we can see it in the server logs
|
||||
# and confirm the field offsets and is_monitoring detection are correct.
|
||||
log.warning(
|
||||
log.debug(
|
||||
"_decode_monitor_status: total data=%d bytes section=%d bytes hex=%s",
|
||||
len(data), len(section), section.hex(),
|
||||
)
|
||||
|
||||
# Mode: idle payload is 44 bytes; monitoring is shorter (12 bytes observed)
|
||||
is_monitoring = len(section) < 20
|
||||
# Monitoring flag confirmed from 2ndtry 4-8-26 capture:
|
||||
# section[1] == 0x00 → idle
|
||||
# section[1] == 0x10 → monitoring (flips exactly at start/stop transitions)
|
||||
# Payload length is ~46-49 bytes in BOTH states — length alone is unreliable.
|
||||
is_monitoring = len(section) > 1 and section[1] == 0x10
|
||||
|
||||
battery_v = None
|
||||
memory_total = None
|
||||
memory_free = None
|
||||
|
||||
if not is_monitoring and len(section) >= 0x39:
|
||||
batt_raw = struct.unpack(">H", section[0x2F:0x31])[0]
|
||||
# Battery and memory fields confirmed from 2ndtry IDLE S3 frames:
|
||||
# section[36:38] battery × 100 uint16 BE 0x02A8 = 680 → 6.80 V
|
||||
# section[38:42] memory_total uint32 BE bytes = total flash
|
||||
# section[42:46] memory_free uint32 BE bytes = free flash
|
||||
# These fields appear in BOTH idle and monitoring payloads (battery/memory
|
||||
# are available regardless of mode).
|
||||
if len(section) >= 46:
|
||||
batt_raw = struct.unpack(">H", section[36:38])[0]
|
||||
battery_v = batt_raw / 100.0
|
||||
memory_total = struct.unpack(">I", section[0x31:0x35])[0]
|
||||
memory_free = struct.unpack(">I", section[0x35:0x39])[0]
|
||||
memory_total = struct.unpack(">I", section[38:42])[0]
|
||||
memory_free = struct.unpack(">I", section[42:46])[0]
|
||||
|
||||
return MonitorStatus(
|
||||
is_monitoring=is_monitoring,
|
||||
|
||||
Reference in New Issue
Block a user