优化udp通信代码,增加配电系统通信解析,增加能源系统状态定义
This commit is contained in:
@@ -18,7 +18,7 @@ using namespace std;
|
||||
bool _ListenCB(void * pParam)
|
||||
{
|
||||
PowerManger* pMe = (PowerManger* )pParam;
|
||||
return pMe->ListenLoopCCU();
|
||||
return pMe->ListenLoopUDP();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
@@ -84,7 +84,23 @@ 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();
|
||||
}
|
||||
|
||||
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();
|
||||
m_udpComm.clearMsgQueue();
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -124,9 +140,15 @@ bool PowerManger::OnStartUp()
|
||||
registerVariables();
|
||||
|
||||
if(m_pCcuUdpComm = setUdpScoket(IPORT))
|
||||
{
|
||||
cout<<MOOS::ConsoleColours::green()<< "UDP set succeed!"<< MOOS::ConsoleColours::reset() << endl;
|
||||
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);
|
||||
@@ -177,71 +199,35 @@ XPCUdpSocket* PowerManger::setUdpScoket(long lPort)
|
||||
return pUdpSocket;
|
||||
}
|
||||
|
||||
bool PowerManger::ListenLoopCCU()
|
||||
bool PowerManger::ListenLoopUDP()
|
||||
{
|
||||
unsigned char Buff[MAX_UDP_PKT_SIZE];
|
||||
cout << "------------------" << endl;
|
||||
cout << "SIZEOF" << sizeof(msg_CcuStateFbMsg) << endl;
|
||||
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)
|
||||
{
|
||||
//判断消息
|
||||
char *header = new char[sizeof(m_header)];
|
||||
unsigned short id;
|
||||
memcpy(header,Buff,sizeof(m_header));
|
||||
if(!m_udpComm.getMsgId(header,id))
|
||||
if(!m_udpComm.pushMsgToQueue(Buff))
|
||||
{
|
||||
cout << "------------------" << endl;
|
||||
cout << "id:" << id << endl;
|
||||
cout << "getMsgId faile" << endl;
|
||||
for(int i=0;i<m_udpComm.sError.size();i++)
|
||||
{
|
||||
cout<<MOOS::ConsoleColours::red()<< m_udpComm.sError[i] << MOOS::ConsoleColours::reset() << endl;
|
||||
}
|
||||
}
|
||||
delete []header;
|
||||
//处理消息
|
||||
switch (id)
|
||||
{
|
||||
case CCU_STATE_FB_ID: //CCU_STATE_FB 0x0051
|
||||
msg_CcuStateFbMsg s;
|
||||
if(m_udpComm.getCcuState((char *)Buff,s))
|
||||
{
|
||||
cout << "------------------" << endl;
|
||||
// cout << "id:" << s.header.id << endl;
|
||||
cout << "currentWorkCondition:" << (double)s.currentWorkCondition << endl;
|
||||
cout << "fcuState:" << (double)s.fcuState << endl;
|
||||
cout << "fcuFaultLeve:" << (double)s.fcuFaultLeve << endl;
|
||||
cout << "powerLimit:" << (double)s.powerLimit << endl;
|
||||
cout << "checkCode:" << (double)s.checkCode << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0;i < m_udpComm.sError.size();i++)
|
||||
cout << m_udpComm.sError[i] << endl;
|
||||
m_udpComm.sError.clear();
|
||||
}
|
||||
break;
|
||||
case CCU_SET_PARM_FB_ID: //CCU_SET_PARM_FB 0x0040
|
||||
msg_CcuSetParmFbMsg p;
|
||||
if(m_udpComm.getCcuSetParmFb((char *)Buff,p))
|
||||
{
|
||||
cout << "------------------" << endl;
|
||||
cout << "id:" << p.header.id << endl;
|
||||
cout << "Flas:" << p.flag << endl;
|
||||
cout << "FailCode" << p.failureCode << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0;i < m_udpComm.sError.size();i++)
|
||||
cout << m_udpComm.sError[i] << endl;
|
||||
m_udpComm.sError.clear();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user