优化了UDP通信代码,增加了消息的时间戳

This commit is contained in:
zjk
2024-11-21 18:13:26 +08:00
parent eb2877f03f
commit abd91d0e88
6 changed files with 219 additions and 48 deletions
+58 -13
View File
@@ -83,19 +83,16 @@ bool PowerManger::OnConnectToServer()
bool PowerManger::Iterate()
{
AppCastingMOOSApp::Iterate();
// Do your thing here!
if(!m_udpComm.m_qReceiveCcuStateBuffer.empty())
{
m_CcuCurrentState = m_udpComm.m_qReceiveCcuStateBuffer.front();
cout << m_CcuCurrentState.checkCode << endl;
m_udpComm.m_qReceiveCcuStateBuffer.pop();
}
// 更新当前状态
updatePmState();
updateTime();
//输出错误信息
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;
cout<<MOOS::ConsoleColours::red() << m_udpComm.sError[i] << MOOS::ConsoleColours::reset() << endl;
}
m_udpComm.sError.clear();
}
@@ -223,11 +220,59 @@ bool PowerManger::ListenLoopUDP()
bool PowerManger::updatePmState()
{
m_pmCurrentState.ccustate = m_CcuCurrentState.data;
m_pmCurrentState.bus1State = m_disHighVolBusCurrentState.data;
m_pmCurrentState.bus2State = m_disHighAVolBusCurrentState.data;
m_pmCurrentState.bus3State = m_disHighBVolBusCurrentState.data;
m_pmCurrentState.bus4State = m_disLowBusState.data;
if(!m_udpComm.m_qReceiveCcuStateBuffer.empty())
{
double time;
m_udpComm.getCcuStateMsgFromQueue(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.getDisSysHVBusFbMsgFromQueue(time,m_disHighVolBusCurrentState);
m_pmCurrentState.bus1State = m_disHighVolBusCurrentState.data;
}
if(!m_udpComm.m_qReceiveDisHighAVolBusBuffer.empty())
{
double time;
m_udpComm.getDisSysHVABusFbMsgFromQueue(time,m_disHighAVolBusCurrentState);
m_pmCurrentState.bus2State = m_disHighAVolBusCurrentState.data;
}
if(!m_udpComm.m_qReceiveDisHighBVolBusBuffer.empty())
{
double time;
m_udpComm.getDisSysHVBBusFbMsgFromQueue(time,m_disHighBVolBusCurrentState);
m_pmCurrentState.bus3State = m_disHighBVolBusCurrentState.data;
}
if(!m_udpComm.m_qReceiveDisLowBusBuffer.empty())
{
double time;
m_udpComm.getDisSysLVBusFbMsgFromQueue(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;
}
bool PowerManger::buildPowerSysReport()
{
//TODO: 构建能源系统报告
// string suffix;
// Json::Value json;
return true;
}