feat(mlg): read Blastware .MLG files, every record's checksum verified
minimateplus/mlg_file.py parses the measured format: an 18-byte prefix, then length-led 292-byte records, each with a CRC-16/AUG-CCITT over [0:288] stored little-endian. A record that fails its checksum is returned flagged, never silently dropped. One shared CRC function (minimateplus/crc.py) replaces micromate/setup_block's copy. Fixtures: 12 real .MLG files (DL2's ACH folder + 3 bench files) in tests/fixtures/mlg-11-9-26/, force-added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALX2R9LdWawLzUxwewZGA1
This commit is contained in:
1 parent
74ce7abcc6
commit
3cd95db405
17 files changed
+322
-10
No files matched your search
@@ -729,6 +729,52 @@ class MonitorLogEntry:
|
||||
return f"MonitorLog#{self.index} key={self.key} {start}→{stop}{dur}"
|
||||
|
||||
|
||||
# ── Blastware monitor log (.MLG) ──────────────────────────────────────────────
|
||||
|
||||
@dataclass
|
||||
class MlgRecord:
|
||||
"""One log record of a Blastware .MLG file (minimateplus/mlg_file.py).
|
||||
|
||||
Times are the unit's own local clock. `flags` is the monitor-log flag word
|
||||
(the event footer's, reference D.6.14); 0xFFFF means monitoring started
|
||||
and has no stop yet."""
|
||||
index: int # position in the file; 0 is the header record
|
||||
start: datetime.datetime
|
||||
stop: Optional[datetime.datetime]
|
||||
flags: int
|
||||
trigger_source: int # 0x0001-0x0008 a channel, 0x0400 a histogram, 0 none
|
||||
serial: str
|
||||
text_raw: bytes = field(repr=False) # record[34:288] exactly, for write_mlg
|
||||
event_time: Optional[datetime.datetime] = None
|
||||
text: str = "" # Blastware's text, after any event time
|
||||
trigger_level: Optional[str] = None # e.g. "Geo: 0.0500 in/s Mic: 125.0 dB(L)", "Histogram"
|
||||
description: str = "" # "Monitoring started", or Blastware's words
|
||||
crc_ok: bool = True
|
||||
|
||||
@property
|
||||
def is_start(self) -> bool:
|
||||
return self.flags == 0xFFFF
|
||||
|
||||
|
||||
@dataclass
|
||||
class MlgFile:
|
||||
"""A whole .MLG file: the serial from its header record and its log records,
|
||||
in file order. An empty file (the 18-byte prefix alone) has neither."""
|
||||
serial: Optional[str]
|
||||
records: list[MlgRecord] = field(default_factory=list)
|
||||
header_crc_ok: bool = True
|
||||
|
||||
@property
|
||||
def empty(self) -> bool:
|
||||
return self.serial is None and not self.records
|
||||
|
||||
@property
|
||||
def crc_failures(self) -> list[int]:
|
||||
"""Indexes of the records whose checksum fails (0 is the header record)."""
|
||||
head = [] if self.header_crc_ok else [0]
|
||||
return head + [r.index for r in self.records if not r.crc_ok]
|
||||
|
||||
|
||||
# ── MonitorStatus ─────────────────────────────────────────────────────────────
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in new issue
Block a user