diff --git a/minimateplus/sensor_check.py b/minimateplus/sensor_check.py index 7432ea8..870c02f 100644 --- a/minimateplus/sensor_check.py +++ b/minimateplus/sensor_check.py @@ -98,25 +98,25 @@ def _decode_delta_stream(buf: bytes) -> List[int]: def _find_chain(body: bytes): - """Locate the four length-prefixed sensor-check records. + """Locate the length-prefixed sensor-check records. Returns a list of ``(offset, id, length)`` or ``None``. The chain is - validated by walking the ids 0x3c → 0x3d → 0x3e → 0x3f via their own length - prefixes, so a stray 0x3c byte in the waveform data cannot match. + validated by walking the ids 0x3c → 0x3d → 0x3e (→ 0x3f) via their own + length prefixes, so a stray 0x3c byte in the waveform data cannot match. + A unit without a mic has no 0x3f (BE16352, all 8 of its DL2 events, + 2026-11-06), so the three geophone records are enough. """ for p in range(len(body) - 6): if body[p + 2] == 0x3C and body[p + 3] == 0 and body[p + 4] == 0: q = p recs = [] - ok = True for expect in _CHAIN_IDS: if q + 3 > len(body) or body[q + 2] != expect: - ok = False break length = int.from_bytes(body[q:q + 2], "big") recs.append((q, expect, length)) q = q + 2 + length - if ok and len(recs) == 4: + if len(recs) >= 3: return recs return None @@ -124,8 +124,8 @@ def _find_chain(body: bytes): def decode_sensor_check(raw: bytes) -> Dict[str, List[int]]: """Decode the four sensor self-check traces from a series-3 event binary. - Returns ``{"Tran": [...], "Vert": [...], "Long": [...], "MicL": [...]}`` in - raw decode units (same 16-count LSB as the main waveform), or ``{}`` if the + Returns ``{"Tran": [...], "Vert": [...], "Long": [...], "MicL": [...]}`` (no + "MicL" on a unit without a mic) in raw decode units (same 16-count LSB as the main waveform), or ``{}`` if the binary carries no sensor-check block (a histogram event, a non-series-3 file, or a unit/firmware that doesn't store it). """ diff --git a/tests/test_sensor_check.py b/tests/test_sensor_check.py index b39924a..ecb832a 100644 --- a/tests/test_sensor_check.py +++ b/tests/test_sensor_check.py @@ -65,3 +65,14 @@ def test_mic_channel_is_a_pulse_train(): def test_returns_empty_when_no_sensor_check_block(): assert decode_sensor_check(b"not a blastware file") == {} assert decode_sensor_check(b"") == {} + + +def test_a_unit_without_a_mic_has_its_three_geophone_traces(): + # BE16352 records no mic: its chain carries 0x3c-0x3e only (all 8 of its + # DL2 events, 2026-11-06), and the three ring-downs were being dropped. + raw = (Path(__file__).parent / "fixtures" / "decode-checker-10-29-26" / "R352HFZ7.530H").read_bytes() + sc = decode_sensor_check(raw) + assert set(sc) == {"Tran", "Vert", "Long"} + for ch in ("Tran", "Vert", "Long"): + tr = np.asarray(sc[ch], dtype=float) + assert len(tr) > 200 and tr.min() < -500, (ch, len(tr), tr.min())