/************************************************************/ /* NAME: */ /* ORGN: MIT, Cambridge MA */ /* FILE: PowerManger.cpp */ /* DATE: December 29th, 1963 */ /************************************************************/ #include #include "MBUtils.h" #include "ACTable.h" #include "PowerManger.h" #include using namespace std; bool _ListenCB(void * pParam) { PowerManger* pMe = (PowerManger* )pParam; return pMe->ListenLoopUDP(); } bool _FsmCB(void * pParam) { PowerManger* pMe = (PowerManger* )pParam; return pMe->FsmLoop(); } //--------------------------------------------------------- // Constructor() PowerManger::PowerManger() { workCondition = 0; currentMod = 0; powerState = 0; falutLevel = 0; soc = 0; sustainableTime = 0; m_faultNum = 0; 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; connectState = 0; //初始化断路器状态 initControlCmd(); //初始化数据库 string dbPath = "/home/zjk/project/H100/H100PowerManger/data/power_data.db"; m_db = new SQLiteDB(dbPath); m_db->createPowerDataTables(); m_db->createStateTables(); m_db->createDisCcuSysTables(); //注册状态机 m_fsm.RegisterState("Init", 1, m_Inite_s1); m_fsm.RegisterState("Stady", 2, m_Standby_s2); m_fsm.RegisterState("Fault", 99, m_Fault_s99); m_fsm.RegisterHandleFunction(&m_Inite_s1, handleInite_s1); m_fsm.RegisterHandleFunction(&m_Standby_s2, handleStandby_s2); m_fsm.RegisterHandleFunction(&m_Fault_s99, handleFault_s99); // 初始化状态机 m_pmState = m_Inite_s1; } //--------------------------------------------------------- // Destructor PowerManger::~PowerManger() { } //--------------------------------------------------------- // Procedure: OnNewMail() bool PowerManger::OnNewMail(MOOSMSG_LIST &NewMail) { AppCastingMOOSApp::OnNewMail(NewMail); MOOSMSG_LIST::iterator p; for(p=NewMail.begin(); p!=NewMail.end(); p++) { CMOOSMsg &msg = *p; string key = msg.GetKey(); #if 0 // Keep these around just for template string comm = msg.GetCommunity(); double dval = msg.GetDouble(); string sval = msg.GetString(); string msrc = msg.GetSource(); double mtime = msg.GetTime(); bool mdbl = msg.IsDouble(); bool mstr = msg.IsString(); #endif if(key == "FOO") cout << "great!"; else if(key != "APPCAST_REQ") // handled by AppCastingMOOSApp reportRunWarning("Unhandled Mail: " + key); } return(true); } //--------------------------------------------------------- // Procedure: OnConnectToServer() bool PowerManger::OnConnectToServer() { registerVariables(); return(true); } //--------------------------------------------------------- // Procedure: Iterate() // happens AppTick times per second //固定为4Hz 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(); } //4. 打印错误信息 if(!m_udpComm.sError.empty()) { for(int i=0;iiRecieveMessage(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; } 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; } 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; } 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; } 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; } void PowerManger::ccuOption() { m_db->insertCcuSysCmd(m_CcuColCmd); if(!m_udpComm.sendCcuColCmd(m_CcuColCmd)) cout << "send ccu col cmd failed!" << endl; } void PowerManger::disSysOption() { //1.更新断路器的状态 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; m_currentDisBreakerState.bus1Breaker = *pdis1; m_currentDisBreakerState.bus2Breaker = *pdis2; m_currentDisBreakerState.bus3Breaker = *pdis3; m_currentDisBreakerState.bus4Breaker = *pdis4; delete pdis1; delete pdis2; delete pdis3; delete pdis4; //2.根据目标状态进行断路器操作 //a. 高压母线的断路器 disHighVolBusCmd a; a.fuelCellCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.fuelCellCircuitBreaker); a.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.lithiumBatteryGroupInstrumentCircuitBreaker); a.dcDc5ModuleCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.dcDc5ModuleCircuitBreaker); a.powerLithiumBatteryCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.powerLithiumBatteryCircuitBreaker); a.propulsionMotorCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.propulsionMotorCircuitBreaker); a.bowHighVoltageDistributionBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.bowHighVoltageDistributionBoxCircuitBreaker); a.tyzReservedCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.tyzReservedCircuitBreaker); a.sternFTDevice45CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.sternFTDevice45CircuitBreaker); a.sternRudderSwitch1CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.sternRudderSwitch1CircuitBreaker); a.sternRudderSwitch2CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.sternRudderSwitch2CircuitBreaker); a.reservedCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.reservedCircuitBreaker); a.fbReservedCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.fbReservedCircuitBreaker); m_udpComm.sendDisSysCmd(a); //b. 高压汇流排A断路器 disHighAVolBusCmd b; b.bowFTDevice123CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.bowFTDevice123CircuitBreaker); b.actuatorCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.actuatorCircuitBreaker); b.mastSteeringGearControlBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.mastSteeringGearControlBoxCircuitBreaker); b.xczCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.xczCircuitBreaker); b.bowRudderControlBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.bowRudderControlBoxCircuitBreaker); b.openWaterCoverStartCylinderCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.openWaterCoverStartCylinderCircuitBreaker); m_udpComm.sendDisSysCmd(b); //c. 高压汇流排B断路器 disHighBVolBusCmd c; c.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.lithiumBatteryGroupInstrumentCircuitBreaker); c.bowLowVoltageDistributionBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.bowLowVoltageDistributionBoxCircuitBreaker); c.unit4InstrumentDC48VCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.unit4InstrumentDC48VCircuitBreaker); c.dcC1DCDistributionPanelCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.dcC1DCDistributionPanelCircuitBreaker); c.reservedCircuitBreaker1 = getBreakerOption(m_targetDisBreakerState.bus3Breaker.reservedCircuitBreaker1); c.reservedCircuitBreaker2 = getBreakerOption(m_targetDisBreakerState.bus3Breaker.reservedCircuitBreaker2); c.emergencyLithiumBatteryGroup2CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.emergencyLithiumBatteryGroup2CircuitBreaker); m_udpComm.sendDisSysCmd(c); //d. 闭合低压汇流排断路器 disLowBusCmd d; d.unit1CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.unit1CircuitBreaker); d.unit2CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.unit2CircuitBreaker); d.unit3CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.unit3CircuitBreaker); d.unit5CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.unit5CircuitBreaker); d.bowPZDeviceCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.bowPZDeviceCircuitBreaker); d.reservedCircuitBreaker1 = getBreakerOption(m_targetDisBreakerState.bus4Breaker.reservedCircuitBreaker1); d.reservedCircuitBreaker2 = getBreakerOption(m_targetDisBreakerState.bus4Breaker.reservedCircuitBreaker2); d.emergencyLithiumBatteryGroup1CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.emergencyLithiumBatteryGroup1CircuitBreaker); m_udpComm.sendDisSysCmd(d); //将指令写入数据库 m_db->insertDisSysCmd(a); m_db->insertDisSysCmd(b); m_db->insertDisSysCmd(c); m_db->insertDisSysCmd(d); } 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() { m_stateData.state_id = m_pmState.id; m_stateData.state_name = m_pmState.name; m_stateData.event = m_pmEvent; m_stateData.event_id = 1; m_stateData.fault_code = m_faultNum; m_stateData.note = "No fault"; if(!m_db->insertStateData(m_stateData)) return false; // //写入配电系统状态 // if(!m_db->insertDisCcuData(m_pmCurrentState)) // return false; return true; } void PowerManger::printState(FSM_State st, string desp){ cout << MOOS::ConsoleColours::Yellow() << "STATE " << st.id << " [" << st.name << "] " << MOOS::ConsoleColours::reset(); cout << MOOS::ConsoleColours::Blue() << " -> " << MOOS::ConsoleColours::reset(); // 检查desp是否有“故障” if (desp.find("故障") != string::npos) { cout << MOOS::ConsoleColours::Red() << desp << MOOS::ConsoleColours::reset() << endl; return; } cout << MOOS::ConsoleColours::Green() << desp << MOOS::ConsoleColours::reset() << endl; } int PowerManger::handleInite_s1(FSM_State &fsm, void* pData) { PowerManger* pm = (PowerManger*)pData; //1. 检查通信是否正常 如果超时则进入故障状态 double StartTime = pm->GetAppStartTime(); while (!pm->connectState == 5) { MOOSPause(1000); pm->updateTime(); double dft = abs(pm->m_current_time - StartTime); if(dft > 10) { pm->m_pmState = pm->m_Fault_s99; pm->m_faultNum = 1; break; } string desp = "等待复合管控消息 : " + to_string(10-dft); pm->printState(fsm,desp); } //2. 检查复合管控器是否上报故障 如果故障则进入故障状态 bool ok = true; if(pm->m_pmCurrentState.ccustate.fcuGZ_1H != 0 || pm->m_pmCurrentState.ccustate.fcuGZ_1L != 0 || pm->m_pmCurrentState.ccustate.fcuGZ_2H != 0 || pm->m_pmCurrentState.ccustate.fcuGZ_2L != 0 || pm->m_pmCurrentState.ccustate.fcuGZ_3H != 0 || pm->m_pmCurrentState.ccustate.fcuGZ_3L != 0 || pm->m_pmCurrentState.ccustate.insEmergencyStatusWord != 0) { ok = false; } if(!ok) { pm->m_pmState = pm->m_Fault_s99; } //3. 初始化系统为待机状态 pm->initControlCmd(); pm->m_pmState = pm->m_Standby_s2; return 0; } int PowerManger::handleStandby_s2(FSM_State &fsm, void* pData) { PowerManger* pm = (PowerManger*)pData; pm->m_stateData.note = "待机状态"; while (true) { string desp = "待机状态"; pm->printState(fsm,desp); MOOSPause(1000); } } int PowerManger::handleFault_s99(FSM_State &fsm, void* pData) { // cout << fsm.name << endl; PowerManger* pm = (PowerManger*)pData; switch (pm->m_faultNum) { case 1: pm->printState(fsm,"通信故障"); pm->m_pmEvent = "复合管控连接超时"; break; default: break; } pm->printState(fsm,"故障"); return 0; } void PowerManger::initControlCmd() { //================初始化配电指令============================= m_targetDisBreakerState.bus1Breaker.fuelCellCircuitBreaker = 0; m_targetDisBreakerState.bus1Breaker.powerLithiumBatteryCircuitBreaker = 1; //动力锂电池默认接入 m_targetDisBreakerState.bus1Breaker.propulsionMotorCircuitBreaker = 0; m_targetDisBreakerState.bus1Breaker.lithiumBatteryGroupInstrumentCircuitBreaker = 1; //仪表锂电池默认接入 m_targetDisBreakerState.bus1Breaker.dcDc5ModuleCircuitBreaker = 1; //DC-DC模块默认接入 m_targetDisBreakerState.bus1Breaker.bowHighVoltageDistributionBoxCircuitBreaker = 1; //艏部高压母线断路器默认接入 m_targetDisBreakerState.bus1Breaker.sternFTDevice45CircuitBreaker = 0; // sternFTDevice45CircuitBreaker默认接入 m_targetDisBreakerState.bus1Breaker.sternRudderSwitch1CircuitBreaker = 0; m_targetDisBreakerState.bus1Breaker.sternRudderSwitch2CircuitBreaker = 0; m_targetDisBreakerState.bus1Breaker.fbReservedCircuitBreaker = 0; m_targetDisBreakerState.bus1Breaker.tyzReservedCircuitBreaker = 0; m_targetDisBreakerState.bus1Breaker.reservedCircuitBreaker = 0; m_targetDisBreakerState.bus2Breaker.bowFTDevice123CircuitBreaker = 0; m_targetDisBreakerState.bus2Breaker.actuatorCircuitBreaker = 0; m_targetDisBreakerState.bus2Breaker.mastSteeringGearControlBoxCircuitBreaker = 0; m_targetDisBreakerState.bus2Breaker.xczCircuitBreaker = 0; m_targetDisBreakerState.bus2Breaker.bowRudderControlBoxCircuitBreaker = 0; m_targetDisBreakerState.bus2Breaker.openWaterCoverStartCylinderCircuitBreaker = 0; //锂电池默认接入 m_targetDisBreakerState.bus3Breaker.lithiumBatteryGroupInstrumentCircuitBreaker = 1; m_targetDisBreakerState.bus3Breaker.bowLowVoltageDistributionBoxCircuitBreaker = 1; m_targetDisBreakerState.bus3Breaker.unit4InstrumentDC48VCircuitBreaker = 1; m_targetDisBreakerState.bus3Breaker.dcC1DCDistributionPanelCircuitBreaker = 1; m_targetDisBreakerState.bus3Breaker.reservedCircuitBreaker1 = 0; m_targetDisBreakerState.bus3Breaker.reservedCircuitBreaker2 = 0; m_targetDisBreakerState.bus3Breaker.emergencyLithiumBatteryGroup2CircuitBreaker = 1; m_targetDisBreakerState.bus4Breaker.unit1CircuitBreaker = 1; m_targetDisBreakerState.bus4Breaker.unit2CircuitBreaker = 1; m_targetDisBreakerState.bus4Breaker.unit3CircuitBreaker = 1; m_targetDisBreakerState.bus4Breaker.unit5CircuitBreaker = 1; m_targetDisBreakerState.bus4Breaker.bowPZDeviceCircuitBreaker = 1; m_targetDisBreakerState.bus4Breaker.reservedCircuitBreaker1 = 0; m_targetDisBreakerState.bus4Breaker.reservedCircuitBreaker2 = 0; m_targetDisBreakerState.bus4Breaker.emergencyLithiumBatteryGroup1CircuitBreaker = 1; //紧急锂电池默认接入 //================初始化复合管控============================= m_CcuColCmd.workCondition = 0x00; //默认无效 m_CcuColCmd.fcuCmd = 0x00; //无效指令 m_CcuColCmd.fcuPowerEfficiency = 15; //默认为15kw m_CcuColCmd.fcuInsEfficiency = 00; //预留指令,无效 m_CcuColCmd.insBatCmd = 0x00; //无效指令 m_CcuColCmd.powerBatCmd = 0x00; //无效指令 m_CcuColCmd.powerBatEfficiency = 230; //默认为最大 m_CcuColCmd.heartbeat = 0; m_CcuColCmd.masterState = 0xAA;//主站状态,运行中 } char PowerManger::getBreakerOption(char cmd) { if(cmd ==1) return 0x55; else if(cmd ==0) return 0xAA; else return 0x00; } 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_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; }