Commit 7398bc23 authored by Michael Büsch's avatar Michael Büsch

Change core server API to expect HwmodDescriptors

Signed-off-by: Michael Büsch's avatarMichael Buesch <[email protected]>
parent e4fa10bc
...@@ -281,10 +281,9 @@ def runWithServerBackend(inputFile): ...@@ -281,10 +281,9 @@ def runWithServerBackend(inputFile):
# Load hardware modules # Load hardware modules
for modDesc in project.getHwmodSettings().getLoadedModules(): for modDesc in project.getHwmodSettings().getLoadedModules():
client.loadHardwareModule(modDesc.getModuleName(), client.loadHardwareModule(modDesc)
modDesc.getParameters())
for name, parameters in opt_hwmods: for name, parameters in opt_hwmods:
client.loadHardwareModule(name, parameters) client.loadHardwareModule(HwmodDescriptor(name, parameters))
# Configure the core # Configure the core
if opt_noCpuDump: if opt_noCpuDump:
......
...@@ -356,8 +356,7 @@ def main(): ...@@ -356,8 +356,7 @@ def main():
# Configure the core and the core server. # Configure the core and the core server.
server = AwlSimServer() server = AwlSimServer()
for modDesc in hwmodSettings.getLoadedModules(): for modDesc in hwmodSettings.getLoadedModules():
server.loadHardwareModule(modDesc.getModuleName(), server.loadHardwareModule(modDesc)
modDesc.getParameters())
server.cpuEnableObTempPresets(project.getObTempPresetsEn()) server.cpuEnableObTempPresets(project.getObTempPresetsEn())
server.cpuEnableExtendedInsns(project.getExtInsnsEn() or\ server.cpuEnableExtendedInsns(project.getExtInsnsEn() or\
opt_extInsns) opt_extInsns)
......
# -*- coding: utf-8 -*-
#
# AWL simulator - Hardware module descriptors
#
# Copyright 2014-2015 Michael Buesch <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
from __future__ import division, absolute_import, print_function, unicode_literals
from awlsim.common.compat import *
from awlsim.common.util import *
class HwmodDescriptor(object):
"""Hardware module descriptor."""
def __init__(self, moduleName, parameters = None):
"""Hardware module descriptor initialization.
moduleName -> module name string
parameters -> parameter dict with
keys -> parameter name
values -> parameter value
"""
self.setModuleName(moduleName)
self.setParameters(parameters)
def dup(self):
"""Duplicate this descriptor.
"""
return HwmodDescriptor(self.getModuleName(),
dict(self.getParameters()))
def setModuleName(self, moduleName):
"""Set the module name string.
"""
self.moduleName = moduleName
def getModuleName(self):
"""Get the module name string.
"""
return self.moduleName
def setParameters(self, parameters):
"""Set the parameters dict.
"""
if not parameters:
parameters = {}
self.parameters = parameters
def addParameter(self, name, value):
"""Add a parameter to the parameter dict.
"""
self.setParameterValue(name, value)
def setParameterValue(self, name, value):
"""Set the value of a parameter.
"""
self.parameters[name] = value
def removeParameter(self, name):
"""Remove a parameter from the parameter dict.
"""
self.parameters.pop(name, None)
def getParameters(self):
"""Get the parameters dict (reference).
"""
return self.parameters
def getParameter(self, name):
"""Get one parameter by name.
"""
return self.parameters.get(name)
#TODO hash
...@@ -24,6 +24,7 @@ from awlsim.common.compat import * ...@@ -24,6 +24,7 @@ from awlsim.common.compat import *
from awlsim.common.cpuspecs import * from awlsim.common.cpuspecs import *
from awlsim.common.sources import * from awlsim.common.sources import *
from awlsim.common.hwmod import *
from awlsim.common.util import * from awlsim.common.util import *
from awlsim.library.libselection import * from awlsim.library.libselection import *
...@@ -40,43 +41,6 @@ else: ...@@ -40,43 +41,6 @@ else:
from configparser import Error as _ConfigParserError from configparser import Error as _ConfigParserError
class HwmodDescriptor(object):
"""Hardware module descriptor."""
def __init__(self, moduleName, parameters = None):
self.setModuleName(moduleName)
self.setParameters(parameters)
def dup(self):
return HwmodDescriptor(self.getModuleName(),
dict(self.getParameters()))
def setModuleName(self, moduleName):
self.moduleName = moduleName
def getModuleName(self):
return self.moduleName
def setParameters(self, parameters):
if not parameters:
parameters = {}
self.parameters = parameters
def addParameter(self, name, value):
self.setParameterValue(name, value)
def setParameterValue(self, name, value):
self.parameters[name] = value
def removeParameter(self, name):
self.parameters.pop(name, None)
def getParameters(self):
return self.parameters
def getParameter(self, name):
return self.parameters.get(name)
class GuiSettings(object): class GuiSettings(object):
def __init__(self, def __init__(self,
editorAutoIndentEn=True, editorAutoIndentEn=True,
......
...@@ -425,11 +425,10 @@ class AwlSimClient(object): ...@@ -425,11 +425,10 @@ class AwlSimClient(object):
raise AwlSimError("AwlSimClient: Failed to load library block selection") raise AwlSimError("AwlSimClient: Failed to load library block selection")
return True return True
def loadHardwareModule(self, name, parameters={}): def loadHardwareModule(self, hwmodDesc):
if not self.__transceiver: if not self.__transceiver:
return False return False
msg = AwlSimMessage_HWMOD(name = name, msg = AwlSimMessage_HWMOD(hwmodDesc)
paramDict = parameters)
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 hardware module") raise AwlSimError("AwlSimClient: Failed to load hardware module")
......
...@@ -24,6 +24,7 @@ from awlsim.common.compat import * ...@@ -24,6 +24,7 @@ from awlsim.common.compat import *
from awlsim.common.cpuspecs import * from awlsim.common.cpuspecs import *
from awlsim.common.project import * from awlsim.common.project import *
from awlsim.common.hwmod import *
from awlsim.common.datatypehelpers import * from awlsim.common.datatypehelpers import *
from awlsim.coreserver.memarea import * from awlsim.coreserver.memarea import *
...@@ -101,7 +102,8 @@ class AwlSimMessage(object): ...@@ -101,7 +102,8 @@ class AwlSimMessage(object):
MSG_ID_LIBSEL = EnumGen.item MSG_ID_LIBSEL = EnumGen.item
MSG_ID_GET_IDENTS = EnumGen.itemAt(0x0190) MSG_ID_GET_IDENTS = EnumGen.itemAt(0x0190)
MSG_ID_IDENTS = EnumGen.item MSG_ID_IDENTS = EnumGen.item
#TODO: add messages to get compiled block info MSG_ID_GET_BLOCKINFO = EnumGen.item
MSG_ID_BLOCKINFO = EnumGen.item
#TODO: add messages to delete compiled blocks and sources #TODO: add messages to delete compiled blocks and sources
# Configuration # Configuration
MSG_ID_GET_OPT = EnumGen.itemAt(0x0200) #TODO not implemented, yet MSG_ID_GET_OPT = EnumGen.itemAt(0x0200) #TODO not implemented, yet
...@@ -338,15 +340,15 @@ class AwlSimMessage_AWLSRC(_AwlSimMessage_source): ...@@ -338,15 +340,15 @@ class AwlSimMessage_AWLSRC(_AwlSimMessage_source):
class AwlSimMessage_HWMOD(AwlSimMessage): class AwlSimMessage_HWMOD(AwlSimMessage):
msgId = AwlSimMessage.MSG_ID_HWMOD msgId = AwlSimMessage.MSG_ID_HWMOD
def __init__(self, name, paramDict): # hwmodDesc -> HwmodDescriptor instance
self.name = name def __init__(self, hwmodDesc):
self.paramDict = paramDict self.hwmodDesc = hwmodDesc
def toBytes(self): def toBytes(self):
payload = b"" payload = b""
try: try:
payload += self.packString(self.name) payload += self.packString(self.hwmodDesc.getModuleName())
for pname, pval in self.paramDict.items(): for pname, pval in self.hwmodDesc.getParameters().items():
payload += self.packString(pname) payload += self.packString(pname)
payload += self.packString(pval) payload += self.packString(pval)
return AwlSimMessage.toBytes(self, len(payload)) + payload return AwlSimMessage.toBytes(self, len(payload)) + payload
...@@ -368,7 +370,7 @@ class AwlSimMessage_HWMOD(AwlSimMessage): ...@@ -368,7 +370,7 @@ class AwlSimMessage_HWMOD(AwlSimMessage):
paramDict[pname] = pval paramDict[pname] = pval
except (ValueError) as e: except (ValueError) as e:
raise TransferError("LOAD_HW: Invalid data format") raise TransferError("LOAD_HW: Invalid data format")
return cls(name = name, paramDict = paramDict) return cls(HwmodDescriptor(name, paramDict))
class AwlSimMessage_LIBSEL(AwlSimMessage): class AwlSimMessage_LIBSEL(AwlSimMessage):
msgId = AwlSimMessage.MSG_ID_LIBSEL msgId = AwlSimMessage.MSG_ID_LIBSEL
...@@ -809,7 +811,7 @@ class AwlSimMessage_IDENTS(AwlSimMessage): ...@@ -809,7 +811,7 @@ class AwlSimMessage_IDENTS(AwlSimMessage):
# awlSources: List of AwlSource()s # awlSources: List of AwlSource()s
# symTabSources: List of SymTabSource()s # symTabSources: List of SymTabSource()s
# hwMods: List of tuples: (modName, parametersDict) # hwMods: List of HwmodDescriptor()s
# libSelections: List of AwlLibEntrySelection()s # libSelections: List of AwlLibEntrySelection()s
def __init__(self, awlSources, symTabSources, hwMods, libSelections): def __init__(self, awlSources, symTabSources, hwMods, libSelections):
self.awlSources = awlSources self.awlSources = awlSources
...@@ -831,10 +833,11 @@ class AwlSimMessage_IDENTS(AwlSimMessage): ...@@ -831,10 +833,11 @@ class AwlSimMessage_IDENTS(AwlSimMessage):
payload.append(self.packString(src.name)) payload.append(self.packString(src.name))
payload.append(self.packString(src.filepath)) payload.append(self.packString(src.filepath))
payload.append(self.packBytes(src.identHash)) payload.append(self.packBytes(src.identHash))
for modName, parametersDict in self.hwMods: for hwmodDesc in self.hwMods:
payload.append(self.plModStruct.pack(len(parametersDict), 0)) params = hwmodDesc.getParameters()
payload.append(self.packString(modName)) payload.append(self.plModStruct.pack(len(params), 0))
for pName, pVal in parametersDict.items(): payload.append(self.packString(hwmodDesc.getModuleName()))
for pName, pVal in params.items():
payload.append(self.packString(pName)) payload.append(self.packString(pName))
payload.append(self.packString(pVal)) payload.append(self.packString(pVal))
for libSel in self.libSelections: for libSel in self.libSelections:
...@@ -898,6 +901,37 @@ class AwlSimMessage_IDENTS(AwlSimMessage): ...@@ -898,6 +901,37 @@ class AwlSimMessage_IDENTS(AwlSimMessage):
hwMods = hwMods, hwMods = hwMods,
libSelections = libSelections) libSelections = libSelections)
class AwlSimMessage_GET_BLOCKINFO(AwlSimMessage):
msgId = AwlSimMessage.MSG_ID_GET_BLOCKINFO
# Get-flags. Specify what information to get.
EnumGen.start
GET_OB_INFO = EnumGen.bitmask # Get OB info
GET_FC_INFO = EnumGen.bitmask # Get FC info
GET_FB_INFO = EnumGen.bitmask # Get FB info
GET_DB_INFO = EnumGen.bitmask # Get DB info
EnumGen.end
# Payload header struct:
# Get-flags (32 bit)
# Reserved (32 bit)
plHdrStruct = struct.Struct(str(">II"))
def __init__(self, getFlags):
self.getFlags = getFlags
def toBytes(self):
payload = self.plHdrStruct.pack(self.getFlags, 0)
return AwlSimMessage.toBytes(self, len(payload)) + payload
@classmethod
def fromBytes(cls, payload):
try:
getFlags, _unused = cls.plHdrStruct.unpack_from(payload, 0)
except (ValueError, struct.error) as e:
raise TransferError("GET_BLOCKINFO: Invalid data format")
return cls(getFlags)
class AwlSimMessageTransceiver(object): class AwlSimMessageTransceiver(object):
id2class = { id2class = {
AwlSimMessage.MSG_ID_REPLY : AwlSimMessage_REPLY, AwlSimMessage.MSG_ID_REPLY : AwlSimMessage_REPLY,
......
...@@ -216,8 +216,7 @@ class AwlSimServer(object): ...@@ -216,8 +216,7 @@ class AwlSimServer(object):
self.awlSourceContainer = SourceContainer() self.awlSourceContainer = SourceContainer()
# Container of loaded and managed SymTabSource()s # Container of loaded and managed SymTabSource()s
self.symTabSourceContainer = SourceContainer() self.symTabSourceContainer = SourceContainer()
# List of tuples of loaded hardware modules: # List of tuples of loaded hardware modules (HwmodDescriptor instances)
# (hwModName, parameterDict)
self.loadedHwModules = [] self.loadedHwModules = []
# List of loaded AwlLibEntrySelection()s # List of loaded AwlLibEntrySelection()s
self.loadedLibSelections = [] self.loadedLibSelections = []
...@@ -446,12 +445,13 @@ class AwlSimServer(object): ...@@ -446,12 +445,13 @@ class AwlSimServer(object):
self.symTabSourceContainer.addManager(srcManager) self.symTabSourceContainer.addManager(srcManager)
def loadHardwareModule(self, moduleName, paramDict): def loadHardwareModule(self, hwmodDesc):
printInfo("Loading hardware module '%s'..." % moduleName) printInfo("Loading hardware module '%s'..." %\
hwClass = self.__sim.loadHardwareModule(moduleName) hwmodDesc.getModuleName())
hwClass = self.__sim.loadHardwareModule(hwmodDesc.getModuleName())
self.__sim.registerHardwareClass(hwClass = hwClass, self.__sim.registerHardwareClass(hwClass = hwClass,
parameters = paramDict) parameters = hwmodDesc.getParameters())
self.loadedHwModules.append( (moduleName, paramDict) ) self.loadedHwModules.append(hwmodDesc)
def loadLibraryBlock(self, libSelection): def loadLibraryBlock(self, libSelection):
self.setRunState(self.STATE_STOP) self.setRunState(self.STATE_STOP)
...@@ -557,7 +557,7 @@ class AwlSimServer(object): ...@@ -557,7 +557,7 @@ class AwlSimServer(object):
def __rx_HWMOD(self, client, msg): def __rx_HWMOD(self, client, msg):
printDebug("Received message: HWMOD") printDebug("Received message: HWMOD")
status = AwlSimMessage_REPLY.STAT_OK status = AwlSimMessage_REPLY.STAT_OK
self.loadHardwareModule(msg.name, msg.paramDict) self.loadHardwareModule(msg.hwmodDesc)
client.transceiver.send(AwlSimMessage_REPLY.make(msg, status)) client.transceiver.send(AwlSimMessage_REPLY.make(msg, status))
def __rx_LIBSEL(self, client, msg): def __rx_LIBSEL(self, client, msg):
......
...@@ -597,8 +597,7 @@ class CpuWidget(QWidget): ...@@ -597,8 +597,7 @@ class CpuWidget(QWidget):
client.enableExtendedInsns(project.getExtInsnsEn()) client.enableExtendedInsns(project.getExtInsnsEn())
for modDesc in project.getHwmodSettings().getLoadedModules(): for modDesc in project.getHwmodSettings().getLoadedModules():
client.loadHardwareModule(modDesc.getModuleName(), client.loadHardwareModule(modDesc)
modDesc.getParameters())
for symTabSource in symTabSources: for symTabSource in symTabSources:
client.loadSymTabSource(symTabSource) client.loadSymTabSource(symTabSource)
for libSel in libSelections: for libSel in libSelections:
......
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