diff --git a/CLAUDE.md b/CLAUDE.md index 4a142e8..2b3b30e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -31,6 +31,17 @@ Read this first when picking the project back up. 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. +- **๐Ÿ”‘ Monitor logs (.MLG) and each unit's timeline (2026-11-13, `feat/mlg-import`).** + - **What:** every unit sends an `.MLG` at every call-in, in every mode. SFM reads it + (`minimateplus/mlg_file.py`, reference D.4) and keeps each unit's monitoring timeline: + sessions, gaps and what they mean, clock steps, and the call-ins, including calls that + left no file. + - **Why (Brian, 2026-11-09):** shot reports need proof that a unit which did not trigger was + monitoring. Continuous-mode units send no file on a quiet day. Outage history is the + second use. + - **Spec:** `docs/superpowers/specs/2026-11-09-mlg-unit-timeline-design.md`. + - **Not yet:** the watcher still does not forward `.MLG`s (its repo, Brian's call), and + Terra-View shows none of it. - **๐Ÿ”‘ 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/`). @@ -1859,10 +1870,16 @@ GET /db/monitor_log?serial=BE11529&from_dt=&to_dt= โ† monitoring intervals GET /db/sessions?serial=BE11529&limit=50 โ† ACH call-home sessions, newest first PATCH /db/events/{id}/false_trigger?value=true โ† flag/unflag false triggers GET /db/device_commands?serial=UM20147&limit=100 โ† start/stop audit trail (sent, states), newest first +POST /db/import/mlg_file?serial=&call_in=true โ† Blastware .MLG upload (form field mtimes = JSON {name: unix s UTC}) +GET /db/units/{serial}/timeline?from_dt=&to_dt= โ† sessions, gaps (+ meaning), clock steps, call-ins, from .MLGs +GET /db/units/{serial}/monitoring_at?at= โ† monitoring / not_monitoring / unknown at a unit-clock time +GET /db/mlg_records?serial=BE8081&from_dt=&to_dt= โ† raw .MLG records, oldest first +GET /db/mlg_files/{id} โ† the original .MLG, byte for byte ``` DB file: `bridges/captures/seismo_relay.db` (default; override with `--db-path` at startup). -All DB endpoints are read-only except `PATCH /db/events/{id}/false_trigger`. +All DB endpoints are read-only except `PATCH /db/events/{id}/false_trigger` and the +`/db/import/*` uploads. --- diff --git a/docs/instantel_protocol_reference.md b/docs/instantel_protocol_reference.md index 4b4c3a4..eefc7f9 100644 --- a/docs/instantel_protocol_reference.md +++ b/docs/instantel_protocol_reference.md @@ -11,6 +11,7 @@ | Date | Section | Change | |---|---|---| +| 2026-11-13 | Appendix D.4 (rewritten), D.4.1โ€“D.4.4 | โœ… **The `.MLG` format, measured.** An 18-byte prefix, then 292-byte records `[length 290 LE][id 0e a0 header / 0e 80 log][โ€ฆ][00 00][CRC]`. The CRC is **CRC-16/AUG-CCITT over `[0:288]`, little-endian** (3,329 / 3,329 records, 1,282 files). Fields: times with the year LE, the monitor-log flag word and trigger source LE, the serial, Blastware's text. Also: one file per call-in, how sessions appear, and a Modem Exit that is not a file's last record was a call that left no file. Cross-checked against DL2 event footers: 785 / 785 for BE8081. The old D.4.1โ€“D.4.3 (308-byte header, CRC at the start) are kept, marked retracted. Reader/writer `minimateplus/mlg_file.py`. | | 2026-11-11 | Appendix D.3.3 | โœ… **The footer's last two bytes are a CRC-16/AUG-CCITT** (init `0x1D0F`), big-endian, over the footer record from its length prefix `00 1a` through footer `[0:22]`: 70,041 / 70,041 DL2 files. Found by the `.MLG` session, verified here. Retracts 2026-11-08's "no common CRC-16 fits": every attempt had started at the footer itself. Same CRC family as the Series IV `0x1A` block's and the `.MLG` record's. | | 2026-11-09 | Appendix D.6.15 (NEW), D.6.6, D.6.11 | โœ… **Over range and the mic.** **D.6.15:** a peak past full scale (2,000 units = 32,000 counts; the mic in counts) is Blastware's `OORANGE`, per channel and per histogram interval, from the unit's own summary peaks. The vector sum is `OORANGE` exactly when a geophone is (43 / 43); never on its own (38 / 38 numeric), which retracts D.6.11's open "vector sum alone" case. The `` line marks the mic over (18 / 18). **D.6.6:** the mic has its own range byte (label + 29): at 1 a count is an eighth, 7 DL2 events SFM read 8ร— high. The dB offset is **81.938216**: [81.9383, 81.9385] was too high, and every count Blastware printed leaves [81.9382058, 81.9382266]. Blastware's mic unit labels do not hold on every report; some mix dB and psi in one column. **80 of 88 report fields now match on every DL2 event.** | | 2026-11-08 | Appendix D.6.14 (NEW), D.3.3, D.6.11 | โœ… **The monitor log is in the footer.** Every DL2 report prints one Monitor Log line: the footer's ts1 and ts2, then words for the footer's flag word `[18:20]` (`0x0001` Event Recorded, `0x0002` Keyboard Exit, `0x0004` Remote Exit, `0x0008` Selfcheck Passed, `0x0010` Timer Stop, `0x0020` Modem Exit, `0x0200` Battery Low Exit, `0x0800` Memory Full Exit; the higher session-end bit wins, from one file). Rebuilt, it equals Blastware's character for character on 69,983 / 69,983. **D.3.3:** footer `[20:22]` is the trigger source again, `[22:24]` is zero; `[24:26]` still unknown, and no common CRC-16 or sum fits. **72 of 88 report fields now match on every DL2 event.** | @@ -3504,11 +3505,133 @@ The footer terminates the N00 file. Its bytes come directly from the terminator > the length prefix. It is the same CRC family as the Series IV `0x1A` block's and the `.MLG` > record's (D.4). -### D.4 MLG File Format โ€” Monitor Log +### D.4 MLG File Format โ€” Monitor Log โœ… 2026-11-13 -**File layout:** `[308B header] [N ร— 292B records]` +Measured on **1,273 DL2 files** from Blastware's ACH folder (`C:\Blastware 10\Event\autocall +home`: BE6907 and BE12844 from 2026, BE8081 from 2018โ€“19; local copy `~/dl2-archive/mlg/`) and +**9 bench files** (`example-events/`). Reader and writer: `minimateplus/mlg_file.py`. SFM's +storage and each unit's timeline: `docs/superpowers/specs/2026-11-09-mlg-unit-timeline-design.md`. -#### D.4.1 MLG Header (308 bytes) +**File layout:** an 18-byte prefix, then whole 292-byte records. The size is always +`18 + 292ยทn` (1,282 / 1,282 files) โœ…. + +#### D.4.1 The prefix and the records โœ… + +| Offset | Bytes | Field | +|---|---|---| +| 0 | 18 | prefix `10 00 01 80 00 00 "Instantel\0" 07 2c` (the event file's first 18 bytes) | +| 18 | 292 | the header record (absent in an empty file) | +| 310 | 292 ร— n | log records | + +Every record, header and log alike: + +| Offset | Bytes | Field | +|---|---|---| +| 0 | 2 | length, uint16 **LE** = `0x0122` (290): the bytes after it | +| 2 | 2 | id: `0e a0` the header record (always first), `0e 80` a log record | +| 4 | 284 | content (D.4.2) | +| 288 | 2 | `00 00`, not covered by the CRC | +| 290 | 2 | CRC (D.4.3), **LE** | + +- **The header record** holds only the serial, at `[24:34]` (NUL-padded ASCII). Every other + byte of it is zero on all 1,273 DL2 files. +- **An empty file** is the 18-byte prefix alone: no header record, no serial. 231 of the 1,273 + DL2 files are empty. + +This is the same `[length][id][payload]` shape as the event file's record chain (D.6.13); the +log record's id `0e` is the footer's. The old reading below (a 308-byte header, a CRC at each +record's start) cut every record two bytes early: the "CRC" it saw at `record[0:2]` was the +previous record's tail. + +#### D.4.2 A log record's fields โœ… + +Offsets from the record's length field: + +| Offset | Bytes | Field | +|---|---|---| +| 4 | 8 | start: day, month, year **LE**, 0, hour, minute, second (D.2) | +| 12 | 8 | stop, same format; all zeros = no stop | +| 20 | 2 | monitor-log flag word, uint16 LE: the event footer's (D.3.3, D.6.14); `0xFFFF` = monitoring started | +| 22 | 2 | trigger source, uint16 LE: `0x0001`โ€“`0x0008` a channel, `0x0400` a histogram, 0 none | +| 24 | 10 | serial, NUL-padded ASCII | +| 34 | 254 | text, NUL-padded | + +**The text** (Blastware's, not the unit's: see below): +- **"monitoring started":** `Trigger Level : Geo: 0.0500 in/s Mic: 125.0 dB(L)`, or + `Trigger Level : Histogram` +- **an event:** `08`, then the event's time in 8 bytes (year LE), then + `Geo: 0.0500 in/s Mic: 125.0 dB(L)\rTran: 0.0500 in/s` +- **a histogram:** `08`, its time, `Histogram\r` +- **a closed session:** `Geo: 0.0500 in/s Mic: 125.0 dB(L)` + +โš  **The text is written by Blastware.** Two bench copies of the same three records +(`ach-vs-manual/BE11529.MLG`, `BE115292.MLG`) differ only in `Trigger Level: Histogram` vs +`Trigger Level : Histogram`, and so in their CRCs. A record's identity is its times, flag word +and trigger source, never its text. + +#### D.4.3 The CRC โœ… solved 2026-11-09 + +**CRC-16/AUG-CCITT** (poly `0x1021`, init `0x1D0F`, no reflection), over `record[0:288]` (from +the length field), stored **little-endian** at `[290:292]`. It matches **3,329 / 3,329** records +(1,282 files, header records included). + +It is the same rule as the Series IV setup blocks (`content[0:2]` = N, CRC over `[0:N-2]`, stored +at `[N:N+2]`) and the event footer (D.3.3), which store it big-endian. +`minimateplus/crc.py` computes it for all three. + +#### D.4.4 How Blastware writes them, and how a session appears + +Measured on the three DL2 units unless marked: + +- **One file per call-in**, named `.MLG` with nothing between, e.g. + `BE11010304.MLG`. DL2's first file has no counter (`BE8081.MLG`). The name cannot be split by + reading it; the serial inside the file is authoritative. +- **No log record appears in two call-in files.** Each holds what happened since the previous + call-in. A cable or direct download is cumulative: the bench `4-3-26-multi/BE11529.MLG` + repeats the 4-1 records. +- **A file is written 1โ€“2 minutes after the unit stops for its call-in** ("Modem Exit"), so the + unit's clock and the PC's agree to within those minutes. + - โš  Through a Windows zip, file dates read an hour early from March to October (Windows + converts with the offset in force at zip time). robocopy keeps true times. +- **A Modem Exit that is not a file's last record was a call that left no file.** Example: + `BE8081321.MLG` holds Modem Exits on 2019-04-12 18:33, 04-13 07:00 and 04-15 17:15, and only + the last produced a file. + - 38 files of the 1,273 hold more than one Modem Exit. + - ๐Ÿ”ถ Inferred: the call failed, or the PC did not take it. +- **Empty files:** BE6907 writes one or two 2โ€“3 minutes after nearly every real call-in (230 of + its 369 files). BE12844 and BE8081 never do. ๐Ÿ”ถ Inferred: the unit calls back and has nothing + new. +- **The unit's clock steps back an hour at the first call-in after daylight saving ends.** On + 2026-11-01 BE12844 ran `06:00:13 โ†’ 18:45:00` (still EDT), called in at 17:46 EST, and its next + session is `17:47:25 โ†’ 18:45:00`; BE6907 likewise. ๐Ÿ”ถ Inferred: Blastware sets the unit's clock + at the call-in. + +**How a session appears:** +- **No events:** one closed record (start, stop, flag word = why it stopped). +- **With events:** a "monitoring started" record (`0xFFFF`, no stop), then one record per event + (`0x0001` + the channel). + - The unit calls in minutes after each event, and monitoring resumes as a *new* session. + - The first session's end is written nowhere; it lies between its last event's stop and the + next start. +- **A histogram:** a "monitoring started" record at T, then a histogram record from T+1 s to + the stop, carrying the stop reason (`0x0021` = Event Recorded + Modem Exit, source `0x0400`). + Waveform event records whose start falls inside it belong to that histogram session. + +**Cross-check (2026-11-13, `scratch/check_mlg_vs_events.py`):** each Event Recorded record was +matched to a DL2 event file by stop time + flag word + trigger source. +- **BE8081:** 785 / 785 records match a file, and every one of its 785 event files in that period + has its record. +- **BE6907 and BE12844:** all 25 event files have a record. The 42 records with no file all stop + after 2026-08-25, where the DL2 copy ends. +- **The footer CRCs:** all 4,303 of those three units' event files pass (D.3.3). + +> โš  **RETRACTED 2026-11-13: D.4.1โ€“D.4.3 below (the old reading).** The 308-byte header, the CRC +> at `record[0:2]`, the big-endian times, the 4-byte "record flags" table and the unknown CRC are +> all superseded by the sections above. They are kept as history, per this document's convention. +> The 2026-11-09 note inside them (little-endian, the flag word) was the first step of the new +> reading. + +#### D.4.1 (retracted) MLG Header (308 bytes) | Offset | Length | Field | Notes | |---|---|---|---| @@ -3517,7 +3640,7 @@ The footer terminates the N00 file. Its bytes come directly from the terminator | 0x2A | 8 | serial number | null-padded ASCII (e.g. `"BE11529"`) | | 0x32 | remainder | zero pad | pads to 308 bytes total | -#### D.4.2 MLG Record (292 bytes each) +#### D.4.2 (retracted) MLG Record (292 bytes each) | Offset | Length | Field | Notes | |---|---|---|---| @@ -3564,7 +3687,10 @@ The footer terminates the N00 file. Its bytes come directly from the terminator | 1โ€“8 | ts1 copy (8B big-endian) | | 9+ | `"Geo: X.XXX in/s\x00"` ASCII geo threshold | -#### D.4.3 MLG CRC +#### D.4.3 (retracted) MLG CRC + +> โš  **Solved 2026-11-09:** CRC-16/AUG-CCITT over the record from its length field, at the record's +> end (the new D.4.3 above). Every attempt below looked for it at the record's start. The 2-byte CRC at record[0:2] uses an unconfirmed algorithm. Tested against CRC-16/CCITT, CRC-16/IBM, CRC-32 (truncated), word sums, XOR variants, and 40+ polynomial/init combinations โ€” none matched. The writer emits `00 00`. Blastware may reject files with incorrect CRCs (impact on import unknown โ€” TODO: test). diff --git a/docs/superpowers/specs/2026-11-09-mlg-unit-timeline-design.md b/docs/superpowers/specs/2026-11-09-mlg-unit-timeline-design.md index 3ed1504..8dc86a7 100644 --- a/docs/superpowers/specs/2026-11-09-mlg-unit-timeline-design.md +++ b/docs/superpowers/specs/2026-11-09-mlg-unit-timeline-design.md @@ -289,10 +289,10 @@ An empty file holds no serial. Take, in order: - Rewrite the reference's D.4 (`docs/instantel_protocol_reference.md`) with the measured framing, checksum, fields and file behaviour, keeping the old text as a retraction. Mark D.4.3 solved. The file is CRLF: edit it with the Edit tool. -- ๐Ÿ”‘ **For Brian to pass to the decoder session, not edited here:** the event-file footer's - checksum (D.3.3, open since April) is the same rule. AUG-CCITT over the footer record from its - length `00 1a` through byte 24, stored big-endian. It matches **70,041 / 70,041** DL2 files. - Inferred: every record in the event file's tail chain (D.6.13) carries one. +- ๐Ÿ”‘ **The event-file footer's checksum** (D.3.3, open since April) is the same rule: + AUG-CCITT over the footer record from its length `00 1a` through byte 24, stored big-endian, + **70,041 / 70,041** DL2 files. Recorded on `dev` by the decoder session (`8544e9c`, + 2026-11-11). Inferred: every record in the event file's tail chain (D.6.13) carries one. ## Testing