diff --git a/CLAUDE.md b/CLAUDE.md index 131a49c..58a4cac 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -27,6 +27,14 @@ Read this first when picking the project back up. ⚠ **No command has ever been originated against a unit by this project.** Every write was performed by THOR while we recorded. That line is worth keeping. + **Series-4 write path, phase 2 is done (2026-10-22):** the write encoder, a + send-side opcode gate and write *plans* for start/stop, call-home enable and + the setup rewrite, reproduced byte for byte against THOR's captured frames. + `bridges/mm_dry_run.py` prints a write's planned frames from a live unit's + reads (run on UM20147: sizes equal UM12947's). `MicromateProtocol._send` + refuses every write opcode unless explicitly allowed, and `0xA2` always, so + "no command has ever been originated against a unit" is still true and is now + enforced in code. - **✅ `micromate/` HAS a live client (2026-10-02).** `framing.py`, `protocol.py`, `client.py` + models, **119 tests**, mirroring the `minimateplus/` stack and reusing its `transport.py` unchanged. Connect over diff --git a/bridges/mm_dry_run.py b/bridges/mm_dry_run.py new file mode 100644 index 0000000..d803b32 --- /dev/null +++ b/bridges/mm_dry_run.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +"""Dry run a Micromate write against a live unit: do the reads, print the plan. + +Sends READS only. The write frames are built from the unit's own blocks and +printed for review -- step 1 of the bench protocol for every first live write +(parity spec, Testing). The protocol's opcode gate refuses every write SUB on +this connection, so nothing else can go out even by mistake. + + sg dialout -c ".venv/bin/python bridges/mm_dry_run.py /dev/ttyACM0 call-home-off" + .venv/bin/python bridges/mm_dry_run.py --host 10.0.0.5 --tcp-port 9034 setup-rewrite + +The JSON carries a `reads` block (length of each block read, and for +setup-rewrite the blocks themselves in hex) so the plan can be checked against +what the unit actually said. +""" +from __future__ import annotations + +import argparse +import json +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + +from micromate.client import CONTENT, MicromateClient # noqa: E402 +from micromate.writes import ( # noqa: E402 + plan_call_home_enabled, plan_setup_push, plan_start_monitoring, plan_stop_monitoring, +) +from minimateplus.transport import SerialTransport, TcpTransport # noqa: E402 + +ACTIONS = ("start", "stop", "call-home-on", "call-home-off", "setup-rewrite") + + +def _content(data: bytes) -> bytes: + """The protocol's read_* methods return the response data with its 11-byte prefix.""" + return bytes(data)[CONTENT:] + + +def main() -> int: + ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + ap.add_argument("port", nargs="?", help="serial port, e.g. /dev/ttyACM0") + ap.add_argument("action", choices=ACTIONS) + ap.add_argument("--host") + ap.add_argument("--tcp-port", type=int, default=9034) + ap.add_argument("--baud", type=int, default=115200) + a = ap.parse_args() + if not (a.port or a.host): + ap.error("give a serial port or --host") + transport = TcpTransport(a.host, port=a.tcp_port) if a.host else SerialTransport(a.port, a.baud) + mm = MicromateClient(transport) # no allowed_writes: the gate refuses every write + mm.open() + try: + info = mm.connect() + p = mm.protocol + reads = {} + if a.action == "start": + plan = plan_start_monitoring() + elif a.action == "stop": + plan = plan_stop_monitoring() + elif a.action.startswith("call-home"): + ch = _content(p.read_call_home_config()) + reads["0x2C"] = {"len": len(ch)} + plan = plan_call_home_enabled(ch, a.action == "call-home-on") + else: + name = mm.get_active_setup() + prefs = _content(p.read_event_index()) + trig = _content(p.read_trigger_config()) + setup = _content(p.read_compliance_config()) + reads = {"active_setup": name, + "0x08": {"len": len(prefs), "hex": prefs.hex()}, + "0x2E": {"len": len(trig), "hex": trig.hex()}, + "0x1A": {"len": len(setup), "hex": setup.hex()}} + plan = plan_setup_push(prefs, trig, setup, name) + out = plan.describe() + out["unit"] = {"serial": info.serial, "firmware_line": info.firmware_line} + out["reads"] = reads + print(json.dumps(out, indent=1)) + finally: + mm.close() + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/docs/micromate_protocol_reference.md b/docs/micromate_protocol_reference.md index 6541355..3694f0e 100644 --- a/docs/micromate_protocol_reference.md +++ b/docs/micromate_protocol_reference.md @@ -1782,6 +1782,21 @@ Do **not** retune `_GEO_LSB_IPS` — this is corroboration, not a correction. - **Scheduler / call-home writes.** `callhome.MMB` is a file too, so it may go through the same `0xDA` + block-write shape with a different target name. +### Write-plan dry run on a second unit and firmware line (2026-10-22) + +2026-10-22 — UM20147 (11.0BD) block sizes equal UM12947's (11.0CB): `0x1A` +content 2092 B, `0x08` 90 B, `0x2E` 28 B, `0x2C` 126 B (all CRCs good where a +CRC applies). Its dry-run plans (`bridges/mm_dry_run.py`) have the same SUB +order, offsets and data lengths as THOR's frames from UM12947: `0x96` / `0x97` +(offset `0xFFFF`, 0 B); `0x7E` @ `0x007E` 126 B + `0x7F`; `0xDA` @ `0x0100` 256 B, +`0x68` @ `0x005A` 88 B, `0x73`, `0x82` @ `0x001C` 28 B, `0x83`, `0x71` @ `0x082C` +2090 B, `0x72`. So THOR's write offsets apply to both firmware lines **as far +as size goes** (measured, one unit each; **nothing sent** -- reads only, the +opcode gate refused every write SUB). Not shown: that 11.0BD *accepts* these +frames. The call-home on/off plans differ in exactly one data byte (`[5]`); +the setup-rewrite `0x71` data equals the unit's `0x1A` content `[3:2090]` behind +three zero bytes. + ### ✅ `0xDA` CREATES setup files (confirmed on the device, 2026-09-24) `TEST1.mmb` did not exist on the unit before the push. Afterwards it is