def parseSenderReceiverInterface(self, xmlRoot, rootProject=None, parent=None): name = xmlRoot.find("./SHORT-NAME") if name is not None: if self.version == 3: portInterface = autosar.portinterface.SenderReceiverInterface( name.text) if hasAdminData(xmlRoot): portInterface.adminData = parseAdminDataNode( xmlRoot.find('ADMIN-DATA')) if xmlRoot.find("./IS-SERVICE").text == 'true': portInterface.isService = True for xmlItem in xmlRoot.findall( './DATA-ELEMENTS/DATA-ELEMENT-PROTOTYPE'): name = xmlItem.find("./SHORT-NAME") if name is not None: isQueued = True if xmlItem.find( "./IS-QUEUED").text == 'true' else False typeRef = xmlItem.find("./TYPE-TREF").text dataElem = autosar.portinterface.DataElement( name.text, typeRef, isQueued, parent=portInterface) portInterface.dataElements.append(dataElem) if xmlRoot.find('MODE-GROUPS') is not None: portInterface.modeGroups = [] for xmlItem in xmlRoot.findall( './MODE-GROUPS/MODE-DECLARATION-GROUP-PROTOTYPE'): modeGroup = autosar.portinterface.ModeGroup( xmlItem.find("./SHORT-NAME").text, xmlItem.find("./TYPE-TREF").text, portInterface) portInterface.modeGroups.append(modeGroup) return portInterface
def parseParameterInterface(self, xmlRoot, rootProject=None, parent=None): assert (xmlRoot.tag == 'CALPRM-INTERFACE') xmlName = xmlRoot.find("./SHORT-NAME") if xmlName is not None: if self.version == 3: portInterface = autosar.portinterface.ParameterInterface( xmlName.text) if xmlRoot.find("./IS-SERVICE").text == 'true': portInterface.isService = True for xmlElem in xmlRoot.findall( './CALPRM-ELEMENTS/CALPRM-ELEMENT-PROTOTYPE'): xmlElemName = xmlElem.find("./SHORT-NAME") if xmlElemName is not None: typeRef = xmlElem.find("./TYPE-TREF").text dataElem = autosar.portinterface.DataElement( xmlElemName.text, typeRef, parent=portInterface) if hasAdminData(xmlElem): dataElem.adminData = parseAdminDataNode( xmlElem.find('ADMIN-DATA')) if xmlElem.find('SW-DATA-DEF-PROPS'): for xmlItem in xmlElem.findall( 'SW-DATA-DEF-PROPS/SW-ADDR-METHOD-REF'): dataElem.swAddrMethodRefList.append( xmlItem.text) portInterface.dataElements.append(dataElem) return portInterface
def parseDataConstraint(self, xmlRoot, parent=None): assert (xmlRoot.tag == 'DATA-CONSTR') name = xmlRoot.find("./SHORT-NAME").text rules=[] for xmlItem in xmlRoot.findall('./DATA-CONSTR-RULES/DATA-CONSTR-RULE/*'): if xmlItem.tag == 'INTERNAL-CONSTRS': lowerLimitXML = xmlItem.find('./LOWER-LIMIT') upperLimitXML = xmlItem.find('./UPPER-LIMIT') lowerLimit = parseTextNode(lowerLimitXML) upperLimit = parseTextNode(upperLimitXML) lowerLimitType = 'CLOSED' upperLimitType = 'CLOSED' if lowerLimitXML.attrib['INTERVAL-TYPE']=='OPEN': lowerLimitType='OPEN' if upperLimitXML.attrib['INTERVAL-TYPE']=='OPEN': upperLimitType='OPEN' try: lowerLimit = int(lowerLimit) except ValueError: lowerLimit = str(lowerLimit) try: upperLimit = int(upperLimit) except ValueError: upperLimit = str(upperLimit) rules.append({'type': 'internalConstraint', 'lowerLimit':lowerLimit, 'upperLimit':upperLimit, 'lowerLimitType':lowerLimitType, 'upperLimitType':upperLimitType,}) else: raise NotImplementedError(xmlItem.tag) elem = DataConstraint(name, rules, parent) if hasAdminData(xmlRoot): elem.adminData=parseAdminDataNode(xmlRoot.find('ADMIN-DATA')) return elem
def parseCalPrmInterface(self, xmlRoot, parent=None): assert (xmlRoot.tag == 'CALPRM-INTERFACE') xmlName = xmlRoot.find("./SHORT-NAME") if xmlName is not None: portInterface = autosar.portinterface.ParameterInterface( xmlName.text) if xmlRoot.find("./IS-SERVICE").text == 'true': portInterface.isService = True for xmlElem in xmlRoot.findall( './CALPRM-ELEMENTS/CALPRM-ELEMENT-PROTOTYPE'): xmlElemName = xmlElem.find("./SHORT-NAME") if xmlElemName is not None: typeRef = xmlElem.find("./TYPE-TREF").text parameter = autosar.portinterface.Parameter( xmlElemName.text, typeRef, parent=portInterface) if hasAdminData(xmlElem): parameter.adminData = parseAdminDataNode( xmlElem.find('ADMIN-DATA')) if xmlElem.find('SW-DATA-DEF-PROPS'): for xmlItem in xmlElem.findall( 'SW-DATA-DEF-PROPS/SW-ADDR-METHOD-REF'): parameter.swAddressMethodRef = self.parseTextNode( xmlItem) portInterface.elements.append(parameter) return portInterface
def parseClientServerInterface(self,xmlRoot,parent=None): assert(xmlRoot.tag=='CLIENT-SERVER-INTERFACE') name = self.parseTextNode(xmlRoot.find('SHORT-NAME')) if name is not None: portInterface = autosar.portinterface.ClientServerInterface(name) if hasAdminData(xmlRoot): portInterface.adminData=parseAdminDataNode(xmlRoot.find('ADMIN-DATA')) for xmlElem in xmlRoot.findall('./*'): if (xmlElem.tag == 'SHORT-NAME') or (xmlElem.tag == 'ADMIN-DATA'): continue elif xmlElem.tag == 'IS-SERVICE': if self.parseTextNode(xmlElem) == 'true': portInterface.isService = True elif xmlElem.tag == 'OPERATIONS': for xmlChildItem in xmlElem.findall('./*'): if (self.version < 4.0 and xmlChildItem.tag == 'OPERATION-PROTOTYPE') or (self.version >= 4.0 and xmlChildItem.tag == 'CLIENT-SERVER-OPERATION'): operation = self._parseOperationPrototype(xmlChildItem, portInterface) portInterface.operations.append(operation) else: raise NotImplementedError(xmlChildItem.tag) elif xmlElem.tag == 'POSSIBLE-ERRORS': for xmlError in xmlElem.findall('APPLICATION-ERROR'): applicationError = self._parseApplicationError(xmlError, portInterface) portInterface.applicationErrors.append(applicationError) elif xmlElem.tag == 'SERVICE-KIND': portInterface.serviceKind = self.parseTextNode(xmlElem) else: raise NotImplementedError(xmlElem.tag) return portInterface
def parseDataTypeMappingSet(self, xmlRoot, dummy, parent=None): assert (xmlRoot.tag == 'DATA-TYPE-MAPPING-SET') name = parseTextNode(xmlRoot.find('SHORT-NAME')) if hasAdminData(xmlRoot): adminData = parseAdminDataNode(xmlRoot.find('ADMIN-DATA')) else: adminData = None return DataTypeMappingSet(name, parent, adminData)
def parseSwBaseType(self, xmlRoot, dummy, parent=None): assert (xmlRoot.tag == 'SW-BASE-TYPE') name = parseTextNode(xmlRoot.find('SHORT-NAME')) size = parseTextNode(xmlRoot.find('BASE-TYPE-SIZE')) typeEncoding = parseTextNode(xmlRoot.find('BASE-TYPE-ENCODING')) nativeDeclaration = parseTextNode(xmlRoot.find('NATIVE-DECLARATION')) category = parseTextNode(xmlRoot.find('CATEGORY')) if hasAdminData(xmlRoot): adminData = parseAdminDataNode(xmlRoot.find('ADMIN-DATA')) else: adminData = None return SwBaseType(name, size, typeEncoding, nativeDeclaration, category, parent, adminData)
def parseSwBaseType(self, xmlRoot, parent = None): assert (xmlRoot.tag == 'SW-BASE-TYPE') name = parseTextNode(xmlRoot.find('SHORT-NAME')) size = parseTextNode(xmlRoot.find('BASE-TYPE-SIZE')) typeEncoding = parseTextNode(xmlRoot.find('BASE-TYPE-ENCODING')) nativeDeclaration = parseTextNode(xmlRoot.find('NATIVE-DECLARATION')) category = parseTextNode(xmlRoot.find('CATEGORY')) if hasAdminData(xmlRoot): adminData=parseAdminDataNode(xmlRoot.find('ADMIN-DATA')) else: adminData=None elem = SwBaseType(name, size, typeEncoding, nativeDeclaration, category, parent, adminData) self.parseDesc(xmlRoot,elem) return elem
def parseModeDeclarationGroup(self,xmlRoot,rootProject=None,parent=None): assert(xmlRoot.tag == 'MODE-DECLARATION-GROUP') name = self.parseTextNode(xmlRoot.find("./SHORT-NAME")) category = self.parseTextNode(xmlRoot.find("./CATEGORY")) initialModeRef = self.parseTextNode(xmlRoot.find('./INITIAL-MODE-REF')) modeDclrGroup = autosar.portinterface.ModeDeclarationGroup(name,initialModeRef,None,parent) if xmlRoot.find('./MODE-DECLARATIONS') is not None: self.parseModeDeclarations(xmlRoot.find('./MODE-DECLARATIONS'), modeDclrGroup) if hasAdminData(xmlRoot): adminData = self.parseAdminDataNode(xmlRoot.find('ADMIN-DATA')) modeDclrGroup.adminData = adminData if category is not None: modeDclrGroup.category = category return modeDclrGroup
def parseModeDeclarationGroup(self,xmlRoot,rootProject=None,parent=None): assert(xmlRoot.tag == 'MODE-DECLARATION-GROUP') name = xmlRoot.find("./SHORT-NAME").text initialModeRef = None modeDeclarations = None if xmlRoot.find('./INITIAL-MODE-REF'): modeDeclarations = self.parseModeDeclarations(xmlRoot.find('./INITIAL-MODE-REF'),rootProject) if xmlRoot.find('./INITIAL-MODE-REF'): initialModeRef = xmlRoot.find('./INITIAL-MODE-REF').text modeDclrGroup = ModeDeclarationGroup(name,initialModeRef,modeDeclarations) if hasAdminData(xmlRoot): adminData = parseAdminDataNode(xmlRoot.find('ADMIN-DATA')) modeDclrGroup.adminData = adminData return modeDclrGroup
def parseConstantSpecification(self,xmlRoot,rootProject=None,parent=None): assert(xmlRoot.tag == 'CONSTANT-SPECIFICATION') xmlName = xmlRoot.find('SHORT-NAME') if xmlName is not None: name = xmlName.text xmlValue = xmlRoot.find('./VALUE/*') if xmlValue is not None: constantValue = self.parseConstantValue(xmlValue) else: constantValue = None constant = Constant(name,constantValue) if hasAdminData(xmlRoot): constant.adminData=parseAdminDataNode(xmlRoot.find('ADMIN-DATA')) return constant return None
def parseClientServerInterface(self, xmlRoot, rootProject=None, parent=None): assert (xmlRoot.tag == 'CLIENT-SERVER-INTERFACE') xmlName = xmlRoot.find("./SHORT-NAME") if xmlName is not None: if self.version == 3: portInterface = autosar.portinterface.ClientServerInterface( xmlName.text) if hasAdminData(xmlRoot): portInterface.adminData = parseAdminDataNode( xmlRoot.find('ADMIN-DATA')) if xmlRoot.find("./IS-SERVICE").text == 'true': portInterface.isService = True for xmlOperation in xmlRoot.findall( './OPERATIONS/OPERATION-PROTOTYPE'): xmlOperationName = xmlOperation.find("./SHORT-NAME") if xmlOperationName is not None: operation = autosar.portinterface.Operation( xmlOperationName.text, portInterface) self.parseDesc(xmlOperation, operation) if xmlOperation.find('./ARGUMENTS') is not None: for xmlArgument in xmlOperation.findall( './ARGUMENTS/ARGUMENT-PROTOTYPE'): name = xmlArgument.find("./SHORT-NAME").text typeRef = xmlArgument.find("./TYPE-TREF").text direction = xmlArgument.find( "./DIRECTION").text operation.arguments.append( autosar.portinterface.Argument( name, typeRef, direction)) if xmlOperation.find('./POSSIBLE-ERROR-REFS'): for xmlErrorRef in xmlOperation.findall( './POSSIBLE-ERROR-REFS/POSSIBLE-ERROR-REF' ): operation.errorRefs.append(xmlErrorRef.text) portInterface.operations.append(operation) if xmlRoot.find('./POSSIBLE-ERRORS'): for xmlError in xmlRoot.findall( './POSSIBLE-ERRORS/APPLICATION-ERROR'): name = xmlError.find("./SHORT-NAME").text errorCode = xmlError.find("./ERROR-CODE").text portInterface.applicationErrors.append( autosar.portinterface.ApplicationError( name, errorCode, portInterface)) return portInterface
def parseParameterInterface(self,xmlRoot,rootProject=None,parent=None): assert(xmlRoot.tag=='CALPRM-INTERFACE') xmlName = xmlRoot.find("./SHORT-NAME") if xmlName is not None: if self.version==3: portInterface = ParameterInterface(xmlName.text) if xmlRoot.find("./IS-SERVICE").text == 'true': portInterface.isService = True for xmlElem in xmlRoot.findall('./CALPRM-ELEMENTS/CALPRM-ELEMENT-PROTOTYPE'): xmlElemName = xmlElem.find("./SHORT-NAME") if xmlElemName is not None: typeRef=xmlElem.find("./TYPE-TREF").text dataElem = DataElement(xmlElemName.text,typeRef,parent=portInterface) if hasAdminData(xmlElem): dataElem.adminData=parseAdminDataNode(xmlElem.find('ADMIN-DATA')) if xmlElem.find('SW-DATA-DEF-PROPS'): for xmlItem in xmlElem.find('SW-DATA-DEF-PROPS/SW-ADDR-METHOD-REF'): dataElem.swAddrMethodRef.append(xmlItem.text) portInterface.dataElements.append(dataElem) return portInterface
def parseDataConstraint(self, xmlRoot, parent=None): assert (xmlRoot.tag == 'DATA-CONSTR') name = xmlRoot.find("./SHORT-NAME").text rules = [] for xmlItem in xmlRoot.findall( './DATA-CONSTR-RULES/DATA-CONSTR-RULE/*'): if xmlItem.tag == 'INTERNAL-CONSTRS': lowerLimitXML = xmlItem.find('./LOWER-LIMIT') upperLimitXML = xmlItem.find('./UPPER-LIMIT') lowerLimit = parseTextNode(lowerLimitXML) upperLimit = parseTextNode(upperLimitXML) lowerLimitType = 'CLOSED' upperLimitType = 'CLOSED' if lowerLimitXML.attrib['INTERVAL-TYPE'] == 'OPEN': lowerLimitType = 'OPEN' if upperLimitXML.attrib['INTERVAL-TYPE'] == 'OPEN': upperLimitType = 'OPEN' try: lowerLimit = int(lowerLimit) except ValueError: lowerLimit = str(lowerLimit) try: upperLimit = int(upperLimit) except ValueError: upperLimit = str(upperLimit) rules.append({ 'type': 'internalConstraint', 'lowerLimit': lowerLimit, 'upperLimit': upperLimit, 'lowerLimitType': lowerLimitType, 'upperLimitType': upperLimitType, }) else: raise NotImplementedError(xmlItem.tag) elem = DataConstraint(name, rules, parent) if hasAdminData(xmlRoot): elem.adminData = parseAdminDataNode(xmlRoot.find('ADMIN-DATA')) return elem
def parseComponentPorts(self, componentType, xmlRoot): xmlPorts = xmlRoot.find('PORTS') assert (xmlPorts is not None) for xmlPort in xmlPorts.findall('*'): if (xmlPort.tag == "R-PORT-PROTOTYPE"): portName = xmlPort.find('SHORT-NAME').text portInterfaceRef = self.parseTextNode( xmlPort.find('REQUIRED-INTERFACE-TREF')) port = autosar.port.RequirePort(portName, portInterfaceRef, parent=componentType) if hasAdminData(xmlPort): port.adminData = parseAdminDataNode( xmlPort.find('ADMIN-DATA')) if xmlPort.findall('./REQUIRED-COM-SPECS') is not None: for xmlItem in xmlPort.findall('./REQUIRED-COM-SPECS/*'): if xmlItem.tag == 'CLIENT-COM-SPEC': operationName = _getOperationNameFromComSpec( xmlItem, portInterfaceRef) comspec = autosar.port.OperationComSpec( operationName) port.comspec.append(comspec) elif xmlItem.tag == 'UNQUEUED-RECEIVER-COM-SPEC' or xmlItem.tag == 'NONQUEUED-RECEIVER-COM-SPEC': dataElemName = _getDataElemNameFromComSpec( xmlItem, portInterfaceRef) comspec = autosar.port.DataElementComSpec( dataElemName) if xmlItem.find('./ALIVE-TIMEOUT') is not None: comspec.aliveTimeout = self.parseTextNode( xmlItem.find('./ALIVE-TIMEOUT')) if self.version >= 4.0: xmlElem = xmlItem.find('./INIT-VALUE') if xmlElem != None: for xmlChild in xmlElem.findall('./*'): if xmlChild.tag == 'CONSTANT-REFERENCE': comspec.initValueRef = self.parseTextNode( xmlChild.find( './CONSTANT-REF')) else: values = self.constant_parser.parseValueV4( xmlElem, None) if len(values) != 1: raise ValueError( 'INIT-VALUE cannot cannot contain multiple elements' ) comspec.initValue = values[0] else: if xmlItem.find('./INIT-VALUE-REF') != None: comspec.initValueRef = self.parseTextNode( xmlItem.find('./INIT-VALUE-REF')) port.comspec.append(comspec) elif xmlItem.tag == 'QUEUED-RECEIVER-COM-SPEC': dataElemName = _getDataElemNameFromComSpec( xmlItem, portInterfaceRef) comspec = autosar.port.DataElementComSpec( dataElemName) if xmlItem.find('./QUEUE-LENGTH') != None: comspec.queueLength = self.parseTextNode( xmlItem.find('./QUEUE-LENGTH')) port.comspec.append(comspec) elif xmlItem.tag == 'MODE-SWITCH-RECEIVER-COM-SPEC': comspec = self._parseModeSwitchReceiverComSpec( xmlItem) port.comspec.append(comspec) elif xmlItem.tag == 'PARAMETER-REQUIRE-COM-SPEC': comspec = self._parseParameterComSpec( xmlItem, portInterfaceRef) port.comspec.append(comspec) else: raise NotImplementedError(xmlItem.tag) componentType.requirePorts.append(port) elif (xmlPort.tag == 'P-PORT-PROTOTYPE'): portName = xmlPort.find('SHORT-NAME').text portInterfaceRef = self.parseTextNode( xmlPort.find('PROVIDED-INTERFACE-TREF')) port = autosar.port.ProvidePort(portName, portInterfaceRef, parent=componentType) if hasAdminData(xmlPort): port.adminData = parseAdminDataNode( xmlPort.find('ADMIN-DATA')) if xmlPort.findall('./PROVIDED-COM-SPECS') is not None: for xmlItem in xmlPort.findall('./PROVIDED-COM-SPECS/*'): if xmlItem.tag == 'SERVER-COM-SPEC': operationName = _getOperationNameFromComSpec( xmlItem, portInterfaceRef) comspec = autosar.port.OperationComSpec( operationName) comspec.queueLength = self.parseIntNode( xmlItem.find('QUEUE-LENGTH')) port.comspec.append(comspec) elif xmlItem.tag == 'UNQUEUED-SENDER-COM-SPEC' or xmlItem.tag == 'NONQUEUED-SENDER-COM-SPEC': dataElemName = _getDataElemNameFromComSpec( xmlItem, portInterfaceRef) comspec = autosar.port.DataElementComSpec( dataElemName) if self.version >= 4.0: xmlElem = xmlItem.find('./INIT-VALUE') if xmlElem != None: for xmlChild in xmlElem.findall('./*'): if xmlChild.tag == 'CONSTANT-REFERENCE': comspec.initValueRef = self.parseTextNode( xmlChild.find( './CONSTANT-REF')) else: values = self.constant_parser.parseValueV4( xmlElem, None) if len(values) != 1: raise ValueError( 'INIT-VALUE cannot cannot contain multiple elements' ) comspec.initValue = values[0] else: if xmlItem.find( './INIT-VALUE-REF') is not None: comspec.initValueRef = self.parseTextNode( xmlItem.find('./INIT-VALUE-REF')) if xmlItem.find('./CAN-INVALIDATE') != None: comspec.canInvalidate = True if self.parseTextNode( xmlItem.find('./CAN-INVALIDATE') ) == 'true' else False port.comspec.append(comspec) elif xmlItem.tag == 'QUEUED-SENDER-COM-SPEC': dataElemName = _getDataElemNameFromComSpec( xmlItem, portInterfaceRef) comspec = autosar.port.DataElementComSpec( dataElemName) assert (comspec is not None) port.comspec.append(comspec) elif xmlItem.tag == 'PARAMETER-PROVIDE-COM-SPEC': comspec = self._parseParameterComSpec( xmlItem, portInterfaceRef) assert (comspec is not None) port.comspec.append(comspec) elif xmlItem.tag == 'MODE-SWITCH-SENDER-COM-SPEC': comspec = self._parseModeSwitchSenderComSpec( xmlItem) assert (comspec is not None) port.comspec.append(comspec) else: raise NotImplementedError(xmlItem.tag) componentType.providePorts.append(port)
def parseCompuMethod(self,xmlRoot,parent=None): assert (xmlRoot.tag == 'COMPU-METHOD') name = parseTextNode(xmlRoot.find("./SHORT-NAME")) category = parseTextNode(xmlRoot.find("./CATEGORY")) unitRef = xmlRoot.find("./UNIT-REF") semanticsType = None semanticElements=[] if hasAdminData(xmlRoot): adminData=parseAdminDataNode(xmlRoot.find('ADMIN-DATA')) else: adminData=None xmlCompuScales = xmlRoot.findall('./COMPU-INTERNAL-TO-PHYS/COMPU-SCALES/COMPU-SCALE') if xmlCompuScales is None: raise NotImplementedError("No COMPU-SCALE? item=%s"%name) else: for xmlItem in xmlCompuScales: rational = xmlItem.find('./COMPU-RATIONAL-COEFFS') const = xmlItem.find('./COMPU-CONST') label = self.parseTextNode(xmlItem.find('./SHORT-LABEL')) mask = self.parseIntNode(xmlItem.find('./MASK')) symbol = self.parseTextNode(xmlItem.find('./SYMBOL')) if rational is not None: if (semanticsType is not None) and (semanticsType !='compuRational'): raise NotImplementedError('mixed compuscales not supported, item=%s'%name) else: semanticsType='compuRational' v=rational.findall('./COMPU-NUMERATOR/V') offset=v[0].text numerator=v[1].text denominator=rational.find('./COMPU-DENOMINATOR/V').text semanticElements.append({'offset':offset, 'numerator':numerator, 'denominator':denominator, 'label':label, 'symbol': symbol}) if const is not None: if (semanticsType is not None) and (semanticsType !='compuConst'): raise NotImplementedError('mixed compuscales not supported, item=%s'%name) else: semanticsType='compuConst' lowerLimit = parseTextNode(xmlItem.find('./LOWER-LIMIT')) upperLimit = parseTextNode(xmlItem.find('./UPPER-LIMIT')) textValue = parseTextNode(const.find('./VT')) semanticElements.append({'lowerLimit':int(lowerLimit),'upperLimit':int(upperLimit), 'textValue': textValue, 'label': label, 'symbol': symbol}) if mask is not None: if (semanticsType is not None) and (semanticsType !='compuMask'): raise NotImplementedError('mixed compuscales not supported, item=%s'%name) else: semanticsType='compuMask' lowerLimit = parseTextNode(xmlItem.find('./LOWER-LIMIT')) upperLimit = parseTextNode(xmlItem.find('./UPPER-LIMIT')) semanticElements.append({'lowerLimit':int(lowerLimit),'upperLimit':int(upperLimit), 'mask': mask, 'label': label, 'symbol': symbol}) if semanticsType == 'compuRational': if unitRef is not None: unitRef=unitRef.text method=CompuMethodRational(name, unitRef, semanticElements, category=category, adminData=adminData) return method elif semanticsType == 'compuConst': method = CompuMethodConst(name, semanticElements, category=category, adminData=adminData) return method elif semanticsType == 'compuMask': method = CompuMethodMask(name, semanticElements, category=category, adminData=adminData) return method else: raise ValueError("unprocessed semanticsType,item=%s"%name)
def parseCompuMethod(self, xmlRoot, parent=None): assert (xmlRoot.tag == 'COMPU-METHOD') name = parseTextNode(xmlRoot.find("./SHORT-NAME")) category = parseTextNode(xmlRoot.find("./CATEGORY")) unitRef = xmlRoot.find("./UNIT-REF") semanticsType = None semanticElements = [] if hasAdminData(xmlRoot): adminData = parseAdminDataNode(xmlRoot.find('ADMIN-DATA')) else: adminData = None xmlCompuScales = xmlRoot.findall( './COMPU-INTERNAL-TO-PHYS/COMPU-SCALES/COMPU-SCALE') if xmlCompuScales is None: raise NotImplementedError("No COMPU-SCALE? item=%s" % name) else: for xmlItem in xmlCompuScales: rational = xmlItem.find('./COMPU-RATIONAL-COEFFS') const = xmlItem.find('./COMPU-CONST') label = self.parseTextNode(xmlItem.find('./SHORT-LABEL')) mask = self.parseIntNode(xmlItem.find('./MASK')) symbol = self.parseTextNode(xmlItem.find('./SYMBOL')) if rational is not None: if (semanticsType is not None) and (semanticsType != 'compuRational'): raise NotImplementedError( 'mixed compuscales not supported, item=%s' % name) else: semanticsType = 'compuRational' v = rational.findall('./COMPU-NUMERATOR/V') offset = v[0].text numerator = v[1].text denominator = rational.find( './COMPU-DENOMINATOR/V').text semanticElements.append({ 'offset': offset, 'numerator': numerator, 'denominator': denominator, 'label': label, 'symbol': symbol }) if const is not None: if (semanticsType is not None) and (semanticsType != 'compuConst'): raise NotImplementedError( 'mixed compuscales not supported, item=%s' % name) else: semanticsType = 'compuConst' lowerLimit = parseTextNode( xmlItem.find('./LOWER-LIMIT')) upperLimit = parseTextNode( xmlItem.find('./UPPER-LIMIT')) textValue = parseTextNode(const.find('./VT')) semanticElements.append({ 'lowerLimit': int(lowerLimit), 'upperLimit': int(upperLimit), 'textValue': textValue, 'label': label, 'symbol': symbol }) if mask is not None: if (semanticsType is not None) and (semanticsType != 'compuMask'): raise NotImplementedError( 'mixed compuscales not supported, item=%s' % name) else: semanticsType = 'compuMask' lowerLimit = parseTextNode( xmlItem.find('./LOWER-LIMIT')) upperLimit = parseTextNode( xmlItem.find('./UPPER-LIMIT')) semanticElements.append({ 'lowerLimit': int(lowerLimit), 'upperLimit': int(upperLimit), 'mask': mask, 'label': label, 'symbol': symbol }) if semanticsType == 'compuRational': if unitRef is not None: unitRef = unitRef.text method = CompuMethodRational(name, unitRef, semanticElements, category=category, adminData=adminData) return method elif semanticsType == 'compuConst': method = CompuMethodConst(name, semanticElements, category=category, adminData=adminData) return method elif semanticsType == 'compuMask': method = CompuMethodMask(name, semanticElements, category=category, adminData=adminData) return method else: raise ValueError("unprocessed semanticsType,item=%s" % name)