修复了UDP通信的BUG并优化了相关代码,增加了json报告功能

This commit is contained in:
zjk
2024-11-23 17:28:51 +08:00
parent abd91d0e88
commit 6374e60b91
14 changed files with 881 additions and 464 deletions
+466 -8
View File
@@ -26,6 +26,13 @@ bool _ListenCB(void * pParam)
PowerManger::PowerManger()
{
workCondition = 0;
currentMod = 0;
powerState = 0;
falutLevel = 0;
soc = 0;
sustainableTime = 0;
faultCode.push_back(0);
}
//---------------------------------------------------------
@@ -86,7 +93,7 @@ bool PowerManger::Iterate()
// 更新当前状态
updatePmState();
updateTime();
buildPowerSysReport();
//输出错误信息
if(!m_udpComm.sError.empty())
{
@@ -224,7 +231,7 @@ bool PowerManger::updatePmState()
if(!m_udpComm.m_qReceiveCcuStateBuffer.empty())
{
double time;
m_udpComm.getCcuStateMsgFromQueue(time,m_CcuCurrentState);
m_udpComm.popMsgFormQueue(time,m_CcuCurrentState);
m_pmCurrentState.ccustate = m_CcuCurrentState.data;
double df;
IsSkewed(time, &df);
@@ -233,25 +240,25 @@ bool PowerManger::updatePmState()
if(!m_udpComm.m_qReceiveDisHighVolBusBuffer.empty())
{
double time;
m_udpComm.getDisSysHVBusFbMsgFromQueue(time,m_disHighVolBusCurrentState);
m_udpComm.popMsgFormQueue(time,m_disHighVolBusCurrentState);
m_pmCurrentState.bus1State = m_disHighVolBusCurrentState.data;
}
if(!m_udpComm.m_qReceiveDisHighAVolBusBuffer.empty())
{
double time;
m_udpComm.getDisSysHVABusFbMsgFromQueue(time,m_disHighAVolBusCurrentState);
m_udpComm.popMsgFormQueue(time,m_disHighAVolBusCurrentState);
m_pmCurrentState.bus2State = m_disHighAVolBusCurrentState.data;
}
if(!m_udpComm.m_qReceiveDisHighBVolBusBuffer.empty())
{
double time;
m_udpComm.getDisSysHVBBusFbMsgFromQueue(time,m_disHighBVolBusCurrentState);
m_udpComm.popMsgFormQueue(time,m_disHighBVolBusCurrentState);
m_pmCurrentState.bus3State = m_disHighBVolBusCurrentState.data;
}
if(!m_udpComm.m_qReceiveDisLowBusBuffer.empty())
{
double time;
m_udpComm.getDisSysLVBusFbMsgFromQueue(time,m_disLowBusState);
m_udpComm.popMsgFormQueue(time,m_disLowBusState);
m_pmCurrentState.bus4State = m_disLowBusState.data;
}
return true;
@@ -268,11 +275,462 @@ bool PowerManger::IsSkewed(double dfTimeNow, double * pdfSkew)
return (dfSkew > SKEW_TOLERANCE) ? true : false;
}
string PowerManger::getTypeName(const string typeName)
{
// 映射类型名称到指定的字符串
if (typeName == "i" || typeName == "c") {
return "_int8";
} else if (typeName == "h" || typeName == "C") {
return "_uint8";
} else if (typeName == "s" || typeName == "S") {
return "_int16";
} else if (typeName == "t" || typeName == "T") {
return "_uint16";
} else if (typeName == "i" || typeName == "I") {
return "_int32";
} else if (typeName == "j" || typeName == "J") {
return "_uint32";
} else if (typeName == "x" || typeName == "X") {
return "_int64";
} else if (typeName == "f" || typeName == "F") {
return "_fp32";
} else if (typeName == "d" || typeName == "D") {
return "_fp64";
} else if (typeName == "b" || typeName == "B") {
return "_bool";
} else if (typeName == "NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE") {
return "_str";
} else if (typeName == "St6vector" || typeName == "St5deque" || typeName == "St4list" || typeName == "St4pair") {
return "_array";
} else {
// 默认情况下,我们假设它是一个对象
return "_obj";
}
}
bool PowerManger::buildPowerSysReport()
{
//TODO: 构建能源系统报告
// string suffix;
// Json::Value json;
string suffix;
Json::Value pms;
Json::Value fcs;
Json::Value lbs;
Json::Value dis;
// 构建能源系统报告
//1.构建系统状态报告
suffix = getTypeName(typeid(workCondition).name());
pms[VAR_TO_STR(workCondition)+suffix] = workCondition;
suffix = getTypeName(typeid(currentMod).name());
pms[VAR_TO_STR(currentMod)+suffix] = currentMod;
suffix = getTypeName(typeid(powerState).name());
pms[VAR_TO_STR(powerState)+suffix] = powerState;
suffix = getTypeName(typeid(falutLevel).name());
pms[VAR_TO_STR(falutLevel)+suffix] = falutLevel;
Json::Value faultCode_array;
for(auto val : faultCode)
{
faultCode_array.append(val);
}
pms[VAR_TO_STR(faultCode_array)] = faultCode_array;
suffix = getTypeName(typeid(soc).name());
pms[VAR_TO_STR(soc)+suffix] = soc;
suffix = getTypeName(typeid(sustainableTime).name());
pms[VAR_TO_STR(sustainableTime)+suffix] = sustainableTime;
//2.构建燃料电池状态报告
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuState).name());
fcs[VAR_TO_STR(fcuState)+suffix] = m_pmCurrentState.ccustate.fcuState;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuFaultLeve).name());
fcs[VAR_TO_STR(fcuFaultLeve)+suffix] = m_pmCurrentState.ccustate.fcuFaultLeve;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerLimit).name());
fcs[VAR_TO_STR(powerLimit)+suffix] = m_pmCurrentState.ccustate.powerLimit;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.totalPowerGeneration).name());
fcs[VAR_TO_STR(totalPowerGeneration)+suffix] = m_pmCurrentState.ccustate.totalPowerGeneration;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.ch4o).name());
fcs[VAR_TO_STR(ch4o)+suffix] = m_pmCurrentState.ccustate.ch4o;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.o2).name());
fcs[VAR_TO_STR(o2)+suffix] = m_pmCurrentState.ccustate.o2;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuVoltage).name());
fcs[VAR_TO_STR(fcuVoltage)+suffix] = m_pmCurrentState.ccustate.fcuVoltage;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuCurrent).name());
fcs[VAR_TO_STR(fcuCurrent)+suffix] = m_pmCurrentState.ccustate.fcuCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.o2Level).name());
fcs[VAR_TO_STR(o2Level)+suffix] = m_pmCurrentState.ccustate.o2Level;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.exchangerTemperature).name());
fcs[VAR_TO_STR(exchangerTemperature)+suffix] = m_pmCurrentState.ccustate.exchangerTemperature;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuOutPower).name());
fcs[VAR_TO_STR(fcuOutPower)+suffix] = m_pmCurrentState.ccustate.fcuOutPower;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuOutIns).name());
fcs[VAR_TO_STR(fcuOutIns)+suffix] = m_pmCurrentState.ccustate.fcuOutIns;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuVoltageIns).name());
fcs[VAR_TO_STR(fcuVoltageIns)+suffix] = m_pmCurrentState.ccustate.fcuVoltageIns;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuVoltagePower).name());
fcs[VAR_TO_STR(fcuVoltagePower)+suffix] = m_pmCurrentState.ccustate.fcuVoltagePower;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuCurrentIns).name());
fcs[VAR_TO_STR(fcuCurrentIns)+suffix] = m_pmCurrentState.ccustate.fcuCurrentIns;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuCurrentPower).name());
fcs[VAR_TO_STR(fcuCurrentPower)+suffix] = m_pmCurrentState.ccustate.fcuCurrentPower;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.h2Concentration1).name());
fcs[VAR_TO_STR(h2Concentration1)+suffix] = m_pmCurrentState.ccustate.h2Concentration1;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.h2Concentration2).name());
fcs[VAR_TO_STR(h2Concentration2)+suffix] = m_pmCurrentState.ccustate.h2Concentration2;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.o2Concentration1).name());
fcs[VAR_TO_STR(o2Concentration1)+suffix] = m_pmCurrentState.ccustate.o2Concentration1;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.o2Concentration2).name());
fcs[VAR_TO_STR(o2Concentration2)+suffix] = m_pmCurrentState.ccustate.o2Concentration2;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.ch4oConcentration1).name());
fcs[VAR_TO_STR(ch4oConcentration1)+suffix] = m_pmCurrentState.ccustate.ch4oConcentration1;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.ch4oConcentration2).name());
fcs[VAR_TO_STR(ch4oConcentration2)+suffix] = m_pmCurrentState.ccustate.ch4oConcentration2;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.backpressure1).name());
fcs[VAR_TO_STR(backpressure1)+suffix] = m_pmCurrentState.ccustate.backpressure1;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.backpressure2).name());
fcs[VAR_TO_STR(backpressure2)+suffix] = m_pmCurrentState.ccustate.backpressure2;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.flameDetection).name());
//4.构建动力锂电池状态报告
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insPosRelayState).name());
lbs[VAR_TO_STR(insPosRelayState)+suffix] = m_pmCurrentState.ccustate.insPosRelayState;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insNegRelayState).name());
lbs[VAR_TO_STR(insNegRelayState)+suffix] = m_pmCurrentState.ccustate.insNegRelayState;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerPosRelayState).name());
lbs[VAR_TO_STR(powerPosRelayState)+suffix] = m_pmCurrentState.ccustate.powerPosRelayState;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerNegRelayState).name());
lbs[VAR_TO_STR(powerNegRelayState)+suffix] = m_pmCurrentState.ccustate.powerNegRelayState;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insBatLimit).name());
lbs[VAR_TO_STR(insBatLimit)+suffix] = m_pmCurrentState.ccustate.insBatLimit;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerBatLimit).name());
lbs[VAR_TO_STR(powerBatLimit)+suffix] = m_pmCurrentState.ccustate.powerBatLimit;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insBatSoc).name());
lbs[VAR_TO_STR(insBatSoc)+suffix] = m_pmCurrentState.ccustate.insBatSoc;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerBatSoc).name());
lbs[VAR_TO_STR(powerBatSoc)+suffix] = m_pmCurrentState.ccustate.powerBatSoc;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insBatTotalElectricity).name());
lbs[VAR_TO_STR(insBatTotalElectricity)+suffix] = m_pmCurrentState.ccustate.insBatTotalElectricity;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerBatTotalElectricity).name());
lbs[VAR_TO_STR(powerBatTotalElectricity)+suffix] = m_pmCurrentState.ccustate.powerBatTotalElectricity;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insBatCurrentElectricity).name());
lbs[VAR_TO_STR(insBatCurrentElectricity)+suffix] = m_pmCurrentState.ccustate.insBatCurrentElectricity;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerBatCurrentElectricity).name());
lbs[VAR_TO_STR(powerBatCurrentElectricity)+suffix] = m_pmCurrentState.ccustate.powerBatCurrentElectricity;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insChargeState).name());
lbs[VAR_TO_STR(insChargeState)+suffix] = m_pmCurrentState.ccustate.insChargeState;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerChargeState).name());
lbs[VAR_TO_STR(powerChargeState)+suffix] = m_pmCurrentState.ccustate.powerChargeState;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insLinkVoltage).name());
lbs[VAR_TO_STR(insLinkVoltage)+suffix] = m_pmCurrentState.ccustate.insLinkVoltage;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insPackVoltage).name());
lbs[VAR_TO_STR(insPackVoltage)+suffix] = m_pmCurrentState.ccustate.insPackVoltage;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insCurrent).name());
lbs[VAR_TO_STR(insCurrent)+suffix] = m_pmCurrentState.ccustate.insCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insPosInsulationResistance).name());
lbs[VAR_TO_STR(insPosInsulationResistance)+suffix] = m_pmCurrentState.ccustate.insPosInsulationResistance;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insNegInsulationResistance).name());
lbs[VAR_TO_STR(insNegInsulationResistance)+suffix] = m_pmCurrentState.ccustate.insNegInsulationResistance;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerLinkVoltage).name());
lbs[VAR_TO_STR(powerLinkVoltage)+suffix] = m_pmCurrentState.ccustate.powerLinkVoltage;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerPackVoltage).name());
lbs[VAR_TO_STR(powerPackVoltage)+suffix] = m_pmCurrentState.ccustate.powerPackVoltage;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerCurrent).name());
lbs[VAR_TO_STR(powerCurrent)+suffix] = m_pmCurrentState.ccustate.powerCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerPosInsulationResistance).name());
lbs[VAR_TO_STR(powerPosInsulationResistance)+suffix] = m_pmCurrentState.ccustate.powerPosInsulationResistance;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerNegInsulationResistance).name());
lbs[VAR_TO_STR(powerNegInsulationResistance)+suffix] = m_pmCurrentState.ccustate.powerNegInsulationResistance;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insCurrentSocHold1).name());
lbs[VAR_TO_STR(insCurrentSocHold1)+suffix] = m_pmCurrentState.ccustate.insCurrentSocHold1;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insCurrentSocHold2).name());
lbs[VAR_TO_STR(insCurrentSocHold2)+suffix] = m_pmCurrentState.ccustate.insCurrentSocHold2;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insCurrentSocHold3).name());
lbs[VAR_TO_STR(insCurrentSocHold3)+suffix] = m_pmCurrentState.ccustate.insCurrentSocHold3;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuCurrentToInsLimit1).name());
lbs[VAR_TO_STR(fcuCurrentToInsLimit1)+suffix] = m_pmCurrentState.ccustate.fcuCurrentToInsLimit1;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuCurrentToinsLimit2).name());
lbs[VAR_TO_STR(fcuCurrentToinsLimit2)+suffix] = m_pmCurrentState.ccustate.fcuCurrentToinsLimit2;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerCurrentSocHold1).name());
lbs[VAR_TO_STR(powerCurrentSocHold1)+suffix] = m_pmCurrentState.ccustate.powerCurrentSocHold1;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerCurrentSocHold2).name());
lbs[VAR_TO_STR(powerCurrentSocHold2)+suffix] = m_pmCurrentState.ccustate.powerCurrentSocHold2;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerCurrentSocHold3).name());
lbs[VAR_TO_STR(powerCurrentSocHold3)+suffix] = m_pmCurrentState.ccustate.powerCurrentSocHold3;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerCurrentToInsLimit1).name());
lbs[VAR_TO_STR(powerCurrentToInsLimit1)+suffix] = m_pmCurrentState.ccustate.powerCurrentToInsLimit1;
suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerCurrentToinsLimit2).name());
lbs[VAR_TO_STR(powerCurrentToinsLimit2)+suffix] = m_pmCurrentState.ccustate.powerCurrentToinsLimit2;
//5.构建配电系统状态报告
disBus1Breaker* pdis1=new disBus1Breaker;
(m_pmCurrentState.bus1State.fuelCellCircuitBreaker == BREAK_ON) ? pdis1 -> fuelCellCircuitBreaker = 1 : pdis1 -> fuelCellCircuitBreaker = 0;
(m_pmCurrentState.bus1State.powerLithiumBatteryCircuitBreaker == BREAK_ON) ? pdis1 -> powerLithiumBatteryCircuitBreaker = 1 : pdis1 -> powerLithiumBatteryCircuitBreaker = 0;
(m_pmCurrentState.bus1State.propulsionMotorCircuitBreaker == BREAK_ON) ? pdis1 -> propulsionMotorCircuitBreaker = 1 : pdis1 -> propulsionMotorCircuitBreaker = 0;
(m_pmCurrentState.bus1State.lithiumBatteryGroupInstrumentCircuitBreaker == BREAK_ON) ? pdis1 -> lithiumBatteryGroupInstrumentCircuitBreaker = 1 : pdis1 -> lithiumBatteryGroupInstrumentCircuitBreaker = 0;
(m_pmCurrentState.bus1State.dcDc5ModuleCircuitBreaker == BREAK_ON) ? pdis1 -> dcDc5ModuleCircuitBreaker = 1 : pdis1 -> dcDc5ModuleCircuitBreaker = 0;
(m_pmCurrentState.bus1State.bowHighVoltageDistributionBoxCircuitBreaker == BREAK_ON) ? pdis1 -> bowHighVoltageDistributionBoxCircuitBreaker = 1 : pdis1 -> bowHighVoltageDistributionBoxCircuitBreaker = 0;
(m_pmCurrentState.bus1State.sternFTDevice45CircuitBreaker == BREAK_ON) ? pdis1 -> sternFTDevice45CircuitBreaker = 1 : pdis1 -> sternFTDevice45CircuitBreaker = 0;
(m_pmCurrentState.bus1State.sternRudderSwitch1CircuitBreaker == BREAK_ON) ? pdis1 -> sternRudderSwitch1CircuitBreaker = 1 : pdis1 -> sternRudderSwitch1CircuitBreaker = 0;
(m_pmCurrentState.bus1State.sternRudderSwitch2CircuitBreaker == BREAK_ON) ? pdis1 -> sternRudderSwitch2CircuitBreaker = 1 : pdis1 -> sternRudderSwitch2CircuitBreaker = 0;
(m_pmCurrentState.bus1State.fbReservedCircuitBreaker == BREAK_ON) ? pdis1 -> fbReservedCircuitBreaker = 1 : pdis1 -> fbReservedCircuitBreaker = 0;
(m_pmCurrentState.bus1State.tyzReservedCircuitBreaker == BREAK_ON) ? pdis1 -> tyzReservedCircuitBreaker = 1 : pdis1 -> tyzReservedCircuitBreaker = 0;
(m_pmCurrentState.bus1State.reservedCircuitBreaker == BREAK_ON) ? pdis1 -> reservedCircuitBreaker = 1 : pdis1 -> reservedCircuitBreaker = 0;
pdis1 -> paceholder = 0;
disBus2Breaker* pdis2=new disBus2Breaker;
(m_pmCurrentState.bus2State.bowFTDevice123CircuitBreaker == BREAK_ON)? pdis2 -> bowFTDevice123CircuitBreaker = 1 : pdis2 -> bowFTDevice123CircuitBreaker = 0;
(m_pmCurrentState.bus2State.actuatorCircuitBreaker == BREAK_ON)? pdis2 -> actuatorCircuitBreaker = 1 : pdis2 -> actuatorCircuitBreaker = 0;
(m_pmCurrentState.bus2State.mastSteeringGearControlBoxCircuitBreaker == BREAK_ON)? pdis2 -> mastSteeringGearControlBoxCircuitBreaker = 1 : pdis2 -> mastSteeringGearControlBoxCircuitBreaker = 0;
(m_pmCurrentState.bus2State.xczCircuitBreaker == BREAK_ON)? pdis2 -> xczCircuitBreaker = 1 : pdis2 -> xczCircuitBreaker = 0;
(m_pmCurrentState.bus2State.bowRudderControlBoxCircuitBreaker == BREAK_ON)? pdis2 -> bowRudderControlBoxCircuitBreaker = 1 : pdis2 -> bowRudderControlBoxCircuitBreaker = 0;
(m_pmCurrentState.bus2State.openWaterCoverStartCylinderCircuitBreaker == BREAK_ON)? pdis2 -> openWaterCoverStartCylinderCircuitBreaker = 1 : pdis2 -> openWaterCoverStartCylinderCircuitBreaker = 0;
pdis2 -> paceholder = 0;
disBus3Breaker* pdis3=new disBus3Breaker;
(m_pmCurrentState.bus3State.lithiumBatteryGroupInstrumentCircuitBreaker == BREAK_ON)? pdis3 -> lithiumBatteryGroupInstrumentCircuitBreaker = 1 : pdis3 -> lithiumBatteryGroupInstrumentCircuitBreaker = 0;
(m_pmCurrentState.bus3State.bowLowVoltageDistributionBoxCircuitBreaker == BREAK_ON)? pdis3 -> bowLowVoltageDistributionBoxCircuitBreaker = 1 : pdis3 -> bowLowVoltageDistributionBoxCircuitBreaker = 0;
(m_pmCurrentState.bus3State.unit4InstrumentDC48VCircuitBreaker == BREAK_ON)? pdis3 -> unit4InstrumentDC48VCircuitBreaker = 1 : pdis3 -> unit4InstrumentDC48VCircuitBreaker = 0;
(m_pmCurrentState.bus3State.dcC1DCDistributionPanelCircuitBreaker == BREAK_ON)? pdis3 -> dcC1DCDistributionPanelCircuitBreaker = 1 : pdis3 -> dcC1DCDistributionPanelCircuitBreaker = 0;
(m_pmCurrentState.bus3State.reservedCircuitBreaker1 == BREAK_ON)? pdis3 -> reservedCircuitBreaker1 = 1 : pdis3 -> reservedCircuitBreaker1 = 0;
(m_pmCurrentState.bus3State.reservedCircuitBreaker2 == BREAK_ON)? pdis3 -> reservedCircuitBreaker2 = 1 : pdis3 -> reservedCircuitBreaker2 = 0;
(m_pmCurrentState.bus3State.emergencyLithiumBatteryGroup2CircuitBreaker == BREAK_ON)? pdis3 -> emergencyLithiumBatteryGroup2CircuitBreaker = 1 : pdis3 -> emergencyLithiumBatteryGroup2CircuitBreaker = 0;
pdis3->paceholder = 0;
disBus4Breaker* pdis4=new disBus4Breaker;
(m_pmCurrentState.bus4State.unit1CircuitBreaker == BREAK_ON)? pdis4 -> unit1CircuitBreaker = 1 : pdis4 -> unit1CircuitBreaker = 0;
(m_pmCurrentState.bus4State.unit2CircuitBreaker == BREAK_ON)? pdis4 -> unit2CircuitBreaker = 1 : pdis4 -> unit2CircuitBreaker = 0;
(m_pmCurrentState.bus4State.unit3CircuitBreaker == BREAK_ON)? pdis4 -> unit3CircuitBreaker = 1 : pdis4 -> unit3CircuitBreaker = 0;
(m_pmCurrentState.bus4State.unit5CircuitBreaker == BREAK_ON)? pdis4 -> unit5CircuitBreaker = 1 : pdis4 -> unit5CircuitBreaker = 0;
(m_pmCurrentState.bus4State.bowPZDeviceCircuitBreaker == BREAK_ON)? pdis4 -> bowPZDeviceCircuitBreaker = 1 : pdis4 -> bowPZDeviceCircuitBreaker = 0;
(m_pmCurrentState.bus4State.reservedCircuitBreaker1 == BREAK_ON)? pdis4 -> reservedCircuitBreaker1 = 1 : pdis4 -> reservedCircuitBreaker1 = 0;
(m_pmCurrentState.bus4State.reservedCircuitBreaker2 == BREAK_ON)? pdis4 -> reservedCircuitBreaker2 = 1 : pdis4 -> reservedCircuitBreaker2 = 0;
(m_pmCurrentState.bus4State.emergencyLithiumBatteryGroup1CircuitBreaker == BREAK_ON)? pdis4 -> emergencyLithiumBatteryGroup1CircuitBreaker = 1 : pdis4 -> emergencyLithiumBatteryGroup1CircuitBreaker = 0;
pdis4 -> paceholder = 0;
dis["HightVoltageBusBreaker_uint16"] = *(unsigned short*) pdis1;
dis["HightVoltageABusBreaker_unit16"] = *(unsigned short*) pdis2;
dis["HightVoltageBBusBreaker_unit16"] = *(unsigned short*) pdis3;
dis["LowVoltageBusBreaker_uint16"] = *(unsigned short*) pdis3;
delete pdis1;
delete pdis2;
delete pdis3;
delete pdis4;
//TODO: 构建配电系统故障码
Json::Value faultCodeDis_array;
for(auto val : faultCode)
{
faultCodeDis_array.append(val);
}
dis[VAR_TO_STR(faultCode_array)] = faultCodeDis_array;
Json::Value currentBusState;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.powerBusVoltage).name());
currentBusState[VAR_TO_STR(HVBpowerBusVoltage)+suffix] = m_pmCurrentState.bus1State.powerBusVoltage;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.dcDc5ModuleCurrent).name());
currentBusState[VAR_TO_STR(HVBdcDc5ModuleCurrent)+suffix] = m_pmCurrentState.bus1State.dcDc5ModuleCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.powerBusCurrent).name());
currentBusState[VAR_TO_STR(HVBpowerBusCurrent)+suffix] = m_pmCurrentState.bus1State.powerBusCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.busbarAVoltage).name());
currentBusState[VAR_TO_STR(HVBbusbarAVoltage)+suffix] = m_pmCurrentState.bus1State.busbarAVoltage;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.propulsionMotorControlBoxCurrent).name());
currentBusState[VAR_TO_STR(HVBpropulsionMotorControlBoxCurrent)+suffix] = m_pmCurrentState.bus1State.propulsionMotorControlBoxCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.busbarACurrent).name());
currentBusState[VAR_TO_STR(HVBbusbarACurrent)+suffix] = m_pmCurrentState.bus1State.busbarACurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.lithiumBatteryGroupMeterCurrent).name());
currentBusState[VAR_TO_STR(HVBlithiumBatteryGroupMeterCurrent)+suffix] = m_pmCurrentState.bus1State.lithiumBatteryGroupMeterCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.bowHighVoltageDistributionBoxCurrent).name());
currentBusState[VAR_TO_STR(HVBbowHighVoltageDistributionBoxCurrent)+suffix] = m_pmCurrentState.bus1State.bowHighVoltageDistributionBoxCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.sternFTDevice45Current).name());
currentBusState[VAR_TO_STR(HVBsternFTDevice45Current)+suffix] = m_pmCurrentState.bus1State.sternFTDevice45Current;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.tyzReservedSwitchCurrent).name());
currentBusState[VAR_TO_STR(HVBtyzReservedSwitchCurrent)+suffix] = m_pmCurrentState.bus1State.tyzReservedSwitchCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.sternRudderSwitch1Current).name());
currentBusState[VAR_TO_STR(HVBsternRudderSwitch1Current)+suffix] = m_pmCurrentState.bus1State.sternRudderSwitch1Current;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.reservedCurrent1).name());
currentBusState[VAR_TO_STR(HVBreservedCurrent1)+suffix] = m_pmCurrentState.bus1State.reservedCurrent1;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.sternRudderSwitch2Current).name());
currentBusState[VAR_TO_STR(HVBsternRudderSwitch2Current)+suffix] = m_pmCurrentState.bus1State.sternRudderSwitch2Current;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.reservedCurrent2).name());
currentBusState[VAR_TO_STR(HVBreservedCurrent2)+suffix] = m_pmCurrentState.bus1State.reservedCurrent2;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.fbReservedSwitchCurrent).name());
currentBusState[VAR_TO_STR(HVBfbReservedSwitchCurrent)+suffix] = m_pmCurrentState.bus1State.fbReservedSwitchCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.reservedCurrent3).name());
currentBusState[VAR_TO_STR(HVBreservedCurrent3)+suffix] = m_pmCurrentState.bus1State.reservedCurrent3;
suffix = getTypeName(typeid(m_pmCurrentState.bus2State.busbarBVoltage).name());
currentBusState[VAR_TO_STR(HVABbusbarBVoltage)+suffix] = m_pmCurrentState.bus2State.busbarBVoltage;
suffix = getTypeName(typeid(m_pmCurrentState.bus2State.busbarBCurrent).name());
currentBusState[VAR_TO_STR(HVABbusbarBCurrent)+suffix] = m_pmCurrentState.bus2State.busbarBCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus2State.bowFTDevice123Current).name());
currentBusState[VAR_TO_STR(HVABbowFTDevice123Current)+suffix] = m_pmCurrentState.bus2State.bowFTDevice123Current;
suffix = getTypeName(typeid(m_pmCurrentState.bus2State.actuatorCurrent).name());
currentBusState[VAR_TO_STR(HVABactuatorCurrent)+suffix] = m_pmCurrentState.bus2State.actuatorCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus2State.mastSteeringGearControlBoxCurrent).name());
currentBusState[VAR_TO_STR(HVABmastSteeringGearControlBoxCurrent)+suffix] = m_pmCurrentState.bus2State.mastSteeringGearControlBoxCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus2State.xczCurrent).name());
currentBusState[VAR_TO_STR(HVABxczCurrent)+suffix] = m_pmCurrentState.bus2State.xczCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus2State.bowRudderControlBoxCurrent).name());
currentBusState[VAR_TO_STR(HVABbowRudderControlBoxCurrent)+suffix] = m_pmCurrentState.bus2State.bowRudderControlBoxCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus2State.openWaterCoverStartCylinderCurrent).name());
currentBusState[VAR_TO_STR(HVABopenWaterCoverStartCylinderCurrent)+suffix] = m_pmCurrentState.bus2State.openWaterCoverStartCylinderCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus3State.instrumentBusbarVoltage).name());
currentBusState[VAR_TO_STR(HVBBinstrumentBusbarVoltage)+suffix] = m_pmCurrentState.bus3State.instrumentBusbarVoltage;
suffix = getTypeName(typeid(m_pmCurrentState.bus3State.bowLowVoltageDistributionBoxCurrent).name());
currentBusState[VAR_TO_STR(HVBBbowLowVoltageDistributionBoxCurrent)+suffix] = m_pmCurrentState.bus3State.bowLowVoltageDistributionBoxCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus3State.dcC1InstrumentDC48VCurrent).name());
currentBusState[VAR_TO_STR(HVBBdcC1InstrumentDC48VCurrent)+suffix] = m_pmCurrentState.bus3State.dcC1InstrumentDC48VCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus3State.reservedCurrent1).name());
currentBusState[VAR_TO_STR(HVBBreservedCurrent1)+suffix] = m_pmCurrentState.bus3State.reservedCurrent1;
suffix = getTypeName(typeid(m_pmCurrentState.bus3State.emergencyLithiumBatteryGroup2Current).name());
currentBusState[VAR_TO_STR(HVBBemergencyLithiumBatteryGroup2Current)+suffix] = m_pmCurrentState.bus3State.emergencyLithiumBatteryGroup2Current;
suffix = getTypeName(typeid(m_pmCurrentState.bus3State.lithiumBatteryGroupInstrumentCurrent).name());
currentBusState[VAR_TO_STR(HVBBlithiumBatteryGroupInstrumentCurrent)+suffix] = m_pmCurrentState.bus3State.lithiumBatteryGroupInstrumentCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus3State.unit4InstrumentDC48VCurrent).name());
currentBusState[VAR_TO_STR(HVBBunit4InstrumentDC48VCurrent)+suffix] = m_pmCurrentState.bus3State.unit4InstrumentDC48VCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus3State.reservedCurrent2).name());
currentBusState[VAR_TO_STR(HVBBreservedCurrent2)+suffix] = m_pmCurrentState.bus3State.reservedCurrent2;
suffix = getTypeName(typeid(m_pmCurrentState.bus3State.emergency2BusbarVoltage).name());
currentBusState[VAR_TO_STR(HVBBemergency2BusbarVoltage)+suffix] = m_pmCurrentState.bus3State.emergency2BusbarVoltage;
suffix = getTypeName(typeid(m_pmCurrentState.bus3State.compositeEnergyManagementSystemEmergencyDC48VCurrent).name());
currentBusState[VAR_TO_STR(HVBBcompositeEnergyManagementSystemEmergencyDC48VCurrent)+suffix] = m_pmCurrentState.bus3State.compositeEnergyManagementSystemEmergencyDC48VCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus3State.fuelCellSecuritySystemEmergencyDC48VCurrent).name());
currentBusState[VAR_TO_STR(HVBBfuelCellSecuritySystemEmergencyDC48VCurrent)+suffix] = m_pmCurrentState.bus3State.fuelCellSecuritySystemEmergencyDC48VCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus3State.plcControlPowerCurrent).name());
currentBusState[VAR_TO_STR(HVBBplcControlPowerCurrent)+suffix] = m_pmCurrentState.bus3State.plcControlPowerCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus4State.instrumentBusbarVoltage).name());
currentBusState[VAR_TO_STR(LVBinstrumentBusbarVoltage)+suffix] = m_pmCurrentState.bus4State.instrumentBusbarVoltage;
suffix = getTypeName(typeid(m_pmCurrentState.bus4State.instrumentBusbarCurrent).name());
currentBusState[VAR_TO_STR(LVBBinstrumentBusbarCurrent)+suffix] = m_pmCurrentState.bus4State.instrumentBusbarCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus4State.unit1Current).name());
currentBusState[VAR_TO_STR(LVBBunit1Current)+suffix] = m_pmCurrentState.bus4State.unit1Current;
suffix = getTypeName(typeid(m_pmCurrentState.bus4State.unit2Current).name());
currentBusState[VAR_TO_STR(LVBBunit2Current)+suffix] = m_pmCurrentState.bus4State.unit2Current;
suffix = getTypeName(typeid(m_pmCurrentState.bus4State.unit3Current).name());
currentBusState[VAR_TO_STR(LVBBunit3Current)+suffix] = m_pmCurrentState.bus4State.unit3Current;
suffix = getTypeName(typeid(m_pmCurrentState.bus4State.unit5Current).name());
currentBusState[VAR_TO_STR(LVBBunit5Current)+suffix] = m_pmCurrentState.bus4State.unit5Current;
suffix = getTypeName(typeid(m_pmCurrentState.bus4State.bowPZDeviceCurrent).name());
currentBusState[VAR_TO_STR(LVBBbowPZDeviceCurrent)+suffix] = m_pmCurrentState.bus4State.bowPZDeviceCurrent;
suffix = getTypeName(typeid(m_pmCurrentState.bus4State.emergencyLithiumBatteryGroup1Current).name());
currentBusState[VAR_TO_STR(LVBBemergencyLithiumBatteryGroup1Current)+suffix] = m_pmCurrentState.bus4State.emergencyLithiumBatteryGroup1Current;
suffix = getTypeName(typeid(m_pmCurrentState.bus4State.emergency1BusbarVoltage).name());
currentBusState[VAR_TO_STR(LVBBemergency1BusbarVoltage)+suffix] = m_pmCurrentState.bus4State.emergency1BusbarVoltage;
// dis["currentBusState"] = currentBusState;
// pms[VAR_TO_STR(fcs_obj)] = fcs;
// pms[VAR_TO_STR(lbs_obj)] = lbs;
// pms[VAR_TO_STR(dis_obj)] = dis;
Notify(PM_STATE_VAR, pms.toStyledString());
Notify(PM_FCSSTATE_VAR, fcs.toStyledString());
Notify(PM_LIBATSTATE_VAR, lbs.toStyledString());
Notify(PM_DISSTATE_VAR, dis.toStyledString());
Notify(PM_CURRENTSTATE_VAR, currentBusState.toStyledString());
// 使用StreamWriterBuilder来设置保持插入顺序
Json::StreamWriterBuilder builder;
builder["indentation"] = " "; // 设置不缩进,保持紧凑格式
builder["enableYAMLCompatibility"] = true; // 保持插入顺序
// 将Json::Value对象转换为字符串
string pathFile = "/home/zjk/project/H100/H100PowerManger/data/msg/";
string jsonStr = Json::writeString(builder, pms);
saveStringToJsonFile(jsonStr, pathFile+PM_STATE_VAR+".json");
jsonStr = Json::writeString(builder, fcs);
saveStringToJsonFile(jsonStr, pathFile+PM_FCSSTATE_VAR+".json");
jsonStr = Json::writeString(builder, lbs);
saveStringToJsonFile(jsonStr, pathFile+PM_LIBATSTATE_VAR+".json");
jsonStr = Json::writeString(builder, dis);
saveStringToJsonFile(jsonStr, pathFile+PM_DISSTATE_VAR + ".json");
jsonStr = Json::writeString(builder, currentBusState);
saveStringToJsonFile(jsonStr, pathFile+PM_CURRENTSTATE_VAR + ".json");
return true;
}
bool PowerManger::saveStringToJsonFile(const string &strJson, const string &filePath)
{
std::ofstream file(filePath, std::ios::trunc);
if (file.is_open()) {
file << strJson;
file.close();
// std::cout << "字符串已成功保存到文件中。" << std::endl;
return true;
} else {
std::cerr << "无法打开文件!" << std::endl;
return false;
}
}