feat(s3): assemble a settings read into the 2,090-byte block
Unescape each 1A data frame, take data[11:], drop the one non-content byte that starts every frame but the last: 2,090 bytes headed by N = 2090, Series IV's 0x1A layout. Measured on BE9441's 10-26 recording (12 reads, both frame patterns); the read after each Blastware write equals the image written. read_compliance_content is strict (a missing frame raises) and unjudged (a monitoring unit's device-info answer comes back for the caller to recognise). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
e3a77e421d
commit
1bb15573fc
4 files changed
+163
No files matched your search
@@ -11,6 +11,7 @@
|
||||
|
||||
| Date | Section | Change |
|
||||
|---|---|---|
|
||||
| 2026-11-03 | SUB 1A / 71 / 69 (settings read and write) | **The settings block, read and written as content (measured, BE9441's 10-26 recording and BE11529's 2026-04-20 captures).** **Read:** unescape each 1A data frame and take `data[11:]`; every frame but the last starts with one `00` that is not content; dropped, the frames join into **2,090 bytes headed by N = 2090: Series IV's `0x1A` content layout** (12 / 12 reads, Blastware's 4 × 512 + 42 and SFM's 1024 + 1024 + 42). The old "stable anchor" `be 80 00 00 00 00` is content `[12:18]` (pre-trigger −0.25 + stop mode Fixed). **Round trip:** the read after each of Blastware's two 10-26 writes equals the image it had just written, all 2,090 bytes (2 / 2). While monitoring, the read returns the device-info block (`0e 'BE9441' …`, 5 / 5). **`[26:28]`:** Blastware writes `00 00` on all 11 writes; the unit reads `01 7f` after a monitoring session (BE9441 10-26, BE11529 4-20 15:19) and sets it by itself; meaning unknown. **The two bytes after the block** (`[2090:2092]` of the 0x71 image) are Blastware's own per-unit constant -- `7c ea` on all nine of BE11529's writes, `0c e9` on both of BE9441's -- not the block's CRC-16/AUG, and in no reply of BE9441's three-hour session; SFM sends `00 00`. **`0x09` `[200:202]`:** Blastware echoed the unit's `8c 76` on all nine April writes; on 10-26 it read `17 17` and wrote `78 76` (read back so); meaning unknown. Code: `minimateplus.protocol.assemble_compliance_content`, `read_compliance_content`; tests `tests/test_s3_settings_read.py`. |
|
||||
| 2026-11-03 | Appendix D.3.3, D.6.1, D.6.3, D.6.5, D.6.7, §8 | ✅ **File-only decode, second pass (on `dev`).** **D.3.3:** the footer is the file's last 26 bytes (70,041 / 70,041); an earlier stop-time record fooled the first-match search on 14 files, making histograms a day late. Its `[18:24]` is **not** fixed (retracted). **D.6.1:** STRT[18] now picks the codec; the waveform codec had claimed 2018 5 s histograms. **D.6.3:** the job number (flags `k − 9` bit `0x02`, uint16 at `k − 8`; 2,997 / 2,997). **D.6.5:** the PVS² high word is non-zero above 1.28 in/s (retracted "reads 0000"), so the layout check now uses peak ≤ PVS ≤ √3·peak (34,502,955 / 34,502,955); Blastware's "Number of Intervals" is the monitoring time ÷ the interval. **§8:** where the 1995 default-clock events come from. 18 of 88 report fields now match on every DL2 event. |
|
||||
| 2026-11-03 | call home (SUB 2C / 7E / 7F) | **SFM's call-home write, measured both ways.** SFM's 0x7E image (`write_image` of the 0x2C read with byte 5 set, framed ONCE) and its 0x7F confirm reproduce Blastware's 2026-04-20 enable and disable writes byte for byte (BE11529; `tests/test_s3_call_home_bw_frames.py`). Live on BE9441, idle: a no-op, on and off were all acked (0x81 / 0x80) and read back, and the unit's menu agreed. Only byte 5 changes: no unit-maintained field, unlike Series 4's `[118:120]`. Byte 5 is read from the UNESCAPED block. ⚠ Unescaping is not idempotent, so a built image must never pass through `write_image` again: a call-in time of 16:02-16:04 is `10 02`-`10 04` in the image. ⚠ **While monitoring, the unit answers the 0x2C read with its DEVICE-INFO block** ('Instantel', 'MiniMate Plus', its serial), as it answers 1A. Idle again, minutes later, it returns the call-home block. So a monitoring unit's call-home cannot be read-modify-written; SFM refuses with 'stop monitoring first'. A blind write while monitoring stays untested on purpose. |
|
||||
| 2026-11-02 | Appendix D.3.1, D.6 (NEW), §15 | ✅ **Event fields SFM reads from the file alone (v0.33.0, plus the range on `dev`).** New D.6 records the bytes and the DL2 verification for each field: the record type `STRT[18]`, the recording-setup block (sample rate, pre-trigger, record time, the four notes), the geophone range (label + 29 in the setup's channel blocks), each histogram interval's PVS², and the mic scale (one count = 0.25 Pa). **Retracted in place:** D.3.1's `STRT[20]` = record time (it is `00` on every DL2 file; the "70 s" SFM used to report was `STRT[18]`, the record-type byte), and the 2026-08-26 reading of sub-minute histogram records as little-endian (big-endian from byte 5 since v0.32.0, #47/#49). **For #48:** the file's copy of the block puts the pre-trigger where the 1A "stable anchor" `be 80 00 00 00 00` sits. In the file, though, it is each event's own pre-trigger, which varies on the same unit on the same day (253–256 samples at 1024 sps), and Blastware reports it per event. So the file says little about whether the live 1A loses its anchor, and #48 stays open. |
|
||||
|
||||
@@ -1132,6 +1132,21 @@ class MiniMateClient:
|
||||
read-modify-write (`call_home_image`)."""
|
||||
return self._require_proto().read_call_home_config()
|
||||
|
||||
def read_compliance_content(self) -> bytes:
|
||||
"""The 1A settings read as the logical 2,090-byte block, unjudged (a
|
||||
monitoring unit's device-info answer comes back as it is; see
|
||||
`minimateplus.protocol.is_compliance_content`)."""
|
||||
return self._require_proto().read_compliance_content()
|
||||
|
||||
def read_settings_blocks(self) -> dict:
|
||||
"""The four blocks a settings write sends back, each as its read returns it:
|
||||
event index (08), settings (1A, logical), trigger (2E), waveform data (09)."""
|
||||
proto = self._require_proto()
|
||||
return {"event_index": proto.read_event_index(),
|
||||
"compliance": proto.read_compliance_content(),
|
||||
"trigger": proto.read_trigger_config(),
|
||||
"waveform": proto.read_waveform_data_raw()}
|
||||
|
||||
def write_call_home_image(self, image: bytes) -> None:
|
||||
"""Send a `0x7E` image (`call_home_image`) and its `0x7F` confirm, each ack
|
||||
checked -- framed once, never unescaped again. Raises ImageRefused before
|
||||
|
||||
@@ -169,6 +169,33 @@ class ImageRefused(ValueError):
|
||||
"""A write refused before any byte was sent: the image is not a whole block."""
|
||||
|
||||
|
||||
# ── The settings block (SUB 1A), as content ─────────────────────────────────
|
||||
#
|
||||
# Measured 2026-11-03 on BE9441's 10-26 recording (12 reads, both Blastware's
|
||||
# 4 x 512 + 42 pattern and SFM's 1024 + 1024 + 42): unescape each data frame and
|
||||
# take data[11:]; every frame but the last then starts with one `00` that is not
|
||||
# content. Dropped, the frames join into 2,090 bytes that start with their own
|
||||
# length N = 2090 -- Series IV's 0x1A content layout -- and the read after each
|
||||
# of Blastware's two writes equals the image it had just written.
|
||||
# tests/test_s3_settings_read.py.
|
||||
|
||||
COMPLIANCE_CONTENT_LEN = 2090
|
||||
|
||||
|
||||
def assemble_compliance_content(frames: "list[bytes]") -> bytes:
|
||||
"""Join a 1A read's data frames (each S3Frame.data, kept escapes and all, in
|
||||
order) into the logical settings block. Judges nothing: a monitoring unit's
|
||||
device-info answer assembles too -- `is_compliance_content` tells them apart."""
|
||||
parts = [unescape_reply(bytes(f))[11:] for f in frames]
|
||||
return b"".join(p[1:] for p in parts[:-1]) + (parts[-1] if parts else b"")
|
||||
|
||||
|
||||
def is_compliance_content(block: bytes) -> bool:
|
||||
"""Whether `block` is the settings block: 2,090 bytes headed by N = 2090."""
|
||||
return (len(block) == COMPLIANCE_CONTENT_LEN
|
||||
and int.from_bytes(block[0:2], "big") == COMPLIANCE_CONTENT_LEN)
|
||||
|
||||
|
||||
def is_call_home_block(raw: bytes) -> bool:
|
||||
"""Whether a 0x2C reply payload is the call-home block: it starts with its own
|
||||
length N = 0x7C (00 7C DC on every read on record) and is N (or N + 2) bytes
|
||||
@@ -1029,6 +1056,25 @@ class MiniMateProtocol:
|
||||
|
||||
return bytes(config)
|
||||
|
||||
def read_compliance_content(self) -> bytes:
|
||||
"""The 1A read as the logical settings block (see assemble_compliance_content).
|
||||
|
||||
The same requests as read_compliance_config -- probe, then B / C / D -- but
|
||||
strict: a data frame that does not arrive raises, and there is no tail
|
||||
drain, so a short read is never assembled. Returns whatever assembled,
|
||||
unjudged; a MONITORING unit answers with its device-info block, which
|
||||
is_compliance_content() rejects.
|
||||
"""
|
||||
rsp_sub = _expected_rsp_sub(SUB_COMPLIANCE)
|
||||
self._send(build_bw_frame(SUB_COMPLIANCE, 0, bytes([0, 0, 0, 0, 0, 0, 0, 0x64, 0, 0])))
|
||||
self._recv_one(expected_sub=rsp_sub)
|
||||
frames = []
|
||||
for offset, page in ((0x0400, 0x00), (0x0400, 0x04), (0x002A, 0x08)):
|
||||
self._send(build_bw_frame(SUB_COMPLIANCE, offset,
|
||||
bytes([0, 0, page, 0, 0, 0, 0, 0x64, 0, 0])))
|
||||
frames.append(self._recv_one(expected_sub=rsp_sub).data)
|
||||
return assemble_compliance_content(frames)
|
||||
|
||||
# ── Write commands (SUBs 68–83) ───────────────────────────────────────────
|
||||
|
||||
def recv_write_ack(
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
"""A MiniMate's settings read, assembled into the logical 2,090-byte block (phase 5).
|
||||
|
||||
Measured 2026-11-03 on BE9441's 10-26 recording (12 reads): unescape each 1A
|
||||
data frame and take data[11:]; every frame but the last starts with one `00`
|
||||
that is not content -- drop it. The result is the block Blastware writes back:
|
||||
the read after each of its two writes equals the image it had just written.
|
||||
While monitoring, the unit answers with its device-info block instead.
|
||||
"""
|
||||
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__))))
|
||||
|
||||
import minimateplus.protocol as mp # noqa: E402
|
||||
from minimateplus.framing import S3FrameParser # noqa: E402
|
||||
from minimateplus.protocol import ( # noqa: E402
|
||||
COMPLIANCE_CONTENT_LEN, assemble_compliance_content, is_compliance_content,
|
||||
)
|
||||
from test_minimate_write_frames import WRITES, _payload # noqa: E402
|
||||
|
||||
FIX = Path(__file__).parent / "fixtures" / "minimate-bench-10-26-26-histogram"
|
||||
|
||||
|
||||
def _reads() -> list:
|
||||
"""Each recorded 1A read as its data frames' `data`, in order (a probe reply,
|
||||
11 bytes of data, starts each read)."""
|
||||
reads, cur = [], None
|
||||
for f in S3FrameParser().feed((FIX / "unit_replies.bin").read_bytes()):
|
||||
if f.sub != 0xE5:
|
||||
continue
|
||||
if len(f.data) == 11:
|
||||
cur = []
|
||||
reads.append(cur)
|
||||
else:
|
||||
cur.append(bytes(f.data))
|
||||
return reads
|
||||
|
||||
|
||||
READS = _reads()
|
||||
IMAGES = [b"".join(_payload(f)[16:] for f in WRITES[k:k + 13] if _payload(f)[2] == 0x71)
|
||||
for k in (0, 13)]
|
||||
|
||||
|
||||
def test_the_recording_holds_twelve_reads_in_both_patterns():
|
||||
assert len(READS) == 12
|
||||
assert sorted({len(r) for r in READS}) == [3, 5] # SFM's 1024+1024+42, Blastware's 4x512+42
|
||||
|
||||
|
||||
def test_reads_assemble_to_2090_bytes():
|
||||
assert COMPLIANCE_CONTENT_LEN == 2090
|
||||
assert all(len(assemble_compliance_content(r)) == 2090 for r in READS)
|
||||
|
||||
|
||||
def test_a_read_after_a_blastware_write_equals_the_write():
|
||||
assert assemble_compliance_content(READS[1]) == IMAGES[0][:2090]
|
||||
assert assemble_compliance_content(READS[2]) == IMAGES[1][:2090]
|
||||
|
||||
|
||||
def test_a_monitoring_units_answer_is_not_settings():
|
||||
# reads 3-7 were taken while BE9441 was monitoring: they start 0e 'BE9441'
|
||||
assert [is_compliance_content(assemble_compliance_content(r)) for r in READS[3:8]] == [False] * 5
|
||||
assert all(is_compliance_content(assemble_compliance_content(r)) for r in READS[:3] + READS[8:])
|
||||
|
||||
|
||||
def _s3_reply(sub: int, data: bytes) -> bytes:
|
||||
"""A unit reply on the wire: DLE STX, the payload with every 0x10 doubled, ETX.
|
||||
(`data` here holds no 02/03/04, so no escape is needed.)"""
|
||||
body = bytes([0x00, 0x10, sub, 0x00, 0x00]) + data
|
||||
body += bytes([sum(body) & 0xFF])
|
||||
return b"\x10\x02" + body.replace(b"\x10", b"\x10\x10") + b"\x03"
|
||||
|
||||
|
||||
class _ProbeAndOneFrame:
|
||||
"""Answers the probe and frame B, then goes silent: frame C never arrives."""
|
||||
|
||||
def __init__(self):
|
||||
self.sent = []
|
||||
self._replies = [_s3_reply(0xE5, bytes(11)), _s3_reply(0xE5, bytes(11) + bytes(1025))]
|
||||
self._buf = b""
|
||||
|
||||
def write(self, data):
|
||||
self.sent.append(bytes(data))
|
||||
if self._replies:
|
||||
self._buf += self._replies.pop(0)
|
||||
|
||||
def read(self, n):
|
||||
out, self._buf = self._buf[:n], self._buf[n:]
|
||||
return out
|
||||
|
||||
|
||||
def test_read_compliance_content_refuses_a_missing_frame():
|
||||
t = _ProbeAndOneFrame()
|
||||
proto = mp.MiniMateProtocol(t, recv_timeout=0.2)
|
||||
with pytest.raises(mp.ProtocolError):
|
||||
proto.read_compliance_content()
|
||||
assert len(t.sent) == 3 # probe, B, C -- and no D after C went unanswered
|
||||
Reference in new issue
Block a user