diff --git a/data/msg/uPower_currentState_st.json b/data/msg/uPower_currentState_st.json index 41648bf..a8a0701 100644 --- a/data/msg/uPower_currentState_st.json +++ b/data/msg/uPower_currentState_st.json @@ -6,7 +6,7 @@ "HVABbusBVol_uint16": 0, "HVABmastSteGeaCur_uint16": 0, "HVABopenWaterCur_uint16": 0, - "HVABxczCur_uint16": 0, + "HVABxczCur_uint16": 1, "HVBBCCUCur_uint16": 0, "HVBBFCSSecurSysCur_uint16": 0, "HVBBbatInsCur_uint16": 0, diff --git a/data/msg/uPower_disSysState_st.json b/data/msg/uPower_disSysState_st.json index ed8e1bf..90bc4ac 100644 --- a/data/msg/uPower_disSysState_st.json +++ b/data/msg/uPower_disSysState_st.json @@ -1,8 +1,8 @@ { "HVolABusBreaker_unit16": 0, - "HVolBBusBreaker_unit16": 0, - "HVolBusBreaker_uint16": 0, - "LVolBusBreaker_uint16": 0, + "HVolBBusBreaker_unit16": 79, + "HVolBusBreaker_uint16": 58, + "LVolBusBreaker_uint16": 159, "faultCode_array": [ 0 diff --git a/data/msg/uPower_fcsState_st.json b/data/msg/uPower_fcsState_st.json index 31141fb..200368f 100644 --- a/data/msg/uPower_fcsState_st.json +++ b/data/msg/uPower_fcsState_st.json @@ -1,30 +1,30 @@ { - "backpressure1_fp32": 0.0, - "backpressure2_fp32": 0.0, - "ch4oConcent1_fp32": 0.0, - "ch4oConcent2_fp32": 0.0, + "backpressure1_fp32": 5.0, + "backpressure2_fp32": 3.0, + "ch4oConcent1_fp32": 85.0, + "ch4oConcent2_fp32": 48.0, "ch4o_fp32": 0.0, - "excTemp_fp32": 0.0, + "excTemp_fp32": 37.0, "faultCode1_uint16": 0, "faultCode2_uint16": 0, "faultCode3_uint16": 0, "fcuCurIns_fp32": 0.0, "fcuCurPower_fp32": 0.0, - "fcuCur_fp32": 0.0, + "fcuCur_fp32": 6.0, "fcuFaultLeve_uint8": 0, - "fcuOutIns_fp32": 0.0, - "fcuOutPower_fp32": 0.0, + "fcuOutIns_fp32": 76.0, + "fcuOutPower_fp32": 912.0, "fcuState_uint8": 0, "fcuVolIns_fp32": 0.0, "fcuVolPower_fp32": 0.0, - "fcuVol_fp32": 0.0, + "fcuVol_fp32": 236.0, "flameDet_uint8": 0, - "h2Concent1_fp32": 0.0, - "h2Concent2_fp32": 0.0, - "o2Concent1_fp32": 0.0, - "o2Concent2_fp32": 0.0, + "h2Concent1_fp32": 32.0, + "h2Concent2_fp32": 50.0, + "o2Concent1_fp32": 56.0, + "o2Concent2_fp32": 91.0, "o2Level_fp32": 0.0, "o2_fp32": 0.0, - "powLimit_fp32": 0.0, + "powLimit_fp32": 64.0, "powerGen_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 index b3e9fd4..a062620 100644 --- a/data/msg/uPower_liBatState_st.json +++ b/data/msg/uPower_liBatState_st.json @@ -2,37 +2,37 @@ "fcuCurToInsLimit1_uint8": 0, "fcuCurToinsLimit2_uint8": 0, "insBatCurElect_uint16": 0, - "insBatLimit_uint16": 0, - "insBatSoc_uint8": 0, - "insBatTotalElect_uint16": 0, + "insBatLimit_uint16": 6, + "insBatSoc_uint8": 9, + "insBatTotalElect_uint16": 667, "insChargeState_uint8": 0, "insCurSocHold1_uint8": 0, "insCurSocHold2_uint8": 0, "insCurSocHold3_uint8": 0, - "insCurrent_uint16": 0, + "insCurrent_uint16": 13, "insLinkVol_uint16": 0, - "insNegRelayState_uint8": 0, + "insNegRelayState_uint8": 1, "insNegRes_uint16": 0, "insPackVol_uint16": 0, "insPosRelayState_uint8": 0, "insPosRes_uint16": 0, "insfaultCode_uint8": 0, "powBatCurElect_uint16": 0, - "powBatSoc_uint8": 0, - "powBatTotalElect_uint16": 0, + "powBatSoc_uint8": 24, + "powBatTotalElect_uint16": 142, "powChargeState_uint8": 0, "powCurSocHold1_uint8": 0, "powCurSocHold2_uint8": 0, "powCurSocHold3_uint8": 0, "powCurToInsLimit1_uint8": 0, "powCurToinsLimit2_uint8": 0, - "powCur_uint16": 0, + "powCur_uint16": 86, "powLinkVol_uint16": 0, - "powNegRelayState_uint8": 0, + "powNegRelayState_uint8": 1, "powNegRes_uint16": 0, - "powPosRelayState_uint8": 0, + "powPosRelayState_uint8": 1, "powPosRes_uint16": 0, - "powerBatLimit_uint16": 0, + "powerBatLimit_uint16": 77, "powerPackVol_uint16": 0, "powfaultCode_uint8": 0 } \ No newline at end of file diff --git a/src/pPowerManger/CMakeLists.txt b/src/pPowerManger/CMakeLists.txt index 2a1f876..067201f 100644 --- a/src/pPowerManger/CMakeLists.txt +++ b/src/pPowerManger/CMakeLists.txt @@ -27,6 +27,7 @@ SET(SRC SQLiteDB.cpp driver.cpp LowerCommManager.cpp + UpperCommManager.cpp ) ADD_EXECUTABLE(pPowerManger ${SRC}) diff --git a/src/pPowerManger/LowerCommManager.cpp b/src/pPowerManger/LowerCommManager.cpp index df27731..8a817eb 100644 --- a/src/pPowerManger/LowerCommManager.cpp +++ b/src/pPowerManger/LowerCommManager.cpp @@ -130,6 +130,105 @@ void LowerCommManager::clearMsgQueue(){ m_udpComm->clearMsgQueue(); } + +bool LowerCommManager::updatePoweSystemStates(){ + // std::cout << "updatePoweSystemStates" << std::endl; + if(!m_udpComm->m_qReceiveCcuStateBuffer.empty()) + { + double time; + m_udpComm->popMsgFormQueue(time,m_CcuCurrentState); + m_pm->m_pmCurrentState.ccustate = m_CcuCurrentState.data; + // m_db->insertCcuData(m_CcuCurrentState.data); //写入数据库 + msg_CcuStateFbMsg_Update_time = time; + } + if(!m_udpComm->m_qReceiveDisHighVolBusBuffer.empty()) + { + double time; + m_udpComm->popMsgFormQueue(time,m_disHighVolBusCurrentState); + m_pm->m_pmCurrentState.bus1State = m_disHighVolBusCurrentState.data; + // m_db->insertDisHighVolBusData(m_disHighVolBusCurrentState.data); //写入数据库 + msg_disHighVolBusFbMsg_Update_time = time; + + disBus1Breaker* pdis1=new disBus1Breaker; + (m_pm->m_pmCurrentState.bus1State.fuelCellCircuitBreaker == BREAK_ON) ? pdis1 -> fuelCellCircuitBreaker = 1 : pdis1 -> fuelCellCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus1State.powerLithiumBatteryCircuitBreaker == BREAK_ON) ? pdis1 -> powerLithiumBatteryCircuitBreaker = 1 : pdis1 -> powerLithiumBatteryCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus1State.propulsionMotorCircuitBreaker == BREAK_ON) ? pdis1 -> propulsionMotorCircuitBreaker = 1 : pdis1 -> propulsionMotorCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus1State.lithiumBatteryGroupInstrumentCircuitBreaker == BREAK_ON) ? pdis1 -> lithiumBatteryGroupInstrumentCircuitBreaker = 1 : pdis1 -> lithiumBatteryGroupInstrumentCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus1State.dcDc5ModuleCircuitBreaker == BREAK_ON) ? pdis1 -> dcDc5ModuleCircuitBreaker = 1 : pdis1 -> dcDc5ModuleCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus1State.bowHighVoltageDistributionBoxCircuitBreaker == BREAK_ON) ? pdis1 -> bowHighVoltageDistributionBoxCircuitBreaker = 1 : pdis1 -> bowHighVoltageDistributionBoxCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus1State.sternFTDevice45CircuitBreaker == BREAK_ON) ? pdis1 -> sternFTDevice45CircuitBreaker = 1 : pdis1 -> sternFTDevice45CircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus1State.sternRudderSwitch1CircuitBreaker == BREAK_ON) ? pdis1 -> sternRudderSwitch1CircuitBreaker = 1 : pdis1 -> sternRudderSwitch1CircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus1State.sternRudderSwitch2CircuitBreaker == BREAK_ON) ? pdis1 -> sternRudderSwitch2CircuitBreaker = 1 : pdis1 -> sternRudderSwitch2CircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus1State.fbReservedCircuitBreaker == BREAK_ON) ? pdis1 -> fbReservedCircuitBreaker = 1 : pdis1 -> fbReservedCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus1State.tyzReservedCircuitBreaker == BREAK_ON) ? pdis1 -> tyzReservedCircuitBreaker = 1 : pdis1 -> tyzReservedCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus1State.reservedCircuitBreaker == BREAK_ON) ? pdis1 -> reservedCircuitBreaker = 1 : pdis1 -> reservedCircuitBreaker = 0; + pdis1 -> paceholder = 0; + m_pm->m_currentDisBreakerState.bus1Breaker = *pdis1; + delete pdis1; + } + if(!m_udpComm->m_qReceiveDisHighAVolBusBuffer.empty()) + { + double time; + m_udpComm->popMsgFormQueue(time,m_disHighAVolBusCurrentState); + m_pm->m_pmCurrentState.bus2State = m_disHighAVolBusCurrentState.data; + // m_db->insertDisHighAVolBusData(m_disHighAVolBusCurrentState.data); //写入数据库 + msg_disHighAVolBusFbMsg_Update_time = time; + + disBus2Breaker* pdis2=new disBus2Breaker; + (m_pm->m_pmCurrentState.bus2State.bowFTDevice123CircuitBreaker == BREAK_ON)? pdis2 -> bowFTDevice123CircuitBreaker = 1 : pdis2 -> bowFTDevice123CircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus2State.actuatorCircuitBreaker == BREAK_ON)? pdis2 -> actuatorCircuitBreaker = 1 : pdis2 -> actuatorCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus2State.mastSteeringGearControlBoxCircuitBreaker == BREAK_ON)? pdis2 -> mastSteeringGearControlBoxCircuitBreaker = 1 : pdis2 -> mastSteeringGearControlBoxCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus2State.xczCircuitBreaker == BREAK_ON)? pdis2 -> xczCircuitBreaker = 1 : pdis2 -> xczCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus2State.bowRudderControlBoxCircuitBreaker == BREAK_ON)? pdis2 -> bowRudderControlBoxCircuitBreaker = 1 : pdis2 -> bowRudderControlBoxCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus2State.openWaterCoverStartCylinderCircuitBreaker == BREAK_ON)? pdis2 -> openWaterCoverStartCylinderCircuitBreaker = 1 : pdis2 -> openWaterCoverStartCylinderCircuitBreaker = 0; + pdis2 -> paceholder = 0; + m_pm->m_currentDisBreakerState.bus2Breaker = *pdis2; + delete pdis2; + } + if(!m_udpComm->m_qReceiveDisHighBVolBusBuffer.empty()) + { + double time; + m_udpComm->popMsgFormQueue(time,m_disHighBVolBusCurrentState); + m_pm->m_pmCurrentState.bus3State = m_disHighBVolBusCurrentState.data; + // m_db->insertDisHighBVolBusData(m_disHighBVolBusCurrentState.data); //写入数据库 + msg_disHighBVolBusFbMsg_Update_time = time; + + disBus3Breaker* pdis3=new disBus3Breaker; + (m_pm->m_pmCurrentState.bus3State.lithiumBatteryGroupInstrumentCircuitBreaker == BREAK_ON)? pdis3 -> lithiumBatteryGroupInstrumentCircuitBreaker = 1 : pdis3 -> lithiumBatteryGroupInstrumentCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus3State.bowLowVoltageDistributionBoxCircuitBreaker == BREAK_ON)? pdis3 -> bowLowVoltageDistributionBoxCircuitBreaker = 1 : pdis3 -> bowLowVoltageDistributionBoxCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus3State.unit4InstrumentDC48VCircuitBreaker == BREAK_ON)? pdis3 -> unit4InstrumentDC48VCircuitBreaker = 1 : pdis3 -> unit4InstrumentDC48VCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus3State.dcC1DCDistributionPanelCircuitBreaker == BREAK_ON)? pdis3 -> dcC1DCDistributionPanelCircuitBreaker = 1 : pdis3 -> dcC1DCDistributionPanelCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus3State.reservedCircuitBreaker1 == BREAK_ON)? pdis3 -> reservedCircuitBreaker1 = 1 : pdis3 -> reservedCircuitBreaker1 = 0; + (m_pm->m_pmCurrentState.bus3State.reservedCircuitBreaker2 == BREAK_ON)? pdis3 -> reservedCircuitBreaker2 = 1 : pdis3 -> reservedCircuitBreaker2 = 0; + (m_pm->m_pmCurrentState.bus3State.emergencyLithiumBatteryGroup2CircuitBreaker == BREAK_ON)? pdis3 -> emergencyLithiumBatteryGroup2CircuitBreaker = 1 : pdis3 -> emergencyLithiumBatteryGroup2CircuitBreaker = 0; + pdis3->paceholder = 0; + m_pm->m_currentDisBreakerState.bus3Breaker = *pdis3; + delete pdis3; + } + if(!m_udpComm->m_qReceiveDisLowBusBuffer.empty()) + { + double time; + m_udpComm->popMsgFormQueue(time,m_disLowBusState); + m_pm->m_pmCurrentState.bus4State = m_disLowBusState.data; + // m_db->insertDisLowBusData(m_disLowBusState.data); //写入数据库 + msg_disLowBusFbMsg_Update_time = time; + + disBus4Breaker* pdis4=new disBus4Breaker; + (m_pm->m_pmCurrentState.bus4State.unit1CircuitBreaker == BREAK_ON)? pdis4 -> unit1CircuitBreaker = 1 : pdis4 -> unit1CircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus4State.unit2CircuitBreaker == BREAK_ON)? pdis4 -> unit2CircuitBreaker = 1 : pdis4 -> unit2CircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus4State.unit3CircuitBreaker == BREAK_ON)? pdis4 -> unit3CircuitBreaker = 1 : pdis4 -> unit3CircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus4State.unit5CircuitBreaker == BREAK_ON)? pdis4 -> unit5CircuitBreaker = 1 : pdis4 -> unit5CircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus4State.bowPZDeviceCircuitBreaker == BREAK_ON)? pdis4 -> bowPZDeviceCircuitBreaker = 1 : pdis4 -> bowPZDeviceCircuitBreaker = 0; + (m_pm->m_pmCurrentState.bus4State.reservedCircuitBreaker1 == BREAK_ON)? pdis4 -> reservedCircuitBreaker1 = 1 : pdis4 -> reservedCircuitBreaker1 = 0; + (m_pm->m_pmCurrentState.bus4State.reservedCircuitBreaker2 == BREAK_ON)? pdis4 -> reservedCircuitBreaker2 = 1 : pdis4 -> reservedCircuitBreaker2 = 0; + (m_pm->m_pmCurrentState.bus4State.emergencyLithiumBatteryGroup1CircuitBreaker == BREAK_ON)? pdis4 -> emergencyLithiumBatteryGroup1CircuitBreaker = 1 : pdis4 -> emergencyLithiumBatteryGroup1CircuitBreaker = 0; + pdis4 -> paceholder = 0; + m_pm->m_currentDisBreakerState.bus4Breaker = *pdis4; + delete pdis4; + } + return true; +} + bool LowerCommManager::listenThreadFunc() { cout<sError[i] << MOOS::ConsoleColours::reset() << endl; } } + //更新当前状态 + if(!updatePoweSystemStates()) + { + std::cerr << "Error updating power system states" << std::endl; + } } catch(const std::exception& e) { cerr << "Error processing message: " << e.what() << endl; @@ -201,6 +305,7 @@ void LowerCommManager::stopListenThread() if(m_ListenThread.IsThreadRunning()) { m_ListenThread.Stop(); + std::cout << "LowerCommManager::stopListenThread" << std::endl; } } diff --git a/src/pPowerManger/LowerCommManager.h b/src/pPowerManger/LowerCommManager.h index 496a9bb..c3bd91c 100644 --- a/src/pPowerManger/LowerCommManager.h +++ b/src/pPowerManger/LowerCommManager.h @@ -27,10 +27,11 @@ public: void clearMsgQueue(); public: - CMOOSLock m_CommMutex; // 保护UDP通信资源 - // 初始化UDP通信 bool initUdpComm(); + + // TODO:实现连接检查功能 + bool checkConnection(); // 更新设备状态 bool updatePoweSystemStates(); @@ -49,6 +50,19 @@ public: //转换函数 char getBreakerOption(char cmd); + // 配电和CCU的反馈状态 + msg_CcuStateFbMsg m_CcuCurrentState; + msg_disHighVolBusFbMsg m_disHighVolBusCurrentState; + msg_disHighAVolBusFbMsg m_disHighAVolBusCurrentState; + msg_disHighBVolBusFbMsg m_disHighBVolBusCurrentState; + msg_disLowBusFbMsg m_disLowBusState; + // 配电和CCU的反馈状态时间戳 + double msg_CcuStateFbMsg_Update_time; + // double msg_CcuSetParmFbMsg_Update_time; + double msg_disHighVolBusFbMsg_Update_time; + double msg_disHighAVolBusFbMsg_Update_time; + double msg_disHighBVolBusFbMsg_Update_time; + double msg_disLowBusFbMsg_Update_time; public: long m_port; long m_ccuPort; diff --git a/src/pPowerManger/PowerManger.cpp b/src/pPowerManger/PowerManger.cpp index 158b04d..7e651b6 100644 --- a/src/pPowerManger/PowerManger.cpp +++ b/src/pPowerManger/PowerManger.cpp @@ -35,12 +35,12 @@ PowerManger::PowerManger() m_ticker = 0; faultCode.push_back(0); - msg_CcuStateFbMsg_Update_time = 0; - // msg_CcuSetParmFbMsg_Update_time = 0; - msg_disHighVolBusFbMsg_Update_time = 0; - msg_disHighAVolBusFbMsg_Update_time = 0; - msg_disHighBVolBusFbMsg_Update_time = 0; - msg_disLowBusFbMsg_Update_time = 0; + // msg_CcuStateFbMsg_Update_time = 0; + // // msg_CcuSetParmFbMsg_Update_time = 0; + // msg_disHighVolBusFbMsg_Update_time = 0; + // msg_disHighAVolBusFbMsg_Update_time = 0; + // msg_disHighBVolBusFbMsg_Update_time = 0; + // msg_disLowBusFbMsg_Update_time = 0; connectState = 0; @@ -68,6 +68,9 @@ PowerManger::PowerManger() //初始化UDP通信 m_lowerCommManager = new LowerCommManager(this,IPORT,CCUPORT,CCUHOST); m_lowerCommManager->initUdpComm(); + + //初始化上位机通信 + m_upperCommManager = new UpperCommManager(this); // 初始化状态机 cout << "init fsm" << endl; @@ -164,29 +167,16 @@ bool PowerManger::OnConnectToServer() bool PowerManger::Iterate() { AppCastingMOOSApp::Iterate(); - //1. 更新当前状态 - // updatePmState(); - updateConnectState(); - //2. 运行状态机 - // if (FSM_RUN_IS_OK) - // m_FsmThread.Start(); - // else - // m_FsmThread.Stop(); - //3. 进行操作 每秒执行一次 if (m_ticker++ % 5 == 0) { - //a. 配电系统操作 - // disSysOption(); - //b. ccu操作 - // ccuOption(); - //c. 上位机反馈 - buildPowerSysReport(); + m_lowerCommManager->processPeriodicTasks(); + m_upperCommManager->processPeriodicTasks(); + // buildPowerSysReport(); Notify(PM_TO_DB_SUBDISCMD,m_driver.saveDriverTableToJson(&m_subDisSysCmd)); Notify(PM_TO_DB_EQUIPMENTSTATE,m_driver.saveDriverTableToJson(&m_currentDriverState)); //d.保存到数据库 writeDataToDB(); } - m_lowerCommManager->processPeriodicTasks(); /////////////////////// // string a = m_driver.getSubDisCmdJson(&m_subDisSysCmd); @@ -290,35 +280,6 @@ XPCUdpSocket* PowerManger::setUdpScoket(long lPort) return pUdpSocket; } -// bool PowerManger::ListenLoopUDP() -// { -// unsigned char Buff[MAX_UDP_PKT_SIZE]; -// while(!m_ListenThread.IsQuitRequested()) -// { -// int nRead = m_pCcuUdpComm->iRecieveMessage(Buff,sizeof(Buff)); -// cout< 0) -// { -// if(!m_udpComm.pushMsgToQueue(Buff)) -// { -// for(int i=0;iinsertCcuData(m_CcuCurrentState.data); //写入数据库 -// msg_CcuStateFbMsg_Update_time = time; -// } -// if(!m_udpComm.m_qReceiveDisHighVolBusBuffer.empty()) -// { -// double time; -// m_udpComm.popMsgFormQueue(time,m_disHighVolBusCurrentState); -// m_pmCurrentState.bus1State = m_disHighVolBusCurrentState.data; -// m_db->insertDisHighVolBusData(m_disHighVolBusCurrentState.data); //写入数据库 -// msg_disHighVolBusFbMsg_Update_time = time; - -// 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; -// m_currentDisBreakerState.bus1Breaker = *pdis1; -// delete pdis1; -// } -// if(!m_udpComm.m_qReceiveDisHighAVolBusBuffer.empty()) -// { -// double time; -// m_udpComm.popMsgFormQueue(time,m_disHighAVolBusCurrentState); -// m_pmCurrentState.bus2State = m_disHighAVolBusCurrentState.data; -// m_db->insertDisHighAVolBusData(m_disHighAVolBusCurrentState.data); //写入数据库 -// msg_disHighAVolBusFbMsg_Update_time = time; - -// 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; -// m_currentDisBreakerState.bus2Breaker = *pdis2; -// delete pdis2; -// } -// if(!m_udpComm.m_qReceiveDisHighBVolBusBuffer.empty()) -// { -// double time; -// m_udpComm.popMsgFormQueue(time,m_disHighBVolBusCurrentState); -// m_pmCurrentState.bus3State = m_disHighBVolBusCurrentState.data; -// m_db->insertDisHighBVolBusData(m_disHighBVolBusCurrentState.data); //写入数据库 -// msg_disHighBVolBusFbMsg_Update_time = time; - -// 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; -// m_currentDisBreakerState.bus3Breaker = *pdis3; -// delete pdis3; -// } -// if(!m_udpComm.m_qReceiveDisLowBusBuffer.empty()) -// { -// double time; -// m_udpComm.popMsgFormQueue(time,m_disLowBusState); -// m_pmCurrentState.bus4State = m_disLowBusState.data; -// m_db->insertDisLowBusData(m_disLowBusState.data); //写入数据库 -// msg_disLowBusFbMsg_Update_time = time; - -// 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; -// m_currentDisBreakerState.bus4Breaker = *pdis4; -// delete pdis4; -// } -// return true; -// } - - -bool PowerManger::IsSkewed(double dfTimeNow, double * pdfSkew) -{ - double dfSkew = fabs(dfTimeNow - m_current_time); - if(pdfSkew != NULL) - { - *pdfSkew = dfSkew; - } - return (dfSkew > SKEW_TOLERANCE) ? true : false; -} - -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; - } -} - bool PowerManger::writeDataToDB() { // //写入配电系统状态 @@ -614,17 +427,6 @@ void PowerManger::initControlCmd() } -char PowerManger::getBreakerOption(char cmd) -{ - if(cmd ==1) - return 0x55; - else if(cmd ==0) - return 0xAA; - else - return 0x00; -} - - bool PowerManger::getMsCmdFromJson(MSControlCmd &cmd, const std::string &strJson) { @@ -669,429 +471,4 @@ bool PowerManger::getMsCmdFromJson(MSControlCmd &cmd, const std::string &strJson return false; // 缺少或类型不匹配 } return true; // 成功 -} - -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 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(powLimit)+suffix] = m_pmCurrentState.ccustate.powerLimit; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.totalPowerGeneration).name()); - fcs[VAR_TO_STR(powerGen)+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(fcuVol)+suffix] = m_pmCurrentState.ccustate.fcuVoltage; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuCurrent).name()); - fcs[VAR_TO_STR(fcuCur)+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(excTemp)+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(fcuVolIns)+suffix] = m_pmCurrentState.ccustate.fcuVoltageIns; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuVoltagePower).name()); - fcs[VAR_TO_STR(fcuVolPower)+suffix] = m_pmCurrentState.ccustate.fcuVoltagePower; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuCurrentIns).name()); - fcs[VAR_TO_STR(fcuCurIns)+suffix] = m_pmCurrentState.ccustate.fcuCurrentIns; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuCurrentPower).name()); - fcs[VAR_TO_STR(fcuCurPower)+suffix] = m_pmCurrentState.ccustate.fcuCurrentPower; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.h2Concentration1).name()); - fcs[VAR_TO_STR(h2Concent1)+suffix] = m_pmCurrentState.ccustate.h2Concentration1; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.h2Concentration2).name()); - fcs[VAR_TO_STR(h2Concent2)+suffix] = m_pmCurrentState.ccustate.h2Concentration2; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.o2Concentration1).name()); - fcs[VAR_TO_STR(o2Concent1)+suffix] = m_pmCurrentState.ccustate.o2Concentration1; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.o2Concentration2).name()); - fcs[VAR_TO_STR(o2Concent2)+suffix] = m_pmCurrentState.ccustate.o2Concentration2; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.ch4oConcentration1).name()); - fcs[VAR_TO_STR(ch4oConcent1)+suffix] = m_pmCurrentState.ccustate.ch4oConcentration1; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.ch4oConcentration2).name()); - fcs[VAR_TO_STR(ch4oConcent2)+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()); - fcs[VAR_TO_STR(flameDet)+suffix] = m_pmCurrentState.ccustate.flameDetection; - - unsigned short faultCode1; - unsigned short faultCode2; - unsigned short faultCode3; - faultCode1 = (m_pmCurrentState.ccustate.fcuGZ_1H << 8) | m_pmCurrentState.ccustate.fcuGZ_1L; - faultCode2 = (m_pmCurrentState.ccustate.fcuGZ_2H << 8) | m_pmCurrentState.ccustate.fcuGZ_2L; - faultCode3 = (m_pmCurrentState.ccustate.fcuGZ_3H << 8) | m_pmCurrentState.ccustate.fcuGZ_3L; - - suffix = getTypeName(typeid(faultCode1).name()); - fcs[VAR_TO_STR(faultCode1)+suffix] = faultCode1; - suffix = getTypeName(typeid(faultCode2).name()); - fcs[VAR_TO_STR(faultCode2)+suffix] = faultCode2; - suffix = getTypeName(typeid(faultCode3).name()); - fcs[VAR_TO_STR(faultCode3)+suffix] = faultCode3; - - //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(powPosRelayState)+suffix] = m_pmCurrentState.ccustate.powerPosRelayState; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerNegRelayState).name()); - lbs[VAR_TO_STR(powNegRelayState)+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(powBatSoc)+suffix] = m_pmCurrentState.ccustate.powerBatSoc; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insBatTotalElectricity).name()); - lbs[VAR_TO_STR(insBatTotalElect)+suffix] = m_pmCurrentState.ccustate.insBatTotalElectricity; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerBatTotalElectricity).name()); - lbs[VAR_TO_STR(powBatTotalElect)+suffix] = m_pmCurrentState.ccustate.powerBatTotalElectricity; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insBatCurrentElectricity).name()); - lbs[VAR_TO_STR(insBatCurElect)+suffix] = m_pmCurrentState.ccustate.insBatCurrentElectricity; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerBatCurrentElectricity).name()); - lbs[VAR_TO_STR(powBatCurElect)+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(powChargeState)+suffix] = m_pmCurrentState.ccustate.powerChargeState; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insLinkVoltage).name()); - lbs[VAR_TO_STR(insLinkVol)+suffix] = m_pmCurrentState.ccustate.insLinkVoltage; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insPackVoltage).name()); - lbs[VAR_TO_STR(insPackVol)+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(insPosRes)+suffix] = m_pmCurrentState.ccustate.insPosInsulationResistance; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insNegInsulationResistance).name()); - lbs[VAR_TO_STR(insNegRes)+suffix] = m_pmCurrentState.ccustate.insNegInsulationResistance; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerLinkVoltage).name()); - lbs[VAR_TO_STR(powLinkVol)+suffix] = m_pmCurrentState.ccustate.powerLinkVoltage; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerPackVoltage).name()); - lbs[VAR_TO_STR(powerPackVol)+suffix] = m_pmCurrentState.ccustate.powerPackVoltage; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerCurrent).name()); - lbs[VAR_TO_STR(powCur)+suffix] = m_pmCurrentState.ccustate.powerCurrent; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerPosInsulationResistance).name()); - lbs[VAR_TO_STR(powPosRes)+suffix] = m_pmCurrentState.ccustate.powerPosInsulationResistance; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerNegInsulationResistance).name()); - lbs[VAR_TO_STR(powNegRes)+suffix] = m_pmCurrentState.ccustate.powerNegInsulationResistance; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insCurrentSocHold1).name()); - lbs[VAR_TO_STR(insCurSocHold1)+suffix] = m_pmCurrentState.ccustate.insCurrentSocHold1; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insCurrentSocHold2).name()); - lbs[VAR_TO_STR(insCurSocHold2)+suffix] = m_pmCurrentState.ccustate.insCurrentSocHold2; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insCurrentSocHold3).name()); - lbs[VAR_TO_STR(insCurSocHold3)+suffix] = m_pmCurrentState.ccustate.insCurrentSocHold3; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuCurrentToInsLimit1).name()); - lbs[VAR_TO_STR(fcuCurToInsLimit1)+suffix] = m_pmCurrentState.ccustate.fcuCurrentToInsLimit1; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.fcuCurrentToinsLimit2).name()); - lbs[VAR_TO_STR(fcuCurToinsLimit2)+suffix] = m_pmCurrentState.ccustate.fcuCurrentToinsLimit2; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerCurrentSocHold1).name()); - lbs[VAR_TO_STR(powCurSocHold1)+suffix] = m_pmCurrentState.ccustate.powerCurrentSocHold1; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerCurrentSocHold2).name()); - lbs[VAR_TO_STR(powCurSocHold2)+suffix] = m_pmCurrentState.ccustate.powerCurrentSocHold2; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerCurrentSocHold3).name()); - lbs[VAR_TO_STR(powCurSocHold3)+suffix] = m_pmCurrentState.ccustate.powerCurrentSocHold3; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerCurrentToInsLimit1).name()); - lbs[VAR_TO_STR(powCurToInsLimit1)+suffix] = m_pmCurrentState.ccustate.powerCurrentToInsLimit1; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerCurrentToinsLimit2).name()); - lbs[VAR_TO_STR(powCurToinsLimit2)+suffix] = m_pmCurrentState.ccustate.powerCurrentToinsLimit2; - - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.insAlarmIdentificationWord).name()); - lbs[VAR_TO_STR(insfaultCode)+suffix] = m_pmCurrentState.ccustate.insAlarmIdentificationWord; - suffix = getTypeName(typeid(m_pmCurrentState.ccustate.powerAlarmIdentificationWord).name()); - lbs[VAR_TO_STR(powfaultCode)+suffix] = m_pmCurrentState.ccustate.powerAlarmIdentificationWord; - - //5.构建配电系统状态报告 - disBus1Breaker* pdis1=new disBus1Breaker; - disBus2Breaker* pdis2=new disBus2Breaker; - disBus3Breaker* pdis3=new disBus3Breaker; - disBus4Breaker* pdis4=new disBus4Breaker; - - *pdis1 = m_currentDisBreakerState.bus1Breaker; - *pdis2 = m_currentDisBreakerState.bus2Breaker; - *pdis3 = m_currentDisBreakerState.bus3Breaker; - *pdis4 = m_currentDisBreakerState.bus4Breaker; - - dis["HVolBusBreaker_uint16"] = *(unsigned short*)pdis1; - dis["HVolABusBreaker_unit16"] = *(unsigned short*)pdis2; - dis["HVolBBusBreaker_unit16"] = *(unsigned short*)pdis3; - dis["LVolBusBreaker_uint16"] = *(unsigned short*)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(HVBpowerBusVol)+suffix] = m_pmCurrentState.bus1State.powerBusVoltage; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.dcDc5ModuleCurrent).name()); - currentBusState[VAR_TO_STR(HVBdcDc5Cur)+suffix] = m_pmCurrentState.bus1State.dcDc5ModuleCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.powerBusCurrent).name()); - currentBusState[VAR_TO_STR(HVBpowerBusCur)+suffix] = m_pmCurrentState.bus1State.powerBusCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.busbarAVoltage).name()); - currentBusState[VAR_TO_STR(HVBbusAVol)+suffix] = m_pmCurrentState.bus1State.busbarAVoltage; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.propulsionMotorControlBoxCurrent).name()); - currentBusState[VAR_TO_STR(HVBmotorCur)+suffix] = m_pmCurrentState.bus1State.propulsionMotorControlBoxCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.busbarACurrent).name()); - currentBusState[VAR_TO_STR(HVBbusACur)+suffix] = m_pmCurrentState.bus1State.busbarACurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.lithiumBatteryGroupMeterCurrent).name()); - currentBusState[VAR_TO_STR(HVBbatGroupCur)+suffix] = m_pmCurrentState.bus1State.lithiumBatteryGroupMeterCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.bowHighVoltageDistributionBoxCurrent).name()); - currentBusState[VAR_TO_STR(HVBbowHVolDisBoxCur)+suffix] = m_pmCurrentState.bus1State.bowHighVoltageDistributionBoxCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.sternFTDevice45Current).name()); - currentBusState[VAR_TO_STR(HVBFTDev45Cur)+suffix] = m_pmCurrentState.bus1State.sternFTDevice45Current; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.tyzReservedSwitchCurrent).name()); - currentBusState[VAR_TO_STR(HVBtyzCur)+suffix] = m_pmCurrentState.bus1State.tyzReservedSwitchCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.sternRudderSwitch1Current).name()); - currentBusState[VAR_TO_STR(HVBsternRud1Cur)+suffix] = m_pmCurrentState.bus1State.sternRudderSwitch1Current; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.reservedCurrent1).name()); - currentBusState[VAR_TO_STR(HVBreservedCur1)+suffix] = m_pmCurrentState.bus1State.reservedCurrent1; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.sternRudderSwitch2Current).name()); - currentBusState[VAR_TO_STR(HVBsternRud2Cur)+suffix] = m_pmCurrentState.bus1State.sternRudderSwitch2Current; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.reservedCurrent2).name()); - currentBusState[VAR_TO_STR(HVBreservedCur2)+suffix] = m_pmCurrentState.bus1State.reservedCurrent2; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.fbReservedSwitchCurrent).name()); - currentBusState[VAR_TO_STR(HVBfbCur)+suffix] = m_pmCurrentState.bus1State.fbReservedSwitchCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus1State.reservedCurrent3).name()); - currentBusState[VAR_TO_STR(HVBreservedCur3)+suffix] = m_pmCurrentState.bus1State.reservedCurrent3; - - suffix = getTypeName(typeid(m_pmCurrentState.bus2State.busbarBVoltage).name()); - currentBusState[VAR_TO_STR(HVABbusBVol)+suffix] = m_pmCurrentState.bus2State.busbarBVoltage; - suffix = getTypeName(typeid(m_pmCurrentState.bus2State.busbarBCurrent).name()); - currentBusState[VAR_TO_STR(HVABbusBCur)+suffix] = m_pmCurrentState.bus2State.busbarBCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus2State.bowFTDevice123Current).name()); - currentBusState[VAR_TO_STR(HVABFTDev123Cur)+suffix] = m_pmCurrentState.bus2State.bowFTDevice123Current; - suffix = getTypeName(typeid(m_pmCurrentState.bus2State.actuatorCurrent).name()); - currentBusState[VAR_TO_STR(HVABactCur)+suffix] = m_pmCurrentState.bus2State.actuatorCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus2State.mastSteeringGearControlBoxCurrent).name()); - currentBusState[VAR_TO_STR(HVABmastSteGeaCur)+suffix] = m_pmCurrentState.bus2State.mastSteeringGearControlBoxCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus2State.xczCurrent).name()); - currentBusState[VAR_TO_STR(HVABxczCur)+suffix] = m_pmCurrentState.bus2State.xczCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus2State.bowRudderControlBoxCurrent).name()); - currentBusState[VAR_TO_STR(HVABbowRudCur)+suffix] = m_pmCurrentState.bus2State.bowRudderControlBoxCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus2State.openWaterCoverStartCylinderCurrent).name()); - currentBusState[VAR_TO_STR(HVABopenWaterCur)+suffix] = m_pmCurrentState.bus2State.openWaterCoverStartCylinderCurrent; - - suffix = getTypeName(typeid(m_pmCurrentState.bus3State.instrumentBusbarVoltage).name()); - currentBusState[VAR_TO_STR(HVBBinsBusVol)+suffix] = m_pmCurrentState.bus3State.instrumentBusbarVoltage; - suffix = getTypeName(typeid(m_pmCurrentState.bus3State.bowLowVoltageDistributionBoxCurrent).name()); - currentBusState[VAR_TO_STR(HVBBbowLowVolDisBoxCur)+suffix] = m_pmCurrentState.bus3State.bowLowVoltageDistributionBoxCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus3State.dcC1InstrumentDC48VCurrent).name()); - currentBusState[VAR_TO_STR(HVBBdcC1InsCur)+suffix] = m_pmCurrentState.bus3State.dcC1InstrumentDC48VCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus3State.reservedCurrent1).name()); - currentBusState[VAR_TO_STR(HVBBreservedCur1)+suffix] = m_pmCurrentState.bus3State.reservedCurrent1; - suffix = getTypeName(typeid(m_pmCurrentState.bus3State.emergencyLithiumBatteryGroup2Current).name()); - currentBusState[VAR_TO_STR(HVBBemerBatCur)+suffix] = m_pmCurrentState.bus3State.emergencyLithiumBatteryGroup2Current; - suffix = getTypeName(typeid(m_pmCurrentState.bus3State.lithiumBatteryGroupInstrumentCurrent).name()); - currentBusState[VAR_TO_STR(HVBBbatInsCur)+suffix] = m_pmCurrentState.bus3State.lithiumBatteryGroupInstrumentCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus3State.unit4InstrumentDC48VCurrent).name()); - currentBusState[VAR_TO_STR(HVBBunit4Cur)+suffix] = m_pmCurrentState.bus3State.unit4InstrumentDC48VCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus3State.reservedCurrent2).name()); - currentBusState[VAR_TO_STR(HVBBreservedCur2)+suffix] = m_pmCurrentState.bus3State.reservedCurrent2; - suffix = getTypeName(typeid(m_pmCurrentState.bus3State.emergency2BusbarVoltage).name()); - currentBusState[VAR_TO_STR(HVBBemer2BusVol)+suffix] = m_pmCurrentState.bus3State.emergency2BusbarVoltage; - suffix = getTypeName(typeid(m_pmCurrentState.bus3State.compositeEnergyManagementSystemEmergencyDC48VCurrent).name()); - currentBusState[VAR_TO_STR(HVBBCCUCur)+suffix] = m_pmCurrentState.bus3State.compositeEnergyManagementSystemEmergencyDC48VCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus3State.fuelCellSecuritySystemEmergencyDC48VCurrent).name()); - currentBusState[VAR_TO_STR(HVBBFCSSecurSysCur)+suffix] = m_pmCurrentState.bus3State.fuelCellSecuritySystemEmergencyDC48VCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus3State.plcControlPowerCurrent).name()); - currentBusState[VAR_TO_STR(HVBBplcCur)+suffix] = m_pmCurrentState.bus3State.plcControlPowerCurrent; - - suffix = getTypeName(typeid(m_pmCurrentState.bus4State.instrumentBusbarVoltage).name()); - currentBusState[VAR_TO_STR(LVBinsBusVol)+suffix] = m_pmCurrentState.bus4State.instrumentBusbarVoltage; - suffix = getTypeName(typeid(m_pmCurrentState.bus4State.instrumentBusbarCurrent).name()); - currentBusState[VAR_TO_STR(LVBBinsBusCur)+suffix] = m_pmCurrentState.bus4State.instrumentBusbarCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus4State.unit1Current).name()); - currentBusState[VAR_TO_STR(LVBBunit1Cur)+suffix] = m_pmCurrentState.bus4State.unit1Current; - suffix = getTypeName(typeid(m_pmCurrentState.bus4State.unit2Current).name()); - currentBusState[VAR_TO_STR(LVBBunit2Cur)+suffix] = m_pmCurrentState.bus4State.unit2Current; - suffix = getTypeName(typeid(m_pmCurrentState.bus4State.unit3Current).name()); - currentBusState[VAR_TO_STR(LVBBunit3Cur)+suffix] = m_pmCurrentState.bus4State.unit3Current; - suffix = getTypeName(typeid(m_pmCurrentState.bus4State.unit5Current).name()); - currentBusState[VAR_TO_STR(LVBBunit5Cur)+suffix] = m_pmCurrentState.bus4State.unit5Current; - suffix = getTypeName(typeid(m_pmCurrentState.bus4State.bowPZDeviceCurrent).name()); - currentBusState[VAR_TO_STR(LVBBbowPZDevCur)+suffix] = m_pmCurrentState.bus4State.bowPZDeviceCurrent; - suffix = getTypeName(typeid(m_pmCurrentState.bus4State.emergencyLithiumBatteryGroup1Current).name()); - currentBusState[VAR_TO_STR(LVBBemerBatCur)+suffix] = m_pmCurrentState.bus4State.emergencyLithiumBatteryGroup1Current; - suffix = getTypeName(typeid(m_pmCurrentState.bus4State.emergency1BusbarVoltage).name()); - currentBusState[VAR_TO_STR(LVBBemerBusVol)+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_TO_DB_STATE, pms.toStyledString()); - Notify(PM_TO_DB_FCSSTATE, fcs.toStyledString()); - Notify(PM_TO_DB_LIBATSTATE, lbs.toStyledString()); - Notify(PM_TO_DB_DISSTATE, dis.toStyledString()); - Notify(PM_TO_DB_CURRENTSTATE, 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_TO_DB_STATE+".json"); - - jsonStr = Json::writeString(builder, fcs); - saveStringToJsonFile(jsonStr, pathFile+PM_TO_DB_FCSSTATE+".json"); - - jsonStr = Json::writeString(builder, lbs); - saveStringToJsonFile(jsonStr, pathFile+PM_TO_DB_LIBATSTATE+".json"); - - jsonStr = Json::writeString(builder, dis); - saveStringToJsonFile(jsonStr, pathFile+PM_TO_DB_DISSTATE + ".json"); - - jsonStr = Json::writeString(builder, currentBusState); - saveStringToJsonFile(jsonStr, pathFile+PM_TO_DB_CURRENTSTATE + ".json"); - - return true; -} +} \ No newline at end of file diff --git a/src/pPowerManger/PowerManger.h b/src/pPowerManger/PowerManger.h index 5c148a8..02bd5c0 100644 --- a/src/pPowerManger/PowerManger.h +++ b/src/pPowerManger/PowerManger.h @@ -37,8 +37,8 @@ class PowerManagerFsm; #include "SQLiteDB.h" #include "driver.h" #include "LowerCommManager.h" +#include "UpperCommManager.h" -#define VAR_TO_STR(var) #var #define IPORT 5000 #define CCUPORT 5001 @@ -68,7 +68,6 @@ class PowerManger : public AppCastingMOOSApp PowerManger(); ~PowerManger(); public: - bool ListenLoopUDP(); bool FsmLoop(); protected: // Standard MOOSApp functions to overload @@ -90,16 +89,11 @@ class PowerManger : public AppCastingMOOSApp //通信状态变量及操作函数 XPCUdpSocket* setUdpScoket(long lPort); - bool updatePmState(); - bool updateConnectState(); + // bool updatePmState(); + // bool updateConnectState(); int connectState; - double msg_CcuStateFbMsg_Update_time; - // double msg_CcuSetParmFbMsg_Update_time; - double msg_disHighVolBusFbMsg_Update_time; - double msg_disHighAVolBusFbMsg_Update_time; - double msg_disHighBVolBusFbMsg_Update_time; - double msg_disLowBusFbMsg_Update_time; + /************************************************************/ /* |<------------FEEDBACK--------<-- */ /* | | */ @@ -138,30 +132,18 @@ class PowerManger : public AppCastingMOOSApp Driver m_driver; //设备驱动 std::string m_pmEvent; // 状态机事件描述 //=============================运行变量====================================== - // 配电和CCU的反馈状态 - msg_CcuStateFbMsg m_CcuCurrentState; - msg_disHighVolBusFbMsg m_disHighVolBusCurrentState; - msg_disHighAVolBusFbMsg m_disHighAVolBusCurrentState; - msg_disHighBVolBusFbMsg m_disHighBVolBusCurrentState; - msg_disLowBusFbMsg m_disLowBusState; - - //下位机操作函数 - void disSysOption(); - void ccuOption(); - - char getBreakerOption(char cmd); + // char getBreakerOption(char cmd); void initControlCmd(); //上位机操作函数 - bool buildPowerSysReport(); + // bool buildPowerSysReport(); bool getMsCmdFromJson(MSControlCmd &cmd,const string &strJson); private: - // CMOOSThread m_ListenThread; // CMOOSThread m_FsmThread; LowerCommManager* m_lowerCommManager; - XPCUdpSocket* m_udpSocket; + UpperCommManager* m_upperCommManager; // 状态机实例 PowerManagerFsm m_fsm; @@ -180,8 +162,10 @@ class PowerManger : public AppCastingMOOSApp bool shutdown(); bool powerOn(); bool powerOff(); - - + + bool sendNotification(const std::string& key, const std::string& value) { + return Notify(key, value); + } }; #endif diff --git a/src/pPowerManger/UpperCommManager.cpp b/src/pPowerManger/UpperCommManager.cpp index c760d54..c9a25f4 100644 --- a/src/pPowerManger/UpperCommManager.cpp +++ b/src/pPowerManger/UpperCommManager.cpp @@ -32,14 +32,442 @@ bool UpperCommManager::processUpperMsg(const string& key, const string& strJson) } void UpperCommManager::processPeriodicTasks() { - buildPowerSysReport(); - Notify(PM_TO_DB_SUBDISCMD, - m_pm->m_driver.saveDriverTableToJson(&m_pm->m_subDisSysCmd)); - Notify(PM_TO_DB_EQUIPMENTSTATE, - m_pm->m_driver.saveDriverTableToJson(&m_pm->m_currentDriverState)); + buildSystemReport(); + // m_pm->Notify(PM_TO_DB_SUBDISCMD, m_pm->m_driver.saveDriverTableToJson(&m_pm->m_subDisSysCmd)); + // m_pm->Notify(PM_TO_DB_EQUIPMENTSTATE, m_pm->m_driver.saveDriverTableToJson(&m_pm->m_currentDriverState)); } -void UpperCommManager::buildPowerSysReport() { - // 原有buildPowerSysReport实现 - // 需要从PowerManger.cpp迁移过来 +void UpperCommManager::buildSystemReport() { + //TODO: 构建能源系统报告 + string suffix; + Json::Value pms; + Json::Value fcs; + Json::Value lbs; + Json::Value dis; + // 构建能源系统报告 + //1.构建系统状态报告 + suffix = getTypeName(typeid(m_pm->workCondition).name()); + pms[VAR_TO_STR(workCondition)+suffix] = m_pm->workCondition; + + suffix = getTypeName(typeid(m_pm->currentMod).name()); + pms[VAR_TO_STR(currentMod)+suffix] = m_pm->currentMod; + + suffix = getTypeName(typeid(m_pm->powerState).name()); + pms[VAR_TO_STR(powerState)+suffix] = m_pm->powerState; + + suffix = getTypeName(typeid(m_pm->falutLevel).name()); + pms[VAR_TO_STR(falutLevel)+suffix] = m_pm->falutLevel; + + Json::Value faultCode_array; + for(auto val : m_pm->faultCode) + { + faultCode_array.append(val); + } + pms[VAR_TO_STR(faultCode_array)] = faultCode_array; + + suffix = getTypeName(typeid(m_pm->soc).name()); + pms[VAR_TO_STR(soc)+suffix] = m_pm->soc; + + suffix = getTypeName(typeid(m_pm->sustainableTime).name()); + pms[VAR_TO_STR(sustainableTime)+suffix] = m_pm->sustainableTime; + + //2.构建燃料电池状态报告 + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuState).name()); + fcs[VAR_TO_STR(fcuState)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuState; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuFaultLeve).name()); + fcs[VAR_TO_STR(fcuFaultLeve)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuFaultLeve; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerLimit).name()); + fcs[VAR_TO_STR(powLimit)+suffix] = m_pm->m_pmCurrentState.ccustate.powerLimit; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.totalPowerGeneration).name()); + fcs[VAR_TO_STR(powerGen)+suffix] = m_pm->m_pmCurrentState.ccustate.totalPowerGeneration; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.ch4o).name()); + fcs[VAR_TO_STR(ch4o)+suffix] = m_pm->m_pmCurrentState.ccustate.ch4o; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.o2).name()); + fcs[VAR_TO_STR(o2)+suffix] = m_pm->m_pmCurrentState.ccustate.o2; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuVoltage).name()); + fcs[VAR_TO_STR(fcuVol)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuVoltage; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuCurrent).name()); + fcs[VAR_TO_STR(fcuCur)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuCurrent; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.o2Level).name()); + fcs[VAR_TO_STR(o2Level)+suffix] = m_pm->m_pmCurrentState.ccustate.o2Level; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.exchangerTemperature).name()); + fcs[VAR_TO_STR(excTemp)+suffix] = m_pm->m_pmCurrentState.ccustate.exchangerTemperature; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuOutPower).name()); + fcs[VAR_TO_STR(fcuOutPower)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuOutPower; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuOutIns).name()); + fcs[VAR_TO_STR(fcuOutIns)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuOutIns; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuVoltageIns).name()); + fcs[VAR_TO_STR(fcuVolIns)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuVoltageIns; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuVoltagePower).name()); + fcs[VAR_TO_STR(fcuVolPower)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuVoltagePower; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuCurrentIns).name()); + fcs[VAR_TO_STR(fcuCurIns)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuCurrentIns; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuCurrentPower).name()); + fcs[VAR_TO_STR(fcuCurPower)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuCurrentPower; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.h2Concentration1).name()); + fcs[VAR_TO_STR(h2Concent1)+suffix] = m_pm->m_pmCurrentState.ccustate.h2Concentration1; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.h2Concentration2).name()); + fcs[VAR_TO_STR(h2Concent2)+suffix] = m_pm->m_pmCurrentState.ccustate.h2Concentration2; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.o2Concentration1).name()); + fcs[VAR_TO_STR(o2Concent1)+suffix] = m_pm->m_pmCurrentState.ccustate.o2Concentration1; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.o2Concentration2).name()); + fcs[VAR_TO_STR(o2Concent2)+suffix] = m_pm->m_pmCurrentState.ccustate.o2Concentration2; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.ch4oConcentration1).name()); + fcs[VAR_TO_STR(ch4oConcent1)+suffix] = m_pm->m_pmCurrentState.ccustate.ch4oConcentration1; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.ch4oConcentration2).name()); + fcs[VAR_TO_STR(ch4oConcent2)+suffix] = m_pm->m_pmCurrentState.ccustate.ch4oConcentration2; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.backpressure1).name()); + fcs[VAR_TO_STR(backpressure1)+suffix] = m_pm->m_pmCurrentState.ccustate.backpressure1; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.backpressure2).name()); + fcs[VAR_TO_STR(backpressure2)+suffix] = m_pm->m_pmCurrentState.ccustate.backpressure2; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.flameDetection).name()); + fcs[VAR_TO_STR(flameDet)+suffix] = m_pm->m_pmCurrentState.ccustate.flameDetection; + + unsigned short faultCode1; + unsigned short faultCode2; + unsigned short faultCode3; + faultCode1 = (m_pm->m_pmCurrentState.ccustate.fcuGZ_1H << 8) | m_pm->m_pmCurrentState.ccustate.fcuGZ_1L; + faultCode2 = (m_pm->m_pmCurrentState.ccustate.fcuGZ_2H << 8) | m_pm->m_pmCurrentState.ccustate.fcuGZ_2L; + faultCode3 = (m_pm->m_pmCurrentState.ccustate.fcuGZ_3H << 8) | m_pm->m_pmCurrentState.ccustate.fcuGZ_3L; + + suffix = getTypeName(typeid(faultCode1).name()); + fcs[VAR_TO_STR(faultCode1)+suffix] = faultCode1; + suffix = getTypeName(typeid(faultCode2).name()); + fcs[VAR_TO_STR(faultCode2)+suffix] = faultCode2; + suffix = getTypeName(typeid(faultCode3).name()); + fcs[VAR_TO_STR(faultCode3)+suffix] = faultCode3; + + //4.构建动力锂电池状态报告 + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insPosRelayState).name()); + lbs[VAR_TO_STR(insPosRelayState)+suffix] = m_pm->m_pmCurrentState.ccustate.insPosRelayState; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insNegRelayState).name()); + lbs[VAR_TO_STR(insNegRelayState)+suffix] = m_pm->m_pmCurrentState.ccustate.insNegRelayState; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerPosRelayState).name()); + lbs[VAR_TO_STR(powPosRelayState)+suffix] = m_pm->m_pmCurrentState.ccustate.powerPosRelayState; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerNegRelayState).name()); + lbs[VAR_TO_STR(powNegRelayState)+suffix] = m_pm->m_pmCurrentState.ccustate.powerNegRelayState; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insBatLimit).name()); + lbs[VAR_TO_STR(insBatLimit)+suffix] = m_pm->m_pmCurrentState.ccustate.insBatLimit; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerBatLimit).name()); + lbs[VAR_TO_STR(powerBatLimit)+suffix] = m_pm->m_pmCurrentState.ccustate.powerBatLimit; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insBatSoc).name()); + lbs[VAR_TO_STR(insBatSoc)+suffix] = m_pm->m_pmCurrentState.ccustate.insBatSoc; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerBatSoc).name()); + lbs[VAR_TO_STR(powBatSoc)+suffix] = m_pm->m_pmCurrentState.ccustate.powerBatSoc; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insBatTotalElectricity).name()); + lbs[VAR_TO_STR(insBatTotalElect)+suffix] = m_pm->m_pmCurrentState.ccustate.insBatTotalElectricity; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerBatTotalElectricity).name()); + lbs[VAR_TO_STR(powBatTotalElect)+suffix] = m_pm->m_pmCurrentState.ccustate.powerBatTotalElectricity; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insBatCurrentElectricity).name()); + lbs[VAR_TO_STR(insBatCurElect)+suffix] = m_pm->m_pmCurrentState.ccustate.insBatCurrentElectricity; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerBatCurrentElectricity).name()); + lbs[VAR_TO_STR(powBatCurElect)+suffix] = m_pm->m_pmCurrentState.ccustate.powerBatCurrentElectricity; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insChargeState).name()); + lbs[VAR_TO_STR(insChargeState)+suffix] = m_pm->m_pmCurrentState.ccustate.insChargeState; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerChargeState).name()); + lbs[VAR_TO_STR(powChargeState)+suffix] = m_pm->m_pmCurrentState.ccustate.powerChargeState; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insLinkVoltage).name()); + lbs[VAR_TO_STR(insLinkVol)+suffix] = m_pm->m_pmCurrentState.ccustate.insLinkVoltage; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insPackVoltage).name()); + lbs[VAR_TO_STR(insPackVol)+suffix] = m_pm->m_pmCurrentState.ccustate.insPackVoltage; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insCurrent).name()); + lbs[VAR_TO_STR(insCurrent)+suffix] = m_pm->m_pmCurrentState.ccustate.insCurrent; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insPosInsulationResistance).name()); + lbs[VAR_TO_STR(insPosRes)+suffix] = m_pm->m_pmCurrentState.ccustate.insPosInsulationResistance; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insNegInsulationResistance).name()); + lbs[VAR_TO_STR(insNegRes)+suffix] = m_pm->m_pmCurrentState.ccustate.insNegInsulationResistance; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerLinkVoltage).name()); + lbs[VAR_TO_STR(powLinkVol)+suffix] = m_pm->m_pmCurrentState.ccustate.powerLinkVoltage; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerPackVoltage).name()); + lbs[VAR_TO_STR(powerPackVol)+suffix] = m_pm->m_pmCurrentState.ccustate.powerPackVoltage; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerCurrent).name()); + lbs[VAR_TO_STR(powCur)+suffix] = m_pm->m_pmCurrentState.ccustate.powerCurrent; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerPosInsulationResistance).name()); + lbs[VAR_TO_STR(powPosRes)+suffix] = m_pm->m_pmCurrentState.ccustate.powerPosInsulationResistance; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerNegInsulationResistance).name()); + lbs[VAR_TO_STR(powNegRes)+suffix] = m_pm->m_pmCurrentState.ccustate.powerNegInsulationResistance; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insCurrentSocHold1).name()); + lbs[VAR_TO_STR(insCurSocHold1)+suffix] = m_pm->m_pmCurrentState.ccustate.insCurrentSocHold1; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insCurrentSocHold2).name()); + lbs[VAR_TO_STR(insCurSocHold2)+suffix] = m_pm->m_pmCurrentState.ccustate.insCurrentSocHold2; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insCurrentSocHold3).name()); + lbs[VAR_TO_STR(insCurSocHold3)+suffix] = m_pm->m_pmCurrentState.ccustate.insCurrentSocHold3; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuCurrentToInsLimit1).name()); + lbs[VAR_TO_STR(fcuCurToInsLimit1)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuCurrentToInsLimit1; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuCurrentToinsLimit2).name()); + lbs[VAR_TO_STR(fcuCurToinsLimit2)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuCurrentToinsLimit2; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerCurrentSocHold1).name()); + lbs[VAR_TO_STR(powCurSocHold1)+suffix] = m_pm->m_pmCurrentState.ccustate.powerCurrentSocHold1; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerCurrentSocHold2).name()); + lbs[VAR_TO_STR(powCurSocHold2)+suffix] = m_pm->m_pmCurrentState.ccustate.powerCurrentSocHold2; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerCurrentSocHold3).name()); + lbs[VAR_TO_STR(powCurSocHold3)+suffix] = m_pm->m_pmCurrentState.ccustate.powerCurrentSocHold3; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerCurrentToInsLimit1).name()); + lbs[VAR_TO_STR(powCurToInsLimit1)+suffix] = m_pm->m_pmCurrentState.ccustate.powerCurrentToInsLimit1; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerCurrentToinsLimit2).name()); + lbs[VAR_TO_STR(powCurToinsLimit2)+suffix] = m_pm->m_pmCurrentState.ccustate.powerCurrentToinsLimit2; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insAlarmIdentificationWord).name()); + lbs[VAR_TO_STR(insfaultCode)+suffix] = m_pm->m_pmCurrentState.ccustate.insAlarmIdentificationWord; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerAlarmIdentificationWord).name()); + lbs[VAR_TO_STR(powfaultCode)+suffix] = m_pm->m_pmCurrentState.ccustate.powerAlarmIdentificationWord; + + //5.构建配电系统状态报告 + disBus1Breaker* pdis1=new disBus1Breaker; + disBus2Breaker* pdis2=new disBus2Breaker; + disBus3Breaker* pdis3=new disBus3Breaker; + disBus4Breaker* pdis4=new disBus4Breaker; + + *pdis1 = m_pm->m_currentDisBreakerState.bus1Breaker; + *pdis2 = m_pm->m_currentDisBreakerState.bus2Breaker; + *pdis3 = m_pm->m_currentDisBreakerState.bus3Breaker; + *pdis4 = m_pm->m_currentDisBreakerState.bus4Breaker; + + dis["HVolBusBreaker_uint16"] = *(unsigned short*)pdis1; + dis["HVolABusBreaker_unit16"] = *(unsigned short*)pdis2; + dis["HVolBBusBreaker_unit16"] = *(unsigned short*)pdis3; + dis["LVolBusBreaker_uint16"] = *(unsigned short*)pdis4; + + //TODO: 构建配电系统故障码 + Json::Value faultCodeDis_array; + for(auto val : m_pm->faultCode) + { + faultCodeDis_array.append(val); + } + dis[VAR_TO_STR(faultCode_array)] = faultCodeDis_array; + + + Json::Value currentBusState; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.powerBusVoltage).name()); + currentBusState[VAR_TO_STR(HVBpowerBusVol)+suffix] = m_pm->m_pmCurrentState.bus1State.powerBusVoltage; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.dcDc5ModuleCurrent).name()); + currentBusState[VAR_TO_STR(HVBdcDc5Cur)+suffix] = m_pm->m_pmCurrentState.bus1State.dcDc5ModuleCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.powerBusCurrent).name()); + currentBusState[VAR_TO_STR(HVBpowerBusCur)+suffix] = m_pm->m_pmCurrentState.bus1State.powerBusCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.busbarAVoltage).name()); + currentBusState[VAR_TO_STR(HVBbusAVol)+suffix] = m_pm->m_pmCurrentState.bus1State.busbarAVoltage; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.propulsionMotorControlBoxCurrent).name()); + currentBusState[VAR_TO_STR(HVBmotorCur)+suffix] = m_pm->m_pmCurrentState.bus1State.propulsionMotorControlBoxCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.busbarACurrent).name()); + currentBusState[VAR_TO_STR(HVBbusACur)+suffix] = m_pm->m_pmCurrentState.bus1State.busbarACurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.lithiumBatteryGroupMeterCurrent).name()); + currentBusState[VAR_TO_STR(HVBbatGroupCur)+suffix] = m_pm->m_pmCurrentState.bus1State.lithiumBatteryGroupMeterCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.bowHighVoltageDistributionBoxCurrent).name()); + currentBusState[VAR_TO_STR(HVBbowHVolDisBoxCur)+suffix] = m_pm->m_pmCurrentState.bus1State.bowHighVoltageDistributionBoxCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.sternFTDevice45Current).name()); + currentBusState[VAR_TO_STR(HVBFTDev45Cur)+suffix] = m_pm->m_pmCurrentState.bus1State.sternFTDevice45Current; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.tyzReservedSwitchCurrent).name()); + currentBusState[VAR_TO_STR(HVBtyzCur)+suffix] = m_pm->m_pmCurrentState.bus1State.tyzReservedSwitchCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.sternRudderSwitch1Current).name()); + currentBusState[VAR_TO_STR(HVBsternRud1Cur)+suffix] = m_pm->m_pmCurrentState.bus1State.sternRudderSwitch1Current; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.reservedCurrent1).name()); + currentBusState[VAR_TO_STR(HVBreservedCur1)+suffix] = m_pm->m_pmCurrentState.bus1State.reservedCurrent1; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.sternRudderSwitch2Current).name()); + currentBusState[VAR_TO_STR(HVBsternRud2Cur)+suffix] = m_pm->m_pmCurrentState.bus1State.sternRudderSwitch2Current; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.reservedCurrent2).name()); + currentBusState[VAR_TO_STR(HVBreservedCur2)+suffix] = m_pm->m_pmCurrentState.bus1State.reservedCurrent2; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.fbReservedSwitchCurrent).name()); + currentBusState[VAR_TO_STR(HVBfbCur)+suffix] = m_pm->m_pmCurrentState.bus1State.fbReservedSwitchCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus1State.reservedCurrent3).name()); + currentBusState[VAR_TO_STR(HVBreservedCur3)+suffix] = m_pm->m_pmCurrentState.bus1State.reservedCurrent3; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus2State.busbarBVoltage).name()); + currentBusState[VAR_TO_STR(HVABbusBVol)+suffix] = m_pm->m_pmCurrentState.bus2State.busbarBVoltage; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus2State.busbarBCurrent).name()); + currentBusState[VAR_TO_STR(HVABbusBCur)+suffix] = m_pm->m_pmCurrentState.bus2State.busbarBCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus2State.bowFTDevice123Current).name()); + currentBusState[VAR_TO_STR(HVABFTDev123Cur)+suffix] = m_pm->m_pmCurrentState.bus2State.bowFTDevice123Current; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus2State.actuatorCurrent).name()); + currentBusState[VAR_TO_STR(HVABactCur)+suffix] = m_pm->m_pmCurrentState.bus2State.actuatorCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus2State.mastSteeringGearControlBoxCurrent).name()); + currentBusState[VAR_TO_STR(HVABmastSteGeaCur)+suffix] = m_pm->m_pmCurrentState.bus2State.mastSteeringGearControlBoxCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus2State.xczCurrent).name()); + currentBusState[VAR_TO_STR(HVABxczCur)+suffix] = m_pm->m_pmCurrentState.bus2State.xczCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus2State.bowRudderControlBoxCurrent).name()); + currentBusState[VAR_TO_STR(HVABbowRudCur)+suffix] = m_pm->m_pmCurrentState.bus2State.bowRudderControlBoxCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus2State.openWaterCoverStartCylinderCurrent).name()); + currentBusState[VAR_TO_STR(HVABopenWaterCur)+suffix] = m_pm->m_pmCurrentState.bus2State.openWaterCoverStartCylinderCurrent; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus3State.instrumentBusbarVoltage).name()); + currentBusState[VAR_TO_STR(HVBBinsBusVol)+suffix] = m_pm->m_pmCurrentState.bus3State.instrumentBusbarVoltage; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus3State.bowLowVoltageDistributionBoxCurrent).name()); + currentBusState[VAR_TO_STR(HVBBbowLowVolDisBoxCur)+suffix] = m_pm->m_pmCurrentState.bus3State.bowLowVoltageDistributionBoxCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus3State.dcC1InstrumentDC48VCurrent).name()); + currentBusState[VAR_TO_STR(HVBBdcC1InsCur)+suffix] = m_pm->m_pmCurrentState.bus3State.dcC1InstrumentDC48VCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus3State.reservedCurrent1).name()); + currentBusState[VAR_TO_STR(HVBBreservedCur1)+suffix] = m_pm->m_pmCurrentState.bus3State.reservedCurrent1; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus3State.emergencyLithiumBatteryGroup2Current).name()); + currentBusState[VAR_TO_STR(HVBBemerBatCur)+suffix] = m_pm->m_pmCurrentState.bus3State.emergencyLithiumBatteryGroup2Current; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus3State.lithiumBatteryGroupInstrumentCurrent).name()); + currentBusState[VAR_TO_STR(HVBBbatInsCur)+suffix] = m_pm->m_pmCurrentState.bus3State.lithiumBatteryGroupInstrumentCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus3State.unit4InstrumentDC48VCurrent).name()); + currentBusState[VAR_TO_STR(HVBBunit4Cur)+suffix] = m_pm->m_pmCurrentState.bus3State.unit4InstrumentDC48VCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus3State.reservedCurrent2).name()); + currentBusState[VAR_TO_STR(HVBBreservedCur2)+suffix] = m_pm->m_pmCurrentState.bus3State.reservedCurrent2; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus3State.emergency2BusbarVoltage).name()); + currentBusState[VAR_TO_STR(HVBBemer2BusVol)+suffix] = m_pm->m_pmCurrentState.bus3State.emergency2BusbarVoltage; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus3State.compositeEnergyManagementSystemEmergencyDC48VCurrent).name()); + currentBusState[VAR_TO_STR(HVBBCCUCur)+suffix] = m_pm->m_pmCurrentState.bus3State.compositeEnergyManagementSystemEmergencyDC48VCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus3State.fuelCellSecuritySystemEmergencyDC48VCurrent).name()); + currentBusState[VAR_TO_STR(HVBBFCSSecurSysCur)+suffix] = m_pm->m_pmCurrentState.bus3State.fuelCellSecuritySystemEmergencyDC48VCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus3State.plcControlPowerCurrent).name()); + currentBusState[VAR_TO_STR(HVBBplcCur)+suffix] = m_pm->m_pmCurrentState.bus3State.plcControlPowerCurrent; + + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus4State.instrumentBusbarVoltage).name()); + currentBusState[VAR_TO_STR(LVBinsBusVol)+suffix] = m_pm->m_pmCurrentState.bus4State.instrumentBusbarVoltage; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus4State.instrumentBusbarCurrent).name()); + currentBusState[VAR_TO_STR(LVBBinsBusCur)+suffix] = m_pm->m_pmCurrentState.bus4State.instrumentBusbarCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus4State.unit1Current).name()); + currentBusState[VAR_TO_STR(LVBBunit1Cur)+suffix] = m_pm->m_pmCurrentState.bus4State.unit1Current; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus4State.unit2Current).name()); + currentBusState[VAR_TO_STR(LVBBunit2Cur)+suffix] = m_pm->m_pmCurrentState.bus4State.unit2Current; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus4State.unit3Current).name()); + currentBusState[VAR_TO_STR(LVBBunit3Cur)+suffix] = m_pm->m_pmCurrentState.bus4State.unit3Current; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus4State.unit5Current).name()); + currentBusState[VAR_TO_STR(LVBBunit5Cur)+suffix] = m_pm->m_pmCurrentState.bus4State.unit5Current; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus4State.bowPZDeviceCurrent).name()); + currentBusState[VAR_TO_STR(LVBBbowPZDevCur)+suffix] = m_pm->m_pmCurrentState.bus4State.bowPZDeviceCurrent; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus4State.emergencyLithiumBatteryGroup1Current).name()); + currentBusState[VAR_TO_STR(LVBBemerBatCur)+suffix] = m_pm->m_pmCurrentState.bus4State.emergencyLithiumBatteryGroup1Current; + suffix = getTypeName(typeid(m_pm->m_pmCurrentState.bus4State.emergency1BusbarVoltage).name()); + currentBusState[VAR_TO_STR(LVBBemerBusVol)+suffix] = m_pm->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; + + m_pm->sendNotification(PM_TO_DB_STATE, pms.toStyledString()); + m_pm->sendNotification(PM_TO_DB_FCSSTATE, fcs.toStyledString()); + m_pm->sendNotification(PM_TO_DB_LIBATSTATE, lbs.toStyledString()); + m_pm->sendNotification(PM_TO_DB_DISSTATE, dis.toStyledString()); + m_pm->sendNotification(PM_TO_DB_CURRENTSTATE, 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_TO_DB_STATE+".json"); + + jsonStr = Json::writeString(builder, fcs); + saveStringToJsonFile(jsonStr, pathFile+PM_TO_DB_FCSSTATE+".json"); + + jsonStr = Json::writeString(builder, lbs); + saveStringToJsonFile(jsonStr, pathFile+PM_TO_DB_LIBATSTATE+".json"); + + jsonStr = Json::writeString(builder, dis); + saveStringToJsonFile(jsonStr, pathFile+PM_TO_DB_DISSTATE + ".json"); + + jsonStr = Json::writeString(builder, currentBusState); + saveStringToJsonFile(jsonStr, pathFile+PM_TO_DB_CURRENTSTATE + ".json"); + +// return true; +} +bool UpperCommManager::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; + } +} +string UpperCommManager::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"; + } } \ No newline at end of file diff --git a/src/pPowerManger/UpperCommManager.h b/src/pPowerManger/UpperCommManager.h index 8af515c..2ffa099 100644 --- a/src/pPowerManger/UpperCommManager.h +++ b/src/pPowerManger/UpperCommManager.h @@ -5,6 +5,11 @@ #include "pmSysvariable.h" #include "driver.h" #include "json/json.h" +#include +#include +#include +using namespace std; +#define VAR_TO_STR(var) #var class PowerManger; // 前向声明 @@ -13,20 +18,28 @@ public: UpperCommManager(PowerManger* powerManager); ~UpperCommManager(); + //周期调用 + void processPeriodicTasks(); + // 处理上位机消息 bool processUpperMsg(const std::string& key, const std::string& msg); // 生成系统报告 - bool buildSystemReport(); + void buildSystemReport(); // 获取控制命令 const MSControlCmd& getControlCmd() const { return m_msCmd; } // 更新设备命令状态 void updateEquipmentCmd(const DriverTable& cmd); - + + // 其他公共函数 + string getTypeName(const string typeName); + bool saveStringToJsonFile(const string &strJson, const string &filePath); + + private: - PowerManger* m_powerManager; + PowerManger* m_pm; MSControlCmd m_msCmd; Driver m_driver;