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
@@ -15,6 +15,8 @@ from __future__ import annotations
|
||||
|
||||
import struct
|
||||
|
||||
from minimateplus.crc import crc16_aug_ccitt as _crc16_aug_ccitt
|
||||
|
||||
from .models import MicromateSetup
|
||||
from .protocol import ProtocolError
|
||||
|
||||
@@ -23,8 +25,6 @@ class SetupChecksumError(ProtocolError):
|
||||
"""A config block's trailing CRC does not match its contents."""
|
||||
|
||||
|
||||
_CRC_POLY = 0x1021
|
||||
_CRC_INIT = 0x1D0F # CRC-16/AUG-CCITT
|
||||
_CONTENT_SIZE = 2092 # = content[0:2] (2090) + the 2-byte CRC
|
||||
|
||||
# ── Head of the block ─────────────────────────────────────────────────────────
|
||||
@@ -60,14 +60,6 @@ _ACTIVE_MIC = 3 # block index (0-based)
|
||||
_MIC_TYPES = {2: "linear", 9: "sound_level"}
|
||||
|
||||
|
||||
def _crc16_aug_ccitt(data: bytes) -> int:
|
||||
c = _CRC_INIT
|
||||
for b in data:
|
||||
c ^= b << 8
|
||||
for _ in range(8):
|
||||
c = ((c << 1) ^ _CRC_POLY) & 0xFFFF if c & 0x8000 else (c << 1) & 0xFFFF
|
||||
return c
|
||||
|
||||
|
||||
def crc_ok(content: bytes) -> bool:
|
||||
"""True if a config block's trailing checksum matches its contents.
|
||||
|
||||
Reference in new issue
Block a user