diff --git a/product/src/fes/protocol/iec62541_client/IEC62541DataProcThread.cpp b/product/src/fes/protocol/iec62541_client/IEC62541DataProcThread.cpp index 6ae32475..4a26e07a 100644 --- a/product/src/fes/protocol/iec62541_client/IEC62541DataProcThread.cpp +++ b/product/src/fes/protocol/iec62541_client/IEC62541DataProcThread.cpp @@ -7,7 +7,7 @@ using namespace iot_idl; extern bool g_IEC62541IsMainFes; extern bool g_IEC62541ChanelRun; - +#define UA_DATETIME_UNIX_EPOCH_DIFF_MS 11644473600000LL namespace fes_iec62541_client { 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() { - if(m_ptrUAClient) + + + m_ptrCurChan->SetLinkStatus(CN_FesChanDisconnect); + m_ptrFesChan->SetDataThreadRunFlag(CN_FesStopFlag); + if(m_ptrCurRtu != NULL) { - UA_Client_delete(m_ptrUAClient); - m_ptrUAClient=NULL; + m_ptrCFesBase->WriteRtuSatus(m_ptrCurRtu, CN_FesRtuComDown); } - 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() @@ -91,7 +86,17 @@ void CIEC62541DataProcThread::execute() 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() @@ -161,11 +166,12 @@ int CIEC62541DataProcThread::batchRequestData() UA_ReadResponse response = UA_Client_Service_read(m_ptrUAClient, request); if (response.responseHeader.serviceResult != UA_STATUSCODE_GOOD != UA_STATUSCODE_GOOD || response.resultsSize == 0) { 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); return iotFailed; } + procDiData(response); procAiData(response); procMiData(response); @@ -651,12 +657,12 @@ void CIEC62541DataProcThread::procDiData(UA_ReadResponse &response) DataType dataType=static_cast(pDi->Param1); if(result->hasSourceTimestamp) { - mSec=result->sourceTimestamp; + mSec=result->sourceTimestamp/10000- UA_DATETIME_UNIX_EPOCH_DIFF_MS; } else{ 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) { @@ -690,6 +696,9 @@ void CIEC62541DataProcThread::procDiData(UA_ReadResponse &response) } 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])); } @@ -732,12 +741,12 @@ void CIEC62541DataProcThread::procAiData(UA_ReadResponse &response) DataType dataType=static_cast(pAi->Param1); if(result->hasSourceTimestamp) { - mSec=result->sourceTimestamp; + mSec=result->sourceTimestamp/10000- UA_DATETIME_UNIX_EPOCH_DIFF_MS; } else{ 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; @@ -761,7 +770,10 @@ void CIEC62541DataProcThread::procAiData(UA_ReadResponse &response) } 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(pMi->Param1); if(result->hasSourceTimestamp) { - mSec=result->sourceTimestamp; + mSec=result->sourceTimestamp/10000- UA_DATETIME_UNIX_EPOCH_DIFF_MS; } else{ 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; @@ -828,6 +840,9 @@ void CIEC62541DataProcThread::procMiData(UA_ReadResponse &response) } 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])); } @@ -867,12 +882,12 @@ void CIEC62541DataProcThread::procAccData(UA_ReadResponse &response) DataType dataType=static_cast(pAcc->Param1); if(result->hasSourceTimestamp) { - mSec=result->sourceTimestamp; + mSec=result->sourceTimestamp/10000- UA_DATETIME_UNIX_EPOCH_DIFF_MS; } else{ 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; @@ -895,6 +910,9 @@ void CIEC62541DataProcThread::procAccData(UA_ReadResponse &response) } 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])); }