Review of 352f694: the metadata-page detection fixed every observed stream but
was one case of a general rule. An A5 header is 12 bytes in the stripped sense
(TERM's 11); its raw length is 13 whenever the echoed address carries an inner
DLE pair -- the metadata pages at 0x1002 / 0x1004, but equally a sample chunk
or TERM boundary that lands there (inferred: ~1 in 128 events spanning
0x1000-0x1200, not in any capture). _raw_skip() counts it per frame, the way
probe_skip already did; _has_metadata_pages is gone. The reviewer measured
the rule reproducing the shipped bodies byte for byte on all 26 current-walk
streams on this box. Test: a chunk moved to 0x1002 yields the same body.
No DB or schema change; TOOL_VERSION not bumped (the file builder changed, the
.h5 decode did not).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
77 lines
3.6 KiB
Python
77 lines
3.6 KiB
Python
"""A non-first MiniMate event's 5A stream has no metadata pages.
|
|
|
|
The event-1 walk fetches the two global metadata pages (0x1002, 0x1004) as A5
|
|
frames 1 and 2, which carry a 6-byte inner header (skip 13). A non-first event's
|
|
walk fetches none, so its frames 1 and 2 are ordinary sample chunks (skip 12).
|
|
The body builder skipped 13 on frames 1 and 2 unconditionally: every non-first
|
|
event lost two bytes and decoded truncated. Found on BE9441 at the bench
|
|
(2026-10-25); fixtures are its raw replies (see the fixture README).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from minimateplus.blastware_file import extract_body_bytes, write_blastware_file # noqa: E402
|
|
from minimateplus.event_file_io import read_blastware_file # noqa: E402
|
|
from minimateplus.framing import S3FrameParser # noqa: E402
|
|
from minimateplus.models import Event # noqa: E402
|
|
from minimateplus.waveform_codec import decode_waveform_v2 # noqa: E402
|
|
|
|
FIX = Path(__file__).parent / "fixtures" / "minimate-bench-10-25-26"
|
|
SAMPLES = 21_504 # 5 s record + 0.25 s pre-trigger, at 4096 sps
|
|
UNIT_PEAKS = { # the unit's own 0C peaks, in/s
|
|
"event0": {"Tran": 0.020, "Vert": 0.060, "Long": 0.015},
|
|
"event1": {"Tran": 0.030, "Vert": 0.095, "Long": 0.020},
|
|
}
|
|
FILES = {"event0": "BE9441_event0_01110000_rx.bin", "event1": "BE9441_event1_0111646a_rx.bin"}
|
|
|
|
|
|
def a5_frames(which):
|
|
return [f for f in S3FrameParser().feed((FIX / FILES[which]).read_bytes()) if f.sub == 0xA5]
|
|
|
|
|
|
@pytest.mark.parametrize("which", ["event0", "event1"])
|
|
def test_the_body_decodes_whole_and_matches_the_units_own_peaks(which):
|
|
_strt, body, _footer = extract_body_bytes(a5_frames(which))
|
|
dec = decode_waveform_v2(body)
|
|
for ch, peak in UNIT_PEAKS[which].items():
|
|
assert len(dec[ch]) == SAMPLES, ch
|
|
assert max(abs(x) for x in dec[ch]) * 0.005 == pytest.approx(peak, abs=1e-9), ch
|
|
|
|
|
|
def test_metadata_pages_are_recognised_by_their_echoed_addresses():
|
|
first, other = a5_frames("event0"), a5_frames("event1")
|
|
assert (bytes(first[1].data[4:6]), bytes(first[2].data[4:6])) == (b"\x10\x02", b"\x10\x04")
|
|
assert bytes(other[1].data[4:6]) not in (b"\x10\x02", b"\x10\x04")
|
|
|
|
|
|
@pytest.mark.parametrize("which", ["event0", "event1"])
|
|
def test_the_written_file_reads_back_whole(which, tmp_path):
|
|
ev = Event(index=0)
|
|
ev.timestamp = None # the builder takes the footer from the TERM frame
|
|
path = tmp_path / f"{which}.P00"
|
|
write_blastware_file(ev, a5_frames(which), path)
|
|
pv = read_blastware_file(path).peak_values
|
|
got = {"Tran": pv.tran, "Vert": pv.vert, "Long": pv.long}
|
|
assert got == pytest.approx(UNIT_PEAKS[which], abs=1e-6)
|
|
|
|
|
|
def test_a_sample_chunk_at_0x1002_is_not_mistaken_for_a_header_byte():
|
|
"""Every A5 header is 12 bytes once inner DLE pairs (10 02/03/04) count as one;
|
|
the TERM's is 11. A sample chunk echoing address 0x1002 carries 13 raw header
|
|
bytes, like a metadata page -- the general rule handles both."""
|
|
frames = a5_frames("event1")
|
|
_s, want, _f = extract_body_bytes(frames)
|
|
one = frames[1]
|
|
hdr, payload = bytes(one.data[:12]), bytes(one.data[12:])
|
|
assert hdr[4:6] != b"\x10\x02"
|
|
moved = type(one)(**{**vars(one), "data": hdr[:4] + b"\x10\x02" + b"\x00" + hdr[6:] + payload})
|
|
_s, got, _f = extract_body_bytes([frames[0], moved] + frames[2:])
|
|
assert got == want
|