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:
1 parent
fe13f261f7
commit
61400df667
13 files changed
+426
-38
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
Usage: python sim.py --model 204 --port 9761
|
||||
python sim.py --model 408 --port 9762
|
||||
python sim.py --model 204 --port 9761 --lock A1BA (asks for that lock code on every connection)
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -17,8 +18,10 @@ log = logging.getLogger("sim")
|
||||
|
||||
|
||||
class SimDSP:
|
||||
def __init__(self, model_key: str):
|
||||
def __init__(self, model_key: str, lock_code: str = ""):
|
||||
self.key = model_key
|
||||
self.lock_code = lock_code # hardware lock: "" = none
|
||||
self.unlocked = not lock_code
|
||||
self.model = P.MODELS[model_key]
|
||||
self.state = P.default_state(self.model)
|
||||
self.presets = [copy.deepcopy(self.state) if i == 0 else None for i in range(20)]
|
||||
@@ -33,7 +36,15 @@ class SimDSP:
|
||||
if cmd == P.CMD_DEVICE_INFO:
|
||||
return cmd, f"DSP{self.key} V010 SIM".encode()
|
||||
if cmd == P.CMD_PRESET_COUNT:
|
||||
return cmd, bytes([0, len(self.presets)])
|
||||
return cmd, bytes([0, 0, 0, 0, 0, 0 if self.unlocked else 1])
|
||||
if cmd == P.CMD_UNLOCK:
|
||||
self.unlocked = self.unlocked or p[1:5].decode("latin1") == self.lock_code
|
||||
return cmd, bytes([0, 1 if self.unlocked else 0])
|
||||
if cmd == P.CMD_SET_LOCK_CODE:
|
||||
self.lock_code = p[:4].decode("latin1")
|
||||
return P.CMD_ACK, b"\x00"
|
||||
if not self.unlocked and cmd not in (P.CMD_HANDSHAKE, P.CMD_METER, P.CMD_LOGOUT):
|
||||
return P.CMD_ACK, b"\x00" # locked: ignores everything until the code was entered
|
||||
if cmd == P.CMD_PRESET_NAME:
|
||||
return cmd, bytes([p[0]]) + self.preset_names()[p[0]].encode("latin1").ljust(14, b" ")
|
||||
if cmd == P.CMD_CONFIG_REQUEST:
|
||||
@@ -72,6 +83,7 @@ class SimDSP:
|
||||
async def serve(self, reader, writer):
|
||||
peer = writer.get_extra_info("peername")
|
||||
log.info("client %s connected", peer)
|
||||
self.unlocked = not self.lock_code
|
||||
parser = P.FrameParser()
|
||||
try:
|
||||
while data := await reader.read(4096):
|
||||
@@ -92,9 +104,10 @@ async def main():
|
||||
ap.add_argument("--model", choices=list(P.MODELS), default="204")
|
||||
ap.add_argument("--port", type=int, default=P.PORT)
|
||||
ap.add_argument("--host", default="127.0.0.1")
|
||||
ap.add_argument("--lock", default="", help="lock code (4 characters A-Z/0-9) the DSP asks for")
|
||||
args = ap.parse_args()
|
||||
logging.basicConfig(level=logging.INFO, format=f"%(asctime)s sim{args.model} %(message)s")
|
||||
sim = SimDSP(args.model)
|
||||
sim = SimDSP(args.model, args.lock.upper())
|
||||
server = await asyncio.start_server(sim.serve, args.host, args.port)
|
||||
log.info("simulated DSP %s on %s:%d", args.model, args.host, args.port)
|
||||
async with server:
|
||||
|
||||
Reference in new issue
Block a user