feat(decode): the monitor log line from the file's footer (group F)

Blastware prints one Monitor Log line per event: the footer's start and
stop, then words for the footer's flag word [18:20] -- 69,983 / 69,983
DL2 lines, character for character (2026-11-08):

  0x0001 Event Recorded       0x0010 Timer Stop
  0x0002 Keyboard Exit        0x0020 Modem Exit
  0x0004 Remote Exit          0x0200 Battery Low Exit
  0x0008 Selfcheck Passed     0x0800 Memory Full Exit

One line sets Modem and Timer and prints Modem, so the higher bit wins
(the order of the others is inferred).  Footer [20:22] is the event
record's trigger source again (69,983 / 69,983); [22:24] is zero; [24:26]
is not a common CRC-16 or sum.

Event.monitor_log: MonitorLogLine(start, stop, flags, description), read
only when the file's record chain is whole, which proves the footer.
The checker compares it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-11-08 03:43:05 -05:00
1 parent 4402753e70
commit b6309027b3
13 files changed
+595 -4

No files matched your search

+44 -4
View File
@@ -26,7 +26,8 @@ import struct
from pathlib import Path
from typing import Optional, Union
from .models import DeviceInfo, Event, PeakValues, ProjectInfo, SensorCheckResult, Timestamp
from .models import (DeviceInfo, Event, MonitorLogLine, PeakValues, ProjectInfo, SensorCheckResult,
Timestamp)
from . import blastware_file as _bw # avoid circular reference at module load
from .bw_ascii_report import BwAsciiReport
from . import waveform_codec as _wc
@@ -1162,6 +1163,40 @@ def _sensor_check_results(chain: dict[int, bytes]) -> Optional[dict[str, SensorC
return out or None
# The Monitor Log line Blastware prints for an event is the footer's start and
# stop, then words for the footer's flag word [18:20]: 69,983 / 69,983 DL2
# lines, character for character (2026-11-08). Every DL2 line has "Event
# Recorded"; a session that ended adds how. One line sets Modem and Timer and
# prints Modem, so the higher bit wins -- the order of the others is inferred.
_MONITOR_LOG_RECORDED = 0x0001
_MONITOR_LOG_ENDS = { # highest bit first
0x0800: "Memory Full Exit",
0x0200: "Battery Low Exit",
0x0020: "Modem Exit",
0x0010: "Timer Stop",
0x0008: "Selfcheck Passed",
0x0004: "Remote Exit",
0x0002: "Keyboard Exit",
}
_FOOTER_ID = 0x0E
_FOOTER_LEN = 26
def monitor_log_description(flags: int) -> str:
"""Blastware's Monitor Log words for a footer flag word."""
words = "Event Recorded " if flags & _MONITOR_LOG_RECORDED else ""
end = next((w for bit, w in _MONITOR_LOG_ENDS.items() if flags & bit), None)
return words + (" " + end if end else "")
def _monitor_log(footer: bytes) -> Optional[MonitorLogLine]:
start, stop = _bw._decode_ts_be(footer[2:10]), _bw._decode_ts_be(footer[10:18])
if start is None or stop is None:
return None
flags = int.from_bytes(footer[18:20], "big")
return MonitorLogLine(start, stop, flags, monitor_log_description(flags))
def _parse_record_time_seconds(raw: bytes) -> Optional[float]:
"""The configured post-trigger record time in seconds, from the recording-
setup config block, or None when absent / implausible."""
@@ -1457,12 +1492,13 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
body = raw[body_start : footer_pos]
footer = raw[footer_pos : footer_pos + 26]
# Footer layout:
# Footer layout (the record chain's last record, id 0e: D.6.13):
# [0:2] 0e 08 marker
# [2:10] ts1 (start) BE 8B
# [10:18] ts2 (stop) BE 8B
# [18:24] 00 01 00 02 00 00
# [24:26] crc
# [18:20] the monitor log's flag word (_monitor_log)
# [20:22] the trigger source, as in the event record [22:24] 00 00
# [24:26] not identified (no common CRC-16 or 16-bit sum fits)
ts1 = _bw._decode_ts_be(footer[2:10])
ts2 = _bw._decode_ts_be(footer[10:18])
@@ -1664,6 +1700,10 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
_chain = _record_chain(raw, _record_at) if _record_at is not None else None
_summary = _unit_summary(_chain) if _chain is not None else None
ev.sensor_check_results = _sensor_check_results(_chain) if _chain is not None else None
# A whole chain ends at the file's last byte with the footer, so the last
# 26 bytes are proven to be it.
if _chain is not None and _FOOTER_ID in _chain:
ev.monitor_log = _monitor_log(raw[-_FOOTER_LEN:])
if _summary is not None and ev.peak_values is not None and ev.sample_rate:
_apply_unit_summary(ev.peak_values, _summary, geo_fs, ev.sample_rate,
ev.pretrig_samples if is_waveform_body else None)