Files
seismo-relay/minimateplus/crc.py
T
serversdownandClaude Opus 5.5 3cd95db405 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
2026-11-13 13:39:44 -05:00

24 lines
778 B
Python

"""
minimateplus/crc.py — Instantel's record checksum, shared by every reader that checks one.
CRC-16/AUG-CCITT: poly 0x1021, init 0x1D0F, no reflection, no final XOR. The
same rule covers a Micromate's setup blocks (0x1A, 0x08, 0x2E; stored big-endian),
a Blastware event file's footer (big-endian) and every .MLG record (little-endian).
Each block says where its checksum sits; this module only computes it.
"""
from __future__ import annotations
_POLY = 0x1021
_INIT = 0x1D0F
def crc16_aug_ccitt(data: bytes) -> int:
"""CRC-16/AUG-CCITT of `data` (check value: b"123456789" -> 0xE5CC)."""
c = _INIT
for b in data:
c ^= b << 8
for _ in range(8):
c = ((c << 1) ^ _POLY) & 0xFFFF if c & 0x8000 else (c << 1) & 0xFFFF
return c