diff --git a/CHANGELOG.md b/CHANGELOG.md index ab3ba31..cfce416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,126 @@ All notable changes to seismo-relay are documented here. - ⚠ **Codec change: bump `TOOL_VERSION` at the next release.** The backfill (`backfill_sidecars.py` then `backfill_event_shape.py`) rewrites stored Sensitive events' peaks and `.h5` files. No schema change. +- **Histograms go to the histogram codec, and a loud interval no longer hides + a short one.** These were the histograms the decode checker found decoding + wrongly. + - **The codec now follows the record type.** The file decoder used to try the + waveform codec first, whatever `STRT[18]` said. That codec accepted BE9440, + BE9557 and BE17354's 2018 5 s histograms and returned about 5× too many + "samples" (K440HDXX.XH0H: 44,504 against Blastware's 6,976). Only an + unknown type still falls back to trying both, and a chosen codec that + fails is now a decode problem rather than a silent switch. + - **A loud interval no longer breaks the sub-minute layout check.** The check + required each record's "zero word" to be `0000`. That word is the high word + of the interval's PVS², which is non-zero above 1.28 in/s, so a one-block + histogram with a loud interval decoded to nothing (T193KR5M.X90H, + K440HA3C.JM0H, R352HFZ7.530H). + - The check is now the measured relation peak ≤ PVS ≤ √3·peak. It holds + on 34,502,955 / 34,502,955 DL2 sub-minute intervals. + - The trim for a stream with no terminal tail uses the same test. + - **New decode-checker carve-out, `interval-count-is-duration`.** Blastware's + "Number of Intervals" is (stop − start) / interval. When the unit never + wrote the last minute, Blastware's own interval table lists one block + fewer, and SFM matches the table. It covers 8 events. + - **Decode checker:** 462 comparisons fixed, 0 regressions, 16 of 88 fields + fully match (was 11). + - Every DL2 histogram's Tran / Vert / Long interval peaks now match + Blastware (bar the clipped intervals the saturation carve-out covers). + - Channels 70,042 / 70,042. + - Histogram start dates a day off: 26 → 9. + - Peak vector sum mismatches: 45 → 18. + - ⚠ **Codec change:** it rides the next release's `TOOL_VERSION` bump and + backfill (`backfill_sidecars.py` then `backfill_event_shape.py`). Those + files are stored wrongly on prod today, and the backfill rewrites them. No + schema change. +- **A Blastware file's footer is its last 26 bytes: no more day-late + histograms.** + - **Measured:** every DL2 file ends in a valid footer (`0e 08` and two valid + times), 70,041 / 70,041. + - **The bug:** the decoder took the first "`0e 08` + plausible year". On 14 + files there is an earlier record, about 1.1 KB before the end, holding the + stop time followed by zeros. + - A histogram then started at its own stop: a day late on BE9558's daily + histograms (K558L9XP.FK0H read 2025-10-08 19:10:01 for Blastware's + 2025-10-07 19:14:08). + - T003LCYV.JD0H got no time at all. + - A waveform lost its stop, so its trigger was never computed and the stop + was stamped instead (K440I4LG.JK0W: 11:14:12 for 11:14:08). + - **The fix:** the last 26 bytes are now taken when they are a footer, and + the old search remains only as the fallback. + - **Decode checker:** event times 6,524 / 6,524 and histogram start dates + 63,518 / 63,518. 13 comparisons fixed, 0 regressions, 18 of 88 fields + fully match (was 16). + - **Also:** the protocol reference records where the 1995 default-clock + events come from (units back from calibration with the battery unplugged; + 17 in DL2). + - ⚠ **Codec change:** it rides the next release's `TOOL_VERSION` bump and + backfill. It moves the stored time of those ~14 events on prod. No schema + change. + +### Added +- **A Blastware file's job number, and whether Blastware shows it.** + - **Where it is:** the setup block has Series IV's `0x1A` layout here too. + The report flags sit at 9 bytes before the setup name, with bit `0x02` + meaning the job number is shown. The number is a uint16 BE at 8 bytes + before the name, and it is kept while switched off. + - **Measured:** the flag matches Blastware's JobNumber on 2,997 / 2,997 DL2 + events that print one, and 66,986 / 66,986 that don't. + - Every printed value is 1, so the value is only proven for 1. + - Hidden ones hold real numbers (802, 1012, 1013, 622). + - **`ProjectInfo.job_number_enabled` / `job_number`**, named as in + `micromate.setup_block`. + - **`write_event_hdf5`** stores both as `.h5` attributes when they were read. + - **Decode checker:** JobNumber 2,997 / 2,997, and 11 of 88 fields fully + match (was 10). 0 regressions. A job number only SFM shows now counts as a + mismatch. + - **Not in the database, the API or the PDF report yet.** That needs a + column. + - ⚠ **Codec change:** it rides the next release's `TOOL_VERSION` bump and + backfill (`backfill_sidecars.py` then `backfill_event_shape.py`). The new + `.h5` attributes are additive. No schema change, no migration. + +### Protocol / Documentation +- **Where file-only decoding stands, and that prod's ASCII overlay is + scaffolding.** + - **CLAUDE.md "Where things stand"** now says plainly that a paired + Blastware ASCII report overwrites SFM's decode on import, and that only + report-less events run on the decoder alone. The overlay is to be retired + at step 3 of the plan. + - The checker status is brought up to `dev`: 18 of 88 fields match on every + DL2 event, with the remaining groups A–F in the proposed order. The README + roadmap is updated to match. + - **The protocol reference** records: + - the footer as the file's last 26 bytes (D.3.3, with `[18:24]` retracted + as "fixed") + - the codec chosen by STRT[18] + - the job number + - the PVS² high word and the peak / PVS consistency check (retracting + "reads 0000") + - Blastware's interval count + - a refreshed "not read yet" list + - Docs only: no code change, no migration. +- **`docs/instantel_protocol_reference.md` gains Appendix D.6:** the bytes + and DL2 verification for every field SFM reads from a Blastware event file. + - the record type, `STRT[18]` + - the recording-setup block: sample rate, pre-trigger, record time and the + four notes + - the geophone range + - each histogram interval's PVS² + - the mic scale +- **Retracted in place:** + - `STRT[20]` as the record time: it is `00` on every DL2 file. + - The 2026-08-26 reading of sub-minute histogram records as little-endian: + they are big-endian from byte 5 (#47/#49), and the "2-word tail" is the + PVS². This is corrected in CLAUDE.md too. +- **#48 is still open.** The event file's setup 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**, not the unit's setting: it varies on the + same unit on the same day, and Blastware reports it per event. So the files + say little about whether the live 1A read loses its anchor. (Corrected the + same day; the first version read the file's value as the setting.) +- **CLAUDE.md "Where things stand"** now reflects the range fix. +- Docs only: no code change, no migration. ## v0.33.0 — 2026-11-01 diff --git a/CLAUDE.md b/CLAUDE.md index ef0ba9f..b06eefa 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -10,10 +10,27 @@ pair — lives in `../terra-view/docs/tmi-stack.md`, which is also loaded as --- -## Where things stand (updated 2026-11-01) +## Where things stand (updated 2026-11-03) Read this first when picking the project back up. +- **🔑 Prod still leans on Blastware's ASCII report, and that is scaffolding.** + - **How it works today:** when a `_ASCII.TXT` report arrives with a + Blastware file, `WaveformStore.save_imported_bw` overlays its peaks, notes, + sample rate and record time onto SFM's decode + (`event_file_io.apply_report_to_event`). + - **Only events without a report** run on the decoder alone: all DL2 events + before 2025, and everything SFM downloads itself. + - **Why that matters:** the overlay made SFM trustworthy from day one. It + also hid how much the decoder could not yet do; until the checker (below) + there was no full list of what Blastware reports. + - **The goal is full function without Blastware (Brian, 2026-10-29).** The + README roadmap has four steps: + 1. the checker ✅ + 2. complete the file-only decode, one field group at a time + 3. switch ingest so reports are kept only for checking (retire the overlay) + 4. stop the watchers forwarding reports + - Until step 3, prod keeps the report as truth wherever one exists. - **🔑 The Series-3 decode checker (2026-10-29; v0.33.0).** - **Goal:** SFM produces everything Blastware reports, from the event file alone (spec and plan in `docs/superpowers/`). @@ -25,27 +42,51 @@ Read this first when picking the project back up. `~/dl2-archive/checker-runs/` and is never committed. - **The rule:** every mismatch is SFM's bug unless a carve-out with evidence covers it. + - **Byte layouts** of every field read from the file: + `docs/instantel_protocol_reference.md` Appendix **D.6**. - **As of v0.33.0:** - - ✅ **Match on every event:** sample rate, record time, pre-trigger, notes, - and event type (#41, from STRT[18]). - - ✅ **Geophone samples** are exact on 6,491 / 6,524 waveforms in every year. - The 33 others are the 1.250 in/s range, 8× under SFM's Normal-range - assumption. - - ✅ **Histogram PVS** = the stored per-interval PVS²: 69,919 / 70,042. - - ✅ **Mic: one count = 0.25 Pa,** with Blastware's dB offset at 81.9384. It - fails on only a few dozen events. + **Where the decoder stands on `dev`** (2026-11-03, run `20261103-121047`): + **18 of 88 fields match on every event**, up from about 6 before v0.33.0. + The four `dev` fixes below share one release and one backfill. + - ✅ **Match on every event:** + - sample rate, record time, pre-trigger, notes and event type (v0.33.0) + - geophone range, job number, event times (6,524 / 6,524) and histogram + start dates (63,518 / 63,518) — `dev` + - ✅ **Geophone samples** are exact on **6,524 / 6,524** waveforms in every + year (`dev`; v0.33.0 had 6,491, its 33 others being Sensitive-range events + read 8× high). + - ✅ **Histograms** decode to Blastware's own interval table on every DL2 + file: Tran / Vert / Long interval peaks have 0 mismatches (`dev`). + - The codec is now chosen by STRT[18]. The waveform codec had been + claiming 2018 5 s histograms. + - The sub-minute layout check now tests peak ≤ PVS ≤ √3·peak. + - Blastware's "Number of Intervals" is the monitoring time ÷ the interval: + a carve-out, 8 events. + - ✅ **Histogram PVS** = the stored per-interval PVS²: 69,989 / 70,042. + **Mic:** one count = 0.25 Pa, dB offset 81.9384; a few dozen stragglers. - ❌ **Open:** - - histogram start times are 1 s early (#51) - - 35 sub-minute (5 s / 2 s) histograms decode wrongly, plus 2 one-minute - no-mic histograms (`R352HFZ7`-shaped, likely a separate cause) - - 26 histogram start dates are a day off - - the per-interval PVS is not stored + - histogram start times are 1 s early (#51; fixing it moves every stored + histogram by 1 s, and the event key is (serial, time), so it needs a + decision first) + - the mic stragglers: ~20 one-minute histograms with an interval or two off - Blastware prints `OORANGE` when the vector sum alone exceeds the range (a carve-out to prove) - - ⬜ **Not read yet:** job number, ZC frequency, acceleration, displacement, - time of peak, sensor check, battery, calibration, range, units, monitor - log. + - ⬜ **Not read yet, in the order proposed** (2026-11-03): + - **A. Setup fields:** trigger source and levels, stop mode, mic type, + display units, firmware version, serial number, calibration, battery. + - **B. Histogram interval detail:** per-interval frequencies (#50: they + assume 1024 sps), per-interval PVS, interval size, stop time. + - **C. #51 timing:** start time, per-interval times, peak times. + - **D. Blastware's waveform calculations:** ZC frequency, acceleration, + displacement, time of peak. + - **E. Sensor check results.** + - **F. Monitor log:** probably not in the event file at all. + - 🔶 **#48 is still open.** The event file's setup 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**, not the setting: 253–256 samples at + 1024 sps, alternating on the same unit on the same day, and reported that + way by Blastware. So the files say little about whether the live 1A read + loses its anchor (reference D.6.2). - **The Series-4 LIVE wire protocol is reverse-engineered end to end (2026-09-25).** `docs/micromate_protocol_reference.md` is the Series-4 Rosetta Stone, sibling to `instantel_protocol_reference.md`. **A Micromate @@ -408,8 +449,9 @@ Read this first when picking the project back up. take: Blastware downloading BE9441 event 2 (`0111c92c`) or 19 (`0118a4ca`) through the recording bridge. Blastware's own files for both are fixtures (`tests/fixtures/minimate-bench-10-25-26/blastware/`), as byte-exact targets. -- **Open, not blocking:** 14 sensitive-range files show an exact 8x - (= 10.0/1.25) units discrepancy; `scripts/backfill_sidecars.py --force` also +- **Open, not blocking:** ~~14 sensitive-range files show an exact 8x + (= 10.0/1.25) units discrepancy~~ (**resolved on `dev` 2026-11-02:** the + range is read from the file, reference D.6.4); `scripts/backfill_sidecars.py --force` also inserts DB rows for store files that have none (one-time per store) and the dry-run does not report that count. - **After any codec change, regenerate the store** — `backfill_sidecars.py` @@ -822,6 +864,14 @@ block still covers exactly one minute: | 15 s | 4 | 92 | | 2 s | 30 | 612 | +> ⚠ **CORRECTED in v0.32.0 (#47/#49), recorded here 2026-11-02.** The +> records are **big-endian, starting at byte 5**. Each holds a uint16 peak +> and a uint16 half-period per channel, then the interval's **PVS² as a +> uint32 BE**. Record = 4 × channels + 4 bytes: 20 with the mic, 16 +> without. `stride = 12 + n × record`. The little-endian reading below was +> the same words shifted by one byte. Its "2-word tail" is the PVS² +> (reference D.6.5). + `stride = 12 + n * 20`. Block = `[00][segment][ctr uint16 LE][0a][00]`, then n x 20-byte records of 8 x uint16 **LITTLE**-endian values (`T_peak, T_halfp, V_peak, V_halfp, L_peak, L_halfp, M_peak, M_halfp`) @@ -829,6 +879,7 @@ plus a 2-word tail whose first word is `0000` on every real interval, then a 6-byte block trailer. ⚠ The standard 32-byte block is BIG-endian; this variant is LITTLE-endian. +*(Retracted: both are big-endian; see the box above.)* Recovers **415 files** (216 on BE18193, 199 on BE9440) that decoded to nothing. Ground truth `BE9440/K440L3AQ.T70H` matches its BW ASCII export @@ -856,6 +907,9 @@ block has its own tail signature. Two long-standing errors: `1e 0a 00 00`, with arbitrary bytes at `[21:23]`. Rejecting it dropped the final interval of nearly every histogram — frequently the one holding the event peak, so the file's PPV read low. +- **`[21:25]` is the interval's PVS² as a uint32 BE** (v0.33.0, reference + D.6.5). The "arbitrary bytes" above are probably its high half + (inferred). Verified against 1211 production histograms paired with their BW ASCII exports: **1211/1211 decode exactly** (interval count plus every @@ -864,11 +918,13 @@ with zero mismatches. Before: 1 of 1196. ### What's NOT solved -- **MicL channel conversion to dB(L)** — the codec emits MicL as +- ~~**MicL channel conversion to dB(L)** — the codec emits MicL as raw ADC counts (same format as geo channels), but BW's ASCII export shows mic in dB(L) with ~6 dB quantization steps. Need to map ADC counts → dB(L) for direct comparison; likely - `dB = 20*log10(|counts|) + offset` or similar. + `dB = 20*log10(|counts|) + offset` or similar.~~ **Solved in v0.33.0.** + One count = 0.25 Pa, and dB(L) = 81.9384 + 20·log10(|count|), an offset + measured from Blastware's printed values (reference D.6.6). - **Variable-prefix segment descriptors** — 3 of the 75 ground-truth production events still truncate. The walk reaches a segment header whose channel-id field is preceded by a *variable-width* prefix (2, 4 @@ -1565,7 +1621,7 @@ Do NOT use fixed absolute offsets for sample_rate or record_time. | trigger_level_geo | float32 BE, located in channel block | | alarm_level_geo | float32 BE, adjacent to trigger_level_geo | | geo_hardware_constant (adc_scale_factor) | float32 BE at **channel_label+28** in both read (E5) and write (SUB 71) payloads — reads **6.206053** on BOTH tested units (BE11529 and BE18189); identical across all geo channels (Tran/Vert/Long) and all captures. **Confirmed 2026-04-17 from Interface Handbook §4.5**: this is the **ADC-to-velocity scale factor** = 1/sensitivity = (in/s per V). Firmware uses it as: `PPV (in/s) = ADC_voltage × 6.206053`. Cross-check: `1.61133 V (ADC full-scale) × 6.206053 = 10.000 in/s` (Normal range ✅). Do NOT write this field — it is a hardware/firmware constant. | -| geo_range (sensitivity selector) | **uint8 at channel_label+33** in both read (E5) and write (SUB 71) payloads — **CONFIRMED 2026-04-20** from 4-20-26 geo sensitivity captures: `0x00` = Normal 10.000 in/s (standard gain), `0x01` = Sensitive 1.250 in/s (high gain). Present in all three geo channel blocks (Tran, Vert, Long). **NOTE: `channel_label+20` reads `0x01` on ALL captures regardless of range setting — it is NOT this field.** Note: the "SUB 71 write offset = +29" that appears in earlier analysis was an artifact of incorrect BW-style destuffing applied to write frame data — write frame data is RAW, so the literal `0x10` bytes in the channel block header are preserved, and the offset is the same as in the E5 read payload. | +| geo_range (sensitivity selector) | **uint8 at channel_label+33** in both read (E5) and write (SUB 71) payloads (an event file's setup copy has it at label+29: reference D.6.4) — **CONFIRMED 2026-04-20** from 4-20-26 geo sensitivity captures: `0x00` = Normal 10.000 in/s (standard gain), `0x01` = Sensitive 1.250 in/s (high gain). Present in all three geo channel blocks (Tran, Vert, Long). **NOTE: `channel_label+20` reads `0x01` on ALL captures regardless of range setting — it is NOT this field.** Note: the "SUB 71 write offset = +29" that appears in earlier analysis was an artifact of incorrect BW-style destuffing applied to write frame data — write frame data is RAW, so the literal `0x10` bytes in the channel block header are preserved, and the offset is the same as in the E5 read payload. | | setup_name | ASCII, null-padded, in cfg body | | project / client / operator / sensor_location | ASCII, label-value pairs | diff --git a/README.md b/README.md index 0f60513..8792c52 100644 --- a/README.md +++ b/README.md @@ -636,16 +636,34 @@ Implementation steps (concrete): ### High-impact (unblocks product features) -- [x] **Series III waveform body codec reverse-engineering.** ✅ The body codec is fully decoded (`minimateplus/waveform_codec.py`, `histogram_codec.py`), and verified per-sample against Blastware's own exports. As of v0.33.0, geophone samples are exact on 6,491 / 6,524 DL2 waveforms against their `_XML.XML` reports, across 2016–2026. -- [ ] **SFM produces everything Blastware reports, from the event file alone.** The four-piece plan: +- [x] **Series III waveform body codec reverse-engineering.** ✅ The body codec is fully decoded (`minimateplus/waveform_codec.py`, `histogram_codec.py`), and verified per-sample against Blastware's own exports. Geophone samples are exact on all 6,524 DL2 waveforms against their `_XML.XML` reports, across 2016–2026 (`dev`; v0.33.0 had 6,491, before the geophone range was read from the file). +- [ ] **SFM produces everything Blastware reports, from the event file alone.** + + **Why this matters:** until it's done, prod overlays Blastware's ASCII report onto SFM's decode wherever a report exists. That made SFM trustworthy from day one, but it is scaffolding: the goal is full function without Blastware. + + The four-piece plan: 1. the decode checker ✅ v0.33.0 2. complete the file-only decode, one field group at a time, each proven by the checker - 3. flip ingest so reports are kept only for checking + 3. flip ingest so reports are kept only for checking (retire the overlay) 4. stop the watchers forwarding reports - **Done so far:** setup fields, notes, event type, histogram PVS, mic. + **Done so far: 18 of 88 report fields match on every DL2 event.** + - In v0.33.0: setup fields, notes, event type, histogram PVS, mic. + - On `dev`: + - the geophone range + - the job number + - histograms that decoded wrongly + - the footer: no more day-late histograms; every waveform time exact - **Next:** histogram start times (#51), the 37 histograms that decode wrongly, the job number, the geophone range (Sensitive-range events read 8×), and the values Blastware computes itself (ZC frequency, acceleration, displacement, time of peak), plus the sensor check, battery, calibration and monitor log. Design: `docs/superpowers/specs/2026-10-29-s3-decode-checker-design.md`. + **Next:** + - setup fields still unread: trigger, stop mode, units, serial, calibration, battery + - histogram interval detail: frequencies (#50), per-interval PVS, interval size, stop time + - histogram start times (#51) + - the values Blastware computes itself: ZC frequency, acceleration, displacement, time of peak + - the sensor check results + - the monitor log + + Design: `docs/superpowers/specs/2026-10-29-s3-decode-checker-design.md`. Status detail: CLAUDE.md "Where things stand". - [x] **Series IV (Thor IDF) binary codec reverse-engineering.** ✅ v0.21.0 — `micromate/idf_file.read_idf_file()` decodes both IDFW (waveform body at offset `0x0f1f`, reusing `decode_waveform_v2()`; 87–99% sample fidelity on quiet events) and IDFH (dedicated segment-based decoder: all 859 corpus files decode, 181,071 intervals, peaks within ~1.8% of sidecar values). `WaveformStore.save_imported_idf` now also projects parsed Thor data into a `bw_report` block via `micromate/idf_to_bw_report.py` so Thor events render in the existing Event Report PDF pipeline without a separate renderer. - [ ] **In-app waveform viewer accuracy.** Depends on Series III codec decode. Plot.v1 JSON pipeline + viewer skeleton already exist; will start showing real waveforms automatically once `_decode_a5_waveform` produces correct samples. Series IV waveforms come online when the IDF codec lands. - [ ] **Series IV live-device support.** Once the IDF binary is decoded, extend `micromate/` with `transport.py` / `framing.py` / `protocol.py` / `client.py` mirroring the `minimateplus/` package layout — depends on capturing Thor's wire protocol (TCP / RS-232 captures TBD). diff --git a/docs/instantel_protocol_reference.md b/docs/instantel_protocol_reference.md index 2977d63..924a7ac 100644 --- a/docs/instantel_protocol_reference.md +++ b/docs/instantel_protocol_reference.md @@ -11,7 +11,9 @@ | Date | Section | Change | |---|---|---| +| 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. | | 2026-10-29 | §7.6.1, §6 | **The SUB 1A settings fields are read AFTER unescaping (measured, BE9441).** The unit escapes 02/03/04/10 in its replies and `S3FrameParser` keeps the `10` of `10 02/03/04`, so on the raw bytes an escaped mode, sample rate or interval shifts every field after it: BE9441 at Histogram / 4096 sps / 2 s read 0 sps and a 4098 s interval, and a Continuous unit read as Single Shot. After `unescape_reply`, every recorded reply (4 settings, two of them Blastware's own writes: 15 min, then 2 s) has one layout: **mode anchor−7, sample rate anchor−6 (u16 BE), histogram interval anchor−4 (u16 BE, s), record time anchor+6 (f32 BE)**. ⚠ The older table's "anchor−7 = constant 0x10" (and mode at anchor−8) was the escape in front of `04` at 1024 sps — right only at that rate. The channel block (`Tran`+28 scale, +33 range, +34 trigger) and the note strings are correct on the RAW bytes and wrong unescaped; 🔶 open: a trigger/alarm float that itself contains 02/03/04/10 would read shifted there. Also measured: **while monitoring, BE9441 answered the 1A reads with its device-info block** (`BE9441`, `Instantel` — the 0x01 reply), so no settings can be read then; the decoder leaves them unknown. The 2026-10-17 anchor question is untouched: every reply measured so far carries the anchor. Fixed in SFM `b320a53`. ⚠ **The write side was not moved:** `_encode_compliance_config` still patches the raw bytes at the 1024-sps offsets (mode anchor−8), which at 2048/4096 sps rewrite the byte in front of the mode (measured on BE9441's 10-25 block); it now refuses a patch whose four fields do not read back as asked (`a72d3a9`) until rewritten on unescaped bytes (#46). | | 2026-10-27 | §3 writes | **⚠ RETRACTS the write-frame model (#46, measured).** Every Blastware request on record re-encodes under the uniform rule (02/03/04/10 escaped, SUM8): 3,869/3,869 frames in the Feb–Apr 2026 captures, plus BE9441's 26 write frames of 2026-10-26. A write's [4:6] is its data LENGTH. Config blocks are their header N + 2 bytes: event index (68) and trigger (82) are written as read plus `02 00` / `00 00` (constant on 15 sends); waveform data (69) and the 2,092-byte compliance image (71) are written whole, the latter in addressed chunks (params[2:4] = address; 1,024 B in March, 512 B with Blastware 10.74). The trailing two bytes are not a CRC and went out stale, so the unit evidently ignores them. "Only BW_CMD doubled", the "DLE-aware checksum", "offset = data[1] + 2" and "chunks 1,027 / 1,055 at offset 0x1004" were these frames read with their escape bytes in. The trigger block is read first (SUB 0x2E, 26 bytes); its byte 5 has been 01 / 03 / 04 by unit and session (meaning unknown). | | 2026-10-26 (5) | §7.8.9 | ✅ **The embedded event record: the instrument's trigger time, inside the 5A stream.** Every Blastware waveform file carries `00 28 05 00 ?? ?? fe 80 [trigger 8 B][stop 8 B]`, times as `dd mm yyyy(BE) 00 hh mm ss`. The trigger equals Blastware's report 1,320/1,320, the filename 7,935/7,935 and the unit's 0C record 10/10. It occurs once in the unit's own A5 payloads (8/8 events) and in SFM-only downloads (2/2): instrument data, not Blastware's. The footer's `ts2 - record time` is only an estimate, a second off on ~19%. Decoder rule, validation and an open case (3 waveform-named files the codec does not recognise) in §7.8.9. 🔶 The §7.5 `0C` "sub_code" timestamp variants look like the same 8-byte form read with its escapes. | @@ -21,7 +23,7 @@ | 2026-10-26 | §7.8 | **5A requests must DLE-escape a checksum that is a framing byte (measured, BE9441).** The request for chunk 0x7D06 of event 01122f06 ends `… 02 03`: a bare 0x02 checksum (STX) before ETX. BE9441 never answered it, twice on two days, and rebooted ~11 s later each time; that was the 'mid-download reboot' of 2026-10-25 (row below). Sent as `… 10 02 03` it answered in 28 ms. So did chunk 0x7F06 (checksum 0x04 → `10 04`) and 0x8B06 (checksum 0x10 → `10 10`; sent bare, that reads as DLE+ETX), and the event downloaded whole and matched the unit's peaks. Escape set {02, 03, 04, 10}: a Micromate's for every byte (251/251 THOR requests), and consistent with §7.8's de-stuffing rule (`10 02/03/04` literal). About 1 chunk request in 64 has such a checksum. ⚠ Not known: whether standard (non-5A) requests need the same. No such keyed-read checksum has been sent. Also measured on the re-run: events that end in the next 64 KB page (BE9441 events 2 and 19) read an end offset lower than their start (the known page bug); every other event downloaded whole and verified. | | 2026-10-25 | §7.2, §7.8, §6 | **MiniMate bench check, BE9441 (S338.17, mic disabled, serial cable). SFM read its 24-entry event index, listed 20 events, and downloaded 4.** Measured: (1) **§7.2: the 0x15 serial is a C string.** `"BE9441\x00?"`: a six-character serial leaves a stray byte after its NUL. (2) **§7.8: every A5 reply echoes the address it answers at `data[2:6]`.** The metadata pages come back as `01 11 10 02` and `01 11 10 04`; sample chunks as their own address, e.g. `01 11 66 6a`. The event-1 walk fetches the metadata pages as frames 1 and 2. A non-first event's walk fetches none and goes straight from the probe to sample chunks. SFM's body builder assumed metadata pages in every stream, so every non-first event it assembled was 2 bytes short and decoded truncated; it now checks the echoed addresses. The bug was in SFM's assembly; the protocol was as already documented. (3) **§6: the unit boots when its serial port opens.** It sent `Operating System` ~3 s after the port opened (twice) and ignored a POLL sent before that. After a mid-download reboot it answered 8.8 s after its banner (one data point). (4) **The unit rebooted once mid-download.** The chunk at 0x7D06 got one stray `0x41`, then silence, then the banner 11 s later. Cause unknown, inferred not measured: battery 6.33–6.37 V, a firmware reset. ⚠ **RETRACTED 2026-10-26:** the cause is measured, and it was our request. The chunk request had a bare 0x02 checksum. See the 2026-10-26 row. (5) The event index said 24 while the header walk listed 20 full records. **Inferred:** the other 4 are monitor-log entries. Single-shot events at 4096 sps with a 5 s record give **21,504 samples per channel** (5 s record + 0.25 s pre-trigger = 5.25 s at 4096 sps), all three channels equal, peaks equal to the unit's own 0C values. | | 2026-10-17 | §7.6.1 | 🔶 **OPEN — the 6-byte "stable anchor" may be two settings at their defaults, not a constant.** Series IV's `0x1A` has the same field order as the S3 compliance block, and a keypad diff pass on a Micromate (UM20147) measured the bytes in the anchor's position: `[f32 BE pre-trigger, negative seconds][record stop mode, 00 00 = Fixed]`. `be 80 00 00` is exactly −0.25 s. If S3 matches — **inferred, not measured on S3** — then any S3 unit set to Record Stop Mode = Auto (a basic Blastware Compliance Setup option) or a non-default pre-trigger loses the anchor, and `client.py` silently decodes no recording mode / sample rate / interval / record time and skips them on write. No S3 capture has ever been taken in Auto stop mode (see the 2026-03-09 Auto Window rows), which would explain why the anchor never broke. To settle: one BW capture with Record Stop Mode = Auto. See `docs/micromate_protocol_reference.md` → *The `0x1A` field map from a keypad pass*. | -| 2026-08-26 | S7.6.2, S15 | **MULTI-INTERVAL HISTOGRAM BLOCKS - sub-minute intervals pack several per block.** The device always writes one minute of data per block, so a shorter histogram interval means more intervals packed into a longer block: 1 min -> 1 (the standard 32-byte block), 15 s -> 4 (stride 92), 2 s -> 30 (stride 612), with `stride = 12 + n * 20`. Each 20-byte record holds 8 x uint16 **little**-endian values (peak/half-period per channel) plus a 2-word tail whose first word is `0000` on every real interval. The standard block is big-endian - the variant is not. This recovers **415 files** (216 on BE18193 at 2 s, 199 on BE9440 at 15 s) that previously decoded to nothing, and before that were being accepted by the WAVEFORM codec and returning garbage up to 400x the device-reported PPV. | +| 2026-08-26 | S7.6.2, S15 | **MULTI-INTERVAL HISTOGRAM BLOCKS - sub-minute intervals pack several per block.** ⚠ *Corrected 2026-11-02: the records are big-endian from byte 5, not little-endian (v0.32.0, #47/#49), and the "2-word tail" is the interval's PVS². See D.6.5.* The device always writes one minute of data per block, so a shorter histogram interval means more intervals packed into a longer block: 1 min -> 1 (the standard 32-byte block), 15 s -> 4 (stride 92), 2 s -> 30 (stride 612), with `stride = 12 + n * 20`. Each 20-byte record holds 8 x uint16 **little**-endian values (peak/half-period per channel) plus a 2-word tail whose first word is `0000` on every real interval. The standard block is big-endian - the variant is not. This recovers **415 files** (216 on BE18193 at 2 s, 199 on BE9440 at 15 s) that previously decoded to nothing, and before that were being accepted by the WAVEFORM codec and returning garbage up to 400x the device-reported PPV. | | 2026-08-25 (3) | S7.6.1, S15 | **THE WAVEFORM BODY IS A RECORD CHAIN, NOT A TAG STREAM — supersedes the segment-header model entirely.** Records are self-delimiting: `off+2` is a uint16 BE length and `next = off + 2 + len`; the chain ends on a record whose chan_id is `0x06`. `off+8` holds a 3-valued mode enum - `02 00` (14-byte header, anchors, cumulative deltas), `01 00` (10-byte, no anchors, ABSOLUTE values), `00 03` (10-byte, no tags at all, raw 12-bit absolute). **`40 NN` is an ordinary int16 BE data block of length 2*NN+2**, never a header; reading it as a 2*NN+16 header is what made walks drift, and the 'variable prefix' of 0/2/4/6/8 bytes reported earlier the same day was walker drift, exactly `4 - (old_stop - true_record_start)`. Verified: chain terminates on `06` in 1387/1388 files; all four channels equal length in **1388/1388** (was 156/1388); ASCII sample-count exact 72/75 -> **75/75**, fully exact 70/75 -> **73/75**; device PPV on a live decode **1306/1306** waveform (mean abs ratio error 0.00000) and **4458/4459** histogram. Also eliminated the walker-over-read class: 24 of those files were histograms the waveform codec was wrongly accepting. The superseded model is retained as `decode_waveform_legacy` because `micromate/idf_file.py` pins it for Thor IDFW body-offset search. | | 2026-08-25 (2) | S7.6.2, S15 | **HISTOGRAM BLOCK IS BIG-ENDIAN + terminal block tail.** The 32-byte histogram block's per-channel fields are uint16 **big-endian** (`T_peak` [5:7], `T_halfperiod` [7:9], `V_peak` [9:11], `V_halfperiod` [11:13], `L_peak` [13:15], `L_halfperiod` [15:17], `M_peak` [17:19], `M_halfperiod` [19:21]); only `block_ctr` [2:4] is little-endian. The marker is `block[4]` alone - the previous uint16 LE marker test at [4:6] forced `block[5] == 0` and thereby capped every geo peak at 255 counts (1.275 in/s), silently clipping larger peaks. The byte previously documented as a per-channel "annotation" is the high byte of the big-endian half-period, which is why it was non-zero exactly on sub-Hz intervals. Separately, the **final block of each stream carries tail `9c 06 00 42`** rather than `1e 0a 00 00` and holds arbitrary bytes at [21:23]; rejecting it dropped the last interval of nearly every histogram. Verified against 1211 production histograms paired with their Blastware ASCII exports: 1211/1211 decode exactly, plus 842,442 per-interval frequency comparisons with zero mismatches (previously 1 of 1196 files fully correct). | | 2026-08-25 | §7.6.1, §15, Appendix E (NEW) | **BODY CODEC + SCALE PASS — five findings, all verified against 75 production events paired with their preserved Blastware ASCII exports.** (1) **Geo full scale is 32000 ADC counts, not 32768** — one decoder unit (16 counts) is exactly 0.005 in/s, so 10.000 in/s = 32000 counts. Consumers dividing by 32768 read every geophone sample and derived peak **2.34% low**; the error scales with amplitude so it was invisible on quiet events and worst on loud ones. 216 per-channel comparisons: 32768 → 151/216 exact (worst 0.238 in/s on a 10 in/s event); 32000 → 216/216 exact, worst 1 LSB. Affects waveforms, histograms and series-4 alike. (2) **Wide-NN RLE `0X NN`** — the 12-bit NN encoding already known for `1X`/`2X` also applies to the `00 NN` RLE tag (runs > 252 samples). (3) **`30 NN` is not capped at NN=0x10** — data-section blocks reach at least 0x18; the length formula was already right. (4) **`40 NN` segment headers are variable width** — NN counts the previous-channel continuation deltas, so the header is `2*NN + 16` bytes; `40 01` and `40 03` occur alongside `40 02`. A header can also appear **tagless** (the NN=0 case): just the 14-byte tail. (5) **The header field documented as a "monotonic uint32 LE counter" is really `[channel_id][00][00][segment_index]`** with 0x46=Tran 0x47=Vert 0x48=Long 0x49=MicL — verified on 1697/1697 segment headers, zero disagreements. Decoders should take the channel from this field, not from rotation position. Items (2)–(5) each caused **silent channel truncation**: an unhandled tag ends the walk and the decoder returns short channels with no error. Corpus result end-to-end: exact 37 → 72, truncated 23 → 3, full-length value errors 15 → 0. New Appendix E documents the field-observed "offset" device fault. | @@ -2678,6 +2680,11 @@ Appears in event index blocks. Time-of-day fields (hour/min/sec) are absent. | `1E` | 30 | Day (0x1E = 30 decimal) | ✅ CONFIRMED | > ✅ **2026-02-26 — CONFIRMED:** The year 1995 is the **MiniMate Plus factory default RTC date**, which the device reverts to whenever the internal battery is disconnected or the real-time clock loses power. Any event timestamped around 1995 means the clock was not set. This is known device behavior, not an encoding anomaly. +> +> **2026-11-03 — where they come from (operator account, Brian):** units come back from calibration with the internal battery unplugged, so an event triggered while testing communications, before anyone sets the date, carries the default. +> - **DL2 (measured):** 17 such events on 6 units (BE9440, BE9557, BE11529, BE17354, BE18189, BE18190). All fall between 1995-09-01 12:02:02 and 1995-09-03 11:24:06, most of them between 12:02 and 13:01 on 1 September. +> - 🔶 **Inferred:** the clock restarts at a fixed default near 1995-09-01 12:00 and runs from power-up. +> - These files still end in a valid footer. SFM reads the 1995 times and reports them as `CLOCK_NOT_SET` (`models.Timestamp`). ### 8.2 9-byte format (Full Waveform Record / SUB 0C, sub_code=0x10) > ✅ **CONFIRMED 2026-04-01** — Cross-referenced against Blastware event report @@ -3180,7 +3187,7 @@ The `.bin` files produced by `s3_bridge` are **not raw wire bytes**. The logger | **RV55 DCD/DTR default** — newer Sierra Wireless RV55 firmware does not assert DCD/DTR by default, so the MiniMate Plus never detects TCP disconnect and stays idle instead of resuming monitoring. Root cause: RV55 ACEmanager `DCD Control` setting. Workaround not yet found. | MEDIUM | 2026-04-11 | Still open | | ~~**Variable-prefix segment descriptors**~~ - **RESOLVED 2026-08-25:** there is no variable prefix. The body is a chain of self-delimiting records (see S7.6.1); the 0/2/4/6/8-byte prefix was walker drift from reading `40 NN` as a segment header. All 25 affected files now chain cleanly to the `06` terminator. | RESOLVED | 2026-08-25 | Resolved 2026-08-25 | | ~~**Histogram codec drops trailing intervals (series-3)**~~ - **RESOLVED 2026-08-25.** Two errors, both in the block model. (1) The block is **uniformly big-endian**: peaks and half-periods are uint16 BE (`T_peak` [5:7], `T_halfperiod` [7:9], `V_peak` [9:11], ...); only `block_ctr` [2:4] is LE. The old uint8-peak + "annotation"-byte model silently clipped any peak above 1.275 in/s, and the "annotation" byte was really the half-period high byte - non-zero exactly on the sub-Hz intervals BW renders `<1.0`. The marker is `block[4]` alone; testing [4:6] as a uint16 LE marker forced `block[5] == 0`, which is what capped the peak at one byte. (2) The **final block of the stream carries tail `9c 06 00 42`** instead of `1e 0a 00 00`, with arbitrary bytes at [21:23]; rejecting it dropped the last interval of nearly every histogram - often the one holding the event peak. Verified on 1211 production histograms vs their BW ASCII exports: **1211/1211 exact** (interval count + every per-interval peak) and 842,442 frequency comparisons with zero mismatches; was 1/1196. | RESOLVED | 2026-08-25 | Resolved 2026-08-25 | -| ~~**Unmapped histogram block variant (415 files, 2 units)**~~ - **RESOLVED 2026-08-26.** When the histogram interval is SHORTER than one minute the device packs several intervals into a single block so each block still covers exactly one minute: 1 min -> 1 interval (the standard 32-byte block), 15 s -> 4 (stride 92), 2 s -> 30 (stride 612). `stride = 12 + n * 20`. Block is `[00][segment][ctr uint16 LE][0a][00]` then n x 20-byte records of 8 x uint16 **LITTLE**-endian `T_peak,T_halfp,V_peak,V_halfp,L_peak,L_halfp,M_peak,M_halfp` plus a 2-word tail whose first word is `0000` on every real interval (a session ending mid-block leaves buffer garbage in the remaining slots), then a 6-byte block trailer. **Note the endianness flip** - the standard 32-byte block is big-endian. Ground truth `BE9440/K440L3AQ.T70H` (5,710 intervals at 15 s) decodes with 17,130/17,130 geo peaks, 22,840/22,840 frequencies and 5,710/5,710 mic dB(L) matching its Blastware ASCII export exactly; across all 455 affected files 1,354/1,365 channel peaks (99.2%) match the device-reported PPV. | RESOLVED | 2026-08-25 | Resolved 2026-08-26 | +| ~~**Unmapped histogram block variant (415 files, 2 units)**~~ - **RESOLVED 2026-08-26.** ⚠ *Corrected 2026-11-02: the records are big-endian from byte 5, not little-endian (v0.32.0, #47/#49), and the "2-word tail" is the interval's PVS². See D.6.5.* When the histogram interval is SHORTER than one minute the device packs several intervals into a single block so each block still covers exactly one minute: 1 min -> 1 interval (the standard 32-byte block), 15 s -> 4 (stride 92), 2 s -> 30 (stride 612). `stride = 12 + n * 20`. Block is `[00][segment][ctr uint16 LE][0a][00]` then n x 20-byte records of 8 x uint16 **LITTLE**-endian `T_peak,T_halfp,V_peak,V_halfp,L_peak,L_halfp,M_peak,M_halfp` plus a 2-word tail whose first word is `0000` on every real interval (a session ending mid-block leaves buffer garbage in the remaining slots), then a 6-byte block trailer. **Note the endianness flip** - the standard 32-byte block is big-endian. Ground truth `BE9440/K440L3AQ.T70H` (5,710 intervals at 15 s) decodes with 17,130/17,130 geo peaks, 22,840/22,840 frequencies and 5,710/5,710 mic dB(L) matching its Blastware ASCII export exactly; across all 455 affected files 1,354/1,365 channel peaks (99.2%) match the device-reported PPV. | RESOLVED | 2026-08-25 | Resolved 2026-08-26 | | **Micromate (UM-series) IDF decode is ~1000x low** — e.g. `UM11402_20260406130113.IDFW` decodes a Tran peak of 0.0009 in/s against a device-reported 1.1168. Distinct from the Thor IDF path, which decodes sanely. Suspect a different per-count LSB or a body offset that does not hold for UM-series files. | MEDIUM | 2026-08-25 | Still open | | **Thor IDF per-count LSB** — after the 32000 geo full-scale correction, series-4 Thor peaks sit at a median 0.983 of the device-reported peak (was 0.960 under 32768). Closer, but the residual ~1.7% suggests Thor uses its own per-count LSB rather than the BW 16-count/0.005 in/s convention. A code comment in `sfm/waveform_store.py` claims Thor's LSB is 0.0003 in/s, which would predict Thor reading *high* — the measurement shows the opposite, so that comment is unverified. | LOW | 2026-08-25 | Still open | @@ -3407,8 +3414,16 @@ The STRT record immediately follows the 22-byte header. | 4 | 2 | `ff fe` | Fixed | | 6 | 4 | event key (key4) | 4-byte waveform key | | 10 | 4 | device-specific | NOT a repeat of key4 — device-internal field | -| 14 | 6 | device-specific | NOT zero-padded — device-internal fields | -| 20 | 1 | rectime | uint8 seconds | +| 14 | 4 | device-specific | not identified (see the retraction below) | +| 18 | 1 | **record type** ✅ | `0x46` waveform, `0x0A` histogram: 6,541 / 6,541 `…W` and 63,500 / 63,500 `…H` DL2 files (2026-11-02). See D.6.1 | +| 19 | 2 | `00 00` | zero on 70,041 / 70,041 DL2 files | + +> ⚠ **RETRACTED 2026-11-02.** This table used to end `| 14 | 6 | device-specific |` and +> `| 20 | 1 | rectime | uint8 seconds |`. `STRT[20]` is `0x00` on every DL2 file, so it is not +> the record time. Until v0.33.0, SFM read a record time from `STRT[18]`, the record-type byte, +> which is why every waveform reported "70 s" (`0x46`). It also read pre-trigger and sample count +> from `[16:18]`; both were wrong (#45). The record time and pre-trigger live in the +> recording-setup block (D.6.2). **Critical:** The STRT record must be copied verbatim from A5[0].data[7+strt_pos:] — bytes [10:20] contain device-specific values that cannot be reconstructed from protocol-level Event fields alone. @@ -3437,12 +3452,16 @@ 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. +- ⚠ **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. + | Offset | Length | Field | Notes | |---|---|---|---| | 0 | 2 | `0e 08` | Fixed marker | | 2 | 8 | ts1 | Start timestamp (8B big-endian) | | 10 | 8 | ts2 | Stop timestamp (8B big-endian) | -| 18 | 6 | `00 01 00 02 00 00` | Fixed | +| 18 | 6 | varies | ⚠ **Not fixed** (2026-11-03). `00 01 00 02 00 00` in M529LIY6.N00. Elsewhere: `00 21 04 00 00 00` (K558L9XP.FK0H, K439I2WY.RK0H, T1895KDW.6J0H), `00 01 02 00 00 00` (K5575KDW.5L0W), `00 01 00 01 00 00` (S3545KFL.S60W). Not identified | | 24 | 2 | CRC | 2-byte CRC — algorithm unconfirmed | **CRC:** The 2-byte CRC at footer[24:26] has an unconfirmed algorithm. In M529LIY6.N00 it reads `fe da`. Attempts to match CRC-16/CCITT, CRC-16/IBM, CRC-32 (truncated), and 40+ polynomial/init combinations all failed. The writer copies it verbatim from the terminator frame. @@ -3586,6 +3605,10 @@ observed) and does NOT follow the AB0T formula. **DLE-shift offset note for reading recording_mode from N00/9T0 body:** +> ⚠ **2026-11-02:** this note finds the block by the 6-byte anchor. In an event file that anchor +> exists only when the event's own pre-trigger is exactly −0.25 s: 3,886 / 6,541 DL2 waveforms, +> and no histogram. Find the block by its setup name instead (D.6.2). + The compliance block in the file body has been through `_strip_inner_frame_dles`. The 0x10 constant at logical `anchor−7` (between recording_mode and sample_rate_HI) gets stripped when sample_rate_HI = `0x04` (1024 sps), because `0x10` precedes `0x04 ∈ {0x02,0x03,0x04}`. After stripping, the anchor shifts left by 1, so: | 1024 sps (strip occurs) | 2048 or 4096 sps (no strip) | @@ -3604,6 +3627,201 @@ file[anc−4]: histogram_interval_HI file[anc−3]: histogram_interval_LO ``` +### D.6 Event fields read from the file alone ✅ 2026-10-29 → 2026-11-02 + +Since v0.33.0, SFM decodes the fields below from an event file's bytes alone: no filename, no +Blastware report. The code is in `minimateplus/event_file_io.py`, `histogram_codec.py` and +`waveform_codec.py`. + +Each field was proven by the decode checker, `scratch/check_s3_decode.py`. It compares SFM's +decode with Blastware's `_XML.XML` report for every DL2 event: 70,042 events, 2016–2026, local +copy in `~/dl2-archive`. Counts below are from that archive unless stated otherwise. + +#### D.6.1 Record type — `STRT[18]` ✅ + +| `STRT[18]` | Type | DL2 | +|---|---|---| +| `0x46` | Waveform | 6,541 / 6,541 `…W` files | +| `0x0A` | Histogram | 63,500 / 63,500 `…H` files | + +- The 5A stream shows the same byte after the STRT keys (§7.8.5, `data[35]`). +- The filename's `W` / `H` is only a cross-check. On a disagreement SFM logs it and keeps the + byte (#41). +- Checker, event type: 70,042 / 70,042. +- **It also picks the codec** (2026-11-03). Trying the waveform codec first handed it BE9440, + BE9557 and BE17354's 2018 5 s histograms. It accepted them and returned about 5× too many + "samples" (K440HDXX.XH0H: 44,504 for Blastware's 6,976). + +#### D.6.2 Recording-setup block — sample rate, pre-trigger, record time ✅ + +**Find the block by structure:** `1c 08`, then the setup name (1–40 printable ASCII), then `00`. +That pattern occurs exactly once in every DL2 file. Do not search for the name "Standard +Recording Setup": 37% of DL2 files use another name. + +Offsets are from `k`, the first byte of the setup name: + +| Offset | Type | Field | Notes | +|---|---|---|---| +| `k − 42` | uint16 BE | sample rate | 1024 / 2048 / 4096 | +| `k − 36` | float32 BE | pre-trigger | seconds, ≤ 0: `−0.25` is a quarter second before the trigger. **This event's own length, not the unit's setting** (below) | +| `k − 32` | 2 bytes | — | `00 00` on 70,041 / 70,041 files | +| `k − 30` | float32 BE | record time | seconds | + +- Pre-trigger samples = `round(−pre-trigger × sample rate)`. +- A histogram carries the block too, with pre-trigger `0.0` (63,500 / 63,500). Blastware reports + no record time or pre-trigger for a histogram, and SFM reports none. +- Sample rate, record time and pre-trigger match Blastware on every DL2 event that reports them + (#44, #45). + +⚠ **The file's pre-trigger is the event's, not the setting (measured 2026-11-02).** +- **It varies from event to event on the same unit, often on the same day.** BE18193 has both + −0.25 and −0.248 on 2026-08-21. + - At 1024 sps the common values −0.25, −0.249, −0.248 and −0.2471 are 256, 255, 254 and 253 + samples. + - At 4096 sps, BE18193's events range from −0.002 to −0.249 s. +- **Blastware reports the same per-event value** as `Pre-triggerLength`, for example + `-0.094 sec` for `T193KMX5.4Z0W`. +- 🔶 Inferred: the unit's setting stays fixed while the captured length falls short of it. Why it + falls short is unknown. + +**What this means for #48 (the 1A "stable anchor"):** +- This is the 1A compliance layout. Sample rate at anchor − 6 and record time at anchor + 6 + (§7.6.1) put the anchor at `k − 36`, so the 6-byte `be 80 00 00 00 00` is a pre-trigger of + −0.25 s followed by the `00 00` at `k − 32`. +- **In a file**, the anchor bytes appear only when that event's pre-trigger is exactly −0.25 s: + 3,886 / 6,541 waveforms, and no histogram (histogram files store 0.0). A file parser that + searches for the anchor breaks on the rest. SFM's file decoder finds the block by its setup + name instead. +- **The live 1A read holds the setting, not an event's length.** So these files say little about + whether the live read loses its anchor; #48 is still unsettled. +- `k − 32 : k − 30` is `00 00` on all 70,041 files. 🔶 If `[17]` is the stop mode, as on + Series IV, no DL2 event was recorded in Auto stop mode, so the archive cannot test that case. +- The two blocks differ in at least one field. A live 1A in Histogram mode showed the anchor + (−0.25 s), but histogram files store 0.0. + +#### D.6.3 Notes — four label/value pairs after the name ✅ + +- After the name's `00`, NUL-terminated `label`, `value` pairs fill four slots, in order: + project, client, operator ("User Name") and sensor location ("Seis Loc"). +- **Read them by position, never by label.** Blastware lets the operator relabel the slots + ("Seis. Loc:", "Location:", "Project: "). +- An empty value means none. +- They match Blastware on every DL2 event. +- Not read yet: extended notes. + +**Job number** ✅ 2026-11-02, in Series IV's `0x1A` layout (`[39]` report flags, `[40:42]` the +number): + +| Offset | Type | Field | +|---|---|---| +| `k − 9` | uint8 | report flags: bit `0x02` = job number shown | +| `k − 8` | uint16 BE | job number, kept while not shown | + +- **The flag** matches Blastware's `JobNumber` on 2,997 / 2,997 DL2 events that print one, and + 66,986 / 66,986 that don't. +- **The value** matches on all 2,997, but every printed value is 1, so it is only proven for 1. + Hidden ones hold real numbers (802, 1012, 1013, 622). +- Bit `0x04` is also seen (2,311 files); it is not identified. + +#### D.6.4 Geophone range — the setup's channel blocks ✅ 2026-11-01 + +The channel blocks follow the notes, within 2,000 bytes of the name: `00 00 01` then `Tran` / +`Vert` / `Long`. The range is the byte at label + 29, where label is the first byte of +`Tran` / `Vert` / `Long`: + +| label + 29 | Range | Full scale | +|---|---|---| +| `0x00` | Normal | 10.000 in/s | +| `0x01` | Sensitive | 1.250 in/s | + +- It matches the report's `GeoRange` on 70,042 / 70,042 events. The three channels agree on + every event, and 35 are Sensitive. +- The live 1A carries the same byte at label + 33 (§7.6, confirmed 2026-04-20). +- Full scale is 32,000 counts at either range, so a Sensitive count is 8× smaller. +- Until `dev` `057df47` (2026-11-02), SFM assumed Normal and read every Sensitive event 8× high. +- If the channels disagree, a value is unknown or a block is missing, SFM reports no range, logs + a decode problem and assumes Normal. + +#### D.6.5 Histogram interval peak vector sum ✅ 2026-10-30 + +Each interval stores its peak vector sum **squared**: + +| Block | Where | Type | +|---|---|---| +| Standard 32-byte block (intervals of a minute or more) | `[21:25]` | uint32 BE | +| Sub-minute record | the record's last 4 bytes | uint32 BE | + +- `PVS = √value × unit`. The unit is 16 counts: 0.005 in/s at Normal, 0.000625 in/s at + Sensitive. +- **The event's PVS is the largest interval's.** Combining the three channel peaks instead read + high on 86% of DL2 histograms, because the peaks can come from different moments. +- **Verified:** √value matches Blastware's "Geo PVS" on 34.5 M DL2 sub-minute intervals, and the + event PVS matches on 69,989 / 70,042 events (`dev`, 2026-11-03). +- **A consistency check** (2026-11-03): an interval's vector sum is never below its largest + channel peak, nor above √3 times it, give or take one unit of rounding. That holds on + 34,502,955 / 34,502,955 DL2 sub-minute intervals, and is what the codec now uses to recognise + a sub-minute record layout. +- 🔶 On the stream's last block, the "arbitrary bytes at [21:23]" in the 2026-08-25 note are + probably the high half of this field (inferred from the layout, not measured). + +**Sub-minute records (corrected in v0.32.0, #47/#49):** +- They are **big-endian, starting at byte 5** of the block. +- Each holds, per channel, a uint16 peak and a uint16 half-period (Tran, Vert, Long, and MicL + when the mic is on), then the uint32 PVS². +- Record = 4 × channels + 4 bytes: 20 with the mic, 16 without. `stride = 12 + n × record`. + +> ⚠ **RETRACTED:** the 2026-08-26 notes (Changelog, §15) read these records as 8 × uint16 +> little-endian after a 6-byte header. That was the same big-endian words shifted by one byte. +> Their "2-word tail whose first word is 0000" is the PVS², whose high word reads `0000`. +> +> ⚠ **RETRACTED 2026-11-03:** "the high word reads `0000`" holds only on quiet intervals. It is +> non-zero above 1.28 in/s. The layout check required it, so a one-block histogram with a loud +> interval was not recognised at all (T193KR5M.X90H, K440HA3C.JM0H, R352HFZ7.530H). The check is +> now the consistency test above. + +**Blastware's "Number of Intervals" is the monitoring time ÷ the interval** (measured +2026-11-03), from the footer's start and stop: +- It is exact on T193KSWP.FF0H (2,880), M462KSWR.1R0H (1,650) and T193KY0A.740H (6,390). +- When the unit never wrote the last minute, the file holds one block fewer (30 intervals at + 2 s). Blastware's own interval table lists only the stored intervals, which is what SFM + decodes. +- A decode-checker carve-out (`interval-count-is-duration`) covers the 8 DL2 events where the + two differ. + +#### D.6.6 Mic ✅ v0.33.0 + +- One count = **0.25 Pa**, so psi = count × 0.25 / 6894.757. +- dB(L) = **81.9384** + 20·log10(|count|). + - The exact value, 20·log10(0.25 Pa / 20 µPa), is 81.9382. Blastware's printed values pin the + offset in [81.9383, 81.9385] instead. + - With the exact value, 280 events mismatched, all at count 129. + - float32 rounding does not explain the difference. +- **Verified:** interval psi mismatches fell from 42,783 to 26, and mic peak mismatches from 345 + to 40. + +#### D.6.7 Not read from the file yet + +*Updated 2026-11-03. 18 of 88 report fields now match on every DL2 event.* +- **Fields not read yet:** + - trigger source and levels, stop mode, mic type, display units, firmware version, serial + number, calibration, battery + - per-interval frequencies (#50: they assume 1024 sps), per-interval PVS, interval size, + histogram stop time + - extended notes + - the values Blastware computes: ZC frequency, acceleration, displacement, time of peak + - sensor check results + - monitor log +- **Open cases:** + - histogram start times are 1 s early (#51) + - about 20 one-minute histograms with a mic peak an interval or two off + - Blastware prints `OORANGE` when the vector sum alone exceeds the range (a carve-out still to + prove) +- **Resolved on `dev`, 2026-11-02 → 03:** + - the 37 histograms that decoded wrongly (D.6.1, D.6.5) + - the 26 histogram start dates a day off (D.3.3; 17 of them were the same 5 s files, timed + as waveforms) + - the job number (D.6.3) + --- *All findings reverse-engineered from live RS-232 bridge captures.* diff --git a/minimateplus/decode_check.py b/minimateplus/decode_check.py index 6133d77..0c19fdd 100644 --- a/minimateplus/decode_check.py +++ b/minimateplus/decode_check.py @@ -36,7 +36,7 @@ class SfmSide: event: Event values: dict[str, object] # reference tag -> SFM's value; absent or None = blank notes: list[str] # non-empty user-note slots, in order - job_number: Optional[str] # None until the decoder reads it + job_number: Optional[str] # only when the file says Blastware shows it channels: list[str] # channels with decoded data, in Tran/Vert/Long/MicL order counts: dict[str, list[int]] # waveform samples or histogram interval peaks geo_ips_per_count: float = GEO_IPS_PER_COUNT # at the event's range, as SFM read it @@ -78,7 +78,7 @@ def sfm_side(raw: bytes) -> SfmSide: values=values, notes=[v for v in (pi.project, pi.client, pi.operator, pi.sensor_location) if v] if pi is not None else [], - job_number=None, + job_number=str(pi.job_number) if pi is not None and pi.job_number_enabled else None, channels=[ch for ch in _CHANNELS if counts[ch]], counts=counts, geo_ips_per_count=_GEO_FS_BY_RANGE.get(ev.geo_range, _GEO_NORMAL_FS_INS) / _GEO_INT16_FS, @@ -289,6 +289,9 @@ def compare(sfm: SfmSide, ref: XmlReport, carveouts: Sequence["Carveout"] = ()) if sfm.job_number is None else FieldResult("JobNumber", "match" if _same_text(sfm.job_number, ref.job_number) else "mismatch", ref.job_number, sfm.job_number)) + elif sfm.job_number is not None: + # SFM says the job number is shown; Blastware printed none. + out.append(FieldResult("JobNumber", "mismatch", None, sfm.job_number)) out.append(FieldResult("Channels", "match" if ref.channels == sfm.channels else "mismatch", " ".join(ref.channels), " ".join(sfm.channels))) if ref.sample_rows is not None: diff --git a/minimateplus/decode_check_carveouts.py b/minimateplus/decode_check_carveouts.py index 7122f57..244edd2 100644 --- a/minimateplus/decode_check_carveouts.py +++ b/minimateplus/decode_check_carveouts.py @@ -86,4 +86,24 @@ SATURATION = Carveout( applies=_saturation, ) -CARVEOUTS: tuple[Carveout, ...] = (SATURATION,) +def _interval_count_is_duration(sfm: SfmSide, ref: XmlReport, res: FieldResult) -> bool: + """Blastware's count exceeds the intervals in its own table, and SFM decoded + exactly the table's.""" + p = _printed_number(res.bw or "") + n = sfm.values.get("NumberofIntervals") + rows = len(ref.intervals or []) + return p is not None and n is not None and rows == n and p[0] > n + + +INTERVAL_COUNT_IS_DURATION = Carveout( + id="interval-count-is-duration", + fields=("NumberofIntervals",), + evidence=("Blastware's Number of Intervals is (stop - start) / interval from the file's " + "footer times -- exact on T193KSWP.FF0H (2,880), M462KSWR.1R0H (1,650) and " + "T193KY0A.740H (6,390). Its own interval table lists the intervals the file " + "holds: one block (30 at 2 s) fewer when the unit never wrote the last minute. " + "2026-11-02."), + applies=_interval_count_is_duration, +) + +CARVEOUTS: tuple[Carveout, ...] = (SATURATION, INTERVAL_COUNT_IS_DURATION) diff --git a/minimateplus/event_file_io.py b/minimateplus/event_file_io.py index 7907e29..0dbc16c 100644 --- a/minimateplus/event_file_io.py +++ b/minimateplus/event_file_io.py @@ -996,8 +996,29 @@ def _setup_notes(raw: bytes) -> ProjectInfo: text = [p.decode("ascii", errors="replace").strip() or None for p in parts] text += [None] * (2 + 2 * _NOTE_SLOTS - len(text)) project, client, operator, location = text[2:2 + 2 * _NOTE_SLOTS:2] + enabled, number = _setup_job_number(raw, k) return ProjectInfo(setup_name=text[0], project=project, client=client, - operator=operator, sensor_location=location) + operator=operator, sensor_location=location, + job_number_enabled=enabled, job_number=number) + + +# The job number, in Series IV's 0x1A layout ([39] report flags, [40:42] the +# number): flags at k - 9, bit 0x02 = shown; the number, uint16 BE, at k - 8, +# kept while switched off. The flag matches Blastware's JobNumber on 2,997 / +# 2,997 DL2 events that print one and 66,986 / 66,986 that don't, and every +# printed value matches (all are 1; measured 2026-11-02). +_REPORT_FLAGS_BEFORE_NAME = 9 +_JOB_NUMBER_BEFORE_NAME = 8 +_JOB_NUMBER_ON = 0x02 + + +def _setup_job_number(raw: bytes, k: int) -> tuple[Optional[bool], Optional[int]]: + """(shown, number) from the setup block whose name starts at k.""" + if k < _REPORT_FLAGS_BEFORE_NAME: + return None, None + flags = raw[k - _REPORT_FLAGS_BEFORE_NAME] + j = k - _JOB_NUMBER_BEFORE_NAME + return bool(flags & _JOB_NUMBER_ON), int.from_bytes(raw[j:j + 2], "big") # The geophone range sits in the setup's channel blocks, which follow the @@ -1077,22 +1098,34 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event: # Footer: locate the 0e 08 marker, validating the year is in a sane range. body_start = _bw._WAVEFORM_HEADER_SIZE + 21 - # The 0e 08 + plausible-year footer signature can occur inside the sample - # stream. Collect every candidate and prefer the first whose body yields a - # waveform record chain terminating on the 0x06 marker; fall back to the - # first candidate otherwise. Blast radius measured 2026-08-25: changes the - # chosen footer on exactly 1 of 1,388 series-3 waveform files - # (BE17353/S353L4O5.OX0W, false positive at 3800, real footer at 8576). - footer_candidates = [] - pos = body_start - while True: - pos = raw.find(b"\x0e\x08", pos) - if pos < 0 or pos + 26 > len(raw): - break - yr = (raw[pos + 4] << 8) | raw[pos + 5] - if 2015 <= yr <= 2050: - footer_candidates.append(pos) - pos += 1 + # The footer is the file's last 26 bytes whenever they are one -- 0e 08 and + # two valid times: 70,041 / 70,041 DL2 files (measured 2026-11-03). Taking + # the first "0e 08 + plausible year" instead found, on 14 of them, an + # earlier record ~1.1 KB before the end holding the stop time and zeros: a + # histogram then started at its own stop (a day late on BE9558's daily + # histograms) and a waveform lost its stop, so its trigger time too. + # + # Otherwise the search below stands. The signature can occur inside the + # sample stream, so it prefers the first candidate whose body yields a + # waveform record chain terminating on the 0x06 marker, then the first + # candidate (2026-08-25: BE17353/S353L4O5.OX0W, false positive at 3800, + # real footer at 8576). + end = len(raw) - 26 + if (end >= body_start and raw[end:end + 2] == b"\x0e\x08" + and _bw._decode_ts_be(raw[end + 2:end + 10]) is not None + and _bw._decode_ts_be(raw[end + 10:end + 18]) is not None): + footer_candidates = [end] + else: + footer_candidates = [] + pos = body_start + while True: + pos = raw.find(b"\x0e\x08", pos) + if pos < 0 or pos + 26 > len(raw): + break + yr = (raw[pos + 4] << 8) | raw[pos + 5] + if 2015 <= yr <= 2050: + footer_candidates.append(pos) + pos += 1 footer_pos = -1 for cand in footer_candidates: @@ -1149,18 +1182,37 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event: # mode, synthetic test input), fall back to empty channels — the # rest of the event (timestamp, waveform_key, project strings) is # still recoverable and useful. - decoded = decode_waveform_v2(body) - # Discriminator for the timestamp logic below: a waveform (trigger) event - # vs a histogram window. Keyed on the codec, not the filename — the - # save_imported_bw path passes a tmp ".bw" name whose extension lies. - is_waveform_body = decoded is not None - if decoded is None: + # + # The record type comes from the bytes: STRT[18] (#41), 0x46 / 0x0A on + # 70,041 / 70,041 DL2 files. It picks the codec. Trying the waveform codec + # first handed it BE9440 / BE9557 / BE17354's 2018 5 s histograms, which it + # accepted and returned ~5x too many "samples" for. Only an unknown type + # falls back to the old trial order. The filename's last letter is only a + # cross-check -- SFM's own downloads have no name, and a manual download's + # (".QZ0") carries no type at all. + type_byte = strt_raw[18] + record_type = _RECORD_TYPE_BY_STRT.get(type_byte) + problems = [] + if record_type is None: + problems.append(f"unknown record type byte 0x{type_byte:02x} at STRT[18]") + if record_type == "Histogram": decoded = decode_histogram_body(body) + is_waveform_body = False + elif record_type == "Waveform": + decoded = decode_waveform_v2(body) + is_waveform_body = True + else: + decoded = decode_waveform_v2(body) + is_waveform_body = decoded is not None + if decoded is None: + decoded = decode_histogram_body(body) if decoded is None: log.warning( "%s: body codec failed to decode (body starts %s) — " "raw_samples will be empty", label, body[:8].hex(" "), ) + if record_type is not None: + problems.append(f"the {record_type.lower()} codec could not decode the body") samples = {"Tran": [], "Vert": [], "Long": [], "MicL": []} else: samples = decoded_to_adc_counts(decoded) @@ -1169,13 +1221,8 @@ def decode_blastware_bytes(raw: bytes, *, name: Optional[str] = None) -> Event: ev = Event(index=-1) if strt_fields.get("waveform_key"): ev._waveform_key = bytes.fromhex(strt_fields["waveform_key"]) - # The record type comes from the bytes: STRT[18] (#41). The filename's - # last letter is only a cross-check -- SFM's own downloads have no name, - # and a manual download's (".QZ0") carries no type at all. - type_byte = strt_raw[18] - ev.record_type = _RECORD_TYPE_BY_STRT.get(type_byte) - if ev.record_type is None: - ev.decode_problems.append(f"unknown record type byte 0x{type_byte:02x} at STRT[18]") + ev.record_type = record_type + ev.decode_problems.extend(problems) named_type = derive_record_type_from_filename(name, default=None) if name else None if named_type is not None and ev.record_type is not None and named_type != ev.record_type: log.warning("%s: record type %s from the file disagrees with the filename's %s; " diff --git a/minimateplus/histogram_codec.py b/minimateplus/histogram_codec.py index 6978806..3a4f7e6 100644 --- a/minimateplus/histogram_codec.py +++ b/minimateplus/histogram_codec.py @@ -439,16 +439,34 @@ def _stride(rec: int, n: int) -> int: def _records_plausible(body: bytes, off: int, rec: int, m: int) -> bool: - """Every record's zero word is 0000 -- what tells a 16-byte layout from a - 20-byte one when both strides happen to fit (492 = 12 + 16x30 = 12 + 20x24).""" + """Every record's last 4 bytes are its vector sum squared, consistent with + its channel peaks: at least the largest peak, at most sqrt(3) times it (one + unit of rounding either way). That is what tells a 16-byte layout from a + 20-byte one when both strides happen to fit (492 = 12 + 16x30 = 12 + 20x24); + misread, those bytes are other fields. Holds on 34,502,955 / 34,502,955 DL2 + sub-minute intervals (2026-11-02). + + ⚠ RETRACTED 2026-11-02: "every record's zero word is 0000". It is the high + word of the PVS², non-zero on any interval above 1.28 in/s, so a short + histogram with one loud interval was not recognised at all (T193KR5M.X90H, + K440HA3C.JM0H decoded to nothing).""" z = rec - 4 for k in range(m): q = off + _MULTI_HEADER_LEN + rec * k - if q + rec > len(body) or body[q + z] or body[q + z + 1]: + if q + rec > len(body): + return False + peak = max((body[q + i] << 8) | body[q + i + 1] for i in (0, 4, 8)) + if not _pvs_consistent(peak, int.from_bytes(body[q + z:q + z + 4], "big")): return False return True +def _pvs_consistent(peak: int, pvs_sq: int) -> bool: + """A record's vector sum squared against its largest geo peak, one unit of + rounding either way: peak <= PVS <= sqrt(3) * peak.""" + return max(peak - 1, 0) ** 2 <= pvs_sq <= 3 * (peak + 1) ** 2 + + def detect_multi_interval_layout(body: bytes) -> Optional[Tuple[int, int]]: """``(record_len, per_block)`` of a multi-interval body, or None. @@ -543,8 +561,8 @@ def walk_multi_interval_blocks(body: bytes, recs = [_decode_record(body, off + _MULTI_HEADER_LEN + rec * k, rec, off) for k in range(max(m, 0))] for k, r in enumerate(recs): - if (r["meta_var"][:2] != b"\x00\x00" - or max(r["t_peak"], r["v_peak"], r["l_peak"]) > _GEO_MAX_COUNTS): + peak = max(r["t_peak"], r["v_peak"], r["l_peak"]) + if not _pvs_consistent(peak, r["pvs_sq"]) or peak > _GEO_MAX_COUNTS: del recs[k:] break out.extend(recs) diff --git a/minimateplus/models.py b/minimateplus/models.py index abd5d1a..c00830f 100644 --- a/minimateplus/models.py +++ b/minimateplus/models.py @@ -379,6 +379,8 @@ class ProjectInfo: operator: Optional[str] = None # operator / user name sensor_location: Optional[str] = None # sensor location string notes: Optional[str] = None # extended notes + job_number_enabled: Optional[bool] = None # Blastware prints the job number + job_number: Optional[int] = None # kept while switched off # ── Compliance Config ────────────────────────────────────────────────────────── diff --git a/sfm/event_hdf5.py b/sfm/event_hdf5.py index bde0e28..f8c3a4e 100644 --- a/sfm/event_hdf5.py +++ b/sfm/event_hdf5.py @@ -32,6 +32,8 @@ Layout written to `.h5`: client str operator str sensor_location str + job_number int (only when read; kept while not shown) + job_number_enabled bool (Blastware prints the job number) peak_tran_ips float (from 0C; authoritative) peak_vert_ips float peak_long_ips float @@ -257,6 +259,9 @@ def write_event_hdf5( attrs["client"] = (pi.client if pi else "") or "" attrs["operator"] = (pi.operator if pi else "") or "" attrs["sensor_location"] = (pi.sensor_location if pi else "") or "" + if pi is not None and getattr(pi, "job_number", None) is not None: + attrs["job_number"] = int(pi.job_number) + attrs["job_number_enabled"] = bool(pi.job_number_enabled) attrs["peak_tran_ips"] = float(pv.tran if pv and pv.tran is not None else 0.0) attrs["peak_vert_ips"] = float(pv.vert if pv and pv.vert is not None else 0.0) attrs["peak_long_ips"] = float(pv.long if pv and pv.long is not None else 0.0) diff --git a/tests/fixtures/footer-11-03-26/K440I4LG.JK0W b/tests/fixtures/footer-11-03-26/K440I4LG.JK0W new file mode 100755 index 0000000..7537a4b Binary files /dev/null and b/tests/fixtures/footer-11-03-26/K440I4LG.JK0W differ diff --git a/tests/fixtures/footer-11-03-26/K558L9XP.FK0H b/tests/fixtures/footer-11-03-26/K558L9XP.FK0H new file mode 100755 index 0000000..e9d1aeb Binary files /dev/null and b/tests/fixtures/footer-11-03-26/K558L9XP.FK0H differ diff --git a/tests/fixtures/footer-11-03-26/T003LCYV.JD0H b/tests/fixtures/footer-11-03-26/T003LCYV.JD0H new file mode 100755 index 0000000..6d00185 Binary files /dev/null and b/tests/fixtures/footer-11-03-26/T003LCYV.JD0H differ diff --git a/tests/fixtures/footer-11-03-26/T003LCYV_JD0H_XML.XML b/tests/fixtures/footer-11-03-26/T003LCYV_JD0H_XML.XML new file mode 100755 index 0000000..4501047 --- /dev/null +++ b/tests/fixtures/footer-11-03-26/T003LCYV_JD0H_XML.XML @@ -0,0 +1,548 @@ + + +8.0 +Full Histogram +BE18003 +V 10.72-8.17 MiniMate Plus +T003LCYV.JD0H +18:04:25 +2025-12-05 +20:30:00 +2025-12-05 + +Tran +Vert +Long +MicL + +145.00 +1 minute +1024 sps +7.0 Volts +March 14, 2025 by Instantel +in/s and dB(L) +I-80-North Fork Bridges-I80 E. Abutment +Fay Company +Terra-Mechanics, Inc - Harrison +Area 2 - Loc 3 - I-80 - East Abutment + +10.000 +in/s + + +0.035 +in/s + + +0.090 +in/s + + +0.045 +in/s + + +11 +Hz + + +43 +Hz + + +37 +Hz + +20:10:25 +2025-12-05 +19:09:25 +2025-12-05 +20:09:25 +2025-12-05 + +0.099 +in/s + +19:09:25 +2025-12-05 +Linear Weighting + +124.7 +dB(L) + +18:19:25 +2025-12-05 + +2.4 +Hz + +7.7 Hz. +3.5 +Passed +7.6 Hz. +3.1 +Passed +7.4 Hz. +3.9 +Passed +20.1 Hz. +767 mv +Passed + + +2025-12-05 18:04:24 - 2025-12-05 20:30:00 "Event Recorded Timer Stop" + + + Tran Peak in/s + Tran Freq Hz + Vert Peak in/s + Vert Freq Hz + Long Peak in/s + Long Freq Hz + Geo PVS in/s + MicL Peak psi(L) + MicL Peak dB(L) + MicL Freq Hz + + + + +0.020130.070230.030170.0750.003121.51.9 + + +0.0207.60.070470.025470.0740.003119.1>100 + + +0.020140.080340.030340.0840.002118.33.6 + + +0.0207.80.060470.025210.0640.003121.01.9 + + +0.0205.30.055470.020180.0590.004122.82.1 + + +0.030430.080430.035430.0880.003121.04.2 + + +0.025120.085430.035470.0920.003119.82.1 + + +0.0203.20.055470.025200.0610.003119.4>100 + + +0.0205.50.055730.025370.0620.002117.6>100 + + +0.025110.065430.035430.0720.004121.818 + + +0.025130.075470.030510.0810.002118.63.5 + + +0.025120.065470.030510.0720.003120.0>100 + + +0.025110.060470.025390.0650.003119.92.6 + + +0.020130.070470.030430.0770.003119.712 + + +0.025280.065430.030340.0730.005124.72.4 + + +0.025120.060470.025430.0660.003119.41.9 + + +0.0259.80.065470.025390.0700.003121.05.1 + + +0.025200.075430.030510.0790.003119.02.5 + + +0.025170.060470.020510.0630.004122.12.0 + + +0.0207.60.060470.020390.0640.003120.64.4 + + +0.0207.50.075370.030300.0820.002118.25.0 + + +0.025160.060260.025240.0640.003121.43.6 + + +0.025210.080370.030430.0840.003120.13.4 + + +0.025200.045240.020200.0480.002118.12.6 + + +0.025200.060430.025230.0650.003120.12.1 + + +0.0206.30.045220.020300.0510.002115.92.6 + + +0.030240.070390.030390.0730.004122.82.3 + + +0.0205.40.065470.025430.0700.003120.93.1 + + +0.025110.050470.025170.0570.003121.313 + + +0.020220.060470.030300.0660.004122.03.0 + + +0.025200.070470.035180.0770.003120.64.8 + + +0.0205.10.045220.020300.0510.002116.7>100 + + +0.025160.065470.025430.0700.003120.2>100 + + +0.020130.065470.025230.0700.003119.32.3 + + +0.0203.70.055470.020430.0590.003121.32.2 + + +0.020190.065470.030370.0680.004123.111 + + +0.025220.065470.025430.0700.002118.117 + + +0.025270.055470.025390.0620.002118.6>100 + + +0.0206.30.060430.025430.0650.002116.96.3 + + +0.025120.065430.030430.0720.004122.54.1 + + +0.0202.60.060430.025430.0660.004122.05.7 + + +0.0206.20.060470.025110.0640.004121.91.7 + + +0.025140.070430.030430.0760.004122.11.9 + + +0.025340.070430.030180.0760.003120.115 + + +0.0203.50.065470.025570.0700.004121.81.9 + + +0.025180.065430.025240.0690.002117.62.5 + + +0.025100.065430.030470.0700.004122.02.5 + + +0.0204.20.050220.020140.0560.003119.12.7 + + +0.0201.90.055470.020340.0590.004122.14.3 + + +0.020<1.00.065470.025470.0700.002117.22.1 + + +0.020170.065470.025430.0700.003121.1>100 + + +0.020<1.00.060470.025570.0650.003119.81.9 + + +0.025150.070430.025430.0740.003120.94.7 + + +0.0205.90.050220.020280.0510.002117.1>100 + + +0.025130.070470.030510.0770.002117.41.9 + + +0.025270.055850.030170.0580.003120.21.8 + + +0.020170.055430.020430.0590.004123.13.7 + + +0.020<1.00.065430.030430.0700.003120.4>100 + + +0.0206.60.065430.025430.0700.003119.6>100 + + +0.030170.085430.035570.0920.004122.82.2 + + +0.025240.055470.025390.0620.002117.8>100 + + +0.025120.050230.025260.0580.002116.451 + + +0.025140.055430.025260.0590.003119.02.2 + + +0.025110.070470.035300.0780.002117.21.9 + + +0.025150.090430.040470.0990.003120.24.7 + + +0.025170.065470.030430.0720.003119.63.6 + + +0.0203.60.060570.030280.0620.003119.8>100 + + +0.025320.065470.035270.0740.003120.24.0 + + +0.025160.065430.025240.0690.003119.6>100 + + +0.020160.040240.020220.0470.002117.4>100 + + +0.020190.065470.025430.0700.002116.72.0 + + +0.025160.070390.035510.0800.004121.92.0 + + +0.025120.080430.035270.0870.003119.72.7 + + +0.025200.070470.030510.0760.003119.46.7 + + +0.030200.065430.030510.0720.003121.64.7 + + +0.020<1.00.065390.025260.0690.003119.94.1 + + +0.0254.70.060470.030220.0650.002117.91.5 + + +0.025230.065470.030370.0700.002118.22.2 + + +0.020160.065470.025390.0710.003120.02.9 + + +0.0204.00.045340.020180.0500.003118.7>100 + + +0.0202.90.055230.025170.0620.002118.5>100 + + +0.025470.070470.030470.0750.004122.72.7 + + +0.0259.70.065430.035280.0740.003121.12.0 + + +0.025570.090470.040510.0970.003121.31.9 + + +0.025110.050220.020340.0560.002114.82.3 + + +0.025200.065470.030470.0720.003119.151 + + +0.025130.055430.025430.0610.004122.02.6 + + +0.015<1.00.015180.015120.0260.001108.0>100 + + +0.0202.90.050210.025220.0580.002117.2>100 + + +0.0208.30.060470.030240.0660.003121.51.9 + + +0.0205.80.040230.020230.0470.002114.4>100 + + +0.020120.055430.020390.0590.003121.02.8 + + +0.025130.055220.030200.0660.002117.63.1 + + +0.0207.30.050390.020320.0560.004122.22.5 + + +0.030230.070430.035470.0770.003120.3>100 + + +0.025180.065430.025510.0700.004121.82.0 + + +0.020320.065430.035170.0700.003120.114 + + +0.025170.060260.025230.0650.002116.1>100 + + +0.025200.060230.030240.0700.002116.9>100 + + +0.025130.075470.035510.0810.003121.56.0 + + +0.025180.050210.025220.0560.002117.2>100 + + +0.025220.055430.025180.0590.003119.63.0 + + +0.020<1.00.070470.030470.0770.002118.3>100 + + +0.0208.10.030390.020230.0370.002116.6>100 + + +0.025170.070470.025240.0740.002118.63.3 + + +0.0206.20.065430.030510.0720.003118.82.6 + + +0.020130.035210.020200.0410.001112.8>100 + + +0.025140.075470.030470.0810.004121.71.9 + + +0.025120.065430.030370.0720.004121.92.0 + + +0.025160.065430.025470.0700.003120.615 + + +0.025220.060430.030510.0650.003120.72.0 + + +0.025210.060470.025370.0660.003121.12.1 + + +0.0203.60.065470.030470.0720.004121.9>100 + + +0.030180.075470.030510.0790.003121.5>100 + + +0.025120.075430.035300.0810.003119.41.8 + + +0.025200.050220.025230.0570.002115.0>100 + + +0.025110.060470.025180.0660.003119.12.4 + + +0.025220.065470.030390.0730.003119.02.4 + + +0.025150.070470.030430.0760.003119.72.1 + + +0.025160.050340.025390.0550.002115.9>100 + + +0.0206.20.045340.020300.0490.002117.62.3 + + +0.025270.055240.025160.0610.002115.44.9 + + +0.0253.50.090470.040570.0970.004123.12.1 + + +0.025170.060430.025510.0660.003119.92.3 + + +0.025320.090430.045370.0980.002118.61.9 + + +0.035110.070470.030510.0770.003120.33.7 + + +0.025130.065430.025200.0700.002117.4>100 + + +0.0205.30.050240.025260.0590.002118.2>100 + + +0.025130.055470.025430.0610.002117.1>100 + + +0.020130.060470.025510.0640.002118.34.0 + + +0.020120.035240.020190.0430.002115.7>100 + + +0.020100.065430.030510.0720.002117.8>100 + + +0.025320.065430.025430.0690.004123.32.1 + + +0.020130.065470.030370.0700.003119.64.1 + + +0.0203.80.055230.025240.0620.003120.0>100 + + +0.0207.20.050390.025390.0570.002117.8>100 + + +0.0203.20.050230.025260.0590.002116.62.5 + + +0.0206.20.055230.025370.0620.002118.3>100 + + +0.025130.065470.030240.0720.003120.21.8 + + +0.025180.050320.025340.0570.002116.9>100 + + +0.025130.080470.035510.0870.002118.51.9 + + +0.0206.60.040230.020300.0460.002117.6>100 + + +0.020170.040210.020230.0470.002115.2>100 + + +0.025180.090730.040510.0930.003119.3>100 + + +0.025280.075430.030570.0810.004122.22.2 + + + + + + diff --git a/tests/fixtures/histogram-decode-11-02-26/K440HA3C.JM0H b/tests/fixtures/histogram-decode-11-02-26/K440HA3C.JM0H new file mode 100755 index 0000000..bd9bfbc Binary files /dev/null and b/tests/fixtures/histogram-decode-11-02-26/K440HA3C.JM0H differ diff --git a/tests/fixtures/histogram-decode-11-02-26/K440HA3C_JM0H_XML.XML b/tests/fixtures/histogram-decode-11-02-26/K440HA3C_JM0H_XML.XML new file mode 100755 index 0000000..1bab82a --- /dev/null +++ b/tests/fixtures/histogram-decode-11-02-26/K440HA3C_JM0H_XML.XML @@ -0,0 +1,137 @@ + + +8.0 +Full Histogram +BE9440 +V 10.72-8.17 MiniMate Plus +K440HA3C.JM0H +11:42:58 +2018-02-10 +11:43:34 +2018-02-10 + +Tran +Vert +Long +MicL + +8.00 +5 seconds +1024 sps +6.8 Volts +January 11, 2018 by Instantel +in/s and dB(L) +Villanova Stadium Station - Seis. Loc #2 +D'Angleo Brothers, Inc +Terra-Mechanics, Inc - D Harrison +Loc # 2 - OutBound Track + +10.000 +in/s + + +0.390 +in/s + + +2.645 +in/s + + +0.095 +in/s + + +85 +Hz + + +73 +Hz + + +43 +Hz + +11:43:33 +2018-02-10 +11:43:33 +2018-02-10 +11:43:33 +2018-02-10 + +2.656 +in/s + +11:43:33 +2018-02-10 +Linear Weighting + +126.4 +dB(L) + +11:43:18 +2018-02-10 + +>100 +Hz + +7.2 Hz. +4.3 +Passed +7.5 Hz. +3.7 +Passed +7.4 Hz. +4.1 +Passed +19.7 Hz. +634 mv +Passed + + +2018-02-10 11:42:57 - 2018-02-10 11:43:34 "Event Recorded Modem Exit" + + + Tran Peak in/s + Tran Freq Hz + Vert Peak in/s + Vert Freq Hz + Long Peak in/s + Long Freq Hz + Geo PVS in/s + MicL Peak psi(L) + MicL Peak dB(L) + MicL Freq Hz + + + + +0.005>1000.005>1000.005N/A0.0090.00091.4834 + + +0.005>1000.005>1000.005>1000.0090.000100.0>100 + + +0.005>1000.005>1000.005>1000.0090.00087.96>100 + + +0.010>1000.015>1000.010>1000.0160.006126.4>100 + + +0.005>1000.005>1000.005>1000.0090.004122.043 + + +0.005>1000.010>1000.005>1000.0110.00087.96>100 + + +0.390852.645730.095432.6560.00093.98>100 + + +0.005>1000.005>1000.005>1000.0070.00087.96>100 + + + + + + diff --git a/tests/fixtures/histogram-decode-11-02-26/K440HDXX.XH0H b/tests/fixtures/histogram-decode-11-02-26/K440HDXX.XH0H new file mode 100755 index 0000000..f50105a Binary files /dev/null and b/tests/fixtures/histogram-decode-11-02-26/K440HDXX.XH0H differ diff --git a/tests/fixtures/histogram-decode-11-02-26/T193KR5M.X90H b/tests/fixtures/histogram-decode-11-02-26/T193KR5M.X90H new file mode 100755 index 0000000..435b225 Binary files /dev/null and b/tests/fixtures/histogram-decode-11-02-26/T193KR5M.X90H differ diff --git a/tests/fixtures/histogram-decode-11-02-26/T193KR5M_X90H_XML.XML b/tests/fixtures/histogram-decode-11-02-26/T193KR5M_X90H_XML.XML new file mode 100755 index 0000000..ba2492c --- /dev/null +++ b/tests/fixtures/histogram-decode-11-02-26/T193KR5M_X90H_XML.XML @@ -0,0 +1,140 @@ + + +8.0 +Full Histogram +BE18193 +V 10.72-8.17 MiniMate Plus +T193KR5M.X90H +17:22:21 +2024-10-07 +17:22:38 +2024-10-07 + +Tran +Vert +Long +MicL + +9.00 +2 seconds +1024 sps +6.3 Volts +July 10, 2024 by Instantel +in/s and dB(L) +I-80- North Fork Bridges-543 Plank Rd +Fay Company +Terra-Mechanics Inc - Harrison +Loc #1 -Main Line- Area 2 - 543 Plank Rd + +10.000 +in/s + + +2.290 +in/s + + +5.515 +in/s + + +1.520 +in/s + + +11 +Hz + + +34 +Hz + + +18 +Hz + +17:22:37 +2024-10-07 +17:22:37 +2024-10-07 +17:22:37 +2024-10-07 + +5.818 +in/s + +17:22:37 +2024-10-07 +Linear Weighting + +108.0 +dB(L) + +17:22:37 +2024-10-07 + +57 +Hz + +7.6 Hz. +3.7 +Passed +7.7 Hz. +3.5 +Passed +7.5 Hz. +3.6 +Passed +0.0 Hz. +0 mv +Check + + +2024-10-07 17:22:20 - 2024-10-07 17:22:38 "Event Recorded Modem Exit" + + + Tran Peak in/s + Tran Freq Hz + Vert Peak in/s + Vert Freq Hz + Long Peak in/s + Long Freq Hz + Geo PVS in/s + MicL Peak psi(L) + MicL Peak dB(L) + MicL Freq Hz + + + + +0.005>1000.005>1000.010>1000.0110.000104.264 + + +0.005>1000.005>1000.005>1000.0090.000104.264 + + +0.005>1000.005>1000.005>1000.0090.000104.264 + + +0.005>1000.005>1000.005>1000.0090.000104.264 + + +0.005>1000.005>1000.005>1000.0090.000104.264 + + +0.005>1000.005>1000.005>1000.0090.000104.273 + + +0.005>1000.010>1000.005>1000.0110.000104.264 + + +2.290115.515341.520185.8180.001108.057 + + +0.010>1000.0202.90.005>1000.0220.001104.964 + + + + + + diff --git a/tests/fixtures/job-number-11-02-26/K557I55Y.I20H b/tests/fixtures/job-number-11-02-26/K557I55Y.I20H new file mode 100755 index 0000000..f56537a Binary files /dev/null and b/tests/fixtures/job-number-11-02-26/K557I55Y.I20H differ diff --git a/tests/fixtures/job-number-11-02-26/K557I55Y_I20H_XML.XML b/tests/fixtures/job-number-11-02-26/K557I55Y_I20H_XML.XML new file mode 100755 index 0000000..9d649bd --- /dev/null +++ b/tests/fixtures/job-number-11-02-26/K557I55Y_I20H_XML.XML @@ -0,0 +1,116 @@ + + +8.0 +Full Histogram +BE9557 +V 10.72-8.17 MiniMate Plus +K557I55Y.I20H +12:54:02 +2019-10-07 +12:54:28 +2019-10-07 + +Tran +Vert +Long +MicL + +1.00 +1 minute +1024 sps +6.4 Volts +January 18, 2019 by Instantel +in/s and dB(L) +Landmark - The Standard - Atherton Hotel +Landmark Constructors +Terra-Mechanics, Inc. - D. Bartholomae +Loc 2- Atherton Hotel - 125 S. Atherton + +10.000 +in/s + + +0.425 +in/s + + +0.010 +in/s + + +0.485 +in/s + + +>100 +Hz + + +>100 +Hz + + +>100 +Hz + +12:54:28 +2019-10-07 +12:54:28 +2019-10-07 +12:54:28 +2019-10-07 + +0.645 +in/s + +12:54:28 +2019-10-07 +Linear Weighting + +91.5 +dB(L) + +12:54:28 +2019-10-07 + +>100 +Hz + +7.9 Hz. +3.4 +Passed +7.4 Hz. +3.7 +Passed +7.7 Hz. +3.9 +Passed +20.1 Hz. +585 mv +Passed + + +2019-10-07 12:54:01 - 2019-10-07 12:54:28 "Event Recorded Modem Exit" + + + Tran Peak in/s + Tran Freq Hz + Vert Peak in/s + Vert Freq Hz + Long Peak in/s + Long Freq Hz + Geo PVS in/s + MicL Peak psi(L) + MicL Peak dB(L) + MicL Freq Hz + + + + +0.425>1000.010>1000.485>1000.6450.00091.48>100 + + + + + + diff --git a/tests/fixtures/job-number-11-02-26/T438I4V5.DJ0H b/tests/fixtures/job-number-11-02-26/T438I4V5.DJ0H new file mode 100755 index 0000000..9b25a40 Binary files /dev/null and b/tests/fixtures/job-number-11-02-26/T438I4V5.DJ0H differ diff --git a/tests/fixtures/job-number-11-02-26/T438I4V5_DJ0H_XML.XML b/tests/fixtures/job-number-11-02-26/T438I4V5_DJ0H_XML.XML new file mode 100755 index 0000000..03c6b02 --- /dev/null +++ b/tests/fixtures/job-number-11-02-26/T438I4V5_DJ0H_XML.XML @@ -0,0 +1,117 @@ + + +8.0 +Full Histogram +BE18438 +V 10.72-8.17 MiniMate Plus +T438I4V5.DJ0H +16:48:55 +2019-10-01 +16:48:57 +2019-10-01 + +Tran +Vert +Long +MicL + +1.00 +1 minute +1024 sps +6.8 Volts +September 3, 2019 by Instantel +in/s and dB(L) +1 +Univ of Pitt - Scaife Hall-UPMC - Loc 2 +P J Dick, Inc. +Terra-Mechanics, Inc. - D. Harrison +Unit #2 - Station #2 - Loc 2 + +10.000 +in/s + + +0.550 +in/s + + +1.335 +in/s + + +0.270 +in/s + + +N/A +Hz + + +N/A +Hz + + +N/A +Hz + +16:48:57 +2019-10-01 +16:48:57 +2019-10-01 +16:48:57 +2019-10-01 + +1.394 +in/s + +16:48:57 +2019-10-01 +Linear Weighting + +114.4 +dB(L) + +16:48:57 +2019-10-01 + +51 +Hz + +7.5 Hz. +4.0 +Passed +7.5 Hz. +3.9 +Passed +7.6 Hz. +3.7 +Passed +0.0 Hz. +0 mv +Check + + +2019-10-01 16:48:54 - 2019-10-01 16:48:57 "Event Recorded Modem Exit" + + + Tran Peak in/s + Tran Freq Hz + Vert Peak in/s + Vert Freq Hz + Long Peak in/s + Long Freq Hz + Geo PVS in/s + MicL Peak psi(L) + MicL Peak dB(L) + MicL Freq Hz + + + + +0.550N/A1.335N/A0.270N/A1.3940.002114.451 + + + + + + diff --git a/tests/test_bw_file_fields.py b/tests/test_bw_file_fields.py index fc57beb..f3a39d2 100644 --- a/tests/test_bw_file_fields.py +++ b/tests/test_bw_file_fields.py @@ -276,3 +276,92 @@ def test_an_imported_file_and_the_backfill_store_its_range(tmp_path): "--db-path", str(tmp_path / "seismo_relay.db"), "--force"]) == 0 with h5py.File(h5, "r") as f: assert f.attrs["geo_range"] == "sensitive" + + +# ── The job number ────────────────────────────────────────────────────────── +# Series IV's 0x1A layout again: report flags at k - 9 (bit 0x02 = job number +# shown) and the number, uint16 BE, at k - 8, kept while switched off. The flag +# matches Blastware's JobNumber on 2,997 / 2,997 DL2 events that print one and +# 66,986 / 66,986 that don't (measured 2026-11-02). Every printed value is 1; +# hidden ones hold real numbers (802, 1012, 1013, 622). + +@pytest.mark.parametrize("rel,enabled,number", [ + ("decode-checker-10-29-26/T1905KDW.5F0W", True, 1), # XML JobNumber 1 + ("job-number-11-02-26/T438I4V5.DJ0H", True, 1), # histogram, XML JobNumber 1 + ("job-number-11-02-26/K557I55Y.I20H", False, 802), # no JobNumber in the XML + ("decode-checker-10-29-26/R352HFZ7.530H", False, 1), +]) +def test_job_number_comes_from_the_file(rel, enabled, number): + pi = read_blastware_file(_FIX / rel).project_info + assert (pi.job_number_enabled, pi.job_number) == (enabled, number) + + +def test_the_h5_carries_the_job_number(tmp_path): + import h5py + from sfm import event_hdf5 + ev = read_blastware_file(_FIX / "job-number-11-02-26/K557I55Y.I20H") + event_hdf5.write_event_hdf5(tmp_path / "e.h5", ev, serial="BE9557") + with h5py.File(tmp_path / "e.h5", "r") as f: + assert (bool(f.attrs["job_number_enabled"]), int(f.attrs["job_number"])) == (False, 802) + + +# ── Histograms: the codec follows the record type, and loud short blocks ───── +_HD = "histogram-decode-11-02-26" + + +def test_a_histogram_body_goes_to_the_histogram_codec(): + # BE9440, 2018, 5 s intervals. The waveform codec accepted this body when + # it was tried first, and returned ~5x too many "samples". Blastware's + # report: 6,976 intervals, PPV 0.180 / 0.195 / 0.215, PVS 0.270, start + # 2018-04-26 07:53:41. + ev = read_blastware_file(_FIX / _HD / "K440HDXX.XH0H") + assert ev.record_type == "Histogram" + assert len(ev.raw_samples["Tran"]) == 6976 + pv = ev.peak_values + for got, want in zip((pv.tran, pv.vert, pv.long, pv.peak_vector_sum), + (0.180, 0.195, 0.215, 0.270)): + assert abs(got - want) <= 0.0005 + 1e-9, (got, want) + ts = ev.timestamp + assert (ts.year, ts.month, ts.day) == (2018, 4, 26) + + +@pytest.mark.parametrize("name,n", [ + ("T193KR5M.X90H", 9), # 2 s; its 8th interval is 5.8 in/s of vector sum + ("K440HA3C.JM0H", 8), # 5 s +]) +def test_a_loud_interval_does_not_hide_a_short_histogram(name, n): + # A short (one-block) sub-minute histogram is found by its record layout. + # An interval louder than 1.28 in/s has a vector sum squared above 65,535, + # which the old "first word is 0000" test rejected. + ev = read_blastware_file(_FIX / _HD / name) + assert len(ev.raw_samples["Tran"]) == n + + +# ── The footer is the file's last 26 bytes ────────────────────────────────── +# Every DL2 file ends in a valid footer (70,041 / 70,041: 0e 08 and two valid +# times). A few also hold an earlier "0e 08 + date" record, ~1.1 KB before +# the end: the stop time followed by zeros. The first-match footer search took +# it, so a histogram started at its own stop -- a day late on BE9558's daily +# histograms -- and a waveform lost its stop and its trigger time. +_FT = "footer-11-03-26" + + +def test_a_histogram_starts_at_its_footer_not_at_an_earlier_stop_record(): + ts = read_blastware_file(_FIX / _FT / "K558L9XP.FK0H").timestamp + # Blastware: 2025-10-07 19:14:08 (SFM read 2025-10-08 19:10:01) + assert (ts.year, ts.month, ts.day, ts.hour, ts.minute) == (2025, 10, 7, 19, 14) + + +def test_a_histogram_with_the_early_record_gets_its_time(): + ts = read_blastware_file(_FIX / _FT / "T003LCYV.JD0H").timestamp + # Blastware: 2025-12-05 18:04:25 (SFM had no time at all) + assert ts is not None + assert (ts.year, ts.month, ts.day, ts.hour, ts.minute) == (2025, 12, 5, 18, 4) + + +def test_a_waveform_with_the_early_record_is_timed_from_its_trigger(): + ev = read_blastware_file(_FIX / _FT / "K440I4LG.JK0W") + ts = ev.timestamp + # Blastware: 2019-09-26 11:14:08, record time 4 s (SFM read the stop, 11:14:12) + assert (ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second) == (2019, 9, 26, 11, 14, 8) + assert ev.timestamp_source in ("event_record", "estimate") diff --git a/tests/test_decode_check.py b/tests/test_decode_check.py index d030611..a37dca5 100644 --- a/tests/test_decode_check.py +++ b/tests/test_decode_check.py @@ -86,9 +86,8 @@ def test_an_extra_reference_row_is_a_mismatch_with_detail(): assert "row_length_disagreements=1" in res["samples.Tran"].detail -def test_job_number_na_and_above_range(): - res = _results("T1905KDW.5F0W") - assert res["JobNumber"].verdict == "sfm_blank" +def test_zc_frequency_na_and_above_range(): + res = _results("T1905KDW.5F0W") # its JobNumber: test_the_job_number_matches_blastware assert res["TranZCFreq"].verdict == "no_reference" # N/A assert res["VertZCFreq"].verdict == "sfm_blank" # >100, SFM has no flag yet @@ -172,3 +171,53 @@ def test_a_sensitive_range_event_now_matches(): for f in ("GeoRange", "TranPPV", "VertPPV", "LongPPV", "PeakVectorSum", "samples.Tran", "samples.Vert", "samples.Long"): assert res[f].verdict == "match", (f, res[f]) + + +def test_the_job_number_matches_blastware(): + assert _results("T1905KDW.5F0W", CARVEOUTS)["JobNumber"].verdict == "match" + + +def test_a_hidden_job_number_is_not_reported(): + # Flag off: Blastware prints no JobNumber, and SFM's side reports none either. + assert sfm_side((FIX / "R352HFZ7.530H").read_bytes()).job_number is None + + +def test_a_job_number_only_sfm_shows_is_a_mismatch(): + side = sfm_side((FIX / "R352HFZ7.530H").read_bytes()) + side.job_number = "1" + res = {r.field: r for r in compare(side, parse_xml_report_file(FIX / "R352HFZ7_530H_XML.XML"))} + assert res["JobNumber"].verdict == "mismatch" + + +@pytest.mark.parametrize("stem", ["T193KR5M.X90H", "K440HA3C.JM0H"]) +def test_a_loud_short_histogram_matches_blastware(stem): + hd = FIX.parent / "histogram-decode-11-02-26" + res = {r.field: r for r in compare(sfm_side((hd / stem).read_bytes()), + parse_xml_report_file(hd / (stem.replace(".", "_", 1) + "_XML.XML")), + CARVEOUTS)} + for f in ("NumberofIntervals", "intervals.Tran Peak in/s", "intervals.Vert Peak in/s", + "intervals.Long Peak in/s"): + assert res[f].verdict == "match", (f, res[f]) + + +def _count_case(extra, drop_rows=0): + jf = FIX.parent / "job-number-11-02-26" + ref = parse_xml_report_file(jf / "T438I4V5_DJ0H_XML.XML") + rows = len(ref.intervals) + ref.scalars["NumberofIntervals"] = f"{rows + extra}.00" + if drop_rows: + ref.intervals = ref.intervals[:-drop_rows] + side = sfm_side((jf / "T438I4V5.DJ0H").read_bytes()) + return {r.field: r for r in compare(side, ref, CARVEOUTS)}["NumberofIntervals"] + + +def test_blastware_counting_the_monitoring_time_is_accepted(): + # Blastware's Number of Intervals is (stop - start) / interval. When the + # unit never wrote the last minute, Blastware's own table lists one block + # fewer, and SFM matches the table (T193KSWP.FF0H: 2,880 against 2,850 rows). + r = _count_case(30) + assert (r.verdict, r.carveout) == ("accepted", "interval-count-is-duration") + + +def test_the_count_carveout_needs_blastwares_own_table_to_agree_with_sfm(): + assert _count_case(30, drop_rows=1).verdict == "mismatch" diff --git a/tests/test_histogram_codec.py b/tests/test_histogram_codec.py index 74ed89c..9b6522a 100644 --- a/tests/test_histogram_codec.py +++ b/tests/test_histogram_codec.py @@ -525,18 +525,28 @@ from minimateplus.histogram_codec import ( # noqa: E402 def _mk_multi_block(intervals, seg=0, ctr=256): - """Build one multi-interval block from a list of 8-tuples.""" - b = bytearray() - b += bytes([0x00, seg]) - b += int(ctr).to_bytes(2, "little") - b += bytes([0x0A, 0x00]) + """Build one multi-interval block from a list of 8-tuples (T, Tf, V, Vf, L, + Lf, M, Mf) in the measured layout: big-endian from byte 5, each record ending + in its PVS squared -- here the largest geo peak squared, which every real + record is consistent with (34,502,955 / 34,502,955 DL2 intervals).""" + b = bytearray([0x00, seg]) + int(ctr).to_bytes(2, "little") + bytes([0x0A]) + for iv in intervals: + for v in iv: + b += int(v).to_bytes(2, "big") + b += (max(iv[0], iv[2], iv[4]) ** 2).to_bytes(4, "big") + b += bytes(7) + assert len(b) == 12 + 20 * len(intervals) + return bytes(b) + + +def _mk_legacy_le_block(intervals, seg=0, ctr=256): + """The retracted model's bytes: 8 x uint16 LITTLE-endian from byte 6.""" + b = bytearray([0x00, seg]) + int(ctr).to_bytes(2, "little") + bytes([0x0A, 0x00]) for iv in intervals: for v in iv: b += int(v).to_bytes(2, "little") - b += (0).to_bytes(2, "little") - b += (5).to_bytes(2, "little") + b += (0).to_bytes(2, "little") + (5).to_bytes(2, "little") b += bytes(6) - assert len(b) == 12 + 20 * len(intervals) return bytes(b) @@ -569,7 +579,7 @@ def test_multi_interval_values_are_not_little_endian_from_byte_6(): tests/test_histogram_multi_interval.py for the measured cases. """ ivs = [(0x0100, 1, 1, 1, 1, 1, 1, 1), (1, 1, 1, 1, 1, 1, 1, 1)] - body = _mk_multi_block(ivs) + _mk_multi_block(ivs, ctr=257) + body = _mk_legacy_le_block(ivs) + _mk_legacy_le_block(ivs, ctr=257) assert walk_multi_interval_blocks(body)[0]["t_peak"] != 0x0100 diff --git a/tests/test_histogram_multi_interval.py b/tests/test_histogram_multi_interval.py index 3a0511d..4547ac8 100644 --- a/tests/test_histogram_multi_interval.py +++ b/tests/test_histogram_multi_interval.py @@ -56,7 +56,7 @@ def _block(records, *, ctr=0x0100, seg=0, mic=True, last=False) -> bytes: assert len(r) == (8 if mic else 6) for v in r: b += int(v).to_bytes(2, "big") - b += b"\x00\x00" + b"\x00\x2d" # the zero word, then one more + b += (max(r[0], r[2], r[4]) ** 2).to_bytes(4, "big") # PVS², consistent as on real data b += b"\xfc\xf3\x00" + (TERMINAL if last else b"\x5a\x0a\x00\x00") return bytes(b)