def buildCanOutputParam(xpar): paramNameValue = xpar.attrib["paramNameValue"] paramNameStatus = xpar.attrib["paramNameStatus"] paramType = xpar.attrib["paramType"] signal = "" count = 0 for xdest in xpar.iterfind("destination"): sigtype = xdest.attrib["type"] access = int(xdest.attrib["access"]) byteoffset = int(xdest.attrib["offset"]) bitlen = int(xdest.attrib["bits"]) lsb = int(xdest.attrib["lsb"]) scale = float(xdest.attrib["lsbvalue"]) if sigtype == "VALIDITY": encoding = IOM.SIGOUTTYPE_VALIDITY_STATUS else: key = (sigtype, access, paramType) encoding = encoding_table_output.get(key) if encoding is None: raise Exception, "Bad parameter-signal type combination for %s: %s" % (paramNameValue, str(key)) signal += struct.pack(ENDIAN + "Iihhf", byteoffset, bitlen, lsb, encoding, scale) count += 1 param = struct.pack (ENDIAN + "iihhiiLLL", int(xpar.attrib["paramOffsetValue"]), int(xpar.attrib["paramOffsetStatus"]), count, # number of destinations to write to 0, # spare 0 stringtable.append(paramNameValue), stringtable.append(paramNameStatus), 0, 0, 0 # no min, max or default for output params ) if count == 1: # Only one destination, add a second dummy destination so all CAN configs are the same size signal += struct.pack(ENDIAN + "Iihhf", 0, 0, 0, 0, 0) count += 1 if count != 2: raise Exception, "Bad number of CAN Output destinations (min 1, max 2) %s: %s" % (paramNameValue, str(count)) return param + signal
def buildParam(xmlparam): ''' Build one parameter config structure from XML ''' paramType = xmlparam.attrib['paramType'] paramName = xmlparam.attrib['paramNameValue'] valueOffset = int(xmlparam.attrib["paramOffsetValue"]) statusOffset = int(xmlparam.attrib["paramOffsetStatus"]) valueNameOffset = stringtable.append(xmlparam.attrib["paramNameValue"]) statusNameOffset = stringtable.append(xmlparam.attrib["paramNameStatus"]) param = struct.pack( ENDIAN + "iihhiiiii", valueOffset, statusOffset, 1, # always one destination 0, # padding valueNameOffset, statusNameOffset, 0, # Min value not used 0, # Max value not used 0) # default value not used x = xmlparam.find('destination') sigType = x.attrib["type"] sigAccess = int(x.attrib["access"]) byteoffset = messageBufferOffset(x.attrib["message"], int(x.attrib["offset"])) bitlen = int(x.attrib["bits"]) lsb = int(x.attrib["lsb"]) scale = float(x.attrib["lsbvalue"]) key = (sigType, sigAccess, paramType) encoding = encoding_table.get(key) if encoding is None: raise Exception, "Illegal combination of signal and parameter types for %s: %s" % ( paramName, str(key)) signal = struct.pack(ENDIAN + "Iihhf", byteoffset, bitlen, lsb, encoding, scale) return param + signal
def buildParam(xmlparam): ''' Build one parameter config structure from XML ''' paramType = xmlparam.attrib['paramType'] paramName = xmlparam.attrib['paramNameValue'] valueOffset = int(xmlparam.attrib["paramOffsetValue"]) statusOffset = int(xmlparam.attrib["paramOffsetStatus"]) valueNameOffset = stringtable.append(xmlparam.attrib["paramNameValue"]) statusNameOffset = stringtable.append(xmlparam.attrib["paramNameStatus"]) param = struct.pack(ENDIAN + "iihhiiiii", valueOffset, statusOffset, 1, # always one destination 0, # padding valueNameOffset, statusNameOffset, 0, # Min value not used 0, # Max value not used 0) # default value not used x = xmlparam.find('destination') sigType = x.attrib["type"] sigAccess = int(x.attrib["access"]) byteoffset = messageBufferOffset(x.attrib["message"], int(x.attrib["offset"])) bitlen = int(x.attrib["bits"]) lsb = int(x.attrib["lsb"]) scale = float(x.attrib["lsbvalue"]) key = (sigType, sigAccess, paramType) encoding = encoding_table.get(key) if encoding is None: raise Exception, "Illegal combination of signal and parameter types for %s: %s" % (paramName, str(key)) signal = struct.pack(ENDIAN + "Iihhf", byteoffset, bitlen, lsb, encoding, scale) return param + signal
def buildAfdxOutputMessage(xmlmsg): ''' Fill the structure UInt32_t messageId; // Message ID from XML Configuration UInt32_t messageLength; // Length of message payload (what is read from port) UInt32_t queueLength; // Queue Length, 0 for Sampling UInt32_t messageRate; // expected update rate of message in ms UInt32_t messageHdrOffset; // Offset in message buffer UInt32_t portId; // Whatever that is on the platform UInt32_t portNameOffset; // Offset of port Name (or CVT name) into string table ''' global message_offset global message_dict msgid = int(xmlmsg.attrib["id"]) msglen = int(xmlmsg.attrib["length"]) rate = int(xmlmsg.attrib["rate"]) porttype = xmlmsg.attrib["portType"] if porttype[0] == "Q": queuelen = int(xmlmsg.attrib["queueLength"]) else: queuelen = 0 if message_dict.has_key(msgid): raise Exception, "Duplicate message id: %d" % msgid message_dict[msgid] = message_offset out = struct.pack(ENDIAN + "iiiiii", msgid, msglen, queuelen, rate, message_offset, stringtable.append(xmlmsg.attrib["portName"])) # increment message offset: message length padded to IOM.MESSAGE_PADDING bytes blocklen = (msglen + IOM.A664_MESSAGE_PADDING - 1) & ~(IOM.A664_MESSAGE_PADDING-1) message_offset += blocklen return out
def buildAfdxOutputMessage(xmlmsg): ''' Fill the structure UInt32_t messageId; // Message ID from XML Configuration UInt32_t messageLength; // Length of message payload (what is read from port) UInt32_t queueLength; // Queue Length, 0 for Sampling UInt32_t messageRate; // expected update rate of message in ms UInt32_t messageHdrOffset; // Offset in message buffer UInt32_t portId; // Whatever that is on the platform UInt32_t portNameOffset; // Offset of port Name (or CVT name) into string table ''' global message_offset global message_dict msgid = int(xmlmsg.attrib["id"]) msglen = int(xmlmsg.attrib["length"]) rate = int(xmlmsg.attrib["rate"]) porttype = xmlmsg.attrib["portType"] if porttype[0] == "Q": queuelen = int(xmlmsg.attrib["queueLength"]) else: queuelen = 0 if message_dict.has_key(msgid): raise Exception, "Duplicate message id: %d" % msgid message_dict[msgid] = message_offset out = struct.pack(ENDIAN + "iiiiii", msgid, msglen, queuelen, rate, message_offset, stringtable.append(xmlmsg.attrib["portName"])) # increment message offset: message length padded to IOM.MESSAGE_PADDING bytes blocklen = (msglen + IOM.A664_MESSAGE_PADDING - 1) & ~(IOM.A664_MESSAGE_PADDING - 1) message_offset += blocklen return out
def buildCanInputParam(xpar): paramNameValue = xpar.attrib["paramNameValue"] paramNameStatus = xpar.attrib["paramNameStatus"] paramType = xpar.attrib["paramType"] validity = xpar.find("validity") if validity is not None: nofInputs = 2 else: nofInputs = 1 # Get optional min / max / default values if paramType == "FLOAT": # Get min / max / default values as float, setting default values if they are not present minVal = float(xpar.get("paramMin", 0.0)) maxVal = float(xpar.get("paramMax", IOM.MAX_VALUE_FLOAT32)) defVal = float(xpar.get("paramDefault", 0.0)) param = struct.pack (ENDIAN + "iihhiifff", int(xpar.attrib["paramOffsetValue"]), int(xpar.attrib["paramOffsetStatus"]), nofInputs, 0, stringtable.append(paramNameValue), stringtable.append(paramNameStatus), minVal, maxVal, defVal ) else: # Get min / max / default values as integer, setting default values if they are not present minValInt = int(xpar.get("paramMin", 0)) maxValInt = int(xpar.get("paramMax", IOM.MAX_VALUE_UTINT32)) defValInt = int(xpar.get("paramDefault", 0)) param = struct.pack (ENDIAN + "iihhiiLLL", int(xpar.attrib["paramOffsetValue"]), int(xpar.attrib["paramOffsetStatus"]), nofInputs, 0, stringtable.append(paramNameValue), stringtable.append(paramNameStatus), minValInt, maxValInt, defValInt ) x = xpar.find('source') sigtype = x.attrib["type"] access = int(x.attrib["access"]) byteoffset = int(x.attrib["offset"]) bitlen = int(x.attrib["bits"]) lsb = int(x.attrib["lsb"]) scale = float(x.attrib["lsbvalue"]) key = (sigtype, access, paramType) encoding = encoding_table_input.get(key) if encoding is None: raise Exception, "Bad parameter-signal type combination for %s: %s" % (paramNameValue, str(key)) signal = struct.pack(ENDIAN + "Iihhf", byteoffset, bitlen, lsb, encoding, scale) validity = xpar.find("validity") if validity is not None: # NB: always a Boolean encoding = IOM.SIGINTYPE_BOOL byteoffset = int(validity.attrib["offset"]) bitlen = 1 lsb = int(validity.attrib["lsb"]) scale = 1.0 validitySignal = struct.pack(ENDIAN + "Iihhf", byteoffset, bitlen, lsb, encoding, scale) else: # Validity not used, add a dummy struct validitySignal = struct.pack(ENDIAN + "Iihhf", 0, 0, 0, 0, 0.0) return param + signal + validitySignal
def buildParam(xmlparam, numsources): ''' Build one parameter config structure from XML ''' paramsources = 0 param = "" paramType = xmlparam.attrib['paramType'] paramName = xmlparam.attrib['paramNameValue'] for x in xmlparam.iterfind("source"): sigType = x.attrib["type"] sigAccess = int(x.attrib["access"]) byteoffset = messageOffset(x.attrib["message"], int(x.attrib["offset"])) bitlen = int(x.attrib["bits"]) lsb = int(x.attrib["lsb"]) scale = float(x.attrib["lsbvalue"]) key = (sigType, sigAccess, paramType) encoding = encoding_table.get(key) if encoding is None: raise Exception, "Bad parameter-signal type combination for %s: %s" % ( paramName, str(key)) source = struct.pack(ENDIAN + "Iihhf", byteoffset, bitlen, lsb, encoding, scale) paramsources += 1 param += source if paramsources != numsources: raise Exception, "Number of sources mismatch: Logic:%d Parameter:%d" % ( numsources, paramsources) valueOffset = int(xmlparam.attrib["paramOffsetValue"]) statusOffset = int(xmlparam.attrib["paramOffsetStatus"]) valueNameOffset = stringtable.append(xmlparam.attrib["paramNameValue"]) statusNameOffset = stringtable.append(xmlparam.attrib["paramNameStatus"]) # Get optional min / max / default values if paramType == "FLOAT": # Get min / max / default values as 32 bit float minVal = -IOM.MAX_VALUE_FLOAT32 maxVal = IOM.MAX_VALUE_FLOAT32 defVal = 0.0 if xmlparam.get("paramMin"): minVal = float(xmlparam.attrib["paramMin"]) if xmlparam.get("paramMax"): maxVal = float(xmlparam.attrib["paramMax"]) if xmlparam.get("paramDefault"): defVal = float(xmlparam.attrib["paramDefault"]) hdr = struct.pack(ENDIAN + "iihhiifff", valueOffset, statusOffset, paramsources, 0, valueNameOffset, statusNameOffset, minVal, maxVal, defVal) else: # Get min / max / default values as 32 integers minValInt = 0 maxValInt = IOM.MAX_VALUE_UTINT32 defValInt = 0 if xmlparam.get("paramMin"): minValInt = ctypes.c_ulong(int(xmlparam.attrib["paramMin"])).value if xmlparam.get("paramMax"): maxValInt = ctypes.c_ulong(int(xmlparam.attrib["paramMax"])).value if xmlparam.get("paramDefault"): defValInt = ctypes.c_ulong(int( xmlparam.attrib["paramDefault"])).value hdr = struct.pack(ENDIAN + "iihhiiLLL", valueOffset, statusOffset, paramsources, 0, valueNameOffset, statusNameOffset, minValInt, maxValInt, defValInt) return hdr + param