fix(settings): final-review fixes -- revision, resulting limits, logical writes
From the whole-branch review of phase 5: - The preview's revision now covers the changes asked for, so a live change must be exactly what was previewed (any API caller, not only the page). It covers what the preview showed -- the settings block (and a Micromate's setup name) -- not the blocks a write only echoes, which are re-read at send and sent as read (a MiniMate's trigger block byte 5 differs by session, #46). - The units' limits hold on the block that would result: a range, rate or mode change alone can no longer leave a held trigger, alarm or record time over them. - Every MiniMate block read is logical, so push_config_raw no longer unescapes again (a job number of 4098, 10 02, was refused at Send); the preview runs the write's own block check, so a block it would refuse is shown as blocked. - A MiniMate's monitoring refusal says a stop makes it call in (spec). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
385716d8e1
commit
08d0a6c0d4
9 files changed
+209
-43
No files matched your search
+11
-5
@@ -915,6 +915,8 @@ class MiniMateClient:
|
||||
compliance_data: bytes,
|
||||
trigger_data: bytes,
|
||||
waveform_data: bytes,
|
||||
*,
|
||||
escaped: bool = False,
|
||||
) -> None:
|
||||
"""
|
||||
Push a complete config update to the device using the confirmed write
|
||||
@@ -942,6 +944,10 @@ class MiniMateClient:
|
||||
trigger_data: Raw bytes for SUB 82 write (44-byte trigger config).
|
||||
waveform_data: Raw bytes for SUB 69 write.
|
||||
|
||||
`escaped`: False (the default) -- the blocks are logical, as every block
|
||||
read returns them since phase 5; True for blocks that still hold the
|
||||
parser's kept escape bytes.
|
||||
|
||||
Raises:
|
||||
RuntimeError: if the client is not connected.
|
||||
ProtocolError: if any write step fails (timeout, bad ack SUB).
|
||||
@@ -960,29 +966,29 @@ class MiniMateClient:
|
||||
(SUB_TRIGGER_CONFIG_WRITE, trigger_data),
|
||||
(SUB_WAVEFORM_DATA_WRITE, waveform_data)):
|
||||
try:
|
||||
write_image(sub, data)
|
||||
write_image(sub, data, escaped=escaped)
|
||||
except ValueError as exc: # refused before any frame: the caller audits "nothing sent"
|
||||
raise ImageRefused(str(exc)) from exc
|
||||
|
||||
# 68 → 73
|
||||
log.info("push_config_raw: write event index (SUB 68)")
|
||||
proto.write_event_index(event_index_data)
|
||||
proto.write_event_index(event_index_data, escaped=escaped)
|
||||
log.info("push_config_raw: confirm B (SUB 73)")
|
||||
proto.write_confirm(SUB_WRITE_CONFIRM_B)
|
||||
|
||||
# 71×3 → 72 (handled internally by write_compliance_config_raw)
|
||||
log.info("push_config_raw: write compliance config (SUB 71 ×3 + confirm 72)")
|
||||
proto.write_compliance_config_raw(compliance_data)
|
||||
proto.write_compliance_config_raw(compliance_data, escaped=escaped)
|
||||
|
||||
# 82 → 83
|
||||
log.info("push_config_raw: write trigger config (SUB 82)")
|
||||
proto.write_trigger_config(trigger_data)
|
||||
proto.write_trigger_config(trigger_data, escaped=escaped)
|
||||
log.info("push_config_raw: trigger confirm (SUB 83)")
|
||||
proto.write_confirm(SUB_TRIGGER_CONFIRM)
|
||||
|
||||
# 69 → 74 → 72
|
||||
log.info("push_config_raw: write waveform data (SUB 69)")
|
||||
proto.write_waveform_data(waveform_data)
|
||||
proto.write_waveform_data(waveform_data, escaped=escaped)
|
||||
log.info("push_config_raw: confirm C (SUB 74)")
|
||||
proto.write_confirm(SUB_WRITE_CONFIRM_C)
|
||||
log.info("push_config_raw: confirm A (SUB 72)")
|
||||
|
||||
+18
-12
@@ -142,9 +142,14 @@ _WRITE_TAIL = {SUB_EVENT_INDEX_WRITE: b"\x02\x00", SUB_TRIGGER_CONFIG_WRITE: b"\
|
||||
SUB_CALL_HOME_WRITE: b"\x00\x00"}
|
||||
|
||||
|
||||
def write_image(sub: int, data: bytes) -> bytes:
|
||||
def write_image(sub: int, data: bytes, *, escaped: bool = True) -> bytes:
|
||||
"""The whole block a write sends: `data` unescaped, N + 2 bytes.
|
||||
|
||||
`escaped=False`: `data` is already logical (every block read since phase 5 --
|
||||
read_event_index, read_compliance_content, read_trigger_config,
|
||||
read_waveform_data_raw -- returns unescaped bytes), so it is NOT unescaped
|
||||
again: a logical `10 02` (job number 4098) would otherwise collapse.
|
||||
|
||||
A config block starts with its own length N (uint16 BE) and is written as N
|
||||
bytes plus two -- on every Blastware write on record. `data` may be the
|
||||
block as a read returned it (N bytes, or N + 2) and may still hold the
|
||||
@@ -152,7 +157,7 @@ def write_image(sub: int, data: bytes) -> bytes:
|
||||
Anything else is refused before a byte is sent: a block one byte longer than
|
||||
its header says is what an edit beside a kept escape byte leaves behind.
|
||||
"""
|
||||
image = unescape_reply(bytes(data))
|
||||
image = unescape_reply(bytes(data)) if escaped else bytes(data)
|
||||
if len(image) < 2:
|
||||
raise ValueError(f"write SUB 0x{sub:02X}: {len(image)} bytes is not a whole block")
|
||||
n = int.from_bytes(image[:2], "big")
|
||||
@@ -1132,25 +1137,26 @@ class MiniMateProtocol:
|
||||
self._send(frame)
|
||||
return self.recv_write_ack(expected_sub=rsp_sub)
|
||||
|
||||
def _write_block(self, sub: int, data: bytes, params: bytes = bytes(10)) -> S3Frame:
|
||||
def _write_block(self, sub: int, data: bytes, params: bytes = bytes(10), *,
|
||||
escaped: bool = True) -> S3Frame:
|
||||
"""Send one config block as a write and return its ack (0xFF - sub)."""
|
||||
image = write_image(sub, data)
|
||||
image = write_image(sub, data, escaped=escaped)
|
||||
frame = build_bw_write_frame(sub, image, params=params)
|
||||
log.debug("write SUB=0x%02X: %d-byte image", sub, len(image))
|
||||
self._send(frame)
|
||||
return self.recv_write_ack(expected_sub=_expected_rsp_sub(sub))
|
||||
|
||||
def write_event_index(self, data: bytes) -> S3Frame:
|
||||
def write_event_index(self, data: bytes, *, escaped: bool = True) -> S3Frame:
|
||||
"""SUB 68: write the event-index block (as SUB 08 read it). Ack 0x97;
|
||||
callers follow with write_confirm(SUB_WRITE_CONFIRM_B). See write_image."""
|
||||
return self._write_block(SUB_EVENT_INDEX_WRITE, data)
|
||||
return self._write_block(SUB_EVENT_INDEX_WRITE, data, escaped=escaped)
|
||||
|
||||
def write_waveform_data(self, data: bytes) -> S3Frame:
|
||||
def write_waveform_data(self, data: bytes, *, escaped: bool = True) -> S3Frame:
|
||||
"""SUB 69: write the waveform-data block (as SUB 09 read it). Ack 0x96;
|
||||
callers follow with write_confirm C then A. See write_image."""
|
||||
return self._write_block(SUB_WAVEFORM_DATA_WRITE, data)
|
||||
return self._write_block(SUB_WAVEFORM_DATA_WRITE, data, escaped=escaped)
|
||||
|
||||
def write_compliance_config_raw(self, data: bytes) -> None:
|
||||
def write_compliance_config_raw(self, data: bytes, *, escaped: bool = True) -> None:
|
||||
"""SUB 71: write the compliance image in addressed chunks, then confirm (72).
|
||||
|
||||
Measured: the image is 2,092 bytes (its header N = 2,090, plus 2), sent as
|
||||
@@ -1161,7 +1167,7 @@ class MiniMateProtocol:
|
||||
both. (Retracted: "exactly 3 chunks, offset 0x1004, params 00 00 00 10 04"
|
||||
-- the length 0x0400 and address 0x0400, read with their escape bytes.)
|
||||
"""
|
||||
image = write_image(SUB_COMPLIANCE_WRITE, data)
|
||||
image = write_image(SUB_COMPLIANCE_WRITE, data, escaped=escaped)
|
||||
rsp_sub = _expected_rsp_sub(SUB_COMPLIANCE_WRITE)
|
||||
for addr in range(0, len(image), _COMPLIANCE_CHUNK):
|
||||
params = bytes([0x00, 0x00, (addr >> 8) & 0xFF, addr & 0xFF]) + bytes(6)
|
||||
@@ -1172,10 +1178,10 @@ class MiniMateProtocol:
|
||||
self.recv_write_ack(expected_sub=rsp_sub)
|
||||
self.write_confirm(SUB_WRITE_CONFIRM_A)
|
||||
|
||||
def write_trigger_config(self, data: bytes) -> S3Frame:
|
||||
def write_trigger_config(self, data: bytes, *, escaped: bool = True) -> S3Frame:
|
||||
"""SUB 82: write the trigger block (as SUB 0x2E read it). Ack 0x7D;
|
||||
callers follow with write_confirm(SUB_TRIGGER_CONFIRM). See write_image."""
|
||||
return self._write_block(SUB_TRIGGER_CONFIG_WRITE, data)
|
||||
return self._write_block(SUB_TRIGGER_CONFIG_WRITE, data, escaped=escaped)
|
||||
|
||||
def read_trigger_config(self) -> bytes:
|
||||
"""SUB 0x2E two-step read: the 26-byte trigger block that SUB 82 writes.
|
||||
|
||||
Reference in new issue
Block a user