修改了次级配电协议,优化消息结构

This commit is contained in:
zjk
2025-05-14 10:02:47 +08:00
parent a0e16ec538
commit 476be20025
43 changed files with 2229 additions and 1226 deletions
+54 -438
View File
@@ -1,9 +1,9 @@
#include "UpperCommManager.h"
#include "PowerManger.h"
#include "driver.h"
#include "PowerManagerFsm.hpp"
#include "fsm/PowerManagerFsm.hpp"
UpperCommManager::UpperCommManager(PowerManger* pm) : m_pm(pm) {}
UpperCommManager::UpperCommManager(PowerManger* pm) : m_pm(pm) {};
bool UpperCommManager::processUpperMsg(const string& key, const string& strJson) {
if(key == DB_TO_PM_MSCMD) {
@@ -15,11 +15,29 @@ bool UpperCommManager::processUpperMsg(const string& key, const string& strJson)
}
else if(key == DB_TO_PM_EQUIPMENTCMD) {
m_pm->m_MSDriverCmd = getEquipmentCmd(key, strJson);
vector<DriverCommand> devCmdExt = m_pm->m_driver.loadDriverIdFromJson(strJson);
if (devCmdExt.empty()) {
LOG_F(WARNING, "控制指令");
}
else {
for (auto& cmd : devCmdExt) {
DevCmdExt event(cmd.id, cmd.cmd);
PowerManagerFsm::dispatch(event);
}
}
return true;
}
else if(key == DB_TO_PM_SUBDISSTATE) {
m_pm->m_subDisSysState = getSubDisState(key, strJson);
return true;
// else if(key == DB_TO_PM_SUBDISSTATE) {
// m_pm->m_subDisSysState = getSubDisState(key, strJson);
// return true;
// }
// 次级配电状态处理
else if(key == m_secdistStateMsg.key_fb) {
m_secdistStateMsg.parseMsg(strJson, m_pm->m_subDisSysState);
//debug 接受到次级配电状态,自动更新到设备状态
//TODO:自动更新到设备状态
//m_pm->m_subDisSysState = m_pm->m_deviceState;
return true;
}
else if(key == DB_TO_PM_DEEPTH) {
m_pm->m_depth = getDeepth(key, strJson);
@@ -97,6 +115,7 @@ const DriverTable UpperCommManager::getEquipmentCmd(const std::string& key, cons
if (m_pm->m_driver.loadDriverTableFromJson(msg, cmd) < 0) {
cout << MOOS::ConsoleColours::Red << "get equipment cmd error:" << msg
<< MOOS::ConsoleColours::reset << endl;
LOG_F(WARNING, "get equipment cmd error:%s", msg.c_str());
}
return cmd;
}
@@ -107,6 +126,7 @@ const DriverTable UpperCommManager::getSubDisState(const std::string& key, const
if (m_pm->m_driver.loadDriverTableFromJson(msg, state) < 0) {
cout << MOOS::ConsoleColours::Red << "get sub dis state error:" << msg
<< MOOS::ConsoleColours::reset << endl;
LOG_F(WARNING, "get sub dis state error:%s", msg.c_str());
}
}
@@ -120,21 +140,22 @@ const int UpperCommManager::getDeepth(const std::string& key, const std::string&
std::istringstream stream(msg);
if (!Json::parseFromStream(builder, stream, &root, &errs)) {
std::cerr << "JSON解析失败: " << errs << std::endl;
LOG_F(WARNING, "JSON解析失败: %s", errs.c_str());
return -1;
}
// 检查并读取深度数组
if (root.isMember("value_array_uint16") && root["value_array_uint16"].isArray()) {
const Json::Value& array = root["value_array_uint16"];
if (root.isMember("value_array_int32") && root["value_array_int32"].isArray()) {
const Json::Value& array = root["value_array_int32"];
if (array.size() >= 3) {
// 计算三个深度值的平均值
deepth = (array[0].asInt() + array[1].asInt() + array[2].asInt()) / 3;
} else {
std::cerr << "深度数组元素不足3个" << std::endl;
LOG_F(WARNING, "深度数组元素不足3个");
return -1;
}
} else {
std::cerr << "JSON格式错误" << std::endl;
LOG_F(WARNING, "缺少或类型不匹配: value_array_int32");
return -1;
}
@@ -290,11 +311,6 @@ DeviceSwitchCmd UpperCommManager::getSetDevSwitch(const std::string& key, const
}
return false;
}
const std::string UpperCommManager::getCurrentEquState(DriverTable& driver)
{
return m_pm->m_driver.saveDriverTableToJson(&driver);
}
const std::string UpperCommManager::getSubDisCmd(DriverTable& driver)
{
@@ -304,10 +320,15 @@ const std::string UpperCommManager::getSubDisCmd(DriverTable& driver)
void UpperCommManager::processPeriodicTasks() {
buildSystemReport();
std::string strJson;
strJson = getCurrentEquState(m_pm->m_currentDriverState);
m_pm->sendNotification(PM_TO_DB_EQUIPMENTSTATE, strJson);
strJson = getSubDisCmd(m_pm->m_subDisSysCmd);
m_pm->sendNotification(PM_TO_DB_SUBDISCMD, strJson);
//发送当前设备状态
strJson = m_equStateMsg.buildMsg(m_pm->m_currentDriverState);
m_pm->sendNotification(m_equStateMsg.key, strJson);
//发送次级配电指令 修改后的代码
// strJson = getSubDisCmd(m_pm->m_subDisSysCmd);
strJson = m_secdistStateMsg.buildMsg(m_pm->m_subDisSysCmd);
m_pm->sendNotification(m_secdistStateMsg.key_cmd, strJson);
//发送仪表电状态
m_pm->sendNotification(m_equInsStateMsg.key,m_equInsStateMsg.buildMsg(m_pm->m_subDisSysState));
}
bool UpperCommManager::parseControlCmdFromJson(MSControlCmd &cmd, const std::string &strJson)
{
@@ -354,394 +375,21 @@ bool UpperCommManager::parseControlCmdFromJson(MSControlCmd &cmd, const std::str
return true; // 成功
}
void UpperCommManager::buildSystemReport() {
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->faultLevel).name());
pms[VAR_TO_STR(faultLevel)+suffix] = m_pm->faultLevel;
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["soc_uint16"] = m_pm->soc;
suffix = getTypeName(typeid(m_pm->sustainableTime).name());
pms["sustainableTime_int64"] = m_pm->sustainableTime;
pms["leakage_uint8"] = m_pm->m_leakage;
//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;
m_pmStateMsg.state.workCondition = m_pm->workCondition;
m_pmStateMsg.state.currentMod = m_pm->currentMod;
m_pmStateMsg.state.powerState = m_pm->powerState;
m_pmStateMsg.state.faultLevel = m_pm->faultLevel;
m_pmStateMsg.state.faultCode = m_pm->faultCode;
m_pmStateMsg.state.soc = m_pm->soc;
m_pmStateMsg.state.sustainableTime = m_pm->sustainableTime;
m_pmStateMsg.state.m_leakage = m_pm->m_leakage;
m_pmStateMsg.state.m_faultNum = m_pm->m_faultNum;
m_pm->sendNotification(m_pmStateMsg.key, m_pmStateMsg.buildMsg());
m_pm->sendNotification(m_fcsStateMsg.key, m_fcsStateMsg.buildMsg(m_pm->m_pmCurrentState.ccustate));
m_pm->sendNotification(m_liBatStateMsg.key, m_liBatStateMsg.buildMsg(m_pm->m_pmCurrentState.ccustate));
m_pm->sendNotification(m_disSysStateMsg.key, m_disSysStateMsg.buildMsg(m_pm->m_currentDisBreakerState));
m_pm->sendNotification(m_currentStateMsg.key, m_currentStateMsg.buildMsg(m_pm->m_pmCurrentState));
}
bool UpperCommManager::saveStringToJsonFile(const string &strJson, const string &filePath)
{
@@ -755,36 +403,4 @@ bool UpperCommManager::saveStringToJsonFile(const string &strJson, const string
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";
}
}