增加了通信协议解析的功能
This commit is contained in:
@@ -181,6 +181,7 @@ bool PowerManger::ListenLoopCCU()
|
||||
{
|
||||
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));
|
||||
@@ -201,16 +202,17 @@ bool PowerManger::ListenLoopCCU()
|
||||
//处理消息
|
||||
switch (id)
|
||||
{
|
||||
case 0x0051: //CCU_STATE_FB 0x0051
|
||||
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 << "id:" << s.header.id << endl;
|
||||
cout << "currentWorkCondition:" << (double)s.currentWorkCondition << endl;
|
||||
cout << "fcuState:" << s.fcuState << endl;
|
||||
cout << "fcuFaultLeve:" << s.fcuFaultLeve << endl;
|
||||
cout << "powerLimit:" << s.powerLimit << 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
|
||||
{
|
||||
@@ -219,7 +221,7 @@ bool PowerManger::ListenLoopCCU()
|
||||
m_udpComm.sError.clear();
|
||||
}
|
||||
break;
|
||||
case 0x0040: //CCU_SET_PARM_FB 0x0040
|
||||
case CCU_SET_PARM_FB_ID: //CCU_SET_PARM_FB 0x0040
|
||||
msg_CcuSetParmFbMsg p;
|
||||
if(m_udpComm.getCcuSetParmFb((char *)Buff,p))
|
||||
{
|
||||
|
||||
@@ -47,6 +47,12 @@ class PowerManger : public AppCastingMOOSApp
|
||||
protected: // app function
|
||||
// bool _ListenCB();
|
||||
XPCUdpSocket* setUdpScoket(long lPort);
|
||||
//
|
||||
bool buildStateReport();
|
||||
bool buildEquipmentReport();
|
||||
bool buildDisributionReport();
|
||||
bool buildSubDistributionReport();
|
||||
bool buildPredictionReport();
|
||||
|
||||
protected: // app variables
|
||||
long m_lPort;
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
#ifndef CCUUDPMSG__H
|
||||
#define CCUUDPMSG__H
|
||||
#define CCU_UDPMSG_START1 0x20
|
||||
#define CCU_UDPMSG_START2 0x20
|
||||
#define CCU_STATE_FB_ID 0x0051
|
||||
#define CCU_SET_PARM_ID 0x0040
|
||||
#define CCU_SET_PARM_FB_ID 0x0041
|
||||
|
||||
#pragma pack (1)
|
||||
typedef unsigned int Checksum;
|
||||
|
||||
typedef struct {
|
||||
@@ -177,5 +183,6 @@ typedef struct {
|
||||
float placeholder5;
|
||||
Checksum checkCode;
|
||||
} msg_CcuStateFbMsg;
|
||||
#pragma pack ()
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,13 +4,24 @@
|
||||
udpComm::udpComm() {}
|
||||
|
||||
udpComm::~udpComm() {}
|
||||
|
||||
|
||||
Checksum udpComm::calculateChecksum(const unsigned char* data, int size)
|
||||
{
|
||||
Checksum checksum = 0;
|
||||
int size_data = size - sizeof(Checksum);
|
||||
for (int i = 0; i < size_data; i++) {
|
||||
checksum += data[i];
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
bool udpComm::getMsgId(char *m,unsigned short &id)
|
||||
{
|
||||
m_header h;
|
||||
h = *reinterpret_cast<m_header *>(m);
|
||||
// 判断消息是否有效
|
||||
if (h.start1!= 0x20 || h.start2!= 0x20) {
|
||||
// sError.push_back("Msg Header errar");
|
||||
sError.push_back("Msg Header errar");
|
||||
return false;
|
||||
}
|
||||
id = h.id;
|
||||
@@ -31,39 +42,13 @@ bool udpComm::getCcuState(char *m, msg_CcuStateFbMsg &s) {
|
||||
}
|
||||
if (h.id != 0x0051) {
|
||||
sError.push_back("CcuState Msg ID error");
|
||||
// std::cout << "-------" <<h.id << std::endl;
|
||||
return false;
|
||||
}
|
||||
sum =
|
||||
h.id + h.length + h.start1 + h.start2 + p->currentWorkCondition +
|
||||
p->fcuState + p->fcuFaultLeve + p->powerLimit + p->totalPowerGeneration +
|
||||
p->ch4o + p->o2 + p->fcuVoltage + p->fcuCurrent + p->o2Level +
|
||||
p->placeholder1 + p->exchangerTemperature + p->fcuOutPower +
|
||||
p->fcuOutIns + p->fcuVoltageIns + p->fcuVoltagePower + p->fcuCurrentIns +
|
||||
p->fcuCurrentPower + p->h2Concentration1 + p->h2Concentration2 +
|
||||
p->o2Concentration1 + p->o2Concentration2 + p->ch4oConcentration1 +
|
||||
p->ch4oConcentration2 + p->backpressure1 + p->backpressure2 +
|
||||
p->flameDetection + p->fcuGZ_1L + p->fcuGZ_1H + p->fcuGZ_2L +
|
||||
p->fcuGZ_2H + p->fcuGZ_3L + p->fcuGZ_3H + p->insPosRelayState +
|
||||
p->insNegRelayState + p->powerNegRelayState + p->powerPosRelayState +
|
||||
p->insBatLimit + p->powerBatLimit + p->insBatSoc + p->powerBatSoc +
|
||||
p->insBatTotalElectricity + p->powerBatTotalElectricity +
|
||||
p->insBatCurrentElectricity + p->powerBatCurrentElectricity +
|
||||
p->insChargeState + p->powerChargeState + p->insLinkVoltage +
|
||||
p->insPackVoltage + p->insCurrent + p->insPosInsulationResistance +
|
||||
p->insNegInsulationResistance + p->powerLinkVoltage +
|
||||
p->powerPackVoltage + p->powerCurrent + p->powerPosInsulationResistance +
|
||||
p->powerNegInsulationResistance + p->insEmergencyStatusWord +
|
||||
p->powerEmergencyStatusWord + p->insAlarmIdentificationWord +
|
||||
p->powerAlarmIdentificationWord + p->insCurrentSocHold1 +
|
||||
p->insCurrentSocHold2 + p->insCurrentSocHold3 + p->fcuCurrentToInsLimit1 +
|
||||
p->fcuCurrentToinsLimit2 + p->powerCurrentSocHold1 +
|
||||
p->powerCurrentSocHold2 + p->powerCurrentSocHold3 +
|
||||
p->powerCurrentToInsLimit1 + p->powerCurrentToinsLimit2 +
|
||||
p->placeholder2 + p->placeholder3 + p->placeholder5;
|
||||
sum = calculateChecksum((unsigned char*)m, sizeof(msg_CcuStateFbMsg));
|
||||
|
||||
if (sum != p->checkCode) {
|
||||
sError.push_back("CcuStat Msg Check error");
|
||||
//return false; TODO: 暂时不校验
|
||||
return false;
|
||||
}
|
||||
s = *p;
|
||||
return true;
|
||||
@@ -90,7 +75,7 @@ bool udpComm::getCcuSetParmFb(char *m, msg_CcuSetParmFbMsg &s)
|
||||
return false;
|
||||
}
|
||||
|
||||
sum = h.id + h.length + h.start1 + h.start2 + p->flag + p->failureCode;
|
||||
sum = calculateChecksum((unsigned char*)m, sizeof(msg_CcuSetParmFbMsg));
|
||||
|
||||
if (sum!= p->checkCode) {
|
||||
sError.push_back("CcuSetParm Msg Check error");
|
||||
|
||||
@@ -14,6 +14,9 @@ public:
|
||||
bool getCcuSetParmFb(char *m, msg_CcuSetParmFbMsg &s);
|
||||
bool sendCcuColCmd(const msg_CcuColCmdMsg m);
|
||||
bool sendCcuSetParmCmd(const msg_CcuSetParmMsg m);
|
||||
|
||||
Checksum calculateChecksum(const unsigned char* data, int size);
|
||||
|
||||
std::vector<std::string> sError;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user