[fix]opc-ua采集协议的时间边界处理和数据采集不到的错误处理

This commit is contained in:
liang-ys 2026-04-02 16:29:18 +08:00
parent 82e27bf390
commit ec985aa20f

View File

@ -7,7 +7,7 @@
using namespace iot_idl; using namespace iot_idl;
extern bool g_IEC62541IsMainFes; extern bool g_IEC62541IsMainFes;
extern bool g_IEC62541ChanelRun; extern bool g_IEC62541ChanelRun;
#define UA_DATETIME_UNIX_EPOCH_DIFF_MS 11644473600000LL
namespace fes_iec62541_client { namespace fes_iec62541_client {
CIEC62541DataProcThread::CIEC62541DataProcThread(CFesBase *ptrCFesBase, const CFesChanPtr &ptrChan, const fes_iec62541_client::SIEC62541AppConfParam &stConfParam) CIEC62541DataProcThread::CIEC62541DataProcThread(CFesBase *ptrCFesBase, const CFesChanPtr &ptrChan, const fes_iec62541_client::SIEC62541AppConfParam &stConfParam)
@ -29,20 +29,15 @@ CIEC62541DataProcThread::CIEC62541DataProcThread(CFesBase *ptrCFesBase, const CF
CIEC62541DataProcThread::~CIEC62541DataProcThread() CIEC62541DataProcThread::~CIEC62541DataProcThread()
{ {
if(m_ptrUAClient)
m_ptrCurChan->SetLinkStatus(CN_FesChanDisconnect);
m_ptrFesChan->SetDataThreadRunFlag(CN_FesStopFlag);
if(m_ptrCurRtu != NULL)
{ {
UA_Client_delete(m_ptrUAClient); m_ptrCFesBase->WriteRtuSatus(m_ptrCurRtu, CN_FesRtuComDown);
m_ptrUAClient=NULL;
} }
for (size_t i = 0; i < m_cntReadNodeId; ++i) {
UA_ReadValueId* nodeId = &m_ptrReadNodeIds[i];
UA_NodeId_clear(&(nodeId->nodeId));
}
m_ptrFesChan->SetDataThreadRunFlag(CN_FesStopFlag);
} }
int CIEC62541DataProcThread::beforeExecute() int CIEC62541DataProcThread::beforeExecute()
@ -91,7 +86,17 @@ void CIEC62541DataProcThread::execute()
void CIEC62541DataProcThread::beforeQuit() void CIEC62541DataProcThread::beforeQuit()
{ {
if(m_ptrUAClient)
{
UA_Client_delete(m_ptrUAClient);
m_ptrUAClient=NULL;
}
for (size_t i = 0; i < m_cntReadNodeId; ++i) {
UA_ReadValueId* nodeId = &m_ptrReadNodeIds[i];
UA_NodeId_clear(&(nodeId->nodeId));
}
} }
int CIEC62541DataProcThread::init() int CIEC62541DataProcThread::init()
@ -161,11 +166,12 @@ int CIEC62541DataProcThread::batchRequestData()
UA_ReadResponse response = UA_Client_Service_read(m_ptrUAClient, request); UA_ReadResponse response = UA_Client_Service_read(m_ptrUAClient, request);
if (response.responseHeader.serviceResult != UA_STATUSCODE_GOOD != UA_STATUSCODE_GOOD || response.resultsSize == 0) { if (response.responseHeader.serviceResult != UA_STATUSCODE_GOOD != UA_STATUSCODE_GOOD || response.resultsSize == 0) {
std::string statusMessage = getStatusMessage(response.responseHeader.serviceResult); std::string statusMessage = getStatusMessage(response.responseHeader.serviceResult);
LOGERROR("CIEC62541DataProcThread ChanNo=%d request faild err(%s)", m_ptrCurChan->m_Param.ChanNo,statusMessage.c_str()); LOGERROR("CIEC62541DataProcThread ChanNo=%d request faild err(%s) resultsSize(%d)", m_ptrCurChan->m_Param.ChanNo,statusMessage.c_str(), response.resultsSize);
UA_ReadResponse_clear(&response); UA_ReadResponse_clear(&response);
return iotFailed; return iotFailed;
} }
procDiData(response); procDiData(response);
procAiData(response); procAiData(response);
procMiData(response); procMiData(response);
@ -651,12 +657,12 @@ void CIEC62541DataProcThread::procDiData(UA_ReadResponse &response)
DataType dataType=static_cast<DataType>(pDi->Param1); DataType dataType=static_cast<DataType>(pDi->Param1);
if(result->hasSourceTimestamp) if(result->hasSourceTimestamp)
{ {
mSec=result->sourceTimestamp; mSec=result->sourceTimestamp/10000- UA_DATETIME_UNIX_EPOCH_DIFF_MS;
} }
else{ else{
if(result->hasServerTimestamp) if(result->hasServerTimestamp)
{ {
mSec=result->serverTimestamp; mSec=result->serverTimestamp/10000- UA_DATETIME_UNIX_EPOCH_DIFF_MS;
} }
} }
@ -668,7 +674,7 @@ void CIEC62541DataProcThread::procDiData(UA_ReadResponse &response)
if(iotSuccess==getValue(result,indexVec,dataType,resultValue)) if(result->hasValue&&iotSuccess==getValue(result,indexVec,dataType,resultValue))
{ {
if(resultValue != pDi->Value) if(resultValue != pDi->Value)
{ {
@ -690,6 +696,9 @@ void CIEC62541DataProcThread::procDiData(UA_ReadResponse &response)
} }
else else
{ {
DiValue[diPoint].PointNo = diPoint;
DiValue[diPoint].Status = valueStatus;
DiValue[diPoint].Value = 0;
LOGERROR("CIEC62541DataProcThread ChanNo=%d dipoint-no(%d)(%s) can not get the value", m_ptrCurChan->m_Param.ChanNo,pDi->PointNo,&(pDi->TagName[0])); LOGERROR("CIEC62541DataProcThread ChanNo=%d dipoint-no(%d)(%s) can not get the value", m_ptrCurChan->m_Param.ChanNo,pDi->PointNo,&(pDi->TagName[0]));
} }
@ -732,12 +741,12 @@ void CIEC62541DataProcThread::procAiData(UA_ReadResponse &response)
DataType dataType=static_cast<DataType>(pAi->Param1); DataType dataType=static_cast<DataType>(pAi->Param1);
if(result->hasSourceTimestamp) if(result->hasSourceTimestamp)
{ {
mSec=result->sourceTimestamp; mSec=result->sourceTimestamp/10000- UA_DATETIME_UNIX_EPOCH_DIFF_MS;
} }
else{ else{
if(result->hasServerTimestamp) if(result->hasServerTimestamp)
{ {
mSec=result->serverTimestamp; mSec=result->serverTimestamp/10000- UA_DATETIME_UNIX_EPOCH_DIFF_MS;
} }
} }
@ -750,7 +759,7 @@ void CIEC62541DataProcThread::procAiData(UA_ReadResponse &response)
if(iotSuccess==getValue(result,indexVec,dataType,resultValue)) if(result->hasValue&&iotSuccess==getValue(result,indexVec,dataType,resultValue))
{ {
AiValue[aiPoint].PointNo = aiPoint; AiValue[aiPoint].PointNo = aiPoint;
@ -761,7 +770,10 @@ void CIEC62541DataProcThread::procAiData(UA_ReadResponse &response)
} }
else else
{ {
LOGERROR("CIEC62541DataProcThread ChanNo=%d dipoint-no(%d)(%s) can not get the value", m_ptrCurChan->m_Param.ChanNo,pAi->PointNo,&(pAi->TagName[0])); AiValue[aiPoint].PointNo = aiPoint;
AiValue[aiPoint].Status = valueStatus;
AiValue[aiPoint].Value = 0;
LOGERROR("CIEC62541DataProcThread ChanNo=%d aipoint-no(%d)(%s) can not get the value", m_ptrCurChan->m_Param.ChanNo,pAi->PointNo,&(pAi->TagName[0]));
} }
} }
@ -801,12 +813,12 @@ void CIEC62541DataProcThread::procMiData(UA_ReadResponse &response)
DataType dataType=static_cast<DataType>(pMi->Param1); DataType dataType=static_cast<DataType>(pMi->Param1);
if(result->hasSourceTimestamp) if(result->hasSourceTimestamp)
{ {
mSec=result->sourceTimestamp; mSec=result->sourceTimestamp/10000- UA_DATETIME_UNIX_EPOCH_DIFF_MS;
} }
else{ else{
if(result->hasServerTimestamp) if(result->hasServerTimestamp)
{ {
mSec=result->serverTimestamp; mSec=result->serverTimestamp/10000- UA_DATETIME_UNIX_EPOCH_DIFF_MS;
} }
} }
@ -817,7 +829,7 @@ void CIEC62541DataProcThread::procMiData(UA_ReadResponse &response)
} }
if(iotSuccess==getValue(result,indexVec,dataType,resultValue)) if(result->hasValue&&iotSuccess==getValue(result,indexVec,dataType,resultValue))
{ {
MiValue[miPoint].PointNo = miPoint; MiValue[miPoint].PointNo = miPoint;
@ -828,6 +840,9 @@ void CIEC62541DataProcThread::procMiData(UA_ReadResponse &response)
} }
else else
{ {
MiValue[miPoint].PointNo = miPoint;
MiValue[miPoint].Status = valueStatus;
MiValue[miPoint].Value = 0;
LOGERROR("CIEC62541DataProcThread ChanNo=%d mipoint-no(%d)(%s) can not get the value", m_ptrCurChan->m_Param.ChanNo,pMi->PointNo,&(pMi->TagName[0])); LOGERROR("CIEC62541DataProcThread ChanNo=%d mipoint-no(%d)(%s) can not get the value", m_ptrCurChan->m_Param.ChanNo,pMi->PointNo,&(pMi->TagName[0]));
} }
@ -867,12 +882,12 @@ void CIEC62541DataProcThread::procAccData(UA_ReadResponse &response)
DataType dataType=static_cast<DataType>(pAcc->Param1); DataType dataType=static_cast<DataType>(pAcc->Param1);
if(result->hasSourceTimestamp) if(result->hasSourceTimestamp)
{ {
mSec=result->sourceTimestamp; mSec=result->sourceTimestamp/10000- UA_DATETIME_UNIX_EPOCH_DIFF_MS;
} }
else{ else{
if(result->hasServerTimestamp) if(result->hasServerTimestamp)
{ {
mSec=result->serverTimestamp; mSec=result->serverTimestamp/10000- UA_DATETIME_UNIX_EPOCH_DIFF_MS;
} }
} }
@ -884,7 +899,7 @@ void CIEC62541DataProcThread::procAccData(UA_ReadResponse &response)
if(iotSuccess==getValue(result,indexVec,dataType,resultValue)) if(result->hasValue&&iotSuccess==getValue(result,indexVec,dataType,resultValue))
{ {
AccValue[accPoint].PointNo = accPoint; AccValue[accPoint].PointNo = accPoint;
@ -895,6 +910,9 @@ void CIEC62541DataProcThread::procAccData(UA_ReadResponse &response)
} }
else else
{ {
AccValue[accPoint].PointNo = accPoint;
AccValue[accPoint].Status = valueStatus;
AccValue[accPoint].Value = 0;
LOGERROR("CIEC62541DataProcThread ChanNo=%d mipoint-no(%d)(%s) can not get the value", m_ptrCurChan->m_Param.ChanNo,pAcc->PointNo,&(pAcc->TagName[0])); LOGERROR("CIEC62541DataProcThread ChanNo=%d mipoint-no(%d)(%s) can not get the value", m_ptrCurChan->m_Param.ChanNo,pAcc->PointNo,&(pAcc->TagName[0]));
} }