docs(spec): phase 5 -- changing a unit's settings by serial

Brian's intent (UM6047's trigger, notes typos, the backup unit), the
flow, the first-version fields, and what is measured: Series 3's
compliance block has Series 4's 0x1A layout; a whole 1A read assembles
to the 2,090 bytes Blastware writes back (exact on both 10-26 writes);
Blastware writes 00 00 at [26:28] and a per-unit constant after the
block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-11-03 18:12:14 -05:00
1 parent cbce00f8e1
commit 0238e4d3f3
1 file changed
+339
@@ -0,0 +1,339 @@
# Phase 5: changing a unit's settings by serial (design)
**Date:** 2026-11-03. **Status:** draft for Brian. Phase 5 of
`docs/superpowers/specs/2026-10-20-sfm-series4-parity-design.md` (row 10, "change
recording settings"; build phase 5, "setup push: one field first, then several").
**Branch:** `feat/series4-sfm-parity`.
## Intent (Brian, 2026-11-03)
Change **any** of a unit's settings from SFM, and make it as easy and reliable as
possible. The goal is to fix what makes Blastware finicky. Three real cases:
- **One wrong number on a deployed unit.** UM6047 was out monitoring with its
geophone trigger at 0.03 instead of 0.300. Brian remoted into the THOR PC,
stopped it (it called in), changed the setup, made sure it was *sent*, then
restarted monitoring.
- **A typo in the notes.**
- **A backup unit.** The unit set up at the office fails in the field, so a backup
from the truck goes in with blank or stale notes and settings. There is no
computer in the field, so the office re-does the whole setup remotely, by hand,
while the person in the field stands by to press Start or power-cycle if the
link breaks.
What is wrong with THOR, as Brian and his dad experience it:
- The same screen edits a setup on disk and views a unit's setup.
- Setups get saved under random number strings.
- Editing a setup does not change the unit; you verify separately that it was sent.
Saved setups as templates would be acceptable. Not knowing whether you are
changing the unit or a file is not.
## Goals, non-goals, anti-goals
**Goals**
- Edit the unit's **live** settings, both series.
- Show exactly what will change, **old → new**, before anything is sent.
- After sending, **re-read the unit** and show what it now holds.
- Make every refusal say why, in plain words.
**Non-goals (this phase)**
- Templates, saved setups, copying from another unit.
- Restarting monitoring. **Brian presses Start**, as today; SFM never restarts on
its own.
- Setting the unit's clock. That is a later call-home receiver rule.
- Fields not yet decoded. "Any and all" grows as decoding grows.
**Anti-goals: things that would make it a failure even if it "works"**
- Any doubt about whether the unit changed.
- A screen where a file and a unit look alike, or a name SFM made up.
- Writing a byte SFM did not just read. Every byte SFM does not deliberately change
goes back exactly as read. The one exception is a byte that Blastware's (or
THOR's) own writes always set to a fixed value. Each such byte is named in the
codec with its evidence (so far: Series 3 `[26:28]` → `00 00`; my call, below).
- Sending to a monitoring unit.
- A retry. A write is sent once; what happened is read back.
## Measured basis
**1. Series 4 (Micromate): the `0x1A` setup content map.** Measured from 47
keypad snapshots on UM20147 and checksum-verified. `micromate/setup_block.py`
(`decode_setup`) reads it, with 69 tests on 15 fixtures.
| content | field |
|---|---|
| `[5]` | record mode |
| `[6:8]` | sample rate |
| `[8:10]` | histogram interval |
| `[12:16]` | pre-trigger, f32, negative |
| `[17]` | stop mode |
| `[18:22]` | record time, f32 |
| `[23]` | auto-stop |
| `[25]` | active sensors |
| `[29]` | trigger sources |
| `[30:34]` | distance |
| `[34:38]` | charge |
| `[39]` | report flags |
| `[40:42]` | job number |
| `[42:86]` | setup name |
| `[122+64n]` / `[144+64n]` | notes (label / value) |
| from `[1708]` | 48-byte channel blocks: sensor code `+4:8`, trigger `+30` (geo in/s, mic psi) |
The CRC-16/AUG-CCITT over `[0:2088]` is stored at `[2090:2092]`; THOR's write
omits it and the unit recomputes it.
- **The push sequence (from THOR's captures)** is `0xDA` (name) → `0x68`/`0x73`
(`0x08` preferences) → `0x82`/`0x83` (`0x2E` trigger) → `0x71`/`0x72` (`0x1A`
setup). `micromate.writes.plan_setup_push` reproduces THOR's frames (phase 2).
- **Not yet mapped on Series 4:** alarm level, geophone range, GPS, aux I/O, SLM
options.
**2. Series 3 (MiniMate) uses the same layout. Measured 2026-11-03.** The
compliance image as Blastware writes it is logical (unescaped), 2,092 bytes, with
`N = 2090` at `[0:2]` and the channel block "Tran" at `[1708]`.
`micromate.setup_block.decode_setup` reads it correctly:
- **BE9441's 10-26 write** (`tests/fixtures/minimate-bench-10-26-26-histogram`,
two whole sends): name, mode, 4096 sps, interval, record time 20 s, trigger
0.04 in/s, mic linear, job number and the notes all decode. Only the CRC fails
(Series 3's tail goes out stale).
- **BE11529's nine 2026-04-20 Blastware writes** (`bridges/captures/4-20-26/`,
every one with a whole image) each changed exactly the expected bytes:
| Blastware changed | bytes that moved |
|---|---|
| histogram interval (×4) | `[8:10]` |
| recording mode (×3) | `[5]` |
| geophone range | `1737` / `1785` / `1833`, the range byte at each geophone channel label `+29` |
- **The live `SUB 1A` read starts the same block.** Measured on the first data
frame of each of the four recorded reads (`_settings_replies` in
`tests/test_s3_compliance_anchor_fields.py`): unescaped, each carries `N = 2090`
12 bytes before the old "anchor", and content `[5]` reads 1 / 4 / 3 / 3. That
anchor (`be 80 00 00 00 00`) is content `[12:18]`, pre-trigger −0.25 plus stop
mode Fixed. So Series 3 can be read by content offset rather than by anchor
search, which survives an Auto-stop unit (the open question of 2026-10-17).
- **A whole `1A` read assembles to exactly the 2,090 content bytes** (measured
2026-11-03 on BE9441's 10-26 recording, 12 reads). Unescape each data frame and
take `data[11:]`. Every frame but the last then starts with one `00` byte that is
not content; drop it. This holds for Blastware's read (four 512-byte frames plus
42) and SFM's (two 1024-byte frames plus 42).
- **The round trip is exact.** Blastware re-read the block after each of its two
writes, and each re-read equals the image it had just written, all 2,090 bytes.
- **While monitoring**, the read returns `0e 'BE9441' …` (the device-info block),
as the 10-29 finding says. The unit was monitoring for 5 of the 12 reads.
- **Bytes `[26:28]`: Blastware always writes `00 00`** (all 11 writes), though the
unit reads `01 7f` after a monitoring session (BE9441 10-26, BE11529 4-20 15:19).
The unit sets them again by itself. Meaning unknown.
- **The two bytes after the block are Blastware's own.** Blastware sends a per-unit
constant: `7c ea` on all nine of BE11529's writes, `0c e9` on both of BE9441's.
It is not the block's CRC-16/AUG, and no reply in BE9441's three-hour session
contains it. SFM's `write_image` sends `00 00` there. Since a read never returns
those bytes, the read-back cannot show what the unit did with them.
- **The mode byte is shared, but its codes are not.** Series 3: `00` Single Shot,
`01` Continuous, `03` Histogram, `04` Histogram + Continuous. Series 4: `01`
Waveform, `02` Manual, `03` Histogram, `04` Combo.
- **Rules from the checker's file-side work** (seismo-relay-b6, 2026-11-03; it
measured the same content offsets on 70,042 event files and found nothing that
contradicts one shared map):
- A bitmask byte is patched **bit by bit, never rebuilt**. The trigger-sources
byte `[29]` showed an unidentified `0x80` bit on one unit.
- On Series 3, stop mode (`0` Fixed) and mic type (`2` linear) are proven for
one value each. They are not offered for writing.
- An event file's `[12:16]` is that event's captured pre-trigger, not the
setting. SFM writes only from a live read, so this matters only to anyone
tempted to build a write from a file.
- **Series-3-only fields** (measured on Series 3, not Series 4): the geophone range
byte at channel `+29`; the alarm level at channel `+38` (checker-measured on
event files; live raw `+42`).
**3. Series 3 write frames are measured (#46).** Writes use uniform escaping with
a length field. The compliance image goes in 512-byte addressed chunks. `0x68` is
written as read plus `02 00`, `0x82` plus `00 00`. The sequence is
`68→73 | 71×n→72 | 82→83 | 69→74→72`. `push_config_raw` refuses any block that
is not whole. `tests/test_minimate_write_frames.py` rebuilds Blastware's frames
byte for byte.
**4. Monitoring.**
- **Series 3:** while monitoring, the unit answers `1A` (and `0x2C`) with its
device-info block (measured 10-29 and 11-03).
- **Series 4:** it refuses call-home setup while monitoring ("Feature disabled
while monitoring", measured 11-03).
- **A stop with call-home on makes the unit call in** (measured 10-25, 10-29,
11-03).
**5. Series 4 specifics.**
- `0x1A` reads the keypad's edit buffer live: unsaved keypad edits show in the
read, and a push would commit them.
- Loading a `.MMB` replaces the active config byte for byte. The push writes
under the active setup's name (`0xDA`).
## The flow
1. **Read.** `GET /device/settings?serial=…` (it exists) returns the unit's
settings. The page shows them on the Config tab under **"On the unit BE9441 —
read 14:03"**, never anything that looks like a file.
2. **Edit and preview.** The operator changes fields, then **Preview**: a dry run.
SFM re-reads the unit's blocks on the same line, builds the new blocks, and
returns one row per field: **old → new**, plus any warnings. Nothing is sent.
3. **Send.** The same request, live, is an audited change:
- identity check, audit row, one send, never retried, read back;
- **refused with "stop monitoring first"** if the unit is monitoring, noting
that the stop makes it call in when call-home is on;
- **refused** if the unit's settings changed since the preview. The preview
carries a revision (a hash of the blocks read), and the live call must
match it.
4. **Verify.** Re-read the blocks. Every changed field must read its new value.
Every other decoded field, and every byte SFM did not deliberately change, must
read as before. The page shows **"the unit now holds"**: field, old, new, now.
Known unit-maintained bytes (the Series-4 CRC) are compared as the unit's own
checksum (`crc_ok`), not byte for byte.
5. **Start** stays the operator's button.
## Fields in the first version (Brian approved the list)
| field | Series 3 | Series 4 |
|---|---|---|
| geophone trigger level | yes (channel `+30`) | yes (channel `+30`) |
| alarm level | yes (channel `+38`; measure live) | not mapped, so not offered |
| notes: the four note slots, by the unit's own labels | yes (`Project:`, `Client:`, `User Name:`, `Seis. Loc:` on BE9441) | yes (`Location`, `Client`, `Company`, `General Notes`) |
| recording mode | yes (`[5]`; values as measured on Series 3) | yes (`[5]`; Series-4 codes) |
| sample rate | yes | yes |
| record time | yes | yes |
| histogram interval | yes | yes |
| geophone range | yes (channel `+29`) | not mapped, so not offered |
| job number (+ shown on report) | yes | yes |
A field is offered only where it is measured for that series. Values are refused
unless they are among the measured choices: sample rates 1024/2048/4096,
intervals 2/5/15/60/300/900 s, and each series' measured mode codes.
- **Numbers (my call; no unit limits are written down anywhere in the repo):**
- Refuse any value outside the span seen on real units. The builder derives
each span from the DL2 XML reports, the fixtures and the captures, and records
it in the codec with its source. SFM then never sends a value no unit has
been seen to hold. A span can be widened later on evidence.
- A geophone trigger or alarm must also be at or below the range's full scale
(10 / 1.25 in/s). When range and trigger change in one request, check the
trigger against the **new** range.
- **Units:** refuse a level write unless the channel's unit string reads the
measured one (`in.` for a geophone). A unit set to Metric is unmeasured.
- **Notes:** edited by slot, under the label the unit itself shows (labels can be
renamed and are not identifiers). The value is at most its field width less
one byte, printable ASCII.
- Not in v1: Series 3's fifth slot, `Extended Notes` (value `\n` on BE9441).
Blastware's extended notes are unmeasured and may live elsewhere.
- Not in v1: Series 4's 16-byte field at content `[1064]` (`Loc 1` on
UM12947), undecoded.
## Architecture
- **One setup-block codec for both series.** Keep `micromate/setup_block.py` as
the field map and add `encode_setup(content, changes) -> content`: field patches
only, every other byte as given. It stays a pure codec library: no I/O, no
`sfm` imports, no import cycle with `minimateplus`. Series-specific fields (the
Series-3 range and alarm) are marked by series.
- **Series 3 read.** Assemble the `1A` read into the logical 2,090-byte block:
unescape, strip the 12-byte reply prefix and the inter-frame headers
(`read_compliance_config`). Decode it by content offset.
- **Series 3 write.** The patched logical block plus the tail becomes the
compliance image for `push_config_raw`. Event index (`0x08`), trigger (`0x2E`)
and waveform data (`0x09`) are echoed as read, in Blastware's sequence.
- On `0x09`, Blastware echoed the unit's bytes on all nine April writes
(`[200:202]` = `8c 76` read and written). Only BE9441's 10-26 writes changed
them (`17 17` read, `78 76` written, and read back so). The meaning is
unknown, so SFM echoes.
- **The raw-offset `_encode_compliance_config` is retired.**
- **The legacy write (`/device/config`, `/device/config/project`) is retired (my
call).** It retries a whole write on a TCP error, is not audited, does no
read-back, does not refuse a monitoring unit, and needs no serial: every
anti-goal at once. Its only user is the webapp's by-host Config form, and
Terra-View does not call it. Its routes answer with a pointer to the by-serial
change, and the by-host form becomes read-only.
- **Series 4 write.** `plan_setup_push(prefs, trigger, patched_setup, name)`.
- **No setup files in the operator's view (Brian, 2026-11-03).** "We treat the
Micromate setups just like Minimate setups … the unit just has its settings,
and we change it based on the job. We don't send setups to the unit." A
backup unit is usually on whatever setup its previous job left. So SFM
rewrites the setup the unit is running, in place, under its own name. It
never asks for a file or a name, and never creates one. The name may show as
a read-only detail, since the unit's screen shows it.
- The name comes from the `0x41` read, unstripped.
- Refuse `factory.MMB` and any target that is not the active setup (spec). The
refusal says it plainly: "this unit is running its factory setup; load any
other setup on its keypad, then try again." Brian says the team does not use
the factory setup, so this should be rare.
- `ENABLEABLE_WRITES` gains `0xDA 0x68 0x73 0x82 0x83 0x71 0x72`.
- The keypad edit buffer: warn in the preview that a unit with someone in its
menu would have those edits committed. The check the spec names, `0x1A`
against the active `.MMB` via `0x94`/`0x48`, is a bench question first.
- **The change path.** It keeps run_change's guarantees: identity, audit, one
send, read back, `ChangeUnconfirmed` with `sent`/`audit_id`. The "state" is a
set of fields, so either `run_change` takes a verify function or a sibling core
shares its parts. The builder decides; the guarantees do not change. The audit
row keeps the per-field changes, both blocks (hex) and the verdict.
- **Routes.** `POST /device/settings/change?serial=…` (serial required) with body
`{changes: {field: value}, revision}` and `dry_run`, `caller`. The response is
per-field `old` / `new` / `now`, through `_change_response`. A dry run needs no
revision and returns one. **A live call without the revision of a preview is
refused** (my call): nothing reaches a unit unless someone saw old → new.
- **Page.** The Config tab by serial becomes the unit's edit form: Preview → Send
(confirm) → "the unit now holds". New logic goes in
`sfm/static/device_routing.js` with Node tests, and glue in
`sfm/static/sfm_webapp.js` (no inline JS).
## Verification
- **Series 3, byte for byte.** For each of the 11 Blastware compliance writes,
apply the new encoder to the read before it (or the previous image), with the
fields Blastware changed. It must reproduce Blastware's content `[0:2090]`. The
two trailing bytes are compared separately, since they are Blastware's constant.
Ten writes change one field. BE9441's 16:26 write changes five things: mode,
sample rate 2048 → 4096, interval, the mic in the sensors byte `[25]`, and
`[26:28]`. That one is tested with all of them, through the codec, though v1's
page does not offer the sensors byte.
The frames rebuild through `push_config_raw`'s path (the #46 tests).
- **Series 3, read side.** The assembly rule above, pinned as a test on the 12
reads of BE9441's 10-26 recording. Each read-back equals the write before it.
- **Series 4.** THOR's setup-push captures still reproduce, with no field changed.
Any capture where THOR changed a field becomes a byte-for-byte test.
- **Bench, with Brian's go per send, per series:**
1. A dry run of a trigger change, then send, read back, check the unit's menu,
and change it back.
2. A notes change.
3. A several-field "backup unit" change.
4. A dry run while monitoring, expecting the refusal.
## Calls I made (Claude), for Brian to check
- **Series 3 `[26:28]` goes out as `00 00`, as Blastware writes it**, rather than
the `01 7f` the unit may read. Measured beats inferred: Blastware's value is on
11 accepted writes, and writing back `01 7f` has never been tried.
- **The two bytes after the Series 3 block stay `00 00`**, as `write_image` sends
them (a unit accepted that in the April 2026 test). Blastware's per-unit
constant cannot be derived from anything SFM reads. The first bench write checks
that the unit takes the block, and its menu shows the change.
- **The `0x09` block is echoed as read**, as Blastware did on all nine April writes.
- **Numbers are bounded by what real units have been seen to hold**, and level
writes are refused unless the channel's unit string is the measured `in.`.
- **Notes are edited by slot under the unit's own labels**, four slots on each
series. Series 3 extended notes and Series 4's separate location field wait.
- **The legacy by-host write is retired**; the by-host form becomes read-only.
- **A live send needs a preview's revision.**
- **Preview re-reads the unit** rather than trusting the page's copy, and Send
refuses if the unit changed since the preview.
- **The edit form lives on the Config tab, by serial**, replacing the legacy
read-modify-write form for units reached by serial.
## Left to the builder
- The module layout for the shared codec, within the no-cycle, pure-codec rule.
- `run_change` generalised versus a sibling core.
- The exact revision hash.
- Page layout details.