From 15fc9ca16cadfc43e83e57a95886b0fc22b5b9fb Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Wed, 19 Jun 2024 17:18:54 +0200 Subject: [PATCH] add sim for ls372 + fix bin/sim-server Change-Id: I6cad963d9e37faea172ca51a327474406ecafa4a --- bin/sim-server | 1 + frappy_psi/ls370sim.py | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/bin/sim-server b/bin/sim-server index 34636c4..5d045cf 100755 --- a/bin/sim-server +++ b/bin/sim-server @@ -110,6 +110,7 @@ class Server(LineServer): def __init__(self, *args, **kwds): super().__init__(*args, **kwds) + self.secnode = None self.dispatcher = self.Dispatcher() diff --git a/frappy_psi/ls370sim.py b/frappy_psi/ls370sim.py index 1791290..a74f449 100644 --- a/frappy_psi/ls370sim.py +++ b/frappy_psi/ls370sim.py @@ -71,3 +71,57 @@ class Ls370Sim(Communicator): reply = ';'.join(reply) self.comLog('< %s' % reply) return reply + + +class Ls372Sim(Communicator): + CHANNEL_COMMANDS = [ + ('RDGR?%d', '1.0'), + ('RDGK?%d', '1.5'), + ('RDGST?%d', '0'), + ('RDGRNG?%d', '0,5,5,0,0'), + ('INSET?%d', '1,5,5,0,0'), + ('FILTER?%d', '1,5,80'), + ] + OTHER_COMMANDS = [ + ('*IDN?', 'LSCI,MODEL372,372184,05302003'), + ('SCAN?', '3,1'), + ('PID?1', '10,10,0'), + ('*OPC?', '1'), + ] + + def earlyInit(self): + super().earlyInit() + self._data = dict(self.OTHER_COMMANDS) + for fmt, v in self.CHANNEL_COMMANDS: + for chan in range(1,17): + self._data[fmt % chan] = v + + def communicate(self, command): + self.comLog('> %s' % command) + # simulation part, time independent + for channel in range(1,17): + _, _, _, _, excoff = self._data['RDGRNG?%d' % channel].split(',') + if excoff == '1': + self._data['RDGST?%d' % channel] = '6' + else: + self._data['RDGST?%d' % channel] = '0' + + chunks = command.split(';') + reply = [] + for chunk in chunks: + if '?' in chunk: + reply.append(self._data[chunk]) + else: + for nqarg in (1,0): + if nqarg == 0: + qcmd, arg = chunk.split(' ', 1) + qcmd += '?' + else: + qcmd, arg = chunk.split(',', nqarg) + qcmd = qcmd.replace(' ', '?', 1) + if qcmd in self._data: + self._data[qcmd] = arg + break + reply = ';'.join(reply) + self.comLog('< %s' % reply) + return reply