READ_SUBS catalogues every read; a SUB in neither table is refused, and
allowed_writes may only name catalogued writes. Tables are MappingProxyType,
_send checks the exact bytes it writes, check_transmit documents precedence.
Tests cover unknown opcodes, concatenation smuggling and table immutability.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
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
tests/fixtures/ is gitignored, so these were never committed. Since phase 1b
the test fakes read them, so on a fresh clone every test that builds a fake
Micromate -- phase 1a's included -- failed with FileNotFoundError. Same
precedent as tests/fixtures/micromate-setup/: UM20147's own bench events.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
- Series4Session's docstring now states which errors keep the line: an
op raises a DeviceError only for a verdict on a healthy link (not
found, stale, unnameable), and _exchange keeps the line for those; any
library error means the link is suspect and hangs up. DecodeMismatch
is a library error and hangs up -- conservative. Later ops must keep
to it.
- Test: a micromate TimeoutError mid-download, on a fresh DeviceAccess
(no retry path), is NoAnswer, closes the client once and leaves no held
line. It pins existing behaviour; a mutation that keeps the line on
library errors makes it fail.
- README, event rows corrected in place: another unit's id is 422 (not
409); a stale id is 409 without downloading, both series; an event
already stored -- including by THOR's watcher -- returns its row and
changes nothing (detail.already_stored); MiniMate lists give
record_type null, on the normal timeout, and fail on a lost reply.
No code behaviour change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
minimateplus's _extract_record_type returns "Waveform" for every 0C
record layout -- it cannot tell a histogram -- so a MiniMate histogram
was listed as "waveform". The fake's "Histogram" was a value the real
client never produces, which is why no test saw it.
- _s3_ref: record_type is always None, with
detail.record_type_note = "Series 3's event record does not say
waveform or histogram; not decoded yet".
- default_s3_events(): both events "Waveform", as the real client gives.
- The shared-shape contract test allows exactly {"record_type"} to be
None for Series 3 and nothing for Series 4.
Rows SFM stores for Series 3 still carry "Waveform" from the decode (the
same as the legacy blastware_file route); parked in the spec. No codec,
store or DB change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
One lost 1F reply made the list return 1 of 3 events as a 200, and on a
download gave a false 404. The list also ran on the 120 s download
timeout, so each lost reply stalled the walk 120 s with the unit locked.
- get_events() strict mode (headers_only, or only_key): a lost 0A reply,
a lost 1F(browse) reply on the success path and on the partial-record
path all re-raise their ProtocolError; a 1F that hands back a key
already walked raises ProtocolError("event chain did not advance ...").
Legacy calls (none of the new options) behave exactly as before --
pinned by tests of the same three faults under get_events().
- Series3Adapter.list_events runs on the default timeout (10 s on TCP);
download_event keeps 120 s.
- FakeProto gains optional lost-reply injection; its default is unchanged.
The repeat-key guard sits at the loop head, which is reached only for a
non-null key -- equivalent to checking each 1F's key, in one place.
Read-only; nothing new on the wire. No codec, store or DB change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
Series3Adapter.download_event compared the timestamp only after
download_event_by_key had run the whole 5A. A stale id cost a full
download of the wrong event (minutes on cellular), could surface the
64 KB-page 502 instead of 409, and a lost 0C reply was reported as "the
unit was erased".
- get_events() gains only_key_timestamp: with only_key, if the target's 0C
says another time (or none), the target takes the existing bypass --
no 1F(arm), no POLL, no 5A. A new branch only; it adds no command.
- download_event_by_key(key4, *, expected_timestamp=None) passes it on.
- The adapter converts the id's stamp to that ISO form and checks, in
order: no event -> 404; no readable 0C timestamp -> 502 MalformedReply
("could not read ... record (0C)"); a different time -> 409 StaleEvent;
no frames -> 502.
- The fake's download mirrors the real walk (no frames on a mismatch) and
records what it was asked for.
- Legacy get_events() (none of the new options) is pinned by a test of
its exact call sequence and 5A arguments, written before the change.
Read-only; nothing new on the wire. No codec, store or DB change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
Without Thor's TXT report, save_imported_idf fills only the three PPVs.
The unit's 0x0C record -- already read for the list and the stale check --
also gives the peak vector sum and the sensor location, and they were
dropped: Terra-View showed a blank PVS, and find_twins (which matches on
PVS) could not link the event to its histogram twin.
persist_download now overlays DownloadedEvent.record onto the bridged
event before insert_events, filling only fields the file left empty
(creating PeakValues / ProjectInfo when absent). Not the mic: its 0x0C
decode reads a denormal, parked.
The sidecar is written by save_imported_idf before the overlay, so it
still has no vector sum; the DB row does. No schema change, no migration.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
THOR's watcher (and Blastware's ACH) store every event through
/db/import/idf_file and /db/import/blastware_file, with the paired report.
Storing a download of the same event afterwards overwrote that richer copy:
on Series 4 the file, .h5 and sidecar were rewritten (extensions dropped);
on Series 3 the row lost PVS, project strings and ZC frequencies and was
repointed at a second, review-less file set.
persist_download now looks up (serial, timestamp) first. A row there is
returned as it stands -- inserted false, detail.already_stored true -- with
no store call, no insert_events and no sidecar write. Never merge.
- DownloadedEvent gains `timestamp` (the unit's own event time) and
`record` (Series 4's 0x0C fields); both adapters set them.
- The Series-3 `event is None` guard now runs before backfill/save, with a
message that is true there ("nothing was stored").
- Tests build the watcher's state exactly as the import endpoints do and
prove the row dict, the sidecar bytes and the file mtimes are unchanged.
No schema change, no migration, no codec change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
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
list_event_headers() walks every event's 0A/1E/0C/1F without starting a 5A.
download_event_by_key() downloads one event in full and walks past the others
without their 5A, stopping once it has it. Both ride two new keyword options on
get_events() (headers_only, only_key); the default path is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
The /device guard let every non-UM serial through before its held-line
check. FastAPI drops an undeclared `serial`, so `?serial=BE18193` on a
legacy route still ran Series-3 code at an address holding a Series-4
line -- the hole the guard exists to close. Serial-aware routes go
straight to DeviceAccess, which refuses that case itself; everything
else is checked. baud is no longer parsed (it is not in the address
key, and pydantic's coercion made "38400.0" a second way past).
Also, from the same review:
- RingWatchTransport clears its frame state on every write, so a stray
STX on an idle line cannot hide the ring that answers the next request.
- Series4Session.is_open reads _client once; held_serial() calls it
without the unit lock, and a concurrent hang-up between two reads was
an AttributeError (a 500).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
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
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