Release v0.34.0 — Series-4 parity, and most of Blastware's report from the event file alone #59
No files matched your search
+17
-3
@@ -54,10 +54,12 @@ class WriteStep:
|
||||
class WritePlan:
|
||||
action: str
|
||||
steps: Tuple[WriteStep, ...]
|
||||
warnings: Tuple[str, ...] = ()
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
# Copy: a caller's list must not be able to add a step after validation.
|
||||
object.__setattr__(self, "steps", tuple(self.steps))
|
||||
object.__setattr__(self, "warnings", tuple(self.warnings))
|
||||
for s in self.steps:
|
||||
if s.sub in CROSS_SERIES_COLLISIONS:
|
||||
raise OpcodeRefused(
|
||||
@@ -74,6 +76,7 @@ class WritePlan:
|
||||
|
||||
def describe(self) -> dict:
|
||||
return {"action": self.action, "sends_nothing": True,
|
||||
"warnings": list(self.warnings),
|
||||
"steps": [s.describe() for s in self.steps]}
|
||||
|
||||
|
||||
@@ -88,8 +91,11 @@ def plan_stop_monitoring() -> WritePlan:
|
||||
def plan_call_home_enabled(call_home: bytes, enabled: bool) -> WritePlan:
|
||||
"""Read `0x2C`, flip bit 0 of content[5], send the rest back byte for byte.
|
||||
|
||||
`[5]` reads 0x05 enabled / 0x04 disabled; bit 2 is set in both, so only
|
||||
bit 0 is the enable. `[118:120]` is unit-maintained and THOR echoes it.
|
||||
Bit 0 of `[5]` is the enable. 🔶 UM12947 (THOR's unit) read 0x05 enabled /
|
||||
0x04 disabled, bit 2 set in both; UM20147 reads 0x01 (measured, phase-2 dry
|
||||
run). So on UM20147 "off" writes 0x00, a value no capture shows being
|
||||
written: the target value there is unobserved, and the plan's `warnings`
|
||||
say so. `[118:120]` is unit-maintained and THOR echoes it.
|
||||
"""
|
||||
if len(call_home) != _CALL_HOME_LEN:
|
||||
raise ValueError(f"call-home content must be {_CALL_HOME_LEN} B "
|
||||
@@ -97,10 +103,18 @@ def plan_call_home_enabled(call_home: bytes, enabled: bool) -> WritePlan:
|
||||
b5 = (call_home[5] | 0x01) if enabled else (call_home[5] & 0xFE)
|
||||
data = call_home[:5] + bytes([b5]) + call_home[6:]
|
||||
what = "call-home " + ("enable" if enabled else "disable")
|
||||
start = call_home[5]
|
||||
warnings = []
|
||||
if start not in (0x04, 0x05) or b5 not in (0x04, 0x05):
|
||||
warnings.append(f"content[5] 0x{start:02X} -> 0x{b5:02X}: THOR was only ever "
|
||||
"seen writing 0x04/0x05 (UM12947); this value is unobserved")
|
||||
if b5 == start:
|
||||
warnings.append(f"the unit is already call-home {'enabled' if enabled else 'disabled'}"
|
||||
" -- this write changes nothing")
|
||||
return WritePlan(what, (
|
||||
WriteStep(0x7E, 0x007E, data, what="call-home config write"),
|
||||
WriteStep(0x7F, _CONFIRM, what="call-home config confirm"),
|
||||
))
|
||||
), tuple(warnings))
|
||||
|
||||
|
||||
def _checked(block: bytes, size: int, label: str) -> bytes:
|
||||
|
||||
@@ -187,3 +187,28 @@ def test_steps_cannot_be_reassigned():
|
||||
plan = plan_stop_monitoring()
|
||||
with pytest.raises(dataclasses.FrozenInstanceError):
|
||||
plan.steps = ()
|
||||
|
||||
|
||||
# ── warnings: where a plan leaves THOR's observed values ──────────────────────
|
||||
|
||||
def test_call_home_off_from_an_unobserved_start_value_carries_a_warning():
|
||||
r = bytearray(_call_home_reads()[0])
|
||||
r[5] = 0x01 # UM20147 reads 0x01, not THOR's 0x04/0x05
|
||||
plan = plan_call_home_enabled(bytes(r), False)
|
||||
assert any("unobserved" in w and "0x01 -> 0x00" in w for w in plan.warnings)
|
||||
assert plan.describe()["warnings"] and plan.describe()["warnings"] == list(plan.warnings)
|
||||
|
||||
|
||||
def test_call_home_on_when_already_on_says_it_changes_nothing():
|
||||
r = next(x for x in _call_home_reads() if x[5] == 0x05)
|
||||
plan = plan_call_home_enabled(r, True)
|
||||
assert any("changes nothing" in w and "enabled" in w for w in plan.warnings)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("read_idx,enabled", [(0, True), (1, False)])
|
||||
def test_thors_own_call_home_writes_carry_no_unobserved_warning(read_idx, enabled):
|
||||
r = _call_home_reads()[read_idx]
|
||||
plan = plan_call_home_enabled(r, enabled)
|
||||
assert not any("unobserved" in w for w in plan.warnings)
|
||||
assert plan.warnings == ()
|
||||
assert plan_stop_monitoring().describe()["warnings"] == []
|
||||
Reference in new issue
Block a user