verify(micromate): read client works on real hardware, both transports

Run against UM12947 by bridges/mm_client_check.py, read-only, over the USB-B
CDC-ACM port and over the RX55 to TCP :9034.

THE WIRE BYTES ARE IDENTICAL ON BOTH PATHS -- 11,580 B in and 761 B out, to
the byte, with matching identity, state and a 24-entry setup walk.  The
protocol does not care which physical layer it runs over, which is the thing
the modem path needed to prove.

Three findings, one of them a correction to my own prediction:

1. THE MODEM NEEDS FEWER READS, NOT MORE.  36 against USB's 83.  The tool's
   banner claimed the opposite.  The modem coalesces -- it buffers ~1 s then
   forwards one large TCP segment, where CDC-ACM delivers many small chunks.
   That is reassuring rather than alarming: the risk was a frame arriving
   split across reads, and the modem splits LESS than USB does.  Banner fixed
   to state the measured numbers instead of a guess.

2. ~0.65 s PER ROUND TRIP over cellular, independent of payload size.  A
   1,024 B chunk and a 16 B state read cost the same.  list_setups() takes
   16.05 s over the modem against 0.46 s over USB, for 24 commands.

   This is the number that matters for SFM's design: over cellular, minimise
   round trips, not bytes.  Enumerating setups costs 16 s -- cache it, never
   refresh it on a timer.  A 13 KB event is 14 chunks ~ 8.4 s of latency
   against ~0.03 s of data, which makes the unconfirmed single-request 0x5A
   streaming mode worth its two-minute bench test on its own.

3. THERE IS A RECORD-TYPE FIELD: 0x0C content[11], 0x07 waveform, 0x08
   histogram.  The reference says no type field is known and that the type
   must be carried out of the chain walk.  Found by diffing the six bench
   events' 0x0C records against their known types -- exactly one byte
   separates the groups and is constant within each -- then confirmed by
   predicting the right suffix for 6 of 6 on a blind re-run.

   Six events split 4/2 is thin evidence for a byte that could be a counter or
   a channel count, so it is recorded as a strong candidate, not settled, and
   mm_client_check keeps a fallback: it tries the other suffix on failure and
   says when the guess was wrong.

   Also flagged: the reference's claim that the type comes from SUB 0x0A's
   length is not visible in the download capture, where 0x0A is a standalone
   monitor-log walk after the last chain entry, not a per-event probe.

END TO END: all six bench events assembled by read_event_file() from captured
0x5A responses decode with the existing codec -- 4 waveforms at 12,288 /
12,288 / 12,288 / 8,192 samples and 2 histograms.  No new codec work needed;
/db/import/idf_file ingests a directly downloaded event unchanged.

Not covered: 11.0BD (still pure inference), 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
This commit is contained in:
2026-09-29 14:13:36 -04:00
co-authored by Claude Opus 5
parent f7d9a1d9cb
commit 0d6eb1621f
2 changed files with 177 additions and 18 deletions
+68 -18
View File
@@ -154,6 +154,60 @@ class _Timed:
return chunk
# ⚠ HYPOTHESIS, 6 events. content[11] of the 0x0C record separated 4 waveforms
# from 2 histograms cleanly and was constant within each group. A 4/2 split is
# thin evidence for a byte that could be anything, so _decode() below does NOT
# trust it -- it tries the other suffix on failure and says when the guess was
# wrong. The protocol reference states no type field is known; this may be it.
_TYPE_BYTE = 11
_TYPES = {0x07: ".IDFW", 0x08: ".IDFH"}
def _event_type(record: bytes) -> str:
if len(record) <= _TYPE_BYTE:
return "?"
b = record[_TYPE_BYTE]
return {0x07: "waveform", 0x08: "histogram"}.get(b, f"unknown(0x{b:02x})")
def _decode(blob: bytes, key: bytes, record: bytes) -> None:
"""Decode the downloaded bytes, proving they are a real event file.
read_idf_file() picks waveform vs histogram from the FILENAME SUFFIX, and a
wire download has no filename -- so the suffix has to come from somewhere.
This tries the 0x0C type byte first and the other suffix second; getting a
decode either way proves the chunk assembly, and which one worked is itself
the finding.
"""
import tempfile
from micromate.idf_file import read_idf_file
guess = _TYPES.get(record[_TYPE_BYTE] if len(record) > _TYPE_BYTE else -1, ".IDFW")
order = [guess] + [e for e in (".IDFW", ".IDFH") if e != guess]
for n, ext in enumerate(order):
with tempfile.NamedTemporaryFile(suffix=ext, delete=False) as f:
f.write(blob)
tmp = f.name
try:
res = read_idf_file(tmp)
samples = sum(len(v) for v in getattr(res, "samples", {}).values())
note = "" if n == 0 else f" *** the 0x0C type byte guessed {guess} — WRONG ***"
print(f" decoded OK as {ext}: {samples} samples{note}")
os.unlink(tmp)
return
except Exception as e:
last = f"{ext}: {type(e).__name__}: {e}"
finally:
if os.path.exists(tmp):
os.unlink(tmp)
print(f" decode failed BOTH ways — last: {last}")
out = Path(f"./{key.hex()}.bin")
out.write_bytes(blob)
print(f" saved to {out} for offline analysis")
def step(label: str, fn):
"""Run one read, report how long it took and what it returned."""
t0 = time.monotonic()
@@ -241,27 +295,16 @@ def main() -> int:
if not size:
print(" no events stored")
else:
print(f" first event key={key.hex()} size={size} B")
rec = _content(proto.read_event_record(key))
print(f" first event key={key.hex()} size={size} B "
f"type={_event_type(rec)}")
t1 = time.monotonic()
blob = proto.read_event_file(key, size)
dt = time.monotonic() - t1
print(f" downloaded {len(blob)} B in {dt:.1f} s "
f"({len(blob)/dt/1024:.1f} KiB/s)")
assert len(blob) == size
# Decode it with the existing codec to prove the bytes are real.
try:
from micromate.idf_file import read_idf_file
import tempfile
with tempfile.NamedTemporaryFile(suffix=".IDFW", delete=False) as f:
f.write(blob)
tmp = f.name
ev = read_idf_file(tmp)
print(f" decoded OK: {ev}")
except Exception as e:
print(f" decode failed: {type(e).__name__}: {e}")
out = Path(f"./{key.hex()}.IDFW")
out.write_bytes(blob)
print(f" saved to {out} for offline analysis")
_decode(blob, key, rec)
except ProtocolError as e:
print(f"\n ABORTED {type(e).__name__}: {e}")
@@ -269,10 +312,17 @@ def main() -> int:
finally:
mm.close()
elapsed = time.monotonic() - t0
print(f"\n transport: {transport.reads} reads, "
f"{transport.bytes_in} B in, {transport.bytes_out} B out")
print(" A modem path should show MORE reads for the same bytes than USB —")
print(" that is the buffering, and it is exactly what needed proving.\n")
f"{transport.bytes_in} B in, {transport.bytes_out} B out, "
f"{elapsed:.1f} s total")
print(" Measured 2026-09-29, UM12947, same unit both ways:")
print(" USB-B (CDC-ACM) 83 reads list_setups 0.46 s download 394 KiB/s")
print(" RX55 (TCP) 36 reads list_setups 16.05 s download 1.6 KiB/s")
print(" The modem needs FEWER reads, not more -- it buffers ~1 s and then")
print(" forwards one large segment, where CDC-ACM delivers many small ones.")
print(" Cost is ~0.65 s PER ROUND TRIP regardless of payload size, so what")
print(" matters over cellular is the number of commands, not the bytes.\n")
return 0