223 lines
8.7 KiB
Python
223 lines
8.7 KiB
Python
import struct
|
|
|
|
class msg_CcuStateFbMsg:
|
|
def __init__(self):
|
|
self.start1 = 0x20
|
|
self.start2 = 0x20
|
|
self.id = 0x0051
|
|
self.length = 0x0000
|
|
self.currentWorkCondition = 0x00
|
|
self.fcuState = 0x01
|
|
self.fcuFaultLeve = 0x20
|
|
self.powerLimit = 0x00
|
|
self.totalPowerGeneration = 0x00
|
|
self.ch4o = 0x00
|
|
self.o2 = 0x00
|
|
self.fcuVoltage = 0x00
|
|
self.fcuCurrent = 0x00
|
|
self.o2Level = 0x00
|
|
self.placeholder1 = 0x00
|
|
self.exchangerTemperature = 0x00
|
|
self.fcuOutPower = 0x00
|
|
self.fcuOutIns = 0x00
|
|
self.fcuVoltageIns = 0x00
|
|
self.fcuVoltagePower = 0x00
|
|
self.fcuCurrentIns = 0x00
|
|
self.fcuCurrentPower = 0x00
|
|
self.h2Concentration1 = 0x00
|
|
self.h2Concentration2 = 0x00
|
|
self.o2Concentration1 = 0x00
|
|
self.o2Concentration2 = 0x00
|
|
self.ch4oConcentration1 = 0x00
|
|
self.ch4oConcentration2 = 0x00
|
|
self.backpressure1 = 0x00
|
|
self.backpressure2 = 0x00
|
|
self.flameDetection = 0x00
|
|
self.fcuGZ_1L = 0x00
|
|
self.fcuGZ_1H = 0x00
|
|
self.fcuGZ_2L = 0x00
|
|
self.fcuGZ_2H = 0x00
|
|
self.fcuGZ_3L = 0x00
|
|
self.fcuGZ_3H = 0x00
|
|
self.insPosRelayState = 0x00
|
|
self.insNegRelayState = 0x00
|
|
self.powerPosRelayState = 0x00
|
|
self.powerNegRelayState = 0x00
|
|
self.insBatLimit = 0x00
|
|
self.powerBatLimit = 0x00
|
|
self.insBatSoc = 0x00
|
|
self.powerBatSoc = 0x00
|
|
self.insBatTotalElectricity = 0x00
|
|
self.powerBatTotalElectricity = 0x00
|
|
self.insBatCurrentElectricity = 0x00
|
|
self.powerBatCurrentElectricity = 0x00
|
|
self.insChargeState = 0x00
|
|
self.powerChargeState = 0x00
|
|
self.insLinkVoltage = 0x00
|
|
self.insPackVoltage = 0x00
|
|
self.insCurrent = 0x00
|
|
self.insPosInsulationResistance = 0x00
|
|
self.insNegInsulationResistance = 0x00
|
|
self.powerLinkVoltage = 0x00
|
|
self.powerPackVoltage = 0x00
|
|
self.powerCurrent = 0x00
|
|
self.powerPosInsulationResistance = 0x00
|
|
self.powerNegInsulationResistance = 0x00
|
|
self.insEmergencyStatusWord = 0x00
|
|
self.powerEmergencyStatusWord = 0x00
|
|
self.insAlarmIdentificationWord = 0x00
|
|
self.powerAlarmIdentificationWord = 0x00
|
|
self.insCurrentSocHold1 = 0x00
|
|
self.insCurrentSocHold2 = 0x00
|
|
self.insCurrentSocHold3 = 0x00
|
|
self.fcuCurrentToInsLimit1 = 0x00
|
|
self.fcuCurrentToinsLimit2 = 0x00
|
|
self.powerCurrentSocHold1 = 0x00
|
|
self.powerCurrentSocHold2 = 0x00
|
|
self.powerCurrentSocHold3 = 0x00
|
|
self.powerCurrentToInsLimit1 = 0x00
|
|
self.powerCurrentToinsLimit2 = 0x00
|
|
self.placeholder2 = 0x00
|
|
self.placeholder3 = 0x00
|
|
self.placeholder4 = 0x00
|
|
self.placeholder5 = 0x00
|
|
self.checkCode = 0x00
|
|
|
|
|
|
|
|
|
|
def pack(self):
|
|
# 初始化数据
|
|
self.length = 0x0000
|
|
self.checkCode = 0x0000
|
|
|
|
data = struct.pack('<B', self.start1)
|
|
data += struct.pack('<B', self.start2)
|
|
data += struct.pack('<H', self.id)
|
|
data += struct.pack('<H', self.length)
|
|
|
|
# 填充数据
|
|
data += struct.pack('<B', self.currentWorkCondition)
|
|
data += struct.pack('<B', self.fcuState)
|
|
data += struct.pack('<B', self.fcuFaultLeve)
|
|
data += struct.pack('<f', self.powerLimit)
|
|
data += struct.pack('<f', self.totalPowerGeneration)
|
|
data += struct.pack('<f', self.ch4o)
|
|
data += struct.pack('<f', self.o2)
|
|
data += struct.pack('<f', self.fcuVoltage)
|
|
data += struct.pack('<f', self.fcuCurrent)
|
|
data += struct.pack('<f', self.o2Level)
|
|
data += struct.pack('<f', self.placeholder1)
|
|
data += struct.pack('<f', self.exchangerTemperature)
|
|
data += struct.pack('<f', self.fcuOutPower)
|
|
data += struct.pack('<f', self.fcuOutIns)
|
|
data += struct.pack('<f', self.fcuVoltageIns)
|
|
data += struct.pack('<f', self.fcuVoltagePower)
|
|
data += struct.pack('<f', self.fcuCurrentIns)
|
|
data += struct.pack('<f', self.fcuCurrentPower)
|
|
data += struct.pack('<f', self.h2Concentration1)
|
|
data += struct.pack('<f', self.h2Concentration2)
|
|
data += struct.pack('<f', self.o2Concentration1)
|
|
data += struct.pack('<f', self.o2Concentration2)
|
|
data += struct.pack('<f', self.ch4oConcentration1)
|
|
data += struct.pack('<f', self.ch4oConcentration2)
|
|
data += struct.pack('<f', self.backpressure1)
|
|
data += struct.pack('<f', self.backpressure2)
|
|
data += struct.pack('<B', self.flameDetection)
|
|
data += struct.pack('<B', self.fcuGZ_1L)
|
|
data += struct.pack('<B', self.fcuGZ_1H)
|
|
data += struct.pack('<B', self.fcuGZ_2L)
|
|
data += struct.pack('<B', self.fcuGZ_2H)
|
|
data += struct.pack('<B', self.fcuGZ_3L)
|
|
data += struct.pack('<B', self.fcuGZ_3H)
|
|
data += struct.pack('<B', self.insPosRelayState)
|
|
data += struct.pack('<B', self.insNegRelayState)
|
|
data += struct.pack('<B', self.powerPosRelayState)
|
|
data += struct.pack('<B', self.powerNegRelayState)
|
|
data += struct.pack('<H', self.insBatLimit)
|
|
data += struct.pack('<H', self.powerBatLimit)
|
|
data += struct.pack('<B', self.insBatSoc)
|
|
data += struct.pack('<B', self.powerBatSoc)
|
|
data += struct.pack('<H', self.insBatTotalElectricity)
|
|
data += struct.pack('<H', self.powerBatTotalElectricity)
|
|
data += struct.pack('<H', self.insBatCurrentElectricity)
|
|
data += struct.pack('<H', self.powerBatCurrentElectricity)
|
|
data += struct.pack('<B', self.insChargeState)
|
|
data += struct.pack('<B', self.powerChargeState)
|
|
data += struct.pack('<H', self.insLinkVoltage)
|
|
data += struct.pack('<H', self.insPackVoltage)
|
|
data += struct.pack('<H', self.insCurrent)
|
|
data += struct.pack('<H', self.insPosInsulationResistance)
|
|
data += struct.pack('<H', self.insNegInsulationResistance)
|
|
data += struct.pack('<H', self.powerLinkVoltage)
|
|
data += struct.pack('<H', self.powerPackVoltage)
|
|
data += struct.pack('<H', self.powerCurrent)
|
|
data += struct.pack('<H', self.powerPosInsulationResistance)
|
|
data += struct.pack('<H', self.powerNegInsulationResistance)
|
|
data += struct.pack('<B', self.insEmergencyStatusWord)
|
|
data += struct.pack('<B', self.powerEmergencyStatusWord)
|
|
data += struct.pack('<B', self.insAlarmIdentificationWord)
|
|
data += struct.pack('<B', self.powerAlarmIdentificationWord)
|
|
data += struct.pack('<B', self.insCurrentSocHold1)
|
|
data += struct.pack('<B', self.insCurrentSocHold2)
|
|
data += struct.pack('<B', self.insCurrentSocHold3)
|
|
data += struct.pack('<B', self.fcuCurrentToInsLimit1)
|
|
data += struct.pack('<B', self.fcuCurrentToinsLimit2)
|
|
data += struct.pack('<B', self.powerCurrentSocHold1)
|
|
data += struct.pack('<B', self.powerCurrentSocHold2)
|
|
data += struct.pack('<B', self.powerCurrentSocHold3)
|
|
data += struct.pack('<B', self.powerCurrentToInsLimit1)
|
|
data += struct.pack('<B', self.powerCurrentToinsLimit2)
|
|
data += struct.pack('<f', self.placeholder2)
|
|
data += struct.pack('<f', self.placeholder3)
|
|
data += struct.pack('<f', self.placeholder4)
|
|
data += struct.pack('<f', self.placeholder5)
|
|
|
|
|
|
for i in range(len(data)):
|
|
self.checkCode += data[i]
|
|
print(self.checkCode)
|
|
|
|
data += struct.pack('<I', self.checkCode)
|
|
|
|
|
|
last_index = len(data)
|
|
print(struct.unpack('<i',data[last_index-4:last_index]))
|
|
|
|
print(len(data))
|
|
|
|
return data
|
|
|
|
|
|
class msg_CcuSetParamFbMsg:
|
|
def __init__(self):
|
|
self.start1 = 0x20
|
|
self.start2 = 0x20
|
|
self.id = 0x0040
|
|
self.length = 10
|
|
self.flag = 0x01
|
|
self.failvreCode = 0x01
|
|
self.checkCode = 0x01 # 初始值,将在 pack 方法中更新
|
|
|
|
def pack(self):
|
|
# 初始化数据
|
|
# self.checkCode = self.start1 + self.start2 + self.id + self.length + self.flag + self.failvreCode
|
|
self.checkCode = 0x0000
|
|
data = struct.pack('<B', self.start1)
|
|
data += struct.pack('<B', self.start2)
|
|
data += struct.pack('<H', self.id)
|
|
data += struct.pack('<H', self.length)
|
|
|
|
# 填充数据
|
|
data += struct.pack('<B', self.flag)
|
|
data += struct.pack('<B', self.failvreCode)
|
|
# 其他参数...
|
|
for i in range(len(data)):
|
|
self.checkCode += data[i]
|
|
data += struct.pack('<I', self.checkCode)
|
|
return data
|
|
|
|
|
|
if __name__ == "__main__":
|
|
msg = msg_CcuStateFbMsg()
|
|
msg.pack() |