增加了通信协议解析的功能

This commit is contained in:
zjk
2024-11-19 09:58:31 +08:00
parent 590662d7a5
commit 4693ce2619
15 changed files with 924 additions and 169 deletions
+129 -130
View File
@@ -5,83 +5,83 @@ class msg_CcuStateFbMsg:
self.start1 = 0x20
self.start2 = 0x20
self.id = 0x0051
self.length = 0x5A
self.currentWorkCondition = 0x01
self.length = 0x0000
self.currentWorkCondition = 0x00
self.fcuState = 0x01
self.fcuFaultLeve = 0x01
self.powerLimit = 0x01
self.totalPowerGeneration = 0x01
self.ch4o = 0x01
self.o2 = 0x01
self.fcuVoltage = 0x01
self.fcuCurrent = 0x01
self.o2Level = 0x01
self.placeholder1 = 0x01
self.exchangerTemperature = 0x01
self.fcuOutPower = 0x01
self.fcuOutIns = 0x01
self.fcuVoltageIns = 0x01
self.fcuVoltagePower = 0x01
self.fcuCurrentIns = 0x01
self.fcuCurrentPower = 0x01
self.h2Concentration1 = 0x01
self.h2Concentration2 = 0x01
self.o2Concentration1 = 0x01
self.o2Concentration2 = 0x01
self.ch4oConcentration1 = 0x01
self.ch4oConcentration2 = 0x01
self.backpressure1 = 0x01
self.backpressure2 = 0x01
self.flameDetection = 0x01
self.fcuGZ_1L = 0x01
self.fcuGZ_1H = 0x01
self.fcuGZ_2L = 0x01
self.fcuGZ_2H = 0x01
self.fcuGZ_3L = 0x01
self.fcuGZ_3H = 0x01
self.insPosRelayState = 0x01
self.insNegRelayState = 0x01
self.powerPosRelayState = 0x01
self.powerNegRelayState = 0x01
self.insBatLimit = 0x01
self.powerBatLimit = 0x01
self.insBatSoc = 0x01
self.powerBatSoc = 0x01
self.insBatTotalElectricity = 0x01
self.powerBatTotalElectricity = 0x01
self.insBatCurrentElectricity = 0x01
self.powerBatCurrentElectricity = 0x01
self.insChargeState = 0x01
self.powerChargeState = 0x01
self.insLinkVoltage = 0x01
self.insPackVoltage = 0x01
self.insCurrent = 0x01
self.insPosInsulationResistance = 0x01
self.insNegInsulationResistance = 0x01
self.powerLinkVoltage = 0x01
self.powerPackVoltage = 0x01
self.powerCurrent = 0x01
self.powerPosInsulationResistance = 0x01
self.powerNegInsulationResistance = 0x01
self.insEmergencyStatusWord = 0x01
self.powerEmergencyStatusWord = 0x01
self.insAlarmIdentificationWord = 0x01
self.powerAlarmIdentificationWord = 0x01
self.insCurrentSocHold1 = 0x01
self.insCurrentSocHold2 = 0x01
self.insCurrentSocHold3 = 0x01
self.fcuCurrentToInsLimit1 = 0x01
self.fcuCurrentToinsLimit2 = 0x01
self.powerCurrentSocHold1 = 0x01
self.powerCurrentSocHold2 = 0x01
self.powerCurrentSocHold3 = 0x01
self.powerCurrentToInsLimit1 = 0x01
self.powerCurrentToinsLimit2 = 0x01
self.placeholder2 = 0x01
self.placeholder3 = 0x01
self.placeholder4 = 0x01
self.placeholder5 = 0x01
self.checkCode = 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
@@ -89,27 +89,7 @@ class msg_CcuStateFbMsg:
def pack(self):
# 初始化数据
self.length = 0x0000
self.checkCode = self.start1 + self.start2 + self.id + self.length
+ self.currentWorkCondition + self.fcuState + self.fcuFaultLeve
+ self.powerLimit + self.totalPowerGeneration + self.ch4o + self.o2
+ self.fcuVoltage + self.fcuCurrent + self.o2Level + self.placeholder1
+ self.exchangerTemperature + self.fcuOutPower + self.fcuOutIns + self.fcuVoltageIns
+ self.fcuVoltagePower + self.fcuCurrentIns + self.fcuCurrentPower + self.h2Concentration1
+ self.h2Concentration2 + self.o2Concentration1 + self.o2Concentration2 + self.ch4oConcentration1
+ self.ch4oConcentration2 + self.backpressure1 + self.backpressure2 + self.flameDetection + self.fcuGZ_1L
+ self.fcuGZ_1H + self.fcuGZ_2L + self.fcuGZ_2H + self.fcuGZ_3L + self.fcuGZ_3H + self.insPosRelayState
+ self.insNegRelayState + self.powerPosRelayState + self.powerNegRelayState + self.insBatLimit
+ self.powerBatLimit + self.insBatSoc + self.powerBatSoc + self.insBatTotalElectricity
+ self.powerBatTotalElectricity + self.insBatCurrentElectricity + self.powerBatCurrentElectricity
+ self.insChargeState + self.powerChargeState + self.insLinkVoltage + self.insPackVoltage
+ self.insCurrent + self.insPosInsulationResistance + self.insNegInsulationResistance
+ self.powerLinkVoltage + self.powerPackVoltage + self.powerCurrent + self.powerPosInsulationResistance
+ self.powerNegInsulationResistance + self.insEmergencyStatusWord + self.powerEmergencyStatusWord
+ self.insAlarmIdentificationWord + self.powerAlarmIdentificationWord + self.insCurrentSocHold1 + self.insCurrentSocHold2
+ self.insCurrentSocHold3 + self.fcuCurrentToInsLimit1 + self.fcuCurrentToinsLimit2 + self.powerCurrentSocHold1
+ self.powerCurrentSocHold2 + self.powerCurrentSocHold3 + self.powerCurrentToInsLimit1 + self.powerCurrentToinsLimit2
+ self.placeholder2 + self.placeholder3 + self.placeholder4 + self.placeholder5
self.checkCode = 0x0000
data = struct.pack('<B', self.start1)
data += struct.pack('<B', self.start2)
@@ -120,29 +100,29 @@ class msg_CcuStateFbMsg:
data += struct.pack('<B', self.currentWorkCondition)
data += struct.pack('<B', self.fcuState)
data += struct.pack('<B', self.fcuFaultLeve)
data += struct.pack('<I', self.powerLimit)
data += struct.pack('<I', self.totalPowerGeneration)
data += struct.pack('<I', self.ch4o)
data += struct.pack('<I', self.o2)
data += struct.pack('<I', self.fcuVoltage)
data += struct.pack('<I', self.fcuCurrent)
data += struct.pack('<I', self.o2Level)
data += struct.pack('<I', self.placeholder1)
data += struct.pack('<I', self.exchangerTemperature)
data += struct.pack('<I', self.fcuOutPower)
data += struct.pack('<I', self.fcuOutIns)
data += struct.pack('<I', self.fcuVoltageIns)
data += struct.pack('<I', self.fcuVoltagePower)
data += struct.pack('<I', self.fcuCurrentIns)
data += struct.pack('<I', self.fcuCurrentPower)
data += struct.pack('<I', self.h2Concentration1)
data += struct.pack('<I', self.h2Concentration2)
data += struct.pack('<I', self.o2Concentration1)
data += struct.pack('<I', self.o2Concentration2)
data += struct.pack('<I', self.ch4oConcentration1)
data += struct.pack('<I', self.ch4oConcentration2)
data += struct.pack('<I', self.backpressure1)
data += struct.pack('<I', self.backpressure2)
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)
@@ -188,14 +168,26 @@ class msg_CcuStateFbMsg:
data += struct.pack('<B', self.powerCurrentSocHold3)
data += struct.pack('<B', self.powerCurrentToInsLimit1)
data += struct.pack('<B', self.powerCurrentToinsLimit2)
data += struct.pack('<I', self.placeholder2)
data += struct.pack('<I', self.placeholder3)
data += struct.pack('<I', self.placeholder4)
data += struct.pack('<I', self.placeholder5)
data += struct.pack('<H', self.checkCode)
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
import struct
class msg_CcuSetParamFbMsg:
def __init__(self):
@@ -209,8 +201,8 @@ class msg_CcuSetParamFbMsg:
def pack(self):
# 初始化数据
self.checkCode = self.start1 + self.start2 + self.id + self.length + self.flag + self.failvreCode
# 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)
@@ -220,5 +212,12 @@ class msg_CcuSetParamFbMsg:
data += struct.pack('<B', self.flag)
data += struct.pack('<B', self.failvreCode)
# 其他参数...
data += struct.pack('<H', self.checkCode)
return data
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()