924 lines
42 KiB
C++
924 lines
42 KiB
C++
/************************************************************/
|
||
/* NAME: */
|
||
/* ORGN: MIT, Cambridge MA */
|
||
/* FILE: PowerManger.cpp */
|
||
/* DATE: December 29th, 1963 */
|
||
/************************************************************/
|
||
|
||
#include <iterator>
|
||
#include "MBUtils.h"
|
||
#include "ACTable.h"
|
||
#include "PowerManger.h"
|
||
#include <memory>
|
||
|
||
using namespace std;
|
||
|
||
|
||
bool _ListenCB(void * pParam)
|
||
{
|
||
PowerManger* pMe = (PowerManger* )pParam;
|
||
return pMe->ListenLoopUDP();
|
||
}
|
||
|
||
//---------------------------------------------------------
|
||
// Constructor()
|
||
|
||
PowerManger::PowerManger()
|
||
{
|
||
workCondition = 0;
|
||
currentMod = 0;
|
||
powerState = 0;
|
||
falutLevel = 0;
|
||
soc = 0;
|
||
sustainableTime = 0;
|
||
m_connected = false;
|
||
m_faultNum = 0;
|
||
faultCode.push_back(0);
|
||
|
||
//注册状态机
|
||
m_fsm.RegisterState("Init", 1, m_Inite_s1);
|
||
m_fsm.RegisterState("Fault", 99, m_Fault_s99);
|
||
|
||
m_fsm.RegisterHandleFunction(&m_Inite_s1, handleInite_s1);
|
||
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
|
||
|
||
bool PowerManger::Iterate()
|
||
{
|
||
//1. 更新当前状态
|
||
updatePmState();
|
||
updateTime();
|
||
//2. 运行状态机
|
||
m_fsm.run(m_pmState,this);
|
||
// cout <<"CURRENT STATE:" << m_pmState.name << " | CURRENT EVENT :" << m_pmEvent << endl;
|
||
AppCastingMOOSApp::Iterate();
|
||
//3. 输出报告
|
||
buildPowerSysReport();
|
||
//4. 打印错误信息
|
||
if(!m_udpComm.sError.empty())
|
||
{
|
||
for(int i=0;i<m_udpComm.sError.size();i++)
|
||
{
|
||
cout<<MOOS::ConsoleColours::red() << m_udpComm.sError[i] << MOOS::ConsoleColours::reset() << endl;
|
||
}
|
||
m_udpComm.sError.clear();
|
||
}
|
||
//AppCastingMOOSApp::PostReport();
|
||
//5. 清空UDP消息队列
|
||
m_udpComm.clearMsgQueue();
|
||
return(true);
|
||
}
|
||
|
||
//---------------------------------------------------------
|
||
// Procedure: OnStartUp()
|
||
// happens before connection is open
|
||
|
||
bool PowerManger::OnStartUp()
|
||
{
|
||
AppCastingMOOSApp::OnStartUp();
|
||
|
||
STRING_LIST sParams;
|
||
m_MissionReader.EnableVerbatimQuoting(false);
|
||
if(!m_MissionReader.GetConfiguration(GetAppName(), sParams))
|
||
reportConfigWarning("No config block found for " + GetAppName());
|
||
|
||
STRING_LIST::iterator p;
|
||
for(p=sParams.begin(); p!=sParams.end(); p++) {
|
||
string orig = *p;
|
||
string line = *p;
|
||
string param = tolower(biteStringX(line, '='));
|
||
string value = line;
|
||
|
||
bool handled = false;
|
||
if(param == "foo") {
|
||
handled = true;
|
||
}
|
||
else if(param == "bar") {
|
||
handled = true;
|
||
}
|
||
|
||
if(!handled)
|
||
reportUnhandledConfigWarning(orig);
|
||
|
||
}
|
||
|
||
registerVariables();
|
||
//绑定UDP端口
|
||
if(m_pCcuUdpComm = setUdpScoket(IPORT))
|
||
{
|
||
cout<<MOOS::ConsoleColours::green()<< "UDP set succeed!"<< MOOS::ConsoleColours::reset() << endl;
|
||
m_udpComm.ccuHost = CCUHOST;
|
||
m_udpComm.ccuPort = CCUPORT;
|
||
m_udpComm.udpScoket = m_pCcuUdpComm;
|
||
MOOSTrace("UDP set succeed");
|
||
}
|
||
else
|
||
{
|
||
cout<<MOOS::ConsoleColours::red()<< "UDP set Fild!"<< MOOS::ConsoleColours::reset() << endl;
|
||
MOOSTrace("UDP set faile");
|
||
}
|
||
m_ListenThread.Initialise(_ListenCB,this);
|
||
m_ListenThread.Start();
|
||
return(true);
|
||
}
|
||
|
||
//---------------------------------------------------------
|
||
// Procedure: registerVariables()
|
||
|
||
void PowerManger::registerVariables()
|
||
{
|
||
AppCastingMOOSApp::RegisterVariables();
|
||
// Register("FOOBAR", 0);
|
||
}
|
||
|
||
|
||
//------------------------------------------------------------
|
||
// Procedure: buildReport()
|
||
|
||
bool PowerManger::buildReport()
|
||
{
|
||
m_msgs << "============================================" << endl;
|
||
m_msgs << "File: " << endl;
|
||
m_msgs << "============================================" << endl;
|
||
|
||
ACTable actab(4);
|
||
actab << "Alpha | Bravo | Charlie | Delta";
|
||
actab.addHeaderLines();
|
||
actab << "one" << "two" << "three" << "four";
|
||
m_msgs << actab.getFormattedString();
|
||
|
||
return(true);
|
||
}
|
||
|
||
//------------------------------------------------------------
|
||
// Procedure: setUdpScoket()
|
||
XPCUdpSocket* PowerManger::setUdpScoket(long lPort)
|
||
{
|
||
XPCUdpSocket* pUdpSocket = new XPCUdpSocket(lPort);
|
||
try
|
||
{
|
||
pUdpSocket->vBindSocket();
|
||
}
|
||
catch(const std::exception& e)
|
||
{
|
||
std::cerr << e.what() << '\n';
|
||
return NULL;
|
||
}
|
||
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<<MOOS::ConsoleColours::yellow()<< "RECEVE DATA COUNT:" << nRead << MOOS::ConsoleColours::reset() << endl;
|
||
if(nRead > 0)
|
||
{
|
||
if(!m_udpComm.pushMsgToQueue(Buff))
|
||
{
|
||
for(int i=0;i<m_udpComm.sError.size();i++)
|
||
{
|
||
cout<<MOOS::ConsoleColours::red()<< m_udpComm.sError[i] << MOOS::ConsoleColours::reset() << endl;
|
||
}
|
||
}
|
||
m_connected = true;
|
||
}
|
||
// updatePmState();
|
||
}
|
||
return true;
|
||
}
|
||
|
||
|
||
bool PowerManger::updatePmState()
|
||
{
|
||
|
||
if(!m_udpComm.m_qReceiveCcuStateBuffer.empty())
|
||
{
|
||
double time;
|
||
m_udpComm.popMsgFormQueue(time,m_CcuCurrentState);
|
||
m_pmCurrentState.ccustate = m_CcuCurrentState.data;
|
||
double df;
|
||
IsSkewed(time, &df);
|
||
cout << "CcuState Skew:" << df << endl;
|
||
}
|
||
if(!m_udpComm.m_qReceiveDisHighVolBusBuffer.empty())
|
||
{
|
||
double time;
|
||
m_udpComm.popMsgFormQueue(time,m_disHighVolBusCurrentState);
|
||
m_pmCurrentState.bus1State = m_disHighVolBusCurrentState.data;
|
||
}
|
||
if(!m_udpComm.m_qReceiveDisHighAVolBusBuffer.empty())
|
||
{
|
||
double time;
|
||
m_udpComm.popMsgFormQueue(time,m_disHighAVolBusCurrentState);
|
||
m_pmCurrentState.bus2State = m_disHighAVolBusCurrentState.data;
|
||
}
|
||
if(!m_udpComm.m_qReceiveDisHighBVolBusBuffer.empty())
|
||
{
|
||
double time;
|
||
m_udpComm.popMsgFormQueue(time,m_disHighBVolBusCurrentState);
|
||
m_pmCurrentState.bus3State = m_disHighBVolBusCurrentState.data;
|
||
}
|
||
if(!m_udpComm.m_qReceiveDisLowBusBuffer.empty())
|
||
{
|
||
double time;
|
||
m_udpComm.popMsgFormQueue(time,m_disLowBusState);
|
||
m_pmCurrentState.bus4State = m_disLowBusState.data;
|
||
}
|
||
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;
|
||
}
|
||
|
||
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 char fcuGZ_1L;
|
||
// unsigned char fcuGZ_1H;
|
||
// unsigned char fcuGZ_2L;
|
||
// unsigned char fcuGZ_2H;
|
||
// unsigned char fcuGZ_3L;
|
||
// unsigned char fcuGZ_3H;
|
||
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;
|
||
(m_pmCurrentState.bus1State.fuelCellCircuitBreaker == BREAK_ON) ? pdis1 -> fuelCellCircuitBreaker = 1 : pdis1 -> fuelCellCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus1State.powerLithiumBatteryCircuitBreaker == BREAK_ON) ? pdis1 -> powerLithiumBatteryCircuitBreaker = 1 : pdis1 -> powerLithiumBatteryCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus1State.propulsionMotorCircuitBreaker == BREAK_ON) ? pdis1 -> propulsionMotorCircuitBreaker = 1 : pdis1 -> propulsionMotorCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus1State.lithiumBatteryGroupInstrumentCircuitBreaker == BREAK_ON) ? pdis1 -> lithiumBatteryGroupInstrumentCircuitBreaker = 1 : pdis1 -> lithiumBatteryGroupInstrumentCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus1State.dcDc5ModuleCircuitBreaker == BREAK_ON) ? pdis1 -> dcDc5ModuleCircuitBreaker = 1 : pdis1 -> dcDc5ModuleCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus1State.bowHighVoltageDistributionBoxCircuitBreaker == BREAK_ON) ? pdis1 -> bowHighVoltageDistributionBoxCircuitBreaker = 1 : pdis1 -> bowHighVoltageDistributionBoxCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus1State.sternFTDevice45CircuitBreaker == BREAK_ON) ? pdis1 -> sternFTDevice45CircuitBreaker = 1 : pdis1 -> sternFTDevice45CircuitBreaker = 0;
|
||
(m_pmCurrentState.bus1State.sternRudderSwitch1CircuitBreaker == BREAK_ON) ? pdis1 -> sternRudderSwitch1CircuitBreaker = 1 : pdis1 -> sternRudderSwitch1CircuitBreaker = 0;
|
||
(m_pmCurrentState.bus1State.sternRudderSwitch2CircuitBreaker == BREAK_ON) ? pdis1 -> sternRudderSwitch2CircuitBreaker = 1 : pdis1 -> sternRudderSwitch2CircuitBreaker = 0;
|
||
(m_pmCurrentState.bus1State.fbReservedCircuitBreaker == BREAK_ON) ? pdis1 -> fbReservedCircuitBreaker = 1 : pdis1 -> fbReservedCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus1State.tyzReservedCircuitBreaker == BREAK_ON) ? pdis1 -> tyzReservedCircuitBreaker = 1 : pdis1 -> tyzReservedCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus1State.reservedCircuitBreaker == BREAK_ON) ? pdis1 -> reservedCircuitBreaker = 1 : pdis1 -> reservedCircuitBreaker = 0;
|
||
pdis1 -> paceholder = 0;
|
||
|
||
disBus2Breaker* pdis2=new disBus2Breaker;
|
||
(m_pmCurrentState.bus2State.bowFTDevice123CircuitBreaker == BREAK_ON)? pdis2 -> bowFTDevice123CircuitBreaker = 1 : pdis2 -> bowFTDevice123CircuitBreaker = 0;
|
||
(m_pmCurrentState.bus2State.actuatorCircuitBreaker == BREAK_ON)? pdis2 -> actuatorCircuitBreaker = 1 : pdis2 -> actuatorCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus2State.mastSteeringGearControlBoxCircuitBreaker == BREAK_ON)? pdis2 -> mastSteeringGearControlBoxCircuitBreaker = 1 : pdis2 -> mastSteeringGearControlBoxCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus2State.xczCircuitBreaker == BREAK_ON)? pdis2 -> xczCircuitBreaker = 1 : pdis2 -> xczCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus2State.bowRudderControlBoxCircuitBreaker == BREAK_ON)? pdis2 -> bowRudderControlBoxCircuitBreaker = 1 : pdis2 -> bowRudderControlBoxCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus2State.openWaterCoverStartCylinderCircuitBreaker == BREAK_ON)? pdis2 -> openWaterCoverStartCylinderCircuitBreaker = 1 : pdis2 -> openWaterCoverStartCylinderCircuitBreaker = 0;
|
||
pdis2 -> paceholder = 0;
|
||
|
||
disBus3Breaker* pdis3=new disBus3Breaker;
|
||
(m_pmCurrentState.bus3State.lithiumBatteryGroupInstrumentCircuitBreaker == BREAK_ON)? pdis3 -> lithiumBatteryGroupInstrumentCircuitBreaker = 1 : pdis3 -> lithiumBatteryGroupInstrumentCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus3State.bowLowVoltageDistributionBoxCircuitBreaker == BREAK_ON)? pdis3 -> bowLowVoltageDistributionBoxCircuitBreaker = 1 : pdis3 -> bowLowVoltageDistributionBoxCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus3State.unit4InstrumentDC48VCircuitBreaker == BREAK_ON)? pdis3 -> unit4InstrumentDC48VCircuitBreaker = 1 : pdis3 -> unit4InstrumentDC48VCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus3State.dcC1DCDistributionPanelCircuitBreaker == BREAK_ON)? pdis3 -> dcC1DCDistributionPanelCircuitBreaker = 1 : pdis3 -> dcC1DCDistributionPanelCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus3State.reservedCircuitBreaker1 == BREAK_ON)? pdis3 -> reservedCircuitBreaker1 = 1 : pdis3 -> reservedCircuitBreaker1 = 0;
|
||
(m_pmCurrentState.bus3State.reservedCircuitBreaker2 == BREAK_ON)? pdis3 -> reservedCircuitBreaker2 = 1 : pdis3 -> reservedCircuitBreaker2 = 0;
|
||
(m_pmCurrentState.bus3State.emergencyLithiumBatteryGroup2CircuitBreaker == BREAK_ON)? pdis3 -> emergencyLithiumBatteryGroup2CircuitBreaker = 1 : pdis3 -> emergencyLithiumBatteryGroup2CircuitBreaker = 0;
|
||
pdis3->paceholder = 0;
|
||
|
||
disBus4Breaker* pdis4=new disBus4Breaker;
|
||
(m_pmCurrentState.bus4State.unit1CircuitBreaker == BREAK_ON)? pdis4 -> unit1CircuitBreaker = 1 : pdis4 -> unit1CircuitBreaker = 0;
|
||
(m_pmCurrentState.bus4State.unit2CircuitBreaker == BREAK_ON)? pdis4 -> unit2CircuitBreaker = 1 : pdis4 -> unit2CircuitBreaker = 0;
|
||
(m_pmCurrentState.bus4State.unit3CircuitBreaker == BREAK_ON)? pdis4 -> unit3CircuitBreaker = 1 : pdis4 -> unit3CircuitBreaker = 0;
|
||
(m_pmCurrentState.bus4State.unit5CircuitBreaker == BREAK_ON)? pdis4 -> unit5CircuitBreaker = 1 : pdis4 -> unit5CircuitBreaker = 0;
|
||
(m_pmCurrentState.bus4State.bowPZDeviceCircuitBreaker == BREAK_ON)? pdis4 -> bowPZDeviceCircuitBreaker = 1 : pdis4 -> bowPZDeviceCircuitBreaker = 0;
|
||
(m_pmCurrentState.bus4State.reservedCircuitBreaker1 == BREAK_ON)? pdis4 -> reservedCircuitBreaker1 = 1 : pdis4 -> reservedCircuitBreaker1 = 0;
|
||
(m_pmCurrentState.bus4State.reservedCircuitBreaker2 == BREAK_ON)? pdis4 -> reservedCircuitBreaker2 = 1 : pdis4 -> reservedCircuitBreaker2 = 0;
|
||
(m_pmCurrentState.bus4State.emergencyLithiumBatteryGroup1CircuitBreaker == BREAK_ON)? pdis4 -> emergencyLithiumBatteryGroup1CircuitBreaker = 1 : pdis4 -> emergencyLithiumBatteryGroup1CircuitBreaker = 0;
|
||
pdis4 -> paceholder = 0;
|
||
|
||
dis["HVolBusBreaker_uint16"] = *(unsigned short*) pdis1;
|
||
dis["HVolABusBreaker_unit16"] = *(unsigned short*) pdis2;
|
||
dis["HVolBBusBreaker_unit16"] = *(unsigned short*) pdis3;
|
||
dis["LVolBusBreaker_uint16"] = *(unsigned short*) pdis3;
|
||
|
||
delete pdis1;
|
||
delete pdis2;
|
||
delete pdis3;
|
||
delete pdis4;
|
||
|
||
//TODO: 构建配电系统故障码
|
||
Json::Value faultCodeDis_array;
|
||
for(auto val : faultCode)
|
||
{
|
||
faultCodeDis_array.append(val);
|
||
}
|
||
dis[VAR_TO_STR(faultCode_array)] = faultCodeDis_array;
|
||
|
||
|
||
Json::Value currentBusState;
|
||
suffix = getTypeName(typeid(m_pmCurrentState.bus1State.powerBusVoltage).name());
|
||
currentBusState[VAR_TO_STR(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;
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|
||
//TODO:配电系统操作函数
|
||
bool PowerManger::disSystemOperation(disBreaker optBreaker, disBreakerOpt)
|
||
{
|
||
|
||
return true;
|
||
}
|
||
|
||
int PowerManger::handleInite_s1(FSM_State &fsm, void* pData)
|
||
{
|
||
cout << fsm.name << endl;
|
||
PowerManger* pm = (PowerManger*)pData;
|
||
//1. 检查复合管控器连接
|
||
double StartTime = pm->GetAppStartTime();
|
||
while (!pm->m_connected)
|
||
{
|
||
|
||
disHighVolBusCmd a;
|
||
a.fuelCellCircuitBreaker = DIS_BREAKER_OFF;
|
||
a.propulsionMotorCircuitBreaker = DIS_BREAKER_OFF;
|
||
pm->m_udpComm.sendDisSysCmd(a);
|
||
|
||
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);
|
||
usleep(1000000);
|
||
}
|
||
//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. 检查当前配电装置状态
|
||
//a. 断开高压母线的主要断路器
|
||
//TODO 检查并配置当前配电装置状态
|
||
disHighVolBusCmd a;
|
||
a.fuelCellCircuitBreaker = DIS_BREAKER_OFF;
|
||
a.propulsionMotorCircuitBreaker = DIS_BREAKER_OFF;
|
||
a.bowHighVoltageDistributionBoxCircuitBreaker = DIS_BREAKER_OFF;
|
||
a.tyzReservedCircuitBreaker = DIS_BREAKER_OFF;
|
||
a.sternFTDevice45CircuitBreaker = DIS_BREAKER_OFF;
|
||
a.sternRudderSwitch1CircuitBreaker = DIS_BREAKER_OFF;
|
||
a.sternRudderSwitch2CircuitBreaker = DIS_BREAKER_OFF;
|
||
a.reservedCircuitBreaker = DIS_BREAKER_OFF;
|
||
a.fbReservedCircuitBreaker = DIS_BREAKER_OFF;
|
||
pm->m_udpComm.sendDisSysCmd(a);
|
||
//b. 断开艏部高压设备的主要断路器
|
||
disHighAVolBusCmd b;
|
||
b.bowFTDevice123CircuitBreaker = DIS_BREAKER_OFF;
|
||
b.actuatorCircuitBreaker = DIS_BREAKER_OFF;
|
||
b.mastSteeringGearControlBoxCircuitBreaker = DIS_BREAKER_OFF;
|
||
b.xczCircuitBreaker = DIS_BREAKER_OFF;
|
||
b.bowRudderControlBoxCircuitBreaker = DIS_BREAKER_OFF;
|
||
b.openWaterCoverStartCylinderCircuitBreaker = DIS_BREAKER_OFF;
|
||
pm->m_udpComm.sendDisSysCmd(b);
|
||
//c. 闭合低压母线的断路器
|
||
disHighBVolBusCmd c;
|
||
c.lithiumBatteryGroupInstrumentCircuitBreaker = DIS_BREAKER_ON;
|
||
c.bowLowVoltageDistributionBoxCircuitBreaker = DIS_BREAKER_ON;
|
||
c.unit4InstrumentDC48VCircuitBreaker = DIS_BREAKER_ON;
|
||
c.dcC1DCDistributionPanelCircuitBreaker = DIS_BREAKER_ON;
|
||
c.reservedCircuitBreaker1 = DIS_BREAKER_ON;
|
||
c.reservedCircuitBreaker2 = DIS_BREAKER_ON;
|
||
c.emergencyLithiumBatteryGroup2CircuitBreaker = DIS_BREAKER_ON;
|
||
pm->m_udpComm.sendDisSysCmd(c);
|
||
//d. 闭合低压汇流排断路器
|
||
disLowBusCmd d;
|
||
d.unit1CircuitBreaker = DIS_BREAKER_ON;
|
||
d.unit2CircuitBreaker = DIS_BREAKER_ON;
|
||
d.unit3CircuitBreaker = DIS_BREAKER_ON;
|
||
d.unit5CircuitBreaker = DIS_BREAKER_ON;
|
||
d.bowPZDeviceCircuitBreaker = DIS_BREAKER_ON;
|
||
d.reservedCircuitBreaker1 = DIS_BREAKER_ON;
|
||
d.reservedCircuitBreaker2 = DIS_BREAKER_ON;
|
||
d.emergencyLithiumBatteryGroup1CircuitBreaker = DIS_BREAKER_ON;
|
||
pm->m_udpComm.sendDisSysCmd(d);
|
||
MOOSPause(1000);
|
||
// pm->workCondition = "";
|
||
return 0;
|
||
}
|
||
|
||
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,"通信故障");
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
pm->printState(fsm,"故障");
|
||
return 0;
|
||
}
|
||
|
||
|
||
// int PowerManger::handleState1(FSM_State &fsm,void* pData)
|
||
// {
|
||
// cout << fsm.name << endl;
|
||
// PowerManger* pm = (PowerManger*)pData;
|
||
// fsm = pm->m_fsm.getState("PM_STATE2");
|
||
// // pm->m_pmEvent = "a";
|
||
// return 0;
|
||
// }
|
||
// int PowerManger::handleState2(FSM_State &fsm,void* pData)
|
||
// {
|
||
// cout << fsm.name << endl;
|
||
// PowerManger* pm = (PowerManger*)pData;
|
||
// fsm = pm->m_fsm.getState("PM_STATE3");
|
||
// // pm->m_pmEvent = "b";
|
||
// return 0;
|
||
// }
|
||
// int PowerManger::handleState3(FSM_State &fsm,void* pData)
|
||
// {
|
||
// cout << fsm.name << endl;
|
||
// PowerManger* pm = (PowerManger*)pData;
|
||
// fsm = pm->m_fsm.getState("PM_STATE");
|
||
// // pm->m_pmEvent = "c";
|
||
// return 0;
|
||
// }
|