First working version of the MasterMACS EPICS driver

Also added some test code
This commit is contained in:
2023-03-21 14:55:07 +01:00
parent b8896b7a85
commit ccd73babd5
22 changed files with 20883 additions and 0 deletions

53
utils/macmaster.py Normal file
View File

@ -0,0 +1,53 @@
"""
Usage: macmaster.py macmasterhost port
Listen for commands to send and returns reponse
until exit has been typed
Mark Koennecke, March 2023
"""
import socket
import struct
class MasterMACS():
def __init__(self, host, port):
self._socke = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._socke.connect((host, int(port)))
def send(self, command):
buf = struct.pack('BBBB', 0x05, len(command) + 4, 0, 0x19)
buf += bytes(command, 'utf-8')
buf += struct.pack('BB', 0x0D, 0x03)
self._socke.send(buf)
def receive(self):
buf = self._socke.recv(35, socket.MSG_WAITALL)
if len(buf) < 35:
raise EOFException('Master MACS returned only %d bytes, 30 expected' % len(buf))
idx = buf.find(0x0D)
ackbyte = buf[idx-1]
if ackbyte == 0x06:
ack = 'ACK'
elif ackbyte == 0x15:
ack = 'NAK',
else:
ack = 'NO'
reply = buf[4:idx-1].decode('utf-8')
return ack, reply
if __name__ == "__main__":
from sys import argv, exit, stdin
if len(argv) < 3:
print('Usage:\n\tmacmaster.py machost macport')
exit(1)
mac = MasterMACS(argv[1], argv[2])
while(True):
# import pdb; pdb.set_trace()
line = stdin.readline()
if line.find('exit') >= 0:
exit(0)
mac.send(line.strip())
ack, reply = mac.receive()
print('%s, %s' %(ack, reply))