Commit 87e8bca5 authored by Michael Büsch's avatar Michael Büsch

coreserver: Handle symbol table as bytes

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent 4fc131f2
...@@ -294,8 +294,8 @@ class AwlSimClient(object): ...@@ -294,8 +294,8 @@ class AwlSimClient(object):
raise AwlSimError("AwlSimClient: Failed to load code") raise AwlSimError("AwlSimClient: Failed to load code")
return True return True
def loadSymbolTable(self, symTabText): def loadSymbolTable(self, symTabBytes):
msg = AwlSimMessage_LOAD_SYMTAB(symTabText) msg = AwlSimMessage_LOAD_SYMTAB(symTabBytes)
status = self.__sendAndWaitFor_REPLY(msg) status = self.__sendAndWaitFor_REPLY(msg)
if status != AwlSimMessage_REPLY.STAT_OK: if status != AwlSimMessage_REPLY.STAT_OK:
raise AwlSimError("AwlSimClient: Failed to load symbol table") raise AwlSimError("AwlSimClient: Failed to load symbol table")
......
...@@ -201,24 +201,16 @@ class AwlSimMessage_EXCEPTION(AwlSimMessage): ...@@ -201,24 +201,16 @@ class AwlSimMessage_EXCEPTION(AwlSimMessage):
return cls(text) return cls(text)
class AwlSimMessage_LOAD_SYMTAB(AwlSimMessage): class AwlSimMessage_LOAD_SYMTAB(AwlSimMessage):
def __init__(self, symTabText): def __init__(self, symTabBytes):
AwlSimMessage.__init__(self, AwlSimMessage.MSG_ID_LOAD_SYMTAB) AwlSimMessage.__init__(self, AwlSimMessage.MSG_ID_LOAD_SYMTAB)
self.symTabText = symTabText self.symTabBytes = symTabBytes
def toBytes(self): def toBytes(self):
try: return AwlSimMessage.toBytes(self, len(self.symTabBytes)) + self.symTabBytes
data = self.symTabText.encode()
return AwlSimMessage.toBytes(self, len(data)) + data
except UnicodeError:
raise TransferError("LOAD_SYMTAB: Unicode error")
@classmethod @classmethod
def fromBytes(cls, payload): def fromBytes(cls, payload):
try: return cls(payload)
symTabText = payload.decode()
except UnicodeError:
raise TransferError("LOAD_SYMTAB: Unicode error")
return cls(symTabText)
class AwlSimMessage_LOAD_CODE(AwlSimMessage): class AwlSimMessage_LOAD_CODE(AwlSimMessage):
def __init__(self, code): def __init__(self, code):
......
...@@ -333,7 +333,7 @@ class AwlSimServer(object): ...@@ -333,7 +333,7 @@ class AwlSimServer(object):
def __rx_LOAD_SYMTAB(self, client, msg): def __rx_LOAD_SYMTAB(self, client, msg):
status = AwlSimMessage_REPLY.STAT_OK status = AwlSimMessage_REPLY.STAT_OK
symbolTable = SymTabParser.parseData(msg.symTabText, symbolTable = SymTabParser.parseData(msg.symTabBytes,
autodetectFormat = True, autodetectFormat = True,
mnemonics = self.sim.cpu.getSpecs().getMnemonics()) mnemonics = self.sim.cpu.getSpecs().getMnemonics())
self.__setRunState(self.STATE_INIT) self.__setRunState(self.STATE_INIT)
......
...@@ -281,7 +281,8 @@ def runWithServerBackend(inputFile): ...@@ -281,7 +281,8 @@ def runWithServerBackend(inputFile):
# Fire up the core # Fire up the core
writeStdout("Initializing CPU...\n") writeStdout("Initializing CPU...\n")
for symTabFile in project.symTabFiles: for symTabFile in project.symTabFiles:
client.loadSymbolTable(awlFileRead(symTabFile)) client.loadSymbolTable(awlFileRead(symTabFile,
encoding="binary"))
for awlFile in project.awlFiles: for awlFile in project.awlFiles:
client.loadCode(awlFileRead(awlFile)) client.loadCode(awlFileRead(awlFile))
client.setRunState(True) client.setRunState(True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment