Add device lock support and demo mode

Device lock (hardware lock of the DSP, independent of the app lock):
- detect a locked DSP from the 0x2C answer during connect and wait for the code
- unlock with 0x2D, optionally remember the code and unlock automatically
- set a new code (0x2F) from the device settings
- simulator: --lock CODE

Demo mode:
- switch in the settings starts a simulated DSP 204/408 inside the server
- real DSPs are disconnected and greyed out meanwhile and resume afterwards
- demo devices are never saved or exported; sim.py ships with the Pi image and EXEs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GivouandClaude Opus 5.5 committed 2026-11-01 21:14:04 +01:00
1 parent fe13f261f7
commit 61400df667
13 files changed
+426 -38

No files matched your search

+17
View File
@@ -120,6 +120,23 @@ def test_channel_names():
assert P.param_command(m, "in", 0, {"name": "Süd"}, "name") == (0x3D, b"\x00Sued ")
def test_device_lock():
# answer to 0x2C: [time lock][4 bytes time lock data][device lock]
assert P.device_locked(bytes([0, 0, 0, 0, 0, 1]))
assert not P.device_locked(bytes([0, 0, 0, 0, 0, 0]))
assert not P.device_locked(bytes([0, 20])) # short answer: no lock information
assert P.LOCK_CODE.fullmatch("A1BA") and not P.LOCK_CODE.fullmatch("a1ba") and not P.LOCK_CODE.fullmatch("A1B")
assert P.build_frame(P.CMD_UNLOCK, b"\x00A1BA")[5:11] == bytes([0x2D, 0x00]) + b"A1BA"
import sim
dsp = sim.SimDSP("204", "A1BA")
assert P.device_locked(dsp.handle(P.CMD_PRESET_COUNT, b"")[1])
assert dsp.handle(P.CMD_UNLOCK, b"\x00ZZZZ") == (P.CMD_UNLOCK, bytes([0, 0]))
assert dsp.handle(P.CMD_UNLOCK, b"\x00A1BA") == (P.CMD_UNLOCK, bytes([0, 1]))
assert not P.device_locked(dsp.handle(P.CMD_PRESET_COUNT, b"")[1])
dsp.handle(P.CMD_SET_LOCK_CODE, b"B2C3")
assert dsp.lock_code == "B2C3"
if __name__ == "__main__":
for name, fn in list(globals().items()):
if name.startswith("test_"):