14 Commits
Author SHA1 Message Date
serversdownandClaude Opus 5.5 d0335dbbbd feat(micromate): read the schedule file (read-only)
MicromateProtocol.read_file: 0x94 + path, then 0x48 pages to an
all-zero reply -- THOR's frames byte for byte (UM12947, 2026-09-24),
including params[3] = 1 on 0x94 and params[7] = 1 on the first 0x48.
micromate.schedule parses the 260-byte records (two- and five-entry
schedules from THOR's captures) and names the scheduled starts that
would load a setup other than the active one, ignoring case.  The
client gains the raw (unstripped) active-setup name and the prefs /
trigger / setup content reads a setup push sends back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
2026-11-03 21:37:30 -05:00
serversdownandClaude Opus 5.5 eeb55effe9 feat(sfm): Series-4 call-home state and audited enable/disable (phase 4)
- micromate: ENABLEABLE_WRITES gains 0x7E/0x7F (the call-home write and its
  confirm; spec row 9, enable/disable only); MicromateClient.get_call_home_content()
  returns the 126-byte 0x2C content.
- sfm/device_access: CallHomeState (serial, series, enabled, dial_string, detail
  with byte5 and the whole block); s4_call_home_state reads bit 0 of [5] and the
  dial string at [6:46]; s4_change_call_home runs the shared change core with
  micromate.writes.plan_call_home_enabled -- built from the read run_change made
  just before, and that same plan is the one sent.  A unit calling home (run
  state 0x03) is refused, nothing sent.  The read-back judges the edited bit
  only; the snapshot records both blocks and every changed offset -- [118:120]
  is unit-maintained and always moves.
- The write-ceiling tests take 0x71 (the setup write, phase 5) as their
  over-the-ceiling example now that 0x7E is enableable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
2026-11-02 16:56:04 -05:00
serversdownandClaude Opus 5.5 8f68b09f5e fix(sfm): a change that fails after the send says so; the audit row records sent + states; S3 unknown states refused
Final fix wave for phase 3 (start/stop monitoring), per the whole-phase review.

- I1 + M2: every failure after the send has started is a ChangeUnconfirmed
  (audit_id, sent = "acknowledged" | "unknown", the cause's HTTP status) whose
  message says the frame was sent and names the audit record -- the ring in
  place of the ack, the four lost-ack follow-ups, and the three read-back
  paths.  Series4Session releases the line on it.  Every audit finish goes
  through one helper; a finish that fails is AuditIncomplete (500) and still
  says what happened to the unit.  The line is kept.
- I2: device_commands gains `sent` (1 acknowledged, 0 nothing sent, NULL
  unknown) and `states` (before / seen / after), with an idempotent ADD COLUMN
  in _migrate for a table created earlier on this branch.
- M1: a RADIO RING already buffered is caught before 0x96/0x97 goes out
  (pre_send = read_unsolicited, one 10 ms transport read).  That is a
  CallHomeInProgress with sent=0, not ChangeUnconfirmed.
- M3: Series 3 reads the raw 0x1C flag (new MonitorStatus.state_flag); a byte
  other than 0x00/0x10, or a short section, is unknown(...) and refused.
- M8: even_if_already on a unit already in the state notes that the read-back
  proves nothing.
- M10: a scan pins `.protocol.execute(` to sfm/device_access/s4.py; both
  scans fail closed on a file that does not parse.
- M11: docs corrected (CLAUDE.md phase-2 sentence, phase-3 bullet, REST list;
  micromate/protocol.py scope and the 0x49 read_state docstring; s4.py; route
  docstrings).  "No command has ever been originated" is NOT retracted.
- M12: GET /db/device_commands normalises the serial.
- Minors: unused imports, S3 dry-run frames and 120 s timeout pinned, test
  rename, serial-cache and short-0x49 tests, _RUN_STATES comment.

Schema: two NULLable columns on the branch-new device_commands table, added
by _migrate on open; no backfill.  No codec change, TOOL_VERSION unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
2026-10-23 19:16:45 -04:00
serversdownandClaude Haiku 5.5 7ff527df07 feat(micromate): read the unit's run state and refresh its serial on demand
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
2026-10-23 16:20:12 -04:00
serversdownandClaude Opus 5.5 a3e4e85dfd feat(micromate): one opcode table and a send-side gate -- writes refused unless allowed, 0xA2 always
micromate/opcodes.py holds WRITE_SUBS and the cross-series collision 0xA2.
MicromateProtocol._send reads the SUB of the bytes about to go out
(framing.request_sub) and refuses any write SUB not in allowed_writes, and
0xA2 unconditionally.  Docstrings now say the reads-only policy is enforced.

request_sub also refuses any frame not in canonical form
(stuff(unstuff(body)) == body): an interior unescaped 02/03/04, a 10 XX
outside {02,03,04,10}, or a trailing lone DLE.  What the gate checks is then
exactly what the unit parses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
2026-10-22 17:10:23 -04:00
serversdownandClaude Opus 5.5 83d1a98c1c feat(micromate): fetch_event returns the bytes with the checked decode
get_event() now delegates to fetch_event(), which returns (blob, result).
The same peak-vector-sum self-check applies, so a DecodeMismatch still stops
the bytes from being stored. get_event() keeps its signature and behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
2026-10-21 16:52:43 -04:00
serversdownandClaude Opus 5.5 fa032567c2 feat(micromate): get_event_count() and read_unsolicited()
0x06 content[0:4] moves from the bench tool into the client, tested against a real UM20147 read and its chain-walk count.  read_unsolicited() reads without sending, for spotting RADIO RING on an idle session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
2026-10-21 01:04:35 -04:00
serversdownandClaude Opus 5.5 31181f64e6 fix(micromate): is_open() called a property -- TypeError on every real transport
Hidden because the test double defined is_connected as a method; it is now a property, matching BaseTransport.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
2026-10-21 01:02:32 -04:00
serversdownandClaude Opus 5.5 b3aff4ed66 feat(micromate): get_setup() -- the setup block decoded, checksum-verified, and read off a real unit
MicromateClient.get_setup() reads SUB 0x1A once and returns a MicromateSetup:
record mode, sample rate, histogram interval, pre-trigger, stop mode, record
time, auto-stop, active sensors, trigger sources, the three geophone trigger
levels, mic type and (linear) mic trigger, job number, scaled distance, and
the four notes.  MEASURED FIELDS ONLY -- everything graded inferred or
unknown in the reference stays in .raw.

micromate/setup_block.py holds the decode as pure functions (no I/O), plus
crc_ok(): one checksum rule for 0x1A, 0x08 and 0x2E.  A failed checksum
raises SetupChecksumError (a ProtocolError) unless verify=False; a short
block raises either way.

Two things the decoder gets right that a naive one would not:
- the mic comes from channel block 4 (the ACTIVE mic), never blocks 5/6,
  which hold the stored settings of whichever mic is NOT fitted;
- distance and charge weight convert back with the unit's own 3.2808 and
  2.21, so 45 lb entered on the unit reads 45.0, not 44.89.

TESTS: 69 new.  15 real fixtures (2,103 B each) -- 14 UM20147 reads from the
10-17/10-19 keypad passes, chosen so every field takes at least two values,
plus UM12947's read from Thor's 9-24 capture (other firmware line).
Expected values are what the operator read off the unit's screen, never the
decoder's own output.  Fixtures force-added, per the tests/fixtures/
convention.  Full suite 541 passed; the 16 pre-existing failures
(test_bw_ascii_report.py 15, test_event_file_io.py 1) are unchanged.

VERIFIED ON HARDWARE: bridges/mm_client_check.py now prints the decoded
setup; against UM20147 every line matched the unit's screen (Brian, 10-19).

Also: the scratch harness uses the library checksum and checks all three
blocks; mm_client_check's stale labels fixed (0x06 content[4:8] is the
likely monitor-log count, not "unexplained"; 11.0BD is no longer "the first
one this code has met").

No codec, store or DB change; no backfill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
2026-10-19 18:20:25 -04:00
serversdownandClaude Opus 5 711277131a feat(micromate): a config diff harness -- and the blocks turn out to be bit-stable
The Series III config map was built by changing one setting and seeing which
bytes moved.  Whether that method transfers to Series IV depended on an
unmeasured question: how much of a config block moves ON ITS OWN.  If a block
carries a clock or a counter, every diff arrives polluted and there is no way to
tell the real answer from the noise in a single pair.

MEASURED ON UM20147 (11.0BD), FOUR READS BACK TO BACK, NOTHING TOUCHED:

  0x1A compliance    2103 B    0 bytes moved
  0x2C call home      137 B    0
  0x2E trigger         39 B    0
  0x08 event index    101 B    0
  0x01 device info    163 B    0
  0x1C monitor status  59 B    2  (and those two are explained below)

Every config block held every byte still, so the method transfers directly and
needs no noise floor subtracted.  That was the open question.

scratch/mm_config_diff.py drives it: `volatile` establishes the floor, `snap`
saves a labelled read of all five blocks, `diff` reports changed runs with each
plausible field interpretation (u8/u16be/u32be/f32be) and reports any volatile
bytes separately rather than silently hiding them.

CORRECTION TO content[6] OF 0x1C, long recorded only as "NOT the hour": it is a
sub-second tick, ~4020 counts/second in steps of exactly 4, wrapping at 256 --
about a 64 ms period, consistent with the low 6 bits of a millisecond counter.
Consequence worth knowing: a 0x1C block is never byte-identical to itself, so
any "has the status block changed?" check answers yes ~15 times a second.
Compare named fields, never whole blocks.

I nearly recorded that byte wrong, and the trap is cheap enough to document:
sampled once per second it reads as a smooth monotonic counter at ~16/s with a
16-second wrap.  Twelve consecutive samples supported it.  It is aliasing -- a
64 ms counter read once a second is noise that happens to look tidy.  Measure a
counter back to back before trusting any rate from spaced samples.

Also: the settings do not have to be changed from THOR.  The unit's own keypad
works, which needs no Windows VM and does not contend for the modem's single
TCP session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
2026-10-15 12:28:40 -04:00
serversdownandClaude Opus 5 423608ccd1 perf(micromate): 16 KB per request, not 1024 -- 14x fewer round trips
The chunk-size ceiling, measured on UM20147 with every size checked
byte-for-byte against a known-good download:

  1024 / 2048 / 4096 / 8192 / 16384  ->  served in full
  32768 / 65535                      ->  SILENTLY CLAMPED to 16384

The clamp is the important part: a 32,768 B request returns 16,384 B of perfectly
good data and no error.  Nothing in the response says it was truncated; the
length is the only signal.

THAT DICTATES HOW THE LOOP MUST BE WRITTEN.  read_event_file() now tracks its
offset by BYTES RECEIVED rather than striding by chunk index.  A fixed stride
would either fail on a clamp or skip the bytes it never collected; tracking what
actually arrived makes a clamp cost one extra request, and makes the loop
self-correcting against any short response -- precisely the failure mode that has
bitten the Series III side repeatedly.

Consequence of that change, recorded because it reverses an earlier decision: a
short chunk is NO LONGER AN ERROR.  It used to raise, on the principle that a
silently short event is this codebase's recurring bug.  But the device returns
short legitimately, and the real protection is the offset arithmetic plus the
final total-length check -- which still raises on a genuinely truncated event.
The test was rewritten rather than deleted, and says why.

CHUNK_SIZE = 16384.  For UM20147's events: 4,796 B goes 5 requests -> 1,
30,230 B goes 30 -> 2, and 72,560 B goes 71 -> 5.  Over cellular at ~0.65 s per
round trip that is ~46 s -> ~3.2 s on the large one.

Measured on one unit over USB, so THOR_CHUNK_SIZE = 1024 stays available and the
replay tests pin it -- reproducing THOR's exact traffic is one argument away, and
client.download_event()/get_event() take chunk_size for a link where large
responses are not surviving.

Full suite: 472 passed, 16 pre-existing failures unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
2026-10-02 14:14:02 -04:00
serversdownandClaude Opus 5 d7d72cadf8 feat(micromate): the event chain -- walk, records, download, and a self-check
Step 4 of docs/micromate_client_spec.md.  MicromateEventRef plus list_events(),
iter_events(), download_event(), get_event() and decode_error().  14 new tests;
112 micromate tests total.

The load-bearing test replays THOR's captured six-event download session through
iter_events() + get_event() and asserts EVERY BYTE WE EMIT MATCHES THOR'S, in
order -- 74 frames -- while decoding all six events and cross-checking each
waveform's peak vector sum against the float the device computed itself.

Two design decisions worth recording:

1. iter_events() EXISTS BECAUSE THOR INTERLEAVES.  Its captured order is
   0x93 -> 1E -> 0C -> 5A*n -> 0x93 -> 1F -> 0C -> 5A*n, downloading each event
   before advancing the chain.  list_events() walks to the end first, which is
   fine for browsing but leaves the device cursor parked past the event a later
   download addresses.  0x5A is key-addressed so it very probably does not care
   -- but nothing observed says either way, so the interleaved path is the one
   offered for downloads, and it is the one the replay test exercises.

2. get_event(verify=True) RECOMPUTES THE PEAK VECTOR SUM from the decoded
   samples and compares it against the device's own 0x0C float.  Two independent
   computations over the same samples, so a disagreement means our decode is
   wrong.  Agreement on the bench events is 0.000%.  Cheap insurance in a
   codebase whose decode failures have historically been silent -- unhandled
   block tags shorten a channel and nothing raises.  It is a decode-correctness
   check, NOT a truncation detector: a channel cut after its peak still yields
   the right PVS, and the docstring says so.  A test corrupts a stored peak to
   prove the check actually fires.

MicromateEventRef.uid is SERIAL:key, because the key alone is ambiguous across
units, and .filename generates THOR's name (<serial>_<YYYYMMDDHHMMSS>.IDFW/H)
-- returning None rather than guessing when the record type is unknown, since
read_idf_file() dispatches on exactly that suffix.

Recorded as a CANDIDATE, not used: 0x06 content[0:4] looks like the EVENT COUNT
-- 6 on a unit holding 6 events, zeros on an empty one, and THOR reads it BEFORE
the walk then downloads exactly six events without ever reading the chain
sentinel.  If it holds it lets a caller decide whether to walk at all, which
over cellular is the useful part.  Two samples on one unit, and content[4:8]
reads 9 unexplained, so list_events() still walks to the sentinel: slower by one
round trip and correct on evidence rather than inference.

Full suite: 465 passed, 16 pre-existing failures unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
2026-09-30 18:29:32 -04:00
serversdownandClaude Opus 5 b55e4e946a verify(micromate): 11.0BD confirmed on hardware -- every inference held
UM20147 read over USB by mm_client_check.py.  The Thor firmware line was
entirely inference until now, and two of its three differences were covered
only by SYNTHESISED test frames.  All three held:

- flags = 0x03 identifies the line -> reported firmware_line="thor".  That is
  only reachable if `10 03` in the flags position destuffs before indexing,
  since 0x03 is ETX -- so the escaped-flags case is confirmed too.
- the model string is shorter -> reported "MM/ISEE/S" exactly.  Anchoring the
  search on b"MM/" rather than a fixed span is what made this work.
- the 0x1C block is 4 bytes longer with the extras TRAILING, so from-the-start
  offsets survive -> battery 3.55 V and a clock correct to the second.

That last one is the one that mattered.  Series III's from-the-end offsets
would have given this unit 577.92 V, which is why mm_client_check watches for
an impossible voltage: it is a free self-check on exactly the inference most
likely to be wrong.

Also clean: serial UM20147, 5 setups (factory.MMB -> test2.mmb), active setup
test2.mmb, 15,000,000 B total and free, 21 reads / 2,165 B in.

"One protocol stack drives the whole fleet regardless of firmware line" -- the
headline finding of 2026-09-23 -- is now demonstrated by a working client
rather than by matching response SUBs.

Test and docstring claims downgraded from inference to confirmed where the
hardware settled them, and left as synthesised-frame notes where it did not:
the BEHAVIOUR is confirmed but raw BD bytes are still not in the repo.

Added --capture DIR to mm_client_check: writes a raw_bw_*/raw_s3_* pair in the
layout scratch/mm_frame_parse.py already reads, so a run on an unfamiliar unit
becomes a test fixture without setting up a relay.  Verified by round-tripping
its own output through that parser: 28 frames, 0 bad checksums.

Still not covered: a download from a BD unit (UM20147 had no events stored, so
the chunk walk remains CB-only), raw BD fixture bytes, a monitoring unit, a
nearly-full buffer, and the inbound call-home session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
2026-09-30 13:17:53 -04:00
serversdownandClaude Opus 5 f09b7dcaaf feat(micromate): client layer -- connect, state, setups; read-only
Step 3 of docs/micromate_client_spec.md: micromate/client.py, two models in
micromate/models.py, 26 offline tests.  Every response constant in the tests
is a real captured data section from UM12947.

Field offsets were measured rather than taken from the spec, which turned up
one general rule and one trap:

THE RESPONSE SHAPE.  Every response carries an 11-byte prefix and content
starts at data[11].  One rule, every command.

THE TRAP: data[0] is the content length & 0xFF, with no high byte anywhere in
the prefix.  It is therefore correct for every response under 256 bytes --
most of them -- and then reports 44 for a 2,092-byte setup block, 30 for a
286-byte monitor-log record, and 0 for a 1,024-byte download chunk.  182 of
251 captured responses agree with a naive read; the 69 that disagree are
exactly the ones >= 256 bytes.

That is the third length in this protocol read too narrow, after
payload[9]-vs-payload[8:10] in the probe response.  The client takes content
as data[11:] and lets the frame's own length bound it -- nothing needs the
declared length, since the frame already knows how long it is.

Also measured:

- POLL content[3] is 0x50, printable as "P", immediately before "Instantel".
  A generic printable-run scan therefore returns "PInstantel" -- it caught a
  test, not a unit.  Vendor comes from a fixed offset; the model is found by
  searching for "MM/", which is structural rather than positional and so
  survives the Thor line's shorter "MM/ISEE/S".
- The setup walk terminates on an EMPTY NAME, not an error: 23 responses, 22
  names, factory.MMB first through TEST1.mmb last.
- The 0x1C clock has an unidentified byte at content[6]; the hour is at
  content[7].  The protocol reference's 0x1C section already had this right
  and names the byte -- its one-line summary in the divergences list reads as
  six contiguous fields and is the version not to trust.  Re-verified against
  three captures: 19:12:25, 19:13:34 and 01:14:05 against filenames stamped
  19:12:14, 19:12:14 and 01:14:03.
- Battery and memory are read FORWARD from content start, never backward from
  the end.  This block is 4 bytes longer on the Thor line; the Series III
  from-the-end offsets give a 11.0BD unit 577.92 V.  A test appends the four
  trailing bytes and asserts the forward offsets survive.

connect() is narrower than the spec asked.  The spec said to mirror Thor's
POLL -> SERIAL -> 0x49 -> POLL "because it is known-good"; measurement showed
that is Thor's connection check (3 of 8 sessions) and its fourth frame repeats
its first.  So connect() sends the three reads that gather something, and
0x01 is not read at all -- Thor never reads it, its layout is unmapped, and
firmware_line comes free from any response's flags byte.  If a unit ever
refuses the next command after a cold connect, put the fourth POLL back and
record it.

A dead clock battery yields device_time=None rather than failing the whole
state read; an unreadable active setup yields active_setup=None rather than
failing connect.  Both are real device states.

Still verified only against 11.0CB and only over USB.  The BD offsets follow
from the extra bytes being trailing, which is documented but not something
this code has seen.

Full suite unchanged at 16 pre-existing failures; 445 passed, up 26.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru8Lg9HkkYvX9VWWo65SmL
2026-09-28 20:25:40 -04:00