merge: sensor check results from the unit's own records (group E)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
This commit is contained in:
commit
3cd414b589
11 files changed
+4251
-49
No files matched your search
@@ -45,12 +45,12 @@ Read this first when picking the project back up.
|
||||
- **Byte layouts** of every field read from the file:
|
||||
`docs/instantel_protocol_reference.md` Appendix **D.6**.
|
||||
|
||||
**Where the decoder stands on `dev`** (2026-11-05, run `20261105-140021`):
|
||||
**59 of 88 fields match on every event**, up from about 6 before v0.33.0 and
|
||||
47 before group D.
|
||||
**Where the decoder stands on `dev`** (2026-11-06, run `20261106-125854`):
|
||||
**71 of 88 fields match on every event**, up from about 6 before v0.33.0,
|
||||
47 before group D and 59 after it.
|
||||
- Groups A, B, C and D part 1 shipped in v0.34.0 (#50, #51).
|
||||
- D part 2 (the unit's own summary) is on `dev` and owes the next release
|
||||
a backfill.
|
||||
- D part 2 (the unit's own summary) and E (the sensor check) are on `dev`
|
||||
and owe the next release a backfill.
|
||||
- 🔑 **Events are keyed unit + time + type:** `UNIQUE(serial, timestamp,
|
||||
record_type)` (#51, Migration 3 in `sfm/database.py`, `dev`).
|
||||
- A waveform and its histogram may share a second: 209 times in prod's
|
||||
@@ -77,6 +77,14 @@ Read this first when picking the project back up.
|
||||
(fitted g 386.2238): 6,522–6,523 / 6,524. The unit stores its own
|
||||
too, which Blastware ignores. The misses are O117I1NK.R70W, whose
|
||||
samples wrap at the trigger, and S353I5PZ.EP0W Vert (open).
|
||||
- group E (D.6.13): sensor check frequency, ratio, mic amplitude and
|
||||
result, every record type. Also the unit's own, in each sensor-check
|
||||
record's header. "Check" is the unit's status code, not a limit SFM can
|
||||
recompute.
|
||||
- 🔑 **The tail of every event file is one record chain** (D.6.13):
|
||||
event record → unit summary → sensor checks → footer, each
|
||||
`[length][id][payload]`. It ends exactly at the file's end on all 70,041
|
||||
DL2 files, and SFM reads none of it otherwise.
|
||||
- 🔑 **"Units" means three different things — keep them apart** (reference
|
||||
D.6.6):
|
||||
- **Recorded data:** the mic samples and interval peaks in the file, as
|
||||
@@ -114,8 +122,8 @@ Read this first when picking the project back up.
|
||||
- ~~**D. Blastware's waveform calculations**~~ ✅ done. ZC frequency,
|
||||
displacement and time of peak are the unit's own (D.6.12); acceleration
|
||||
is Blastware's.
|
||||
- **E. Sensor check results.** Probably records `0x3c` / `0x3d`, which
|
||||
follow the unit's summary (inferred, D.6.12).
|
||||
- ~~**E. Sensor check results**~~ ✅ done (D.6.13). Plus the traces of a
|
||||
unit without a mic, which the trace decoder had been dropping.
|
||||
- **F. Monitor log:** probably not in the event file at all. Lead, not
|
||||
measured: O117I1NK's report prints its log as the event record's
|
||||
start – stop.
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
| Date | Section | Change |
|
||||
|---|---|---|
|
||||
| 2026-11-06 | Appendix D.6.13 (NEW), D.3.3, D.6.11, D.6.12 | ✅ **The record chain to the footer, and the sensor check.** Walked from the event record, the chain (event `0x05` → unit's summary `0x32`–`0x35` → sensor checks `0x3c`–`0x3f` → footer `0x0e`) ends exactly at the file's end on all 70,041 DL2 files. The footer is its last record: `00 1a` is its length, `0e` its id. **Each sensor-check record's header holds the unit's results:** channel type `[2]`, status `[4]` (0 = passed), frequency × 10 `[5:7]`, ratio × 10 `[7:9]` and amplitude mV `[9:11]`. Blastware prints them as they are: 209,943 / 209,943 geophone frequencies and ratios, 69,975 / 69,975 mic frequencies and amplitudes. The result is Passed / Check / Disabled by status and type. The status is the unit's own verdict, its bits not decoded. D.6.12's "`0x3c` / `0x3d`, before and after" retracted in place: one record per channel. **71 of 88 report fields now match on every DL2 event.** |
|
||||
| 2026-11-05 | Appendix D.6.12 (NEW), D.6.11, §7.8.9 | ✅ **The unit's own event summary, in every event file.** The embedded event record is the first of a `[length][id][payload]` chain. It holds the vector-sum peak's sample (6,492 / 6,493). Then one 22-byte record per channel, ids `0x32` Tran … `0x35` MicL: min, max, peak sample, **half-period** and a **displacement integral**. Blastware prints them as they are. **ZC frequency** = (rate / 2) / half-period, with the interval rule's words: 25,966 / 25,966 waveform and 253,958 / 253,958 histogram channel values. **Peak displacement** = half the integral: 19,479 / 19,479. Recomputing from the samples had reached 46% and 84%: the unit works at full resolution. **Times of peak** follow the unit's peak sample. That differs from the samples only on **O117I1NK.R70W**, whose stored samples wrap at the trigger by 65,536 counts (Blastware's own table has the same values). Peak acceleration is Blastware's own computation from the stored samples (group D part 1, documented here too). The unit stores its own largest step at `[15:21]` (inferred), which Blastware does not print. §7.8.9's "constant, meaning ❓" bytes amended in place. 59 of 88 report fields now match on every DL2 event (47 before group D). |
|
||||
| 2026-11-04 | SUB 1A / 09 reads, SUB 68–74 settings write, the keypad | **SFM's settings write, benched on BE9441 (Brian at the unit; ~12 writes, each with his go).** **Every write** -- trigger 0.04 ↔ 0.05, a note, several fields at once (Project, job number + its report flag, trigger), the alarm 1.0 ↔ 1.5, and a full restore -- was acknowledged on all nine steps (`97 8C 8E×5 8D 7D 7C 96 8B 8D`), read back as sent, and **confirmed on the unit's own screen**; the unit ended byte for byte as found. Moved bytes were exactly the field's: trigger f32 at each geophone channel +30 (`+31..+33` moved), **alarm f32 at channel +38** (`+39` moved; the first Series-3 alarm write), job number `[40:42]`, its report bit `[39]` `0x02`, a note's value window. **`[26:28]`** went `01 7f` → `00 00` on SFM's first write (Blastware's value) and the unit **set `01 7f` again during the next monitoring session**. The **two bytes after the block** went out as `00 00` (Blastware sends a per-unit constant) and were taken. **🔑 Escaped-checksum artifact:** when a reply's checksum byte is itself escaped (02 / 03 / 04, ~1 frame in 85), `S3FrameParser` keeps the escape's `0x10` and strips only the byte after it, so the frame's data gains one trailing `0x10`. It hit the first live 1A read (frame B 1,026 bytes after the header); the 12 recorded reads never had. SFM's settings read and waveform read now take exactly the length they asked for. **🔑 The keypad menu wins:** a write sent while the setup menu was open was acknowledged and read back, then **lost when the operator pressed Cancel or Save** -- the menu writes its own copy of the **whole** block back (both times the block returned byte for byte to its state when the menu was opened). A keypad Cancel with nothing pending leaves the block unchanged. **While monitoring**, the 1A read returns the device-info block (SFM refuses, nothing sent), and the opening poll was answered only intermittently (2 of 3 attempts timed out). Code: `minimateplus.protocol.read_compliance_content` / `read_waveform_data_raw`, `micromate.setup_fields`; notes `~/bench-logs/2026-11-04-sfm-settings/`. |
|
||||
| 2026-11-03 (5) | 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. **Blastware re-renders the mic trigger level:** on BE11529's first write (4-20 15:19) the unit read 0.005 and 0.01 psi in its two `MicL` channel blocks (3 and 7; Series 3 carries 8 channel blocks of 48 bytes from `[1708]`, the second four prefixed `0x32`) and Blastware wrote 0.004983 and 0.010058 -- the same levels to its 0.1 dB; every other write left them alone. **Every one of the 11 Blastware writes reproduces** from the block before it with only the fields Blastware changed (plus that re-render and, on 10-26, the mic bit of `[25]`). Code: `minimateplus.protocol.assemble_compliance_content`, `read_compliance_content`, `micromate.setup_fields`; tests `tests/test_s3_settings_read.py`, `tests/test_setup_fields.py`. |
|
||||
@@ -3466,6 +3467,10 @@ The body is reconstructed from the raw A5 bulk waveform stream frames by strippi
|
||||
The footer terminates the N00 file. Its bytes come directly from the terminator A5 frame's inner content — do NOT reconstruct from event metadata.
|
||||
|
||||
✅ **It is the file's last 26 bytes** (2026-11-03): `0e 08` and two valid times end every one of 70,041 DL2 files.
|
||||
|
||||
> 🔑 **2026-11-06 (measured):** it is the last record of the chain that starts with the event
|
||||
> record (D.6.13). The two bytes before it, `00 1a`, are its length (26), and `0e` is its id.
|
||||
> The chain lands exactly on it in all 70,041 DL2 files.
|
||||
- ⚠ **Do not search for the first `0e 08` + plausible year.** 14 DL2 files also hold an earlier record of that shape, about 1.1 KB before the end, carrying the stop time followed by zeros.
|
||||
- Taking it made a histogram start at its own stop (a day late on BE9558's daily histograms). It also cost a waveform its stop, and with it the trigger time.
|
||||
|
||||
@@ -3959,12 +3964,12 @@ All four channels match every DL2 histogram.
|
||||
|
||||
#### D.6.11 Not read from the file yet
|
||||
|
||||
*Updated 2026-11-05. 59 of 88 report fields now match on every DL2 event, up from 47
|
||||
before group D (run `20261105-140021`, 0 regressions).*
|
||||
*Updated 2026-11-06. 71 of 88 report fields now match on every DL2 event: 47 before group D,
|
||||
59 after it, 71 with the sensor check (run `20261106-125854`, 0 regressions).*
|
||||
- **Fields not read yet:**
|
||||
- extended notes
|
||||
- sensor check results (probably the records after the unit's summary, `0x3c` / `0x3d`;
|
||||
inferred, D.6.12)
|
||||
- ~~sensor check results~~ **read, 2026-11-06 (D.6.13)**: the unit's own, in the header of
|
||||
each sensor-check record
|
||||
- monitor log
|
||||
- ~~the values Blastware computes: ZC frequency, acceleration, displacement, time of peak~~
|
||||
**Read, 2026-11-04 → 05 (D.6.12).** Blastware prints the unit's own ZC frequency,
|
||||
@@ -4017,6 +4022,11 @@ channels. The 4 others are O117I1NK (below).
|
||||
**Then records `0x3c` (and on a histogram `0x3d`)**, length 202–212. Not read yet. Probably
|
||||
the sensor check, before and after (inferred, not measured).
|
||||
|
||||
> ⚠ **RETRACTED 2026-11-06 (measured):** "before and after". They are the sensor check, but
|
||||
> one record per channel: `0x3c` Tran, `0x3d` Vert, `0x3e` Long, `0x3f` MicL, on waveforms and
|
||||
> histograms alike. My first walk stopped at the first id it did not know. The chain runs on
|
||||
> to the footer: D.6.13.
|
||||
|
||||
**What Blastware prints from them.** It prints the unit's values; it does not recompute them:
|
||||
|
||||
| Field | Rule | DL2 |
|
||||
@@ -4047,6 +4057,51 @@ full resolution: a stored sample of ±16 counts hides anything from 1 to 31.
|
||||
from sample 4,096 to 4,097, which its own sample table shows. Not explained. Skipping every
|
||||
4,096-sample boundary fixes this file but breaks another.
|
||||
|
||||
#### D.6.13 The record chain to the footer, and the sensor check ✅ 2026-11-06
|
||||
|
||||
**The whole tail of an event file is one record chain.** Walked from the event record by its
|
||||
length prefixes, it ends exactly at the file's last byte on **all 70,041 DL2 files**, in two
|
||||
shapes:
|
||||
|
||||
| Files | Chain |
|
||||
|---|---|
|
||||
| 70,033 | `0x05` event record → `0x32`–`0x35` unit's summary (D.6.12) → `0x3c`–`0x3f` sensor checks → `0x0e` footer |
|
||||
| 8 | the same without `0x35` and `0x3f`: BE16352, which records no mic |
|
||||
|
||||
The **footer** (D.3.3, "the file's last 26 bytes") is the chain's last record: its length
|
||||
`00 1a` sits just before it, and its first byte, `0e`, is its id. SFM reads nothing in the
|
||||
chain unless the walk ends exactly at the end of the file.
|
||||
|
||||
**Each sensor-check record** (`0x3c` Tran, `0x3d` Vert, `0x3e` Long, `0x3f` MicL) holds the
|
||||
check the unit ran: a header with its results, then the trace Blastware draws in its "Sensor
|
||||
Check" strip (`minimateplus/sensor_check.py`, since 2026-09-15). Payload after the id:
|
||||
|
||||
| bytes | content |
|
||||
|---|---|
|
||||
| `[0:2]` | `00 00` |
|
||||
| `[2]` | channel type: `01` geophone, `02` mic, `00` the check disabled |
|
||||
| `[3]` | `00` |
|
||||
| `[4]` | **status**: `00` passed; 1–15 otherwise |
|
||||
| `[5:7]` | **frequency × 10**, uint16 BE (Hz) |
|
||||
| `[7:9]` | **ratio × 10**, uint16 BE (geophones; the mic's reads 10) |
|
||||
| `[9:11]` | **amplitude, mV**, uint16 BE (the mic's; geophones carry a value too, ~260–700, not printed) |
|
||||
| `[11:19]` | not identified ❓ |
|
||||
| `[19:]` | the trace (`sensor_check.py`'s `_HEADER_LEN` = 20 counts the id byte) |
|
||||
|
||||
**What Blastware prints** (`TestFreq`, `TestRatio`, `TestAmplitude`, `TestResults`):
|
||||
|
||||
| Field | Rule | DL2 |
|
||||
|---|---|---|
|
||||
| geophone test frequency and ratio | as stored, ÷ 10 | 209,943 / 209,943 each |
|
||||
| mic test frequency and amplitude | as stored (frequency ÷ 10) | 69,975 / 69,975 each |
|
||||
| result | `Passed` at status 0, `Check` at any other, `Disabled` at channel type 0 (and nothing else printed) | every channel |
|
||||
|
||||
**The status code is the unit's verdict, not a limit SFM can recompute.** Geophones that pass
|
||||
span 6.7–9.4 Hz and ratio 1.9–6.0, yet K559L6N1's Tran reads `Check` at 8.1 Hz and 3.3. Each
|
||||
of the four bits occurs across the whole range of frequency, ratio and amplitude, so their
|
||||
meanings are not decoded. Every mic `Check` in DL2 (691) is status 13 with frequency 0 and
|
||||
amplitude 0: a mic that did not respond (inferred).
|
||||
|
||||
---
|
||||
|
||||
*All findings reverse-engineered from live RS-232 bridge captures.*
|
||||
|
||||
@@ -157,6 +157,13 @@ def sfm_side(raw: bytes) -> SfmSide:
|
||||
("LongZCFreq", pv.long_zc_freq), ("MicLZCFreq", pv.mic_zc_freq)):
|
||||
if hz is not None:
|
||||
values[tag] = "<1.0" if hz < 1.0 else hz
|
||||
# The unit's sensor check (2026-11-06), every record type.
|
||||
for ch, r in (ev.sensor_check_results or {}).items():
|
||||
values[f"{ch}TestResults"] = r.result
|
||||
for tag, value in (("TestFreq", r.freq_hz), ("TestRatio", r.ratio),
|
||||
("TestAmplitude", r.amplitude_mv)):
|
||||
if value is not None:
|
||||
values[f"{ch}{tag}"] = value
|
||||
if counts["MicL"]:
|
||||
values["MicLPSPL dB(L)"] = mic_count_to_db(max(abs(c) for c in counts["MicL"]))
|
||||
values["MicLPSPL psi(L)"] = pv.micl if pv is not None else None
|
||||
|
||||
@@ -26,7 +26,7 @@ import struct
|
||||
from pathlib import Path
|
||||
from typing import Optional, Union
|
||||
|
||||
from .models import DeviceInfo, Event, PeakValues, ProjectInfo, Timestamp
|
||||
from .models import DeviceInfo, Event, PeakValues, ProjectInfo, SensorCheckResult, Timestamp
|
||||
from . import blastware_file as _bw # avoid circular reference at module load
|
||||
from .bw_ascii_report import BwAsciiReport
|
||||
from . import waveform_codec as _wc
|
||||
@@ -1069,12 +1069,34 @@ def _histogram_event_record(
|
||||
return None, None, (f"{rejected} candidate(s), none valid" if rejected else "no candidate"), None
|
||||
|
||||
|
||||
# The unit's own event summary (measured on DL2, 2026-11-05). The event record
|
||||
# is the first of a chain of [length uint16 BE][id][payload] records, so the
|
||||
# next record starts `length` + 2 bytes after its lead. Its payload holds the
|
||||
# vector-sum peak's sample at [22:26] past the marker. The four that follow,
|
||||
# 22 bytes each, are one per channel (ids 0x32 Tran .. 0x35 MicL; a unit
|
||||
# without a mic has no 0x35):
|
||||
# The event record is the first of a chain of [length uint16 BE][id][payload]
|
||||
# records, the next starting `length` + 2 bytes after a record's lead (measured
|
||||
# on all 70,041 DL2 files, 2026-11-06): the event record 0x05, the unit's
|
||||
# summary 0x32-0x35, its sensor checks 0x3c-0x3f, then the footer 0x0e -- the
|
||||
# file's last 26 bytes. A unit without a mic has no 0x35 or 0x3f (8 files).
|
||||
# The walk ends exactly at the file's end on every one, so a chain that does
|
||||
# not is not read at all.
|
||||
_RECORD_LEAD_TO_MARKER = 6 # the lead `00 28 05 00` and the source sit before the marker
|
||||
|
||||
|
||||
def _record_chain(raw: bytes, marker_at: int) -> Optional[dict[int, bytes]]:
|
||||
"""Each record's payload by id (the first of each), for the chain that
|
||||
starts with the validated event record whose marker is at `marker_at`; None
|
||||
unless the chain ends exactly at the end of the file."""
|
||||
off = marker_at - _RECORD_LEAD_TO_MARKER
|
||||
out: dict[int, bytes] = {}
|
||||
while off < len(raw):
|
||||
ln = int.from_bytes(raw[off:off + 2], "big")
|
||||
if off + 3 > len(raw) or ln < 1 or off + 2 + ln > len(raw):
|
||||
return None
|
||||
out.setdefault(raw[off + 2], raw[off + 3:off + 2 + ln])
|
||||
off += 2 + ln
|
||||
return out
|
||||
|
||||
|
||||
# The unit's own event summary (measured on DL2, 2026-11-05). The event
|
||||
# record's payload holds the vector-sum peak's sample at [25:29] (its marker
|
||||
# + 22). Then one record per channel, 22 bytes (ids 0x32 Tran .. 0x35 MicL):
|
||||
# [0] 0 [1:3] min [3:5] max (int16 BE; geophones in units of 16 counts)
|
||||
# [5:9] peak sample [9:11] half-period, samples [11:15] displacement
|
||||
# integral, units x samples [15:21] probably the unit's own largest sample step
|
||||
@@ -1082,26 +1104,22 @@ def _histogram_event_record(
|
||||
# computation from the samples (_waveform_peak_detail)
|
||||
# min, max and peak sample equal the samples' own on 25,962 / 25,966 DL2
|
||||
# channels (the 4 others: O117I1NK.R70W, whose samples wrap at the trigger).
|
||||
_EVENT_RECORD_ID = 0x05
|
||||
_SUMMARY_PVS_SAMPLE = slice(25, 29)
|
||||
_SUMMARY_CHANNELS = {0x32: "Tran", 0x33: "Vert", 0x34: "Long", 0x35: "MicL"}
|
||||
_SUMMARY_CHANNEL_LEN = 22
|
||||
_RECORD_LEAD_TO_MARKER = 6 # the lead `00 28 05 00` and the source sit before the marker
|
||||
_SUMMARY_PVS_SAMPLE_AT = 22 # past the marker
|
||||
_SUMMARY_CHANNEL_LEN = 21 # the payload; the record is 22 with its id
|
||||
|
||||
|
||||
def _unit_summary(raw: bytes, marker_at: int) -> Optional[dict]:
|
||||
"""The unit's per-channel event summary after the validated event record
|
||||
whose marker is at `marker_at`: {"pvs_sample": int, "Tran": {...}, ...},
|
||||
each channel {"min", "max", "peak_sample", "half_period",
|
||||
"disp_integral"}. None when no channel record follows the event record."""
|
||||
lead = marker_at - _RECORD_LEAD_TO_MARKER
|
||||
off = lead + 2 + int.from_bytes(raw[lead:lead + 2], "big")
|
||||
out: dict = {"pvs_sample": int.from_bytes(
|
||||
raw[marker_at + _SUMMARY_PVS_SAMPLE_AT:marker_at + _SUMMARY_PVS_SAMPLE_AT + 4], "big")}
|
||||
while off + 2 + _SUMMARY_CHANNEL_LEN <= len(raw):
|
||||
ch = _SUMMARY_CHANNELS.get(raw[off + 2])
|
||||
if int.from_bytes(raw[off:off + 2], "big") != _SUMMARY_CHANNEL_LEN or ch is None or ch in out:
|
||||
break
|
||||
p = raw[off + 3:off + 2 + _SUMMARY_CHANNEL_LEN]
|
||||
def _unit_summary(chain: dict[int, bytes]) -> Optional[dict]:
|
||||
"""The unit's per-channel event summary from a record chain:
|
||||
{"pvs_sample": int, "Tran": {...}, ...}, each channel {"min", "max",
|
||||
"peak_sample", "half_period", "disp_integral"}. None when the chain has no
|
||||
channel record."""
|
||||
out: dict = {"pvs_sample": int.from_bytes(chain.get(_EVENT_RECORD_ID, b"")[_SUMMARY_PVS_SAMPLE], "big")}
|
||||
for rid, ch in _SUMMARY_CHANNELS.items():
|
||||
p = chain.get(rid)
|
||||
if p is None or len(p) != _SUMMARY_CHANNEL_LEN:
|
||||
continue
|
||||
out[ch] = {
|
||||
"min": struct.unpack(">h", p[1:3])[0],
|
||||
"max": struct.unpack(">h", p[3:5])[0],
|
||||
@@ -1109,10 +1127,41 @@ def _unit_summary(raw: bytes, marker_at: int) -> Optional[dict]:
|
||||
"half_period": int.from_bytes(p[9:11], "big"),
|
||||
"disp_integral": int.from_bytes(p[11:15], "big"),
|
||||
}
|
||||
off += 2 + _SUMMARY_CHANNEL_LEN
|
||||
return out if len(out) > 1 else None
|
||||
|
||||
|
||||
# The sensor check's results, in the header of each sensor-check record (ids
|
||||
# 0x3c Tran .. 0x3f MicL, whose traces minimateplus.sensor_check decodes).
|
||||
# Payload: [2] channel type (1 geophone, 2 mic, 0 the check disabled) [4] status,
|
||||
# 0 = passed [5:7] frequency x 10 [7:9] ratio x 10 [9:11] amplitude, mV.
|
||||
# Blastware prints them as they are (DL2, 2026-11-06): 209,943 / 209,943
|
||||
# geophone frequencies and ratios, 69,975 / 69,975 mic frequencies and
|
||||
# amplitudes; "Passed" on status 0 and "Check" on every other (1 .. 15: its bits
|
||||
# are not decoded), "Disabled", with nothing else, on type 0.
|
||||
_SENSOR_CHECK_CHANNELS = {0x3c: "Tran", 0x3d: "Vert", 0x3e: "Long", 0x3f: "MicL"}
|
||||
_SENSOR_CHECK_HEADER_LEN = 11
|
||||
|
||||
|
||||
def _sensor_check_results(chain: dict[int, bytes]) -> Optional[dict[str, SensorCheckResult]]:
|
||||
out: dict[str, SensorCheckResult] = {}
|
||||
for rid, ch in _SENSOR_CHECK_CHANNELS.items():
|
||||
p = chain.get(rid)
|
||||
if p is None or len(p) < _SENSOR_CHECK_HEADER_LEN:
|
||||
continue
|
||||
kind, status = p[2], p[4]
|
||||
if kind == 0:
|
||||
out[ch] = SensorCheckResult("Disabled", status)
|
||||
continue
|
||||
r = SensorCheckResult("Passed" if status == 0 else "Check", status,
|
||||
freq_hz=int.from_bytes(p[5:7], "big") / 10)
|
||||
if ch == "MicL":
|
||||
r.amplitude_mv = int.from_bytes(p[9:11], "big")
|
||||
else:
|
||||
r.ratio = int.from_bytes(p[7:9], "big") / 10
|
||||
out[ch] = r
|
||||
return out or None
|
||||
|
||||
|
||||
def _parse_record_time_seconds(raw: bytes) -> Optional[float]:
|
||||
"""The configured post-trigger record time in seconds, from the recording-
|
||||
setup config block, or None when absent / implausible."""
|
||||
@@ -1612,7 +1661,9 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event:
|
||||
if (is_waveform_body and ev.peak_values is not None and ev.sample_rate
|
||||
and ev.pretrig_samples is not None):
|
||||
_waveform_peak_detail(ev.peak_values, samples, geo_fs, ev.sample_rate, ev.pretrig_samples)
|
||||
_summary = _unit_summary(raw, _record_at) if _record_at is not None else None
|
||||
_chain = _record_chain(raw, _record_at) if _record_at is not None else None
|
||||
_summary = _unit_summary(_chain) if _chain is not None else None
|
||||
ev.sensor_check_results = _sensor_check_results(_chain) if _chain is not None else None
|
||||
if _summary is not None and ev.peak_values is not None and ev.sample_rate:
|
||||
_apply_unit_summary(ev.peak_values, _summary, geo_fs, ev.sample_rate,
|
||||
ev.pretrig_samples if is_waveform_body else None)
|
||||
|
||||
@@ -383,6 +383,17 @@ class PeakValues:
|
||||
long_peak_disp_in: Optional[float] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class SensorCheckResult:
|
||||
"""One channel's sensor check, as the unit stores it in the event file
|
||||
(2026-11-06). `result` is Blastware's word for it."""
|
||||
result: str # "Passed", "Check" or "Disabled"
|
||||
status: int # the unit's code: 0 passed; its bits are not decoded
|
||||
freq_hz: Optional[float] = None # geophone resonance / mic test frequency; None when Disabled
|
||||
ratio: Optional[float] = None # geophones only
|
||||
amplitude_mv: Optional[int] = None # the mic only
|
||||
|
||||
|
||||
# ── Project / operator metadata ───────────────────────────────────────────────
|
||||
|
||||
@dataclass
|
||||
@@ -592,6 +603,9 @@ class Event:
|
||||
# Raw ADC counts; the source series' scale differs but the trace is a
|
||||
# shape diagnostic (rendered fit-to-box). None when absent.
|
||||
sensor_check: Optional[dict] = None # {"Tran": [...], ..., "MicL": [...]}
|
||||
# And its results per channel, from the same records (2026-11-06): None
|
||||
# when the file's record chain is not whole.
|
||||
sensor_check_results: Optional[dict] = None # channel -> SensorCheckResult
|
||||
|
||||
# Where `timestamp` came from, when decoded from a Blastware binary
|
||||
# (event_file_io): "event_record" -- the instrument's own event record in
|
||||
|
||||
@@ -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).
|
||||
"""
|
||||
|
||||
BIN
Binary file not shown.
+3977
File diff suppressed because it is too large.
Load diff
@@ -595,10 +595,66 @@ def test_time_of_peak_is_the_units_own_peak_sample():
|
||||
assert pv.pvs_time == 0.0
|
||||
|
||||
|
||||
def test_without_the_units_summary_nothing_is_guessed():
|
||||
def test_an_unreadable_channel_record_leaves_only_that_channel_unread():
|
||||
raw = bytearray((_FIX / f"{_US}/I145L6UJ.3Y0W").read_bytes())
|
||||
i = raw.find(b"\x00\x16\x32")
|
||||
raw[i + 2] = 0x00 # break the Tran record's id
|
||||
raw[i + 2] = 0x00 # break the Tran record's id; the chain holds
|
||||
pv = decode_blastware_bytes(bytes(raw), name=None).peak_values
|
||||
assert (pv.tran_zc_freq, pv.mic_zc_freq, pv.tran_peak_disp_in) == (None, None, None)
|
||||
assert (pv.tran_zc_freq, pv.tran_peak_disp_in) == (None, None)
|
||||
assert abs(pv.tran_time_of_peak - 2.281) <= 0.0005 # the samples' peak, as before
|
||||
assert _prints_as(pv.mic_zc_freq, "43") # the others are read
|
||||
|
||||
|
||||
def test_without_a_whole_record_chain_nothing_is_guessed():
|
||||
# The chain from the event record ends exactly at the file's end on all
|
||||
# 70,041 DL2 files; one that does not is not read at all.
|
||||
raw = bytearray((_FIX / f"{_US}/I145L6UJ.3Y0W").read_bytes())
|
||||
i = raw.find(b"\x00\xd4\x3c") # the Tran sensor-check record, length 212
|
||||
raw[i + 1] = 0xd3 # one byte short
|
||||
ev = decode_blastware_bytes(bytes(raw), name=None)
|
||||
assert ev.sensor_check_results is None
|
||||
pv = ev.peak_values
|
||||
assert (pv.tran_zc_freq, pv.mic_zc_freq, pv.tran_peak_disp_in) == (None, None, None)
|
||||
|
||||
|
||||
|
||||
# ── Group E: the sensor check results ───────────────────────────────────────
|
||||
# Records 0x3c Tran .. 0x3f MicL, after the unit's summary, carry the sensor
|
||||
# check the unit ran: its trace (minimateplus.sensor_check) and, in the record's
|
||||
# header, its results (measured on DL2, 2026-11-06):
|
||||
# [2] channel type (1 geophone, 2 mic, 0 check disabled) [4] status, 0 = passed
|
||||
# [5:7] frequency x 10 [7:9] ratio x 10 [9:11] amplitude, mV
|
||||
# Blastware prints them as they are: 209,943 / 209,943 geophone frequencies and
|
||||
# ratios, 69,975 / 69,975 mic frequencies and amplitudes; "Passed" on status 0,
|
||||
# "Check" on every other status, "Disabled" on type 0.
|
||||
|
||||
@pytest.mark.parametrize("rel,want", [
|
||||
# channel: (result, frequency Hz, ratio, amplitude mV), Blastware's _XML.XML
|
||||
(f"{_US}/I145L6UJ.3Y0W", {"Tran": ("Passed", 7.3, 3.7, None), "Vert": ("Passed", 7.2, 3.9, None),
|
||||
"Long": ("Passed", 7.2, 3.9, None), "MicL": ("Passed", 19.7, None, 592)}),
|
||||
(f"{_US}/K440HJCN.AS0W", {"Tran": ("Check", 9.6, 13.8, None), "Vert": ("Check", 8.5, 7.2, None),
|
||||
"Long": ("Passed", 7.3, 1.9, None), "MicL": ("Passed", 19.7, None, 519)}),
|
||||
(f"{_US}/R349KMF7.9O0W", {"Tran": ("Passed", 7.4, 3.8, None), "Vert": ("Passed", 7.5, 3.5, None),
|
||||
"Long": ("Passed", 7.8, 3.6, None), "MicL": ("Check", 0.0, None, 0)}),
|
||||
(f"{_US}/R352HFZ7.5D0W", {"Tran": ("Disabled", None, None, None), # no mic; check disabled
|
||||
"Vert": ("Disabled", None, None, None),
|
||||
"Long": ("Disabled", None, None, None)}),
|
||||
(f"{_US}/T193HLJ3.X80H", {"Tran": ("Passed", 7.4, 3.9, None), "Vert": ("Passed", 7.2, 3.9, None),
|
||||
"Long": ("Passed", 7.5, 4.1, None), "MicL": ("Passed", 20.1, None, 556)}),
|
||||
])
|
||||
def test_sensor_check_results_are_the_units_own(rel, want):
|
||||
got = read_blastware_file(_FIX / rel).sensor_check_results
|
||||
assert set(got) == set(want)
|
||||
for ch, (result, freq, ratio, amp) in want.items():
|
||||
r = got[ch]
|
||||
assert r.result == result, ch
|
||||
assert r.freq_hz == (pytest.approx(freq) if freq is not None else None), ch
|
||||
assert r.ratio == (pytest.approx(ratio) if ratio is not None else None), ch
|
||||
assert r.amplitude_mv == amp, ch
|
||||
|
||||
|
||||
def test_a_check_keeps_the_units_status_code():
|
||||
# Blastware prints only "Check"; the code's bits are not decoded (K559L6N1's
|
||||
# Tran is a Check at 8.1 Hz and 3.3, inside every passing range).
|
||||
got = read_blastware_file(_FIX / f"{_US}/K440HJCN.AS0W").sensor_check_results
|
||||
assert [got[ch].status for ch in ("Tran", "Vert", "Long", "MicL")] == [11, 2, 0, 0]
|
||||
@@ -43,7 +43,7 @@ def test_report_fields_stay_blank():
|
||||
# since 2026-11-04, ZC frequency and displacement since 2026-11-05:
|
||||
# test_the_setup_fields_match_blastware, test_waveform_peak_detail_*,
|
||||
# test_zc_frequency_and_displacement_match_blastware. Its Tran ZC is N/A.)
|
||||
for tag in ("TranZCFreq", "TranTestResults"):
|
||||
for tag in ("TranZCFreq",): # (sensor check results since 2026-11-06)
|
||||
assert s.values.get(tag) is None
|
||||
|
||||
|
||||
@@ -393,3 +393,26 @@ def test_a_clipped_events_peak_times_match_blastware():
|
||||
for f in ("TranTimeofPeak", "VertTimeofPeak", "LongTimeofPeak", "MicLTimeofPeak",
|
||||
"PeakVectorSumTimeSum"):
|
||||
assert res[f].verdict == "match", (f, res[f])
|
||||
|
||||
|
||||
|
||||
# ── Group E: the sensor check results (2026-11-06) ──────────────────────────
|
||||
_SENSOR_CHECK = [f"{ch}Test{f}" for ch in ("Tran", "Vert", "Long", "MicL")
|
||||
for f in ("Results", "Freq", "Ratio", "Amplitude")]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", [
|
||||
FIX / "R352HIUI.F40W", FIX / "T1905KDW.5F0W", FIX / "T004JTRF.ME0H", FIX / "M529L4XQ.R30H",
|
||||
_US / "K440HJCN.AS0W", # two Checks
|
||||
_US / "K558IKSJ.P20W", _US / "O117I1NK.R70W",
|
||||
])
|
||||
def test_sensor_check_results_match_blastware(path):
|
||||
ref = parse_xml_report_file(path.with_name(path.name.replace(".", "_", 1) + "_XML.XML"))
|
||||
res = {r.field: r for r in compare(sfm_side(path.read_bytes()), ref, CARVEOUTS)}
|
||||
checked = 0
|
||||
for f in _SENSOR_CHECK:
|
||||
if ref.scalars.get(f) is None:
|
||||
continue
|
||||
assert res[f].verdict == "match", (f, res[f])
|
||||
checked += 1
|
||||
assert checked >= 4
|
||||
@@ -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())
|
||||
Reference in new issue
Block a user