diff --git a/data/msg/uPower_currentState_st.json b/data/msg/uPower_currentState_st.json new file mode 100644 index 0000000..d62b00d --- /dev/null +++ b/data/msg/uPower_currentState_st.json @@ -0,0 +1,47 @@ +{ + "HVABactuatorCurrent_uint16": 0, + "HVABbowFTDevice123Current_uint16": 0, + "HVABbowRudderControlBoxCurrent_uint16": 0, + "HVABbusbarBCurrent_uint16": 0, + "HVABbusbarBVoltage_uint16": 0, + "HVABmastSteeringGearControlBoxCurrent_uint16": 0, + "HVABopenWaterCoverStartCylinderCurrent_uint16": 0, + "HVABxczCurrent_uint16": 1, + "HVBBbowLowVoltageDistributionBoxCurrent_uint16": 0, + "HVBBcompositeEnergyManagementSystemEmergencyDC48VCurrent_uint16": 0, + "HVBBdcC1InstrumentDC48VCurrent_uint16": 0, + "HVBBemergency2BusbarVoltage_uint16": 0, + "HVBBemergencyLithiumBatteryGroup2Current_uint16": 0, + "HVBBfuelCellSecuritySystemEmergencyDC48VCurrent_uint16": 0, + "HVBBinstrumentBusbarVoltage_uint16": 0, + "HVBBlithiumBatteryGroupInstrumentCurrent_uint16": 0, + "HVBBplcControlPowerCurrent_uint16": 0, + "HVBBreservedCurrent1_uint16": 0, + "HVBBreservedCurrent2_uint16": 0, + "HVBBunit4InstrumentDC48VCurrent_uint16": 0, + "HVBbowHighVoltageDistributionBoxCurrent_uint16": 0, + "HVBbusbarACurrent_uint16": 0, + "HVBbusbarAVoltage_uint16": 6, + "HVBdcDc5ModuleCurrent_uint16": 0, + "HVBfbReservedSwitchCurrent_uint16": 0, + "HVBlithiumBatteryGroupMeterCurrent_uint16": 0, + "HVBpowerBusCurrent_uint16": 0, + "HVBpowerBusVoltage_uint16": 0, + "HVBpropulsionMotorControlBoxCurrent_uint16": 0, + "HVBreservedCurrent1_uint16": 0, + "HVBreservedCurrent2_uint16": 0, + "HVBreservedCurrent3_uint16": 0, + "HVBsternFTDevice45Current_uint16": 0, + "HVBsternRudderSwitch1Current_uint16": 0, + "HVBsternRudderSwitch2Current_uint16": 0, + "HVBtyzReservedSwitchCurrent_uint16": 0, + "LVBBbowPZDeviceCurrent_uint16": 0, + "LVBBemergency1BusbarVoltage_uint16": 0, + "LVBBemergencyLithiumBatteryGroup1Current_uint16": 0, + "LVBBinstrumentBusbarCurrent_uint16": 0, + "LVBBunit1Current_uint16": 0, + "LVBBunit2Current_uint16": 0, + "LVBBunit3Current_uint16": 0, + "LVBBunit5Current_uint16": 0, + "LVBinstrumentBusbarVoltage_uint16": 0 +} \ No newline at end of file diff --git a/data/msg/uPower_disSysState_st.json b/data/msg/uPower_disSysState_st.json new file mode 100644 index 0000000..3b318e7 --- /dev/null +++ b/data/msg/uPower_disSysState_st.json @@ -0,0 +1,10 @@ +{ + "HightVoltageABusBreaker_unit16": 0, + "HightVoltageBBusBreaker_unit16": 0, + "HightVoltageBusBreaker_uint16": 0, + "LowVoltageBusBreaker_uint16": 0, + "faultCode_array": + [ + 0 + ] +} \ No newline at end of file diff --git a/data/msg/uPower_fcsState_st.json b/data/msg/uPower_fcsState_st.json new file mode 100644 index 0000000..0c80aea --- /dev/null +++ b/data/msg/uPower_fcsState_st.json @@ -0,0 +1,26 @@ +{ + "backpressure1_fp32": 0.0, + "backpressure2_fp32": 0.0, + "ch4oConcentration1_fp32": 0.0, + "ch4oConcentration2_fp32": 0.0, + "ch4o_fp32": 0.0, + "exchangerTemperature_fp32": 0.0, + "fcuCurrentIns_fp32": 0.0, + "fcuCurrentPower_fp32": 0.0, + "fcuCurrent_fp32": 0.0, + "fcuFaultLeve_uint8": 32, + "fcuOutIns_fp32": 0.0, + "fcuOutPower_fp32": 0.0, + "fcuState_uint8": 86, + "fcuVoltageIns_fp32": 0.0, + "fcuVoltagePower_fp32": 0.0, + "fcuVoltage_fp32": 0.0, + "h2Concentration1_fp32": 0.0, + "h2Concentration2_fp32": 0.0, + "o2Concentration1_fp32": 0.0, + "o2Concentration2_fp32": 0.0, + "o2Level_fp32": 0.0, + "o2_fp32": 0.0, + "powerLimit_fp32": 0.0, + "totalPowerGeneration_fp32": 0.0 +} \ No newline at end of file diff --git a/data/msg/uPower_liBatState_st.json b/data/msg/uPower_liBatState_st.json new file mode 100644 index 0000000..c3f7a93 --- /dev/null +++ b/data/msg/uPower_liBatState_st.json @@ -0,0 +1,36 @@ +{ + "fcuCurrentToInsLimit1_uint8": 0, + "fcuCurrentToinsLimit2_uint8": 0, + "insBatCurrentElectricity_uint16": 0, + "insBatLimit_uint16": 0, + "insBatSoc_uint8": 0, + "insBatTotalElectricity_uint16": 0, + "insChargeState_uint8": 0, + "insCurrentSocHold1_uint8": 0, + "insCurrentSocHold2_uint8": 0, + "insCurrentSocHold3_uint8": 0, + "insCurrent_uint16": 0, + "insLinkVoltage_uint16": 0, + "insNegInsulationResistance_uint16": 0, + "insNegRelayState_uint8": 0, + "insPackVoltage_uint16": 0, + "insPosInsulationResistance_uint16": 0, + "insPosRelayState_uint8": 0, + "powerBatCurrentElectricity_uint16": 0, + "powerBatLimit_uint16": 0, + "powerBatSoc_uint8": 0, + "powerBatTotalElectricity_uint16": 0, + "powerChargeState_uint8": 0, + "powerCurrentSocHold1_uint8": 0, + "powerCurrentSocHold2_uint8": 0, + "powerCurrentSocHold3_uint8": 0, + "powerCurrentToInsLimit1_uint8": 0, + "powerCurrentToinsLimit2_uint8": 0, + "powerCurrent_uint16": 0, + "powerLinkVoltage_uint16": 0, + "powerNegInsulationResistance_uint16": 0, + "powerNegRelayState_uint8": 0, + "powerPackVoltage_uint16": 0, + "powerPosInsulationResistance_uint16": 0, + "powerPosRelayState_uint8": 0 +} \ No newline at end of file diff --git a/data/msg/uPower_pmState_st.json b/data/msg/uPower_pmState_st.json index 1ef0f34..43fa2ff 100644 --- a/data/msg/uPower_pmState_st.json +++ b/data/msg/uPower_pmState_st.json @@ -1,105 +1,12 @@ { - "workCondition_unit8" : "idel", - "currentMod_uint8" : "test", - "powerState_uint8" : 1, - "faultLevel_uint8" : 0, - "faultCode_uint16" : [0,1,2], - "soc_uint16" : 10000, - "sustainableTime_uint64" : 10000, - "fcs_obj": - { - "state_uint8" : 1, - "faultLevel_uint8" : 0, - "faultCode_uint16" : 0, - "soc" : 1000, - "output": 20000, - "powerGen" : 30000, - "outputLimit" : 30000, - "ch4o":1000, - "o2":1000, - "temp":1000 - }, - "InsBat_obj": - { - "state" : 1, - "faultLevel" : 0, - "faultCode" : 0, - "soc" : 1000, - "threshold1": 70, - "threshold2": 80, - "threshold3": 90 - }, - "powBat_obj": - { - "state" : 1, - "faultLevel" : 0, - "faultCode" : 0, - "soc" : 1000, - "threshold1": 70, - "threshold2": 80, - "threshold3": 90 - }, - "powDisSys_obj": - { - "state" : 1, - "faultLevel" : 0, - "faultCode" : [0,1,2], - "currentHigVolBusState" : - { - "powerBusVoltage" : 10000, - "dc5ModuleCurrent" : 10000, - "powerBusCurrent" : 10000, - "aBusVoltage" : 10000, - "propMotorCurrent" : 10000, - "aBusCurrent" : 10000, - "batteryGroupCurrent" : 10000, - "bowHigVolDisCurrent" : 10000, - "ftDev45Current" : 10000, - "tyzCurrent" : 10000, - "sternRudder1Current" : 10000, - "reservedCurrent1" : 10000, - "sternRudder2Current" : 10000, - "reservedCurrent2" : 10000, - "fbCurrent" : 10000, - "reservedCurrent3" : 10000 - }, - "currentHigVolBusAState" : - { - "busBVoltage":10000, - "busBCurrent":10000, - "ftDev123Current":10000, - "closureMechCurrent":10000, - "mastSteerCurrent":10000, - "xczCurrent":10000, - "bowRudderCurrent":10000, - "coverActorCurrent":10000 - }, - "currentHigVolBusBState" : - { - "insBusVoltage" : 10000, - "bowLowVoltageDisCurrent" : 10000, - "dcc1Current" : 10000, - "reservedCurrent1" : 10000, - "emerBatGroup2Current" : 10000, - "batGroupInsCurrent" : 10000, - "unit4Current" : 10000, - "reservedCurrent2" : 10000, - "emer2BusVoltage" : 10000, - "ccuEmerCurrent" : 10000, - "fcsSecurityCurrent" : 10000, - "plcCurrent" : 10000 - }, - "currentLowVolBusBState" : - { - "insBusVoltage":10000, - "insBusCurrent":10000, - "unit1Current":10000, - "unit2Current":10000, - "unit3Current":10000, - "unit5Current":10000, - "bowPzDeviceCurrent":10000, - "emerBatGroup1Current":10000, - "emer1BusVoltage":10000 - } - } + "currentMod_uint8": 0, + "falutLevel_uint8": 0, + "faultCode_array": + [ + 0 + ], + "powerState_uint8": 0, + "soc_uint32": 0, + "sustainableTime_obj": 0, + "workCondition_uint8": 0 } \ No newline at end of file diff --git a/src/pPowerManger/CMakeLists.txt b/src/pPowerManger/CMakeLists.txt index bb5cd07..b16aa9b 100644 --- a/src/pPowerManger/CMakeLists.txt +++ b/src/pPowerManger/CMakeLists.txt @@ -30,5 +30,6 @@ TARGET_LINK_LIBRARIES(pPowerManger mbutil m pthread + jsoncpp ${SYSTEM_LIBS}) diff --git a/src/pPowerManger/PowerManger.cpp b/src/pPowerManger/PowerManger.cpp index 7a9d47d..a5bfa30 100644 --- a/src/pPowerManger/PowerManger.cpp +++ b/src/pPowerManger/PowerManger.cpp @@ -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; + } } \ No newline at end of file diff --git a/src/pPowerManger/PowerManger.h b/src/pPowerManger/PowerManger.h index 9357292..fb54af5 100644 --- a/src/pPowerManger/PowerManger.h +++ b/src/pPowerManger/PowerManger.h @@ -29,9 +29,19 @@ #include "udpComm.h" #include "pmSysvariable.h" +#define VAR_TO_STR(var) #var + #define IPORT 5000 #define MAX_UDP_PKT_SIZE 65535 #define SKEW_TOLERANCE 5 + +#define PM_STATE_VAR "uPower_pmState_st" +#define PM_CURRENTSTATE_VAR "uPower_currentState_st" +#define PM_DISSTATE_VAR "uPower_disSysState_st" +#define PM_LIBATSTATE_VAR "uPower_liBatState_st" +#define PM_FCSSTATE_VAR "uPower_fcsState_st" + + class PowerManger : public AppCastingMOOSApp { public: @@ -53,8 +63,9 @@ class PowerManger : public AppCastingMOOSApp XPCUdpSocket* setUdpScoket(long lPort); bool updatePmState(); - bool updateTime(){m_current_time = MOOSTime();} + void updateTime(){m_current_time = MOOSTime();} bool IsSkewed(double dfTimeNow, double * pdfSkew = NULL); + string getTypeName(const string typeName); bool buildPowerSysReport(); bool buildDisributionReport(); @@ -62,13 +73,22 @@ class PowerManger : public AppCastingMOOSApp bool buildPredictionReport(); protected: // app variables + //系统状态 + unsigned char workCondition; + unsigned char currentMod; + unsigned char powerState; + unsigned char falutLevel; + vector faultCode; + unsigned int soc; + unsigned long int sustainableTime; pmState m_pmCurrentState; - + // 当前传输状态 msg_CcuStateFbMsg m_CcuCurrentState; msg_disHighVolBusFbMsg m_disHighVolBusCurrentState; msg_disHighAVolBusFbMsg m_disHighAVolBusCurrentState; msg_disHighBVolBusFbMsg m_disHighBVolBusCurrentState; msg_disLowBusFbMsg m_disLowBusState; + private: // Configuration variables udpComm m_udpComm; XPCUdpSocket *m_pCcuUdpComm; @@ -79,7 +99,8 @@ class PowerManger : public AppCastingMOOSApp double m_current_time; // CMOOSThread m_SendThread; - private: // State variables + private: // + bool inline saveStringToJsonFile(const string &strJson, const string &strFileName); }; #endif diff --git a/src/pPowerManger/ccuUdpMsg.h b/src/pPowerManger/ccuUdpMsg.h index 137b082..9b2074c 100644 --- a/src/pPowerManger/ccuUdpMsg.h +++ b/src/pPowerManger/ccuUdpMsg.h @@ -4,6 +4,11 @@ #define CCU_UDPMSG_START1 0x20 #define CCU_UDPMSG_START2 0x20 + +#define DIS_MSG_HEAD1 0x40 +#define DIS_MSG_HEAD2 0x40 + + #define CCU_STATE_FB_ID 0x0051 #define CCU_SET_PARM_FB_ID 0x0040 #define DIS_HVBUS_FB_ID 0x0005 @@ -13,6 +18,7 @@ #pragma pack (1) typedef unsigned int Checksum; +typedef unsigned char cChecksum; typedef struct { unsigned char start1; @@ -112,81 +118,6 @@ typedef struct { typedef struct { m_header header; ccuState data; - // unsigned char currentWorkCondition; - // unsigned char fcuState; - // unsigned char fcuFaultLeve; - // float powerLimit; - // float totalPowerGeneration; - // float ch4o; - // float o2; - // float fcuVoltage; - // float fcuCurrent; - // float o2Level; - // float placeholder1; - // float exchangerTemperature; - // float fcuOutPower; - // float fcuOutIns; - // float fcuVoltageIns; - // float fcuVoltagePower; - // float fcuCurrentIns; - // float fcuCurrentPower; - // float h2Concentration1; - // float h2Concentration2; - // float o2Concentration1; - // float o2Concentration2; - // float ch4oConcentration1; - // float ch4oConcentration2; - // float backpressure1; - // float backpressure2; - // unsigned char flameDetection; - // unsigned char fcuGZ_1L; - // unsigned char fcuGZ_1H; - // unsigned char fcuGZ_2L; - // unsigned char fcuGZ_2H; - // unsigned char fcuGZ_3L; - // unsigned char fcuGZ_3H; - // unsigned char insPosRelayState; - // unsigned char insNegRelayState; - // unsigned char powerPosRelayState; - // unsigned char powerNegRelayState; - // unsigned short insBatLimit; - // unsigned short powerBatLimit; - // unsigned char insBatSoc; - // unsigned char powerBatSoc; - // unsigned short insBatTotalElectricity; - // unsigned short powerBatTotalElectricity; - // unsigned short insBatCurrentElectricity; - // unsigned short powerBatCurrentElectricity; - // unsigned char insChargeState; - // unsigned char powerChargeState; - // unsigned short insLinkVoltage; - // unsigned short insPackVoltage; - // unsigned short insCurrent; - // unsigned short insPosInsulationResistance; - // unsigned short insNegInsulationResistance; - // unsigned short powerLinkVoltage; - // unsigned short powerPackVoltage; - // unsigned short powerCurrent; - // unsigned short powerPosInsulationResistance; - // unsigned short powerNegInsulationResistance; - // unsigned char insEmergencyStatusWord; - // unsigned char powerEmergencyStatusWord; - // unsigned char insAlarmIdentificationWord; - // unsigned char powerAlarmIdentificationWord; - // unsigned char insCurrentSocHold1; - // unsigned char insCurrentSocHold2; - // unsigned char insCurrentSocHold3; - // unsigned char fcuCurrentToInsLimit1; - // unsigned char fcuCurrentToinsLimit2; - // unsigned char powerCurrentSocHold1; - // unsigned char powerCurrentSocHold2; - // unsigned char powerCurrentSocHold3; - // unsigned char powerCurrentToInsLimit1; - // unsigned char powerCurrentToinsLimit2; - // float placeholder2; - // float placeholder3; - // float placeholder4; - // float placeholder5; Checksum checkCode; } msg_CcuStateFbMsg; @@ -194,118 +125,28 @@ typedef struct { typedef struct { m_header header; disHighVolBusState data; - // unsigned char fuelCellCircuitBreaker; - // unsigned char powerLithiumBatteryCircuitBreaker; - // unsigned char propulsionMotorCircuitBreaker; - // unsigned char lithiumBatteryGroupInstrumentCircuitBreaker; - // unsigned char dcDc5ModuleCircuitBreaker; - // unsigned char bowHighVoltageDistributionBoxCircuitBreaker; - // unsigned char sternFTDevice45CircuitBreaker; - // unsigned char sternRudderSwitch1CircuitBreaker; - // unsigned char sternRudderSwitch2CircuitBreaker; - // unsigned char fbReservedCircuitBreaker; - // unsigned char tyzReservedCircuitBreaker; - // unsigned char reservedCircuitBreaker; - // unsigned char busInsulationLow; - // unsigned char busAInsulationHigh; - // unsigned char lostPower; - // unsigned char lostEmerPower; - // unsigned short powerBusVoltage; - // unsigned short dcDc5ModuleCurrent; - // unsigned short powerBusCurrent; - // unsigned short busbarAVoltage; - // unsigned short propulsionMotorControlBoxCurrent; - // unsigned short busbarACurrent; - // unsigned short lithiumBatteryGroupMeterCurrent; - // unsigned short bowHighVoltageDistributionBoxCurrent; - // unsigned short sternFTDevice45Current; - // unsigned short tyzReservedSwitchCurrent; - // unsigned short sternRudderSwitch1Current; - // unsigned short reservedCurrent1; // 改为 reservedCurrent1 以避免重名 - // unsigned short sternRudderSwitch2Current; - // unsigned short reservedCurrent2; // 改为 reservedCurrent2 以避免重名 - // unsigned short fbReservedSwitchCurrent; - // unsigned short reservedCurrent3; // 改为 reservedCurrent3 以避免重名 - Checksum checkCode; + cChecksum checkCode; } msg_disHighVolBusFbMsg; // 高压母线A配电反馈 typedef struct { m_header header; disHighAVolBusState data; - // unsigned char bowFTDevice123CircuitBreaker; - // unsigned char actuatorCircuitBreaker; - // unsigned char mastSteeringGearControlBoxCircuitBreaker; - // unsigned char xczCircuitBreaker; - // unsigned char bowRudderControlBoxCircuitBreaker; - // unsigned char openWaterCoverStartCylinderCircuitBreaker; - // unsigned char instrumentPowerFailureSignal; - // unsigned char emergencyPowerFailureSignal; - // unsigned char waterIngressionAlarm; - // unsigned short busbarBVoltage; - // unsigned short busbarBCurrent; - // unsigned short bowFTDevice123Current; - // unsigned short actuatorCurrent; - // unsigned short mastSteeringGearControlBoxCurrent; - // unsigned short xczCurrent; - // unsigned short bowRudderControlBoxCurrent; - // unsigned short openWaterCoverStartCylinderCurrent; - Checksum checkCode; + cChecksum checkCode; } msg_disHighAVolBusFbMsg; // 高压母线B配电反馈 typedef struct { m_header header; disHighBVolBusState data; - // unsigned char lithiumBatteryGroupInstrumentCircuitBreaker; - // unsigned char bowLowVoltageDistributionBoxCircuitBreaker; - // unsigned char unit4InstrumentDC48VCircuitBreaker; - // unsigned char dcC1DCDistributionPanelCircuitBreaker; - // unsigned char reservedCircuitBreaker1; // 为了区分,添加了数字后缀 - // unsigned char reservedCircuitBreaker2; // 为了区分,添加了数字后缀 - // unsigned char emergencyLithiumBatteryGroup2CircuitBreaker; - // unsigned char instrumentPowerFailureSignal; - // unsigned char emergencyPowerFailureSignal; - // unsigned char instrumentBusbarInsulationLow; - // unsigned short instrumentBusbarVoltage; - // unsigned short bowLowVoltageDistributionBoxCurrent; - // unsigned short dcC1InstrumentDC48VCurrent; - // unsigned short reservedCurrent1; // 为了区分,添加了数字后缀 - // unsigned short emergencyLithiumBatteryGroup2Current; - // unsigned short lithiumBatteryGroupInstrumentCurrent; - // unsigned short unit4InstrumentDC48VCurrent; - // unsigned short reservedCurrent2; // 为了区分,添加了数字后缀 - // unsigned short emergency2BusbarVoltage; - // unsigned short compositeEnergyManagementSystemEmergencyDC48VCurrent; - // unsigned short fuelCellSecuritySystemEmergencyDC48VCurrent; - // unsigned short plcControlPowerCurrent; - Checksum checkCode; + cChecksum checkCode; } msg_disHighBVolBusFbMsg; //仪表汇流排配电反馈 typedef struct { m_header header; disLowBusState data; - // unsigned char unit1CircuitBreaker; - // unsigned char unit2CircuitBreaker; - // unsigned char unit3CircuitBreaker; - // unsigned char unit5CircuitBreaker; - // unsigned char bowPZDeviceCircuitBreaker; - // unsigned char reservedCircuitBreaker1; // 为了区分,添加了数字后缀 - // unsigned char reservedCircuitBreaker2; // 为了区分,添加了数字后缀 - // unsigned char emergencyLithiumBatteryGroup1CircuitBreaker; - // unsigned char powerFailureSignal; - // unsigned char waterIngressionAlarm; - // unsigned short instrumentBusbarVoltage; - // unsigned short instrumentBusbarCurrent; - // unsigned short unit1Current; - // unsigned short unit2Current; - // unsigned short unit3Current; - // unsigned short unit5Current; - // unsigned short bowPZDeviceCurrent; - // unsigned short emergencyLithiumBatteryGroup1Current; - // unsigned short emergency1BusbarVoltage; - Checksum checkCode; + cChecksum checkCode; } msg_disLowBusFbMsg; #pragma pack () diff --git a/src/pPowerManger/pmSysvariable.h b/src/pPowerManger/pmSysvariable.h index 07b105d..3a3ca42 100644 --- a/src/pPowerManger/pmSysvariable.h +++ b/src/pPowerManger/pmSysvariable.h @@ -1,5 +1,16 @@ #ifndef PMSYSVARIABLE_H #define PMSYSVARIABLE_H + +//宏定义 + + +#define BREAK_OFF 0xAA +#define BREAK_ON 0x55 +#define BREAK_FALSE 0x5A + + + +//消息结构体变量定义 #pragma pack (1) typedef struct ccuState { @@ -187,6 +198,10 @@ typedef struct disLowBusState }disLowBusState; #pragma pack (0) + + +//状态结构体定义 + typedef struct pmState { ccuState ccustate; @@ -196,6 +211,63 @@ typedef struct pmState disLowBusState bus4State; } PmState; + typedef struct disBus1Breaker + { + unsigned char fuelCellCircuitBreaker : 1; + unsigned char powerLithiumBatteryCircuitBreaker : 1; + unsigned char propulsionMotorCircuitBreaker : 1; + unsigned char lithiumBatteryGroupInstrumentCircuitBreaker : 1; + unsigned char dcDc5ModuleCircuitBreaker : 1; + unsigned char bowHighVoltageDistributionBoxCircuitBreaker : 1; + unsigned char sternFTDevice45CircuitBreaker : 1; + unsigned char sternRudderSwitch1CircuitBreaker : 1; + unsigned char sternRudderSwitch2CircuitBreaker : 1; + unsigned char fbReservedCircuitBreaker : 1; + unsigned char tyzReservedCircuitBreaker : 1; + unsigned char reservedCircuitBreaker : 1; + unsigned short paceholder : 4; + } disBus1Breaker; + typedef struct disBus2Breaker + { + unsigned char bowFTDevice123CircuitBreaker : 1; + unsigned char actuatorCircuitBreaker : 1; + unsigned char mastSteeringGearControlBoxCircuitBreaker : 1; + unsigned char xczCircuitBreaker : 1; + unsigned char bowRudderControlBoxCircuitBreaker : 1; + unsigned char openWaterCoverStartCylinderCircuitBreaker : 1; + unsigned short paceholder : 10; + /* data */ + } disBus2Breaker; + + + typedef struct disBus3Breaker + { + unsigned char lithiumBatteryGroupInstrumentCircuitBreaker : 1; + unsigned char bowLowVoltageDistributionBoxCircuitBreaker : 1; + unsigned char unit4InstrumentDC48VCircuitBreaker : 1; + unsigned char dcC1DCDistributionPanelCircuitBreaker : 1; + unsigned char reservedCircuitBreaker1 : 1; + unsigned char reservedCircuitBreaker2 : 1; + unsigned char emergencyLithiumBatteryGroup2CircuitBreaker : 1; + unsigned short paceholder : 9; + /* data */ + } disBus3Breaker; + + + typedef struct disBus4Breaker + { + unsigned char unit1CircuitBreaker : 1; + unsigned char unit2CircuitBreaker : 1; + unsigned char unit3CircuitBreaker : 1; + unsigned char unit5CircuitBreaker : 1; + unsigned char bowPZDeviceCircuitBreaker : 1; + unsigned char reservedCircuitBreaker1 : 1; // 为了区分,添加了数字后缀 + unsigned char reservedCircuitBreaker2 : 1; // 为了区分,添加了数字后缀 + unsigned char emergencyLithiumBatteryGroup1CircuitBreaker : 1; + unsigned short paceholder : 8; + /* data */ + } disBus4Breaker; + #endif \ No newline at end of file diff --git a/src/pPowerManger/udpComm.cpp b/src/pPowerManger/udpComm.cpp index 8e272dc..7fd8a1f 100644 --- a/src/pPowerManger/udpComm.cpp +++ b/src/pPowerManger/udpComm.cpp @@ -16,18 +16,33 @@ Checksum udpComm::calculateChecksum(const unsigned char* data, int size) } return checksum; } - +Checksum udpComm::calculateChecksum(const unsigned char* data, int dataSize, int checkSize) +{ + Checksum checksum = 0; + int size_data = dataSize - checkSize; + for (int i = 0; i < size_data; i++) { + checksum += data[i]; + } + return checksum; +} bool udpComm::getMsgId(char *m,unsigned short &id) { m_header h; h = *reinterpret_cast(m); // 判断消息是否有效 - if (h.start1!= 0x20 || h.start2!= 0x20) { - sError.push_back("Msg Header errar"); - return false; + if (h.start1== DIS_MSG_HEAD1 && h.start2==DIS_MSG_HEAD2) + { + id = h.id; + return true; } - id = h.id; - return true; + else if (h.start1==CCU_UDPMSG_START1 && h.start2==CCU_UDPMSG_START2) + { + id = h.id; + return true; + } + else + sError.push_back("Msg Header errar"); + return false; } bool udpComm::getCcuState(char *m, msg_CcuStateFbMsg &s) { m_header h; @@ -37,14 +52,14 @@ bool udpComm::getCcuState(char *m, msg_CcuStateFbMsg &s) { h = p->header; // 判断消息是否有效 - if (h.start1 != 0x20 || h.start2 != 0x20) { - sError.push_back("CcuState Msg Header errar"); - return false; - } - if (h.id != 0x0051) { - sError.push_back("CcuState Msg ID error"); - return false; - } + // if (h.start1 != 0x20 || h.start2 != 0x20) { + // sError.push_back("CcuState Msg Header errar"); + // return false; + // } + // if (h.id != 0x0051) { + // sError.push_back("CcuState Msg ID error"); + // return false; + // } sum = calculateChecksum((unsigned char*)m, sizeof(msg_CcuStateFbMsg)); if (sum != p->checkCode) { @@ -65,17 +80,16 @@ bool udpComm::getCcuSetParmFb(char *m, msg_CcuSetParmFbMsg &s) h = p->header; // 判断消息是否有效 - if (h.start1!= 0x20 || h.start2!= 0x20) { - sError.push_back("CcuSetParm Msg Header errar"); - return false; - } + // if (h.start1!= 0x20 || h.start2!= 0x20) { + // sError.push_back("CcuSetParm Msg Header errar"); + // return false; + // } - if (h.id!= 0x0040) - { - sError.push_back("CcuSetParm Msg ID error"); - return false; - } - + // if (h.id!= 0x0040) + // { + // sError.push_back("CcuSetParm Msg ID error"); + // return false; + // } sum = calculateChecksum((unsigned char*)m, sizeof(msg_CcuSetParmFbMsg)); if (sum!= p->checkCode) { @@ -90,45 +104,46 @@ bool udpComm::getCcuSetParmFb(char *m, msg_CcuSetParmFbMsg &s) bool udpComm::getDisSysHVBusFb(char *m, msg_disHighVolBusFbMsg &s) { m_header h; - Checksum sum; + cChecksum sum; msg_disHighVolBusFbMsg *p; p = reinterpret_cast(m); h = p->header; // 判断消息是否有效 - if (h.start1!= 0x20 || h.start2!= 0x20) { - sError.push_back("DisSys HVBus Msg Header errar"); - return false; - } - if (h.id!= DIS_HVBUS_FB_ID) { - sError.push_back("DisSys HVBus Msg ID error"); - return false; - } - sum = calculateChecksum((unsigned char*)m, sizeof(msg_disHighVolBusFbMsg)); - if (sum!= p->checkCode) { + // if (h.start1!= 0x20 || h.start2!= 0x20) { + // sError.push_back("DisSys HVBus Msg Header errar"); + // return false; + // } + // if (h.id!= DIS_HVBUS_FB_ID) { + // sError.push_back("DisSys HVBus Msg ID error"); + // return false; + // } + sum = calculateChecksum((unsigned char*)m, sizeof(msg_disHighVolBusFbMsg), sizeof(cChecksum)) & 0xFF; + if (sum != p->checkCode) { sError.push_back("DisSys HVBus Msg Check error"); return false; } s = *p; + cout << s.data.busbarAVoltage << endl; return true; } bool udpComm::getDisSysHVABusFb(char *m, msg_disHighAVolBusFbMsg &s) { m_header h; - Checksum sum; + cChecksum sum; msg_disHighAVolBusFbMsg *p; p = reinterpret_cast(m); h = p->header; // 判断消息是否有效 - if (h.start1!= 0x20 || h.start2!= 0x20) { - sError.push_back("DisSys HVABus Msg Header errar"); - return false; - } - if (h.id!= DIS_HVBUSA_FB_ID) { - sError.push_back("DisSys HVABus Msg ID error"); - return false; - } - sum = calculateChecksum((unsigned char*)m, sizeof(msg_disHighAVolBusFbMsg)); + // if (h.start1!= 0x20 || h.start2!= 0x20) { + // sError.push_back("DisSys HVABus Msg Header errar"); + // return false; + // } + // if (h.id!= DIS_HVBUSA_FB_ID) { + // sError.push_back("DisSys HVABus Msg ID error"); + // return false; + // } + sum = calculateChecksum((unsigned char*)m, sizeof(msg_disHighAVolBusFbMsg), sizeof(cChecksum)) & 0xFF; if (sum!= p->checkCode) { sError.push_back("DisSys HVABus Msg Check error"); return false; @@ -139,20 +154,20 @@ bool udpComm::getDisSysHVABusFb(char *m, msg_disHighAVolBusFbMsg &s) bool udpComm::getDisSysHVBBusFb(char *m, msg_disHighBVolBusFbMsg &s) { m_header h; - Checksum sum; + cChecksum sum; msg_disHighBVolBusFbMsg *p; p = reinterpret_cast(m); h = p->header; // 判断消息是否有效 - if (h.start1!= 0x20 || h.start2!= 0x20) { - sError.push_back("DisSys HVBBus Msg Header errar"); - return false; - } - if (h.id!= DIS_HVBUSB_FB_ID) { - sError.push_back("DisSys HVBBus Msg ID error"); - return false; - } - sum = calculateChecksum((unsigned char*)m, sizeof(msg_disHighBVolBusFbMsg)); + // if (h.start1!= 0x20 || h.start2!= 0x20) { + // sError.push_back("DisSys HVBBus Msg Header errar"); + // return false; + // } + // if (h.id!= DIS_HVBUSB_FB_ID) { + // sError.push_back("DisSys HVBBus Msg ID error"); + // return false; + // } + sum = calculateChecksum((unsigned char*)m, sizeof(msg_disHighBVolBusFbMsg), sizeof(cChecksum)) & 0xFF; if (sum!= p->checkCode) { sError.push_back("DisSys HVBBus Msg Check error"); return false; @@ -164,20 +179,20 @@ bool udpComm::getDisSysHVBBusFb(char *m, msg_disHighBVolBusFbMsg &s) bool udpComm::getDisSysLVBusFb(char *m, msg_disLowBusFbMsg &s) { m_header h; - Checksum sum; + cChecksum sum; msg_disLowBusFbMsg *p; p = reinterpret_cast(m); h = p->header; // 判断消息是否有效 - if (h.start1!= 0x20 || h.start2!= 0x20) { - sError.push_back("DisSys LVBus Msg Header errar"); - return false; - } - if (h.id!= DIS_LVBUS_FB_ID) { - sError.push_back("DisSys LVBus Msg ID error"); - return false; - } - sum = calculateChecksum((unsigned char*)m, sizeof(msg_disLowBusFbMsg)); + // if (h.start1!= 0x20 || h.start2!= 0x20) { + // sError.push_back("DisSys LVBus Msg Header errar"); + // return false; + // } + // if (h.id!= DIS_LVBUS_FB_ID) { + // sError.push_back("DisSys LVBus Msg ID error"); + // return false; + // } + sum = calculateChecksum((unsigned char*)m, sizeof(msg_disLowBusFbMsg), sizeof(cChecksum)) & 0xFF; if (sum!= p->checkCode) { sError.push_back("DisSys LVBus Msg Check error"); return false; @@ -213,9 +228,8 @@ bool udpComm::pushMsgToQueue(unsigned char *m) { if(m_qReceiveCcuStateBuffer.size()data = msg; - p->timeStamp = MOOSTime(); - return p; + if(m_qReceiveCcuStateBuffer.empty()) + return false; + time = m_qReceiveCcuStateBuffer.front().first; + m = m_qReceiveCcuStateBuffer.front().second; + m_qReceiveCcuStateBuffer.pop(); + return true; } -int udpComm::getMsgFormQueue(queue &q,double &time,void* data) +bool udpComm::popMsgFormQueue(double &time,msg_CcuSetParmFbMsg &m) { - if (!q.empty()) - { - if(q.front().data!= NULL) - { - data = q.front().data; - time = q.front().timeStamp; - q.pop(); - return 0; - } - else - return 2; - } - else - return 3; + if(m_qReceiveCcuSetParmBuffer.empty()) + return false; + time = m_qReceiveCcuSetParmBuffer.front().first; + m = m_qReceiveCcuSetParmBuffer.front().second; + m_qReceiveCcuSetParmBuffer.pop(); + return true; } - -int udpComm::getCcuStateMsgFromQueue(double &time,msg_CcuStateFbMsg &m) +bool udpComm::popMsgFormQueue(double &time,msg_disHighVolBusFbMsg &m) { - void* p; - int ret; - ret = getMsgFormQueue(m_qReceiveCcuStateBuffer,time,p); - m = *reinterpret_cast(p); - return ret; + if(m_qReceiveDisHighVolBusBuffer.empty()) + return false; + time = m_qReceiveDisHighVolBusBuffer.front().first; + m = m_qReceiveDisHighVolBusBuffer.front().second; + m_qReceiveDisHighVolBusBuffer.pop(); + return true; } - -int udpComm::getCcuSetParmMsgFromQueue(double &time,msg_CcuSetParmFbMsg &m) +bool udpComm::popMsgFormQueue(double &time,msg_disHighAVolBusFbMsg &m) { - void* p; - int ret; - ret = getMsgFormQueue(m_qReceiveCcuSetParmBuffer,time,p); - m = *reinterpret_cast(p); - return ret; + if(m_qReceiveDisHighAVolBusBuffer.empty()) + return false; + time = m_qReceiveDisHighAVolBusBuffer.front().first; + m = m_qReceiveDisHighAVolBusBuffer.front().second; + m_qReceiveDisHighAVolBusBuffer.pop(); + return true; } - -int udpComm::getDisSysHVBusFbMsgFromQueue(double &time,msg_disHighVolBusFbMsg &m) +bool udpComm::popMsgFormQueue(double &time,msg_disHighBVolBusFbMsg &m) { - void* p; - int ret; - ret = getMsgFormQueue(m_qReceiveDisHighVolBusBuffer,time,p); - m = *reinterpret_cast(p); - return ret; + if(m_qReceiveDisHighBVolBusBuffer.empty()) + return false; + time = m_qReceiveDisHighBVolBusBuffer.front().first; + m = m_qReceiveDisHighBVolBusBuffer.front().second; + m_qReceiveDisHighBVolBusBuffer.pop(); + return true; } - -int udpComm::getDisSysHVABusFbMsgFromQueue(double &time,msg_disHighAVolBusFbMsg &m) +bool udpComm::popMsgFormQueue(double &time,msg_disLowBusFbMsg &m) { - void* p; - int ret; - ret = getMsgFormQueue(m_qReceiveDisHighAVolBusBuffer,time,p); - m = *reinterpret_cast(p); - return ret; -} -int udpComm::getDisSysHVBBusFbMsgFromQueue(double &time,msg_disHighBVolBusFbMsg &m) -{ - void* p; - int ret; - ret = getMsgFormQueue(m_qReceiveDisHighBVolBusBuffer,time,p); - m = *reinterpret_cast(p); - return ret; -} -int udpComm::getDisSysLVBusFbMsgFromQueue(double &time,msg_disLowBusFbMsg &m) -{ - void* p; - int ret; - ret = getMsgFormQueue(m_qReceiveDisLowBusBuffer,time,p); - m = *reinterpret_cast(p); - return ret; + if(m_qReceiveDisLowBusBuffer.empty()) + return false; + time = m_qReceiveDisLowBusBuffer.front().first; + m = m_qReceiveDisLowBusBuffer.front().second; + m_qReceiveDisLowBusBuffer.pop(); + return true; } \ No newline at end of file diff --git a/src/pPowerManger/udpComm.h b/src/pPowerManger/udpComm.h index 9cba343..62d2ea5 100644 --- a/src/pPowerManger/udpComm.h +++ b/src/pPowerManger/udpComm.h @@ -7,12 +7,10 @@ #include #include "MOOS/libMOOS/Utils/MOOSUtilityFunctions.h" #include +#include // for std::pair + using namespace std; #define QUENUE_SIZE 100 -typedef struct { - double timeStamp; - void* data; -} msgWithTime; class udpComm { private: @@ -22,16 +20,6 @@ public: ~udpComm(); bool pushMsgToQueue(unsigned char *m); - int getCcuStateMsgFromQueue(double &time,msg_CcuStateFbMsg &m); - int getCcuSetParmMsgFromQueue(double &time,msg_CcuSetParmFbMsg &m); - int getDisSysHVBusFbMsgFromQueue(double &time,msg_disHighVolBusFbMsg &m); - int getDisSysHVABusFbMsgFromQueue(double &time,msg_disHighAVolBusFbMsg &m); - int getDisSysHVBBusFbMsgFromQueue(double &time,msg_disHighBVolBusFbMsg &m); - int getDisSysLVBusFbMsgFromQueue(double &time,msg_disLowBusFbMsg &m); - - bool clearMsgQueue(); - - bool getMsgId(char *m,unsigned short &id); bool getCcuState(char *m, msg_CcuStateFbMsg &s); bool getCcuSetParmFb(char *m, msg_CcuSetParmFbMsg &s); @@ -44,17 +32,29 @@ public: bool sendCcuColCmd(const msg_CcuColCmdMsg m); bool sendCcuSetParmCmd(const msg_CcuSetParmMsg m); - msgWithTime* stampTimeStamp(void* msg); + bool clearMsgQueue(); + bool getMsgId(char *m,unsigned short &id); Checksum calculateChecksum(const unsigned char* data, int size); - int getMsgFormQueue(queue &q,double &time,void* m); + Checksum calculateChecksum(const unsigned char* data, int dataSize, int checkSize); + bool popMsgFormQueue(double &time,msg_CcuStateFbMsg &m); + bool popMsgFormQueue(double &time,msg_CcuSetParmFbMsg &m); + bool popMsgFormQueue(double &time,msg_disHighVolBusFbMsg &m); + bool popMsgFormQueue(double &time,msg_disHighAVolBusFbMsg &m); + bool popMsgFormQueue(double &time,msg_disHighBVolBusFbMsg &m); + bool popMsgFormQueue(double &time,msg_disLowBusFbMsg &m); + std::vector sError; - std::queue m_qReceiveCcuStateBuffer; - std::queue m_qReceiveCcuSetParmBuffer; - std::queue m_qReceiveDisHighVolBusBuffer; - std::queue m_qReceiveDisHighAVolBusBuffer; - std::queue m_qReceiveDisHighBVolBusBuffer; - std::queue m_qReceiveDisLowBusBuffer; + + std::pair getError(); + + // std::queue m_qReceiveCcuStateBuffer; + std::queue> m_qReceiveCcuStateBuffer; + std::queue> m_qReceiveCcuSetParmBuffer; + std::queue> m_qReceiveDisHighVolBusBuffer; + std::queue> m_qReceiveDisHighAVolBusBuffer; + std::queue> m_qReceiveDisHighBVolBusBuffer; + std::queue> m_qReceiveDisLowBusBuffer; private: msg_CcuColCmdMsg m_ccuColCmd; diff --git a/test/scripts/test.py b/test/scripts/test.py index 20624e5..070a8df 100644 --- a/test/scripts/test.py +++ b/test/scripts/test.py @@ -28,15 +28,17 @@ message = valid_msg3 num_messages = 100 # 发送信息的时间间隔(秒) -interval = 0.1 +interval = 1 for i in range(num_messages): # 发送信息 - sock.sendto(msg_CcuStateFbMsg().pack(), (target_ip, target_port)) + mTest.fcuState += 1 + sock.sendto(mTest.pack(), (target_ip, target_port)) time.sleep(interval) sock.sendto(msg_CcuSetParamFbMsg().pack(), (target_ip, target_port)) time.sleep(interval) - sock.sendto(msg_disHighVolBusFbMsg().pack(), (target_ip, target_port)) + mTest3.busbarAVoltage += 1 + sock.sendto(mTest3.pack(), (target_ip, target_port)) time.sleep(interval) sock.sendto(msg_disHighAVolBusFbMsg().pack(), (target_ip, target_port)) time.sleep(interval) diff --git a/test/scripts/udpmsg.py b/test/scripts/udpmsg.py index 7e33ec5..0ed1047 100644 --- a/test/scripts/udpmsg.py +++ b/test/scripts/udpmsg.py @@ -7,14 +7,14 @@ class msg_CcuStateFbMsg: self.id = 0x0051 self.length = 0x0000 self.currentWorkCondition = 0x00 - self.fcuState = 0x01 + self.fcuState = 80 self.fcuFaultLeve = 0x20 self.powerLimit = 0x00 self.totalPowerGeneration = 0x00 self.ch4o = 0x00 self.o2 = 0x00 - self.fcuVoltage = 0x1230 - self.fcuCurrent = 0x00 + self.fcuVoltage = 0x0000 + self.fcuCurrent = 0x0000 self.o2Level = 0x00 self.placeholder1 = 0x00 self.exchangerTemperature = 0x00 @@ -296,7 +296,8 @@ class msg_disHighVolBusFbMsg: data += struct.pack('