[ref]同步711

This commit is contained in:
shi_jq 2025-03-13 15:52:25 +08:00
parent 28236be4eb
commit 4d85df836b
28 changed files with 11554 additions and 7421 deletions

View File

@ -0,0 +1,117 @@
#include "DebugMbCommunicator.h"
#include "czmq.h"
#include "common/Common.h"
#include "pub_logger_api/logger.h"
#include "pub_utility_api/CharUtil.h"
#define ZMQ_FES_CLIENT_IDENTITY "fes"
using namespace std;
using namespace iot_public;
class CDebugMbCommunicatorInfo
{
public:
CDebugMbCommunicatorInfo() {
m_pServer = NULL;
m_pPoller = NULL;
}
zsock_t *m_pServer;
zpoller_t *m_pPoller;
};
CDebugMbCommunicator::CDebugMbCommunicator()
{
m_pCommInfo = new CDebugMbCommunicatorInfo();
}
CDebugMbCommunicator::~CDebugMbCommunicator()
{
if(m_pCommInfo != NULL)
{
closeServer();
delete m_pCommInfo;
m_pCommInfo = NULL;
}
}
bool CDebugMbCommunicator::init(const int &nPort)
{
if(iotSuccess != initServer(nPort))
{
return false;
}
return true;
}
bool CDebugMbCommunicator::recvMsg(std::string &strMsg, const int &nTimeoutMs)
{
zsock_t *pReader = (zsock_t *)zpoller_wait(m_pCommInfo->m_pPoller,nTimeoutMs);
if(pReader == NULL)
{
return false;
}
zmsg_t *msg = zmsg_recv (m_pCommInfo->m_pServer);
zframe_t *last = zmsg_last(msg);
strMsg.append((char*)zframe_data(last),zframe_size(last));
zmsg_destroy(&msg);
return true;
}
bool CDebugMbCommunicator::sendMsg(const string &strMsg)
{
zmsg_t *sendMsg = zmsg_new ();
zmsg_addstr(sendMsg,ZMQ_FES_CLIENT_IDENTITY);
zmsg_addmem(sendMsg,(void*)strMsg.data(),strMsg.size());
int nRet = zmsg_send(&sendMsg,m_pCommInfo->m_pServer);
zmsg_destroy(&sendMsg);
return (nRet >=0);
}
int CDebugMbCommunicator::initServer(const int &nPort)
{
m_pCommInfo->m_pServer = zsock_new(ZMQ_ROUTER);
if(m_pCommInfo->m_pServer == NULL)
{
LOGERROR("CFesSimServerThread: 创建ROUTER失败");
return iotFailed;
}
string strEndpoints = "tcp://*:" + IntToString(nPort);
int nRet = zsock_bind(m_pCommInfo->m_pServer,strEndpoints.c_str());
if(nRet < 0)
{
LOGERROR("CFesSimServerThread: bind failed. endpoints=%s",strEndpoints.c_str());
closeServer();
return iotFailed;
}
m_pCommInfo->m_pPoller = zpoller_new (m_pCommInfo->m_pServer, NULL);
zpoller_set_nonstop (m_pCommInfo->m_pPoller, true);
LOGINFO("CFesSimServerThread: 绑定成功. endpoints=%s",strEndpoints.c_str());
return iotSuccess;
}
int CDebugMbCommunicator::closeServer()
{
if(m_pCommInfo->m_pPoller != NULL)
{
zpoller_destroy(&m_pCommInfo->m_pPoller);
m_pCommInfo->m_pPoller = NULL;
}
if(m_pCommInfo->m_pServer != NULL)
{
zsock_destroy(&m_pCommInfo->m_pServer);
m_pCommInfo->m_pServer = NULL;
}
return iotSuccess;
}

View File

@ -0,0 +1,26 @@
#ifndef DEBUGMBCOMMUNICATOR_H
#define DEBUGMBCOMMUNICATOR_H
#include <string>
class CDebugMbCommunicatorInfo;
class CDebugMbCommunicator
{
public:
CDebugMbCommunicator();
virtual ~CDebugMbCommunicator();
bool init(const int &nPort);
bool recvMsg(std::string &strMsg,const int &nTimeoutMs);
bool sendMsg(const std::string &strMsg);
int closeServer();
private:
int initServer(const int &nPort);
private:
CDebugMbCommunicatorInfo *m_pCommInfo;
};
#endif // DEBUGMBCOMMUNICATOR_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,175 @@
#ifndef DEBUGTHREAD_H
#define DEBUGTHREAD_H
#include "pub_utility_api/TimerThreadBase.h"
#include "DebugMbCommunicator.h"
#include "FesDebugTool.pb.h"
#include "FesBase.h"
class CDebugThread : public iot_public::CTimerThreadBase
{
public:
CDebugThread(CFesBase *pFesBase);
virtual ~CDebugThread();
virtual void execute();
int init(const int &nPort);
private:
//客户端断开后停止刷新数据
void stopRefreshMonData();
void handleMessage();
void onRecvHeartbeatReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvConnectReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvDisconnectReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvChanParamReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvRtuParamReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvRtuInfoReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvAiParamReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvAiValueReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvDiParamReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvDiValueReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvAccParamReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvAccValueReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvMiParamReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvMiValueReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
//模拟量仿真
void onRecvSimAiStartSimReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvSimAiStopSimReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
//数字量仿真
void onRecvSimDiStartSimReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvSimDiStopSimReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
//混合量仿真
void onRecvSimMiStartSimReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvSimMiStopSimReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
//累积量仿真
void onRecvSimAccStartSimReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvSimAccStopSimReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
//事件仿真
void onRecvSimEventCreateReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
//控制仿真
void onRecvSimAoControlReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvSimDoControlReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvSimMoControlReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
//数据转发
void onRecvFwRtuInfoReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvFwAiParamReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvFwAiValueReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvFwDiParamReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvFwDiValueReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvFwDDiParamReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvFwDDiValueReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvFwMiParamReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvFwMiValueReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvFwAccParamReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvFwAccValueReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
//事件监视
void onRecvSoeEventReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvChanEventReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvSoeMemEventReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
//通道监视
void onRecvChanMonStartReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvChanMonStopReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void onRecvChanMonClearReq(const iot_idl::FesDebugToolReqMsg &objRecvMsg);
void reportChanMonInfo();
std::string* buildChanMonInfo(SFesSimServerChanMonBuf &chanBuf);
void simulate();
void periodSimulate();
//单次模拟
void oneTimeSimulate();
void oneTimeSimulateAi();
void oneTimeSimulateDi();
void oneTimeSimulateMi();
void oneTimeSimulateAcc();
//周期性模拟
void periodSimulateAi();
void periodSimulateDi();
void periodSimulateMi();
void periodSimulateAcc();
float getAiSimValue(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
void simulateSingleAi(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
void simulateRtuAi(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
void simulateAllAi(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
int getDiSimValue(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
void simulateSingleDi(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
void simulateRtuDi(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
void simulateAllDi(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
int getMiSimValue(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
void simulateSingleMi(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
void simulateRtuMi(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
void simulateAllMi(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
double getAccSimValue(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
void simulateSingleAcc(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
void simulateRtuAcc(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
void simulateAllAcc(const iot_idl::FesDebugToolValueSimSetReqMsg &simParam);
private:
CDebugMbCommunicator m_objMbComm;
CFesBase* m_pFesBase;
int64 m_lLastSimScanTime; //上一次执行仿真的时间,单位毫秒
boost::mutex m_mutexSimParam; //保护仿真参数
//模拟量仿真相关参数
bool m_bAiSimRunning; //模拟量正在仿真标识
float m_fLastAiSimValue; //上一次仿真值,用于线性仿真中
float m_fAiSimStepValue; //步进值
int64 m_lAiLastSimTime; //最后一次仿真数据变化的时间,单位毫秒
iot_idl::FesDebugToolValueSimSetReqMsg m_stAiSimParam; //模拟量仿真参数
//数字量仿真相关参数
bool m_bDiSimRunning; //数字量正在仿真标识
int m_nLastDiSimValue; //上一次仿真值,用于线性仿真中
// int m_nDiSimStepValue; //步进值
int64 m_lDiLastSimTime; //最后一次仿真数据变化的时间,单位毫秒
iot_idl::FesDebugToolValueSimSetReqMsg m_stDiSimParam; //数字量仿真参数
//混合量仿真相关参数
bool m_bMiSimRunning; //混合量正在仿真标识
int m_nLastMiSimValue; //上一次仿真值,用于线性仿真中
int m_nMiSimStepValue; //步进值
int64 m_lMiLastSimTime; //最后一次仿真数据变化的时间,单位毫秒
iot_idl::FesDebugToolValueSimSetReqMsg m_stMiSimParam; //混合量仿真参数
//累计量仿真相关参数
bool m_bAccSimRunning; //累计量正在仿真标识
double m_dLastAccSimValue; //上一次仿真值,用于线性仿真中
double m_dAccSimStepValue; //步进值
int64 m_lAccLastSimTime; //最后一次仿真数据变化的时间,单位毫秒
iot_idl::FesDebugToolValueSimSetReqMsg m_stAccSimParam; //累计量仿真参数
//通道监视
int m_nCurMonChanNo; //当前监视的通道
int64 m_lLastHeartbeatTime; //最后一次心跳包时间
bool m_bHasClient; //当前是否有客户端在连接
};
typedef boost::shared_ptr<CDebugThread> CDebugThreadPtr;
#endif // DEBUGTHREAD_H

View File

@ -9,7 +9,6 @@
2020-12-30 thxiao StopThread() m_ptrFesChanManageThread->quit()退
2021-12-02 thxiao DLL的文件名改为绝对路径
2022-07-11 thxiao "fes"
2023-11-25 thxiao 线
*/
//#include <dlfcn.h>
@ -45,6 +44,7 @@ int g_FesChgAnaSendCyc=200; //变化数据发送周期
int g_FesChgAccSendCyc=300; //变化数据发送周期
int g_FesChgMixSendCyc=200; //变化数据发送周期
int g_FesEventSendCyc =500; //变化数据发送周期
const int CN_FES_DebugPort_Offset = 100; //当前为了2种调试端口并存增加一个偏移量
CFesApp::CFesApp()
{
@ -52,13 +52,7 @@ CFesApp::CFesApp()
m_ptrProcManage = NULL;
m_ptrReduSwitchManage = NULL;
m_ptrRedundantMng = NULL;
m_ptrFesRxFesDataThread = NULL;
m_ptrFesRxDPDataThread = NULL;
m_ptrAnaWorkThread = NULL;
m_ptrDigWorkThread = NULL;
m_ptrAccWorkThread = NULL;
m_ptrMixWorkThread = NULL;
m_ptrFesSimServerThread = NULL;
}
CFesApp::~CFesApp()
@ -241,27 +235,14 @@ bool CFesApp::start(int argc, char *argv[], int &/*nStatus*/)
Param.ptrFesFwTxControlCmdThread = m_ptrFesFwTxControlCmdThread;
if (m_CFesBase.FesRxFesDataThreadFlag)
{
Param.ptrFesRxFesDataThread = m_ptrFesRxFesDataThread;
Param.ptrAnaWorkThread = m_ptrAnaWorkThread;
Param.ptrDigWorkThread = m_ptrDigWorkThread;
Param.ptrAccWorkThread = m_ptrAccWorkThread;
Param.ptrMixWorkThread = m_ptrMixWorkThread;
}
else
{
Param.ptrFesRxFesDataThread = NULL;
Param.ptrAnaWorkThread = NULL;
Param.ptrDigWorkThread = NULL;
Param.ptrAccWorkThread = NULL;
Param.ptrMixWorkThread = NULL;
}
if (m_CFesBase.FesRxDPDataThreadFlag)
Param.ptrFesRxDPDataThread = m_ptrFesRxDPDataThread;
else
Param.ptrFesRxDPDataThread = NULL;
/******转发相关线程*************************************************/
m_ptrReduSwitchManage->Init(Param);
@ -421,12 +402,25 @@ bool CFesApp::InitThread()
return false;
}
/* 使用CDebugThread替代CFesSimServerThread停止使用旧的调试类
m_ptrFesSimServerThread = boost::make_shared<CFesSimServerThread>(&m_CFesBase);
if (m_ptrFesSimServerThread == NULL)
{
LOGERROR("m_ptrFesSimServerThread 创建失败");
return false;
}
LOGINFO("FesSimServerThread AppName=%s AppId=%d NetPortNo=%d",m_strAppLabel.c_str(),m_ProcessInfo.nAppId,FesSimServerPortNo);
m_ptrFesSimServerThread->Init(FesSimServerPortNo,CN_FesServerMaxConnects);//Init Server net PortNo
*/
int FesSimServerPortNo = CN_FesSimServerBasePortNo+m_ProcessInfo.nAppId;
m_ptrDebugThread = boost::make_shared<CDebugThread>(&m_CFesBase);
if(m_ptrDebugThread == NULL)
{
LOGERROR("m_ptrDebugThread 创建失败");
return false;
}
m_ptrFesFwRxControlCmdThread = boost::make_shared<CFesFwRxControlCmdThread>(m_ProcessInfo.nDomainId, m_ProcessInfo.nAppId,&m_CFesBase);
if (m_ptrFesFwRxControlCmdThread == NULL)
@ -442,101 +436,30 @@ bool CFesApp::InitThread()
return false;
}
if(m_CFesBase.FesRxFesDataThreadFlag)
m_ptrFesRxFesDataThread = boost::make_shared<CFesRxFesDataThread>(m_ProcessInfo.nDomainId, m_ProcessInfo.nAppId,&m_CFesBase);
if (m_ptrFesRxFesDataThread == NULL)
{
//创建数据接收缓冲;
//==============================================================================================
m_ptrPacketQueue = boost::make_shared<CPacketQueue>();
if (m_ptrPacketQueue == NULL)
{
LOGERROR("CPacketQueue::initialize(), make_shared<CPacketQueue> fail!\n");
return false;
}
m_ptrFesRxFesDataThread = boost::make_shared<CFesRxFesDataThread>(m_ProcessInfo.nDomainId, m_ProcessInfo.nAppId, &m_CFesBase, m_ptrPacketQueue);
if (m_ptrFesRxFesDataThread == NULL)
{
LOGERROR("m_ptrFesRxFesDataThread 创建失败");
return false;
}
//初始化模拟量数据处理线程
//==============================================================================================
m_ptrAnaWorkThread = boost::make_shared<CAnaWorkThread>(&m_CFesBase, m_ptrPacketQueue);
if (m_ptrAnaWorkThread == NULL)
{
LOGERROR("m_ptrAnaWorkThread,创建模拟量工作线程失败!");
return false;
}
if (false == m_ptrAnaWorkThread->initialize())
{
LOGERROR("初始化模拟量工作线程失败!");
return false;
}
//初始化数字量数据处理线程
//==============================================================================================
m_ptrDigWorkThread = boost::make_shared<CDigWorkThread>(&m_CFesBase, m_ptrPacketQueue);
if (m_ptrDigWorkThread == NULL)
{
LOGERROR("m_ptrDigWorkThread,创建数字量工作线程失败!");
return false;
}
if (false == m_ptrDigWorkThread->initialize())
{
LOGERROR("初始化数字量工作线程失败!");
return false;
}
//初始化累计量数据处理线程
//==============================================================================================
m_ptrAccWorkThread = boost::make_shared<CAccWorkThread>(&m_CFesBase, m_ptrPacketQueue);
if (m_ptrAccWorkThread == NULL)
{
LOGERROR("m_ptrAnaWorkThread,创建累计量工作线程失败!");
return false;
}
if (false == m_ptrAccWorkThread->initialize())
{
LOGERROR("初始化累计量工作线程失败!");
return false;
}
//初始化混合量数据处理线程
//==============================================================================================
m_ptrMixWorkThread = boost::make_shared<CMixWorkThread>(&m_CFesBase, m_ptrPacketQueue);
if (m_ptrMixWorkThread == NULL)
{
LOGERROR("m_ptrMixWorkThread,创建混合量工作线程失败!");
return false;
}
if (false == m_ptrMixWorkThread->initialize())
{
LOGERROR("初始化混合量工作线程失败!");
return false;
}
LOGERROR("m_ptrFesRxFesDataThread 创建失败");
return false;
}
if (m_CFesBase.FesRxDPDataThreadFlag)
m_ptrFesRxDPDataThread = boost::make_shared<CFesRxDPDataThread>(m_ProcessInfo.nDomainId, m_ProcessInfo.nAppId,&m_CFesBase);
if (m_ptrFesRxDPDataThread == NULL)
{
m_ptrFesRxDPDataThread = boost::make_shared<CFesRxDPDataThread>(m_ProcessInfo.nDomainId, m_ProcessInfo.nAppId, &m_CFesBase);
if (m_ptrFesRxDPDataThread == NULL)
{
LOGERROR("m_ptrFesRxDPDataThread 创建失败");
return false;
}
if (m_ptrFesRxDPDataThread->initialize() == iotFailed)
{
LOGERROR("m_ptrFesRxDPDataThread ::initialize() fail!\n");
return false;
}
LOGERROR("m_ptrFesRxDPDataThread 创建失败");
return false;
}
if (m_ptrFesRxDPDataThread->initialize() == iotFailed)
{
LOGERROR("m_ptrFesRxDPDataThread ::initialize() fail!\n");
return false;
}
int FesSimServerPortNo = CN_FesSimServerBasePortNo+m_ProcessInfo.nAppId;
LOGINFO("FesSimServerThread AppName=%s AppId=%d NetPortNo=%d",m_strAppLabel.c_str(),m_ProcessInfo.nAppId,FesSimServerPortNo);
m_ptrFesSimServerThread->Init(FesSimServerPortNo,CN_FesServerMaxConnects);//Init Server net PortNo
// m_ptrFesSimServerThread->resume();
if(m_ptrDebugThread->init(FesSimServerPortNo + CN_FES_DebugPort_Offset) != iotSuccess)
{
LOGERROR("m_ptrDebugThread initialize fail");
return false;
}
LOGINFO("InitThread() 创建成功!");
@ -608,6 +531,13 @@ void CFesApp::StopThread()
LOGDEBUG("CFesApp::StopThread m_ptrFesSimServerThread stop ok");
}
if(m_ptrDebugThread != NULL)
{
m_ptrDebugThread->quit();
m_ptrDebugThread.reset();
LOGDEBUG("CFesApp::StopThread m_ptrDebugThread stop ok");
}
if (m_ptrFesFwRxControlCmdThread != NULL)
{
m_ptrFesFwRxControlCmdThread->quit();
@ -644,31 +574,6 @@ void CFesApp::StopThread()
m_ptrAlmApiForApp = NULL;
LOGINFO("CFesApp::StopThread():释放报警处理工作线程成功! \n");
}
if (m_ptrAnaWorkThread != NULL)
{
m_ptrAnaWorkThread->quit();
m_ptrAnaWorkThread.reset();
LOGDEBUG("CFesApp::StopThread m_ptrAnaWorkThread stop ok");
}
if (m_ptrDigWorkThread != NULL)
{
m_ptrDigWorkThread->quit();
m_ptrDigWorkThread.reset();
LOGDEBUG("CFesApp::StopThread m_ptrDigWorkThread stop ok");
}
if (m_ptrAccWorkThread != NULL)
{
m_ptrAccWorkThread->quit();
m_ptrAccWorkThread.reset();
LOGDEBUG("CFesApp::StopThread m_ptrAccWorkThread stop ok");
}
if (m_ptrMixWorkThread != NULL)
{
m_ptrMixWorkThread->quit();
m_ptrMixWorkThread.reset();
LOGDEBUG("CFesApp::StopThread m_ptrMixWorkThread stop ok");
}
}

View File

@ -14,19 +14,13 @@
#include "FesDataSyncThread.h"
#include "FesChanManageThread.h"
#include "FesRedundantManage.h"
#include "DebugThread.h"
#include "FesSimServerThread.h"
#include "FesWaveFormThread.h"
#include "FesFwRxControlCmdThread.h"
#include "FesFwTxControlCmdThread.h"
#include "FesRxFesDataThread.h"
#include "FesRxDPDataThread.h"
#include "PacketQueue.h"
#include "AnaWorkThread.h"
#include "DigWorkThread.h"
#include "AccWorkThread.h"
#include "MixWorkThread.h"
class CFesApp:public iot_public::CBaseService,iot_sys::CProcessQuitInterface
{
@ -35,7 +29,6 @@ public:
~CFesApp();
CFesBase m_CFesBase;
CPacketQueuePtr m_ptrPacketQueue; //消息缓存类
/*
@brief CMsgQueueBuffer;
@ -85,16 +78,12 @@ private:
CFesDataSyncThreadPtr m_PtrFesDataSyncThread;
CFesChanManageThreadPtr m_ptrFesChanManageThread;
CFesSimServerThreadPtr m_ptrFesSimServerThread;
CDebugThreadPtr m_ptrDebugThread;
CFesWaveFormThreadPtr m_ptrFesWaveFormThread;
CFesFwRxControlCmdThreadPtr m_ptrFesFwRxControlCmdThread;
CFesFwTxControlCmdThreadPtr m_ptrFesFwTxControlCmdThread;
CFesRxFesDataThreadPtr m_ptrFesRxFesDataThread;
CFesRxDPDataThreadPtr m_ptrFesRxDPDataThread;
CAnaWorkThreadPtr m_ptrAnaWorkThread;
CDigWorkThreadPtr m_ptrDigWorkThread;
CAccWorkThreadPtr m_ptrAccWorkThread;
CMixWorkThreadPtr m_ptrMixWorkThread;
/**
* @brief CFesApp::InitThread

File diff suppressed because it is too large Load Diff

View File

@ -20,11 +20,9 @@
2021-10-18 thxiao CheckChanStatus()RTU,
2021-12-02 thxiao
2021-12-24 thxiao CheckChanStatus()
2022-09-28 thxiao 1false,1
*/
#include "FesChanManageThread.h"
#include "pub_utility_api/TimeUtil.h"
#include "pub_utility_api/CommonConfigParse.h"
//#include "FesRtu.h"
using namespace iot_public;
@ -32,7 +30,7 @@ using namespace iot_dbms;
extern bool g_IsMainFes;
extern bool g_IsMainFesOld;
CFesChanManageThread::CFesChanManageThread(iot_public::SRunAppInfo stRunAppInfo,void* FesBaseAddr):
CTimerThreadBase("FesChanManageThread", 100)
{
@ -53,21 +51,6 @@ CTimerThreadBase("FesChanManageThread", 100)
m_timerCount = 0;
m_lastOfflineSecTime = getMonotonicMsec();
//2022-09-28 thxiao 每天随机把转发标志设置1小时为false,让通信中断1小时
m_IsMainFesZf = g_IsMainFes;
m_ComDownMSec = getMonotonicMsec(); //启动时间
m_ComDownStepHighLimit=108000000; //计数偏移量,最大偏移值>24h 30*60*60*1000=108000000
m_ComDownStepLowLimit=86400000; //计数偏移量,最小偏移值>24h 24*60*60*1000=86400000
m_ComDownStep=1020000; //偏移值步长17*60*1000=1020000
m_ComDownOffSet = m_ComDownStepLowLimit; //当前偏移值是个有步长的偏移量,到达最高值时,返回最低值继续循环。
m_ComDownStepCount=0; //偏移值计数
m_ComDownKeepMsec = 3600000; //停止持续时间 3600*1000=3600000
m_ComDownStartMSec = m_ComDownMSec+ m_ComDownOffSet; //停止时间
m_ComDownStopMSec = m_ComDownStartMSec + m_ComDownKeepMsec; //停止时间
m_lastCheckDogTimes = 0;
ReadConfigParam();
m_ptrDogAuth = iot_sys::getDogAuthInstance();
LOGDEBUG("current=%lld m_ComDownOffSet=%lld m_ComDownStartMSec=%lld m_ComDownStopMSec=%lld", m_ComDownMSec, m_ComDownOffSet, m_ComDownStartMSec, m_ComDownStopMSec);
}
CFesChanManageThread::~CFesChanManageThread()
@ -100,7 +83,7 @@ void CFesChanManageThread::execute()
{
CFesChanPtr ptrMainFesChan; //CHAN数据区
int ChanNo, MainChanNo,i;
int64 curmsec ;
int64 curmsec;
if (m_timerCount++ >= m_timerCountReset)
{
@ -122,28 +105,11 @@ void CFesChanManageThread::execute()
}
//检查通道状态,同时计算通道误码率
CheckChanStatus();
CheckChanStatus();
if(m_BreakDownFlag) //通信控制
{
if ((curmsec - m_lastCheckDogTimes) >60*1000)//:狗校验失败情况,定时停止转发功能,检查周期 1分钟
{
if(m_ptrDogAuth->checkAuthStatus() != AUTH_STATUS_OK) //狗异常
{
SetIsMainFesZf();
}
else //狗正常
{
m_IsMainFesZf = g_IsMainFes;
}
}
}
else //不控制
{
m_IsMainFesZf = g_IsMainFes;
}
}
if (g_IsMainFes != g_IsMainFesOld)
{
for (int i = 0; i < m_ptrCFesBase->m_ProtocolNum; i++)
@ -159,7 +125,6 @@ void CFesChanManageThread::execute()
g_IsMainFesOld = g_IsMainFes;
}
for (i = 0; i < (int)m_ptrCFesBase->m_vectCFesChanPtr.size(); i++)
{
ptrMainFesChan = m_ptrCFesBase->m_vectCFesChanPtr[i];
@ -284,8 +249,7 @@ void CFesChanManageThread::execute()
ptrMainFesChan->m_CurrentChanIndex = 0;
}
//FES在主机状态下需要打开所有通道
//if (g_IsMainFes == true)
if ((m_IsMainFesZf == true)&&(g_IsMainFes == true))
if(g_IsMainFes == true)
{
CFesChanPtr ptrCurrentChan; //current CHAN数据区
ptrCurrentChan = m_ptrCFesBase->GetChanDataByChanNo(ChanNo);
@ -334,6 +298,8 @@ void CFesChanManageThread::execute()
}
}
}
}
/*
@ -767,76 +733,3 @@ void CFesChanManageThread::NotifyExitSystem()
}
LOGDEBUG("已通知%d个规约模块退出", count);
}
/**
* @brief CFesChanManageThread::SetIsMainFesZf
*
* 1false.
*
* @param
*/
void CFesChanManageThread::SetIsMainFesZf()
{
int64 lMsec;
lMsec = getMonotonicMsec();
if (lMsec > m_ComDownStopMSec)//
{
m_ComDownOffSet = m_ComDownStepLowLimit + m_ComDownStep*m_ComDownStepCount;//当前偏移值
m_ComDownStepCount++;
m_ComDownStartMSec = lMsec + m_ComDownOffSet; //启动时间
m_ComDownStopMSec = m_ComDownStartMSec + m_ComDownKeepMsec; //停止时间
if (m_ComDownOffSet > m_ComDownStepHighLimit)
{
m_ComDownStepCount = 0;
m_ComDownOffSet = m_ComDownStepLowLimit;
}
LOGDEBUG("current=%lld m_ComDownOffSet=%lld m_ComDownStartMSec=%lld m_ComDownStopMSec=%lld", lMsec,m_ComDownOffSet, m_ComDownStartMSec, m_ComDownStopMSec);
}
if ((lMsec>m_ComDownStartMSec)&&(lMsec<m_ComDownStopMSec))
{
if (m_IsMainFesZf == true)
{
m_IsMainFesZf = false;
LOGDEBUG("g_IsMainFesZf change!");
}
}
else
{
if((m_IsMainFesZf == true)&&(g_IsMainFes==true))
{
LOGDEBUG("g_IsMainFesZf recover!");
}
m_IsMainFesZf = g_IsMainFes;
}
return;
}
int CFesChanManageThread::ReadConfigParam()
{
CCommonConfigParse config;
int ivalue;
char strName[48];
//管理机全局参数默认配置
m_BreakDownFlag = 0;
if(config.load("../../data/fes/","fesConfig.xml")==iotFailed)
{
return iotFailed;
}
sprintf(strName,"FESSYS");
if(config.getIntValue(strName,"chan_controlCom",ivalue) == iotSuccess)
{
m_BreakDownFlag = ivalue;
}
else
{
m_BreakDownFlag = 0;
}
return iotSuccess;
}

View File

@ -5,7 +5,6 @@
#include "FesBase.h"
#include "pub_sysinfo_api/SysInfoBase.h"
#include "rdb_api/RdbTableMng.h"
#include "sys_dog_auth_api/DogAuthInterface.h"
class CFesChanManageThread : public iot_public::CTimerThreadBase
{
@ -41,13 +40,9 @@ public:
virtual void beforeQuit();
void NotifyExitSystem();
private:
iot_dbms::CRdbTableMngPtr m_ptrRdbTableMng;
iot_public::SRunAppInfo m_stRunAppInfo ;
iot_sys::CDogAuthInterfacePtr m_ptrDogAuth;
CFesBase *m_ptrCFesBase;
//设备离线监视相关变量
@ -58,22 +53,6 @@ private:
void CheckChanStatus();
//2022-09-28 thxiao 每天随机把转发标志设置1小时为false,让通信中断1小时
bool m_IsMainFesZf;
int64 m_ComDownMSec; //启动时间
int64 m_ComDownStepHighLimit; //最大偏移值
int64 m_ComDownStepLowLimit; //最小偏移值
int64 m_ComDownStep; //偏移值步长
int64 m_ComDownOffSet; //当前偏移值
int m_ComDownStepCount; //偏移值计数
int64 m_ComDownStartMSec; //启动时间
int64 m_ComDownStopMSec; //停止时间
int64 m_ComDownKeepMsec; //持续时间
int64 m_lastCheckDogTimes; //上传检查狗状态时间
void SetIsMainFesZf();
int m_BreakDownFlag;
int ReadConfigParam();
};
typedef boost::shared_ptr<CFesChanManageThread> CFesChanManageThreadPtr;

View File

@ -249,7 +249,7 @@ int CFesDataSyncThread::RtuDiAllResp()
if(m_ptrCFesBase==NULL)
return iotFailed;
count = m_ptrCFesBase->m_vectCFesRtuPtr.size();
count = static_cast<int>(m_ptrCFesBase->m_vectCFesRtuPtr.size());
for(i=0;i<count;i++)
{
ptrCFesRtu = m_ptrCFesBase->m_vectCFesRtuPtr[i];
@ -328,7 +328,7 @@ int CFesDataSyncThread::RtuDDiAllResp()
if (m_ptrCFesBase == NULL)
return iotFailed;
count = m_ptrCFesBase->m_vectCFesRtuPtr.size();
count = static_cast<int>(m_ptrCFesBase->m_vectCFesRtuPtr.size());
for (i = 0; i<count; i++)
{
ptrCFesRtu = m_ptrCFesBase->m_vectCFesRtuPtr[i];
@ -389,12 +389,11 @@ int CFesDataSyncThread::RtuAiAllResp()
{
int i,j,retNum,count;
CFesRtuPtr ptrCFesRtu;
CFesChanPtr pChan;
if(m_ptrCFesBase==NULL)
return iotFailed;
count = m_ptrCFesBase->m_vectCFesRtuPtr.size();
count = static_cast<int>(m_ptrCFesBase->m_vectCFesRtuPtr.size());
for(i=0;i<count;i++)
{
ptrCFesRtu = m_ptrCFesBase->m_vectCFesRtuPtr[i];
@ -469,7 +468,7 @@ int CFesDataSyncThread::RtuAccAllResp()
if(m_ptrCFesBase==NULL)
return iotFailed;
count = m_ptrCFesBase->m_vectCFesRtuPtr.size();
count = static_cast<int>(m_ptrCFesBase->m_vectCFesRtuPtr.size());
for(i=0;i<count;i++)
{
ptrCFesRtu = m_ptrCFesBase->m_vectCFesRtuPtr[i];
@ -507,7 +506,7 @@ int CFesDataSyncThread::RtuAccAllResp()
pRtuAccValue = m_pAccValue+j;
pAccValue = respPkg.add_stpivalue();
pAccValue->set_npointno(pRtuAccValue->PointNo);
pAccValue->set_nvalue(pRtuAccValue->Value);
pAccValue->set_dvalue(pRtuAccValue->Value);
pAccValue->set_ustatus(pRtuAccValue->Status);
pAccValue->set_ultime(pRtuAccValue->time);
}
@ -545,7 +544,7 @@ int CFesDataSyncThread::RtuMiAllResp()
if(m_ptrCFesBase==NULL)
return iotFailed;
count = m_ptrCFesBase->m_vectCFesRtuPtr.size();
count = static_cast<int>(m_ptrCFesBase->m_vectCFesRtuPtr.size());
for(i=0;i<count;i++)
{
ptrCFesRtu = m_ptrCFesBase->m_vectCFesRtuPtr[i];
@ -638,7 +637,7 @@ int CFesDataSyncThread::RtuDiResp(const std::string &RecvStr)
{
for (i = 0; i < count; i++)
{
SFesDiValue diValue = respPkg.stdivalue(i);
const SFesDiValue &diValue = respPkg.stdivalue(i);
SFesFwChgDi RtuDiValue;
RtuDiValue.RemoteNo = diValue.npointno();
RtuDiValue.Value = diValue.nvalue();
@ -659,7 +658,7 @@ int CFesDataSyncThread::RtuDiResp(const std::string &RecvStr)
for (i = 0; i < count; i++)
{
SFesDiValue diValue = respPkg.stdivalue(i);
const SFesDiValue &diValue = respPkg.stdivalue(i);
pRtuDiValue = m_pDiValue + i;
pRtuDiValue->PointNo = diValue.npointno();
pRtuDiValue->Value = diValue.nvalue();
@ -697,7 +696,7 @@ int CFesDataSyncThread::RtuDDiResp(const std::string &RecvStr)
{
for (i = 0; i < count; i++)
{
SFesDiValue diValue = respPkg.stdivalue(i);
const SFesDiValue &diValue = respPkg.stdivalue(i);
SFesFwChgDi RtuDiValue;
RtuDiValue.RemoteNo = diValue.npointno();
RtuDiValue.Value = diValue.nvalue();
@ -740,13 +739,15 @@ int CFesDataSyncThread::RtuAiResp(const std::string &RecvStr)
{
for (i = 0; i < count; i++)
{
SFesAiValue aiValue = respPkg.staivalue(i);
const SFesAiValue &aiValue = respPkg.staivalue(i);
SFesFwChgAi RtuAiValue;
RtuAiValue.RemoteNo = aiValue.npointno();
RtuAiValue.Value = aiValue.fvalue();
RtuAiValue.Status = aiValue.ustatus();
RtuAiValue.time = aiValue.ultime();
ptrCFesRtu->UpdataFwAiValue(RtuAiValue);
//< 直接更新,因为这是从内存中同步过来的,也就是发送的已经是经过系数变换的
float fNewValue = 0.0f;
ptrCFesRtu->UpdataFwAiValue(RtuAiValue,fNewValue,eDirectUpdate);
}
}
else
@ -761,7 +762,7 @@ int CFesDataSyncThread::RtuAiResp(const std::string &RecvStr)
for (i = 0; i < count; i++)
{
SFesAiValue aiValue = respPkg.staivalue(i);
const SFesAiValue &aiValue = respPkg.staivalue(i);
pRtuAiValue = m_pAiValue + i;
pRtuAiValue->PointNo = aiValue.npointno();
pRtuAiValue->Value = aiValue.fvalue();
@ -804,15 +805,16 @@ int CFesDataSyncThread::RtuAccResp(const std::string &RecvStr)
if (ptrCFesRtu->m_RtuProperty == CN_Fes_RTU_Forward)//2020-01-10 thxiao 增加转发数据同步
{
double dNewValue = 0.0;
for (i = 0; i < count; i++)
{
SFesPiValue accValue = respPkg.stpivalue(i);
const SFesPiValue &accValue = respPkg.stpivalue(i);
SFesFwChgAcc RtuAccValue;
RtuAccValue.RemoteNo = accValue.npointno();
RtuAccValue.Value = accValue.nvalue();
RtuAccValue.Value = accValue.dvalue();
RtuAccValue.Status = accValue.ustatus();
RtuAccValue.time = accValue.ultime();
ptrCFesRtu->UpdataFwAccValue(RtuAccValue);
ptrCFesRtu->UpdataFwAccValue(RtuAccValue,dNewValue,eDirectUpdate);
}
}
else
@ -827,10 +829,10 @@ int CFesDataSyncThread::RtuAccResp(const std::string &RecvStr)
for (i = 0; i < count; i++)
{
SFesPiValue accValue = respPkg.stpivalue(i);
const SFesPiValue &accValue = respPkg.stpivalue(i);
pRtuAccValue = m_pAccValue + i;
pRtuAccValue->PointNo = accValue.npointno();
pRtuAccValue->Value = accValue.nvalue();
pRtuAccValue->Value = accValue.dvalue();
pRtuAccValue->Status = accValue.ustatus();
pRtuAccValue->time = accValue.ultime();
}
@ -865,15 +867,16 @@ int CFesDataSyncThread::RtuMiResp(const std::string &RecvStr)
if (ptrCFesRtu->m_RtuProperty == CN_Fes_RTU_Forward)//2020-01-10 thxiao 增加转发数据同步
{
int nNewValue = 0;
for (i = 0; i < count; i++)
{
SFesMiValue miValue = respPkg.stmivalue(i);
const SFesMiValue &miValue = respPkg.stmivalue(i);
SFesFwChgMi RtuMiValue;
RtuMiValue.RemoteNo = miValue.npointno();
RtuMiValue.Value = miValue.nvalue();
RtuMiValue.Status = miValue.ustatus();
RtuMiValue.time = miValue.ultime();
ptrCFesRtu->UpdataFwMiValue(RtuMiValue);
ptrCFesRtu->UpdataFwMiValue(RtuMiValue,nNewValue,eDirectUpdate);
}
}
else
@ -888,7 +891,7 @@ int CFesDataSyncThread::RtuMiResp(const std::string &RecvStr)
for (i = 0; i < count; i++)
{
SFesMiValue miValue = respPkg.stmivalue(i);
const SFesMiValue &miValue = respPkg.stmivalue(i);
pRtuMiValue = m_pMiValue + i;
pRtuMiValue->PointNo = miValue.npointno();
pRtuMiValue->Value = miValue.nvalue();
@ -918,7 +921,7 @@ void CFesDataSyncThread::SendRtuDataReq()
return;
rtuNo = -1;
count = m_ptrCFesBase->m_vectCFesRtuPtr.size();
count = static_cast<int>(m_ptrCFesBase->m_vectCFesRtuPtr.size());
for(i=0;i<count;i++)
{
pRtu = m_ptrCFesBase->m_vectCFesRtuPtr[i];

File diff suppressed because it is too large Load Diff

View File

@ -62,6 +62,12 @@ private:
*/
void GetRdbFwMoTable(CFesRtuPtr RtuPtr, std::string m_strAppLabel);
/**
* @brief CFesBase::UpdateDeadBandValue
*
* @return
*/
void UpdateDeadBandValue(SFesFwAi *pFwAi);
};

View File

@ -68,31 +68,31 @@ void CFesFwRxControlCmdThread::execute()
switch (nMsgType)
{
case MT_FESFW_DO_REQ:
if(CtrlPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize()))
if(CtrlPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) ))
RxDoReq(CtrlPkg);
break;
case MT_FESFW_AO_REQ:
if(CtrlPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize()))
if(CtrlPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) ))
RxAoReq(CtrlPkg);
break;
case MT_FESFW_MO_REQ:
if(CtrlPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize()))
if(CtrlPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) ))
RxMoReq(CtrlPkg);
break;
case MT_FESFW_DO_RESP:
if(CtrlPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize()))
if(CtrlPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) ))
RxDoResp(CtrlPkg);
break;
case MT_FESFW_AO_RESP:
if(CtrlPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize()))
if(CtrlPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) ))
RxAoResp(CtrlPkg);
break;
case MT_FESFW_MO_RESP:
if(CtrlPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize()))
if(CtrlPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) ))
RxMoResp(CtrlPkg);
break;
case MT_FESWUFANG_STATUS_REPORT:
if(StatusPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize()))
if(StatusPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) ))
RxWuFangStatusReport(StatusPkg);
break;
default:

View File

@ -5,7 +5,6 @@
@history
2019-10-17 thxiao =>,线,线
2020-02-25 thxiao FES按备机方式处理
2023-11-25 thxiao 线
*/
#include "FesRedundantManage.h"
@ -93,10 +92,6 @@ void CFesRedundantManage::Init(SRedundantManageThreadParam &Param )
m_ptrFesFwTxControlCmdThread = Param.ptrFesFwTxControlCmdThread;
m_ptrFesRxFesDataThread = Param.ptrFesRxFesDataThread;
m_ptrFesRxDPDataThread = Param.ptrFesRxDPDataThread;
m_ptrAnaWorkThread = Param.ptrAnaWorkThread;
m_ptrDigWorkThread = Param.ptrDigWorkThread;
m_ptrAccWorkThread = Param.ptrAccWorkThread;
m_ptrMixWorkThread = Param.ptrMixWorkThread;
}
/*
@ -152,22 +147,6 @@ void CFesRedundantManage::ResumeThread()
m_ptrFesRxDPDataThread->resume();
}
if (m_ptrAnaWorkThread != NULL)
{
m_ptrAnaWorkThread->resume();
}
if (m_ptrDigWorkThread != NULL)
{
m_ptrDigWorkThread->resume();
}
if (m_ptrAccWorkThread != NULL)
{
m_ptrAccWorkThread->resume();
}
if (m_ptrMixWorkThread != NULL)
{
m_ptrMixWorkThread->resume();
}
}
/*
@ -236,21 +215,4 @@ void CFesRedundantManage::SuspendThread()
m_ptrFesRxDPDataThread->setSlave();
}
if (m_ptrAnaWorkThread != NULL)
{
m_ptrAnaWorkThread->suspend();
}
if (m_ptrDigWorkThread != NULL)
{
m_ptrDigWorkThread->suspend();
}
if (m_ptrAccWorkThread != NULL)
{
m_ptrAccWorkThread->suspend();
}
if (m_ptrMixWorkThread != NULL)
{
m_ptrMixWorkThread->suspend();
}
}

View File

@ -19,10 +19,6 @@
#include "FesFwTxControlCmdThread.h"
#include "FesRxFesDataThread.h"
#include "FesRxDPDataThread.h"
#include "AnaWorkThread.h"
#include "DigWorkThread.h"
#include "AccWorkThread.h"
#include "MixWorkThread.h"
typedef struct{
CFesRxDataUpDateThreadPtr ptrFesRxDataUpDateThread;
@ -37,10 +33,6 @@ typedef struct{
CFesFwTxControlCmdThreadPtr ptrFesFwTxControlCmdThread;
CFesRxFesDataThreadPtr ptrFesRxFesDataThread;
CFesRxDPDataThreadPtr ptrFesRxDPDataThread;
CAnaWorkThreadPtr ptrAnaWorkThread;
CDigWorkThreadPtr ptrDigWorkThread;
CAccWorkThreadPtr ptrAccWorkThread;
CMixWorkThreadPtr ptrMixWorkThread;
}SRedundantManageThreadParam;
class CFesRedundantManage :
@ -110,10 +102,6 @@ private:
CFesFwTxControlCmdThreadPtr m_ptrFesFwTxControlCmdThread;
CFesRxFesDataThreadPtr m_ptrFesRxFesDataThread;
CFesRxDPDataThreadPtr m_ptrFesRxDPDataThread;
CAnaWorkThreadPtr m_ptrAnaWorkThread;
CDigWorkThreadPtr m_ptrDigWorkThread;
CAccWorkThreadPtr m_ptrAccWorkThread;
CMixWorkThreadPtr m_ptrMixWorkThread;
};
typedef boost::shared_ptr<CFesRedundantManage> CFesRedundantManagePtr;

View File

@ -72,6 +72,7 @@ CFesRtu::CFesRtu()
m_MaxDiIndex = 0;
m_MaxAccIndex = 0;
m_MaxMiIndex = 0;
m_MinMiIndex = -1;//实际混合量最小索引即规约参数1最小值,-1表示没有或者无效
m_MaxAoIndex = 0;
m_MaxDoIndex = 0;
m_MaxMoIndex = 0;
@ -357,10 +358,8 @@ SFesMo* CFesRtu::GetMoByPointNo(int PointNo)
*/
int CFesRtu::GetRtuDiChgNum()
{
int num;
boost::mutex::scoped_lock lock(m_DiChgMutex);
num = DiChgBuf.size();
int num = static_cast<int>(DiChgBuf.size());
return num;
}
@ -371,10 +370,8 @@ int CFesRtu::GetRtuDiChgNum()
*/
int CFesRtu::GetRtuAiChgNum()
{
int num;
boost::mutex::scoped_lock lock(m_AiChgMutex);
num = AiChgBuf.size();
int num = static_cast<int>(AiChgBuf.size());
return num;
}
@ -385,10 +382,8 @@ int CFesRtu::GetRtuAiChgNum()
*/
int CFesRtu::GetRtuAccChgNum()
{
int num;
boost::mutex::scoped_lock lock(m_AccChgMutex);
num = AccChgBuf.size();
int num = static_cast<int>(AccChgBuf.size());
return num;
}
@ -399,10 +394,8 @@ int CFesRtu::GetRtuAccChgNum()
*/
int CFesRtu::GetRtuMiChgNum()
{
int num;
boost::mutex::scoped_lock lock(m_MiChgMutex);
num = MiChgBuf.size();
int num = static_cast<int>(MiChgBuf.size());
return num;
}
@ -787,10 +780,8 @@ int CFesRtu::ReadMiValue(int num,SFesAllMi *buffer)
*/
int CFesRtu::GetSoeEventNum()
{
int num;
boost::mutex::scoped_lock lock(m_EventMutex);
num = SoeEventBuf.size();
int num = static_cast<int>(SoeEventBuf.size());
return num;
}
@ -801,10 +792,8 @@ int CFesRtu::GetSoeEventNum()
*/
int CFesRtu::GetChanEventNum()
{
int num;
boost::mutex::scoped_lock lock(m_EventMutex);
num = ChanEventBuf.size();
int num = static_cast<int>(ChanEventBuf.size());
return num;
}
@ -816,10 +805,8 @@ int CFesRtu::GetChanEventNum()
*/
int CFesRtu::GetRtuEventNum()
{
int num;
boost::mutex::scoped_lock lock(m_EventMutex);
num = RtuEventBuf.size();
int num = static_cast<int>(RtuEventBuf.size());
return num;
}
@ -1023,11 +1010,8 @@ void CFesRtu::WriteRxDoCmdBuf(int num,SFesRxDoCmd *buffer)
*/
void CFesRtu::WriteRxAoCmdBuf(int num,SFesRxAoCmd *buffer)
{
int i;
boost::mutex::scoped_lock lock(m_CmdMutex);
for(i=0;i<num;i++)
for(int i=0;i<num;i++)
{
RxAoCmdBuf.push(buffer[i]);
}
@ -1093,10 +1077,8 @@ void CFesRtu::WriteRxDefCmdBuf(int num,SFesRxDefCmd *buffer)
*/
int CFesRtu::GetTxDoCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = TxDoCmdBuf.size();
int num = static_cast<int>(TxDoCmdBuf.size());
return num;
}
@ -1107,10 +1089,8 @@ int CFesRtu::GetTxDoCmdNum()
*/
int CFesRtu::GetTxAoCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = TxAoCmdBuf.size();
int num = static_cast<int>(TxAoCmdBuf.size());
return num;
}
@ -1121,10 +1101,8 @@ int CFesRtu::GetTxAoCmdNum()
*/
int CFesRtu::GetTxmMoCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = TxMoCmdBuf.size();
int num = static_cast<int>(TxMoCmdBuf.size());
return num;
}
@ -1135,10 +1113,8 @@ int CFesRtu::GetTxmMoCmdNum()
*/
int CFesRtu::GetTxSettingCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = TxSettingCmdBuf.size();
int num = static_cast<int>(TxSettingCmdBuf.size());
return num;
}
@ -1149,10 +1125,8 @@ int CFesRtu::GetTxSettingCmdNum()
*/
int CFesRtu::GetTxDefCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = TxDefCmdBuf.size();
int num = static_cast<int>(TxDefCmdBuf.size());
return num;
}
@ -1288,7 +1262,6 @@ int CFesRtu::ReadTxDefCmd(int num,SFesTxDefCmd *buffer)
return tempNum;
}
/**
* @brief CFesRtu::WriteChanEventBuf
* CHAN EVENT缓冲区内容
@ -1315,10 +1288,8 @@ void CFesRtu::WriteChanEventBuf(int num,SFesChanEvent *buffer)
void CFesRtu::WriteSoeEventBuf(int num,SFesSoeEvent *buffer)
{
int i;
CFesRtuPtr rtuPtr;
boost::mutex::scoped_lock lock(m_EventMutex);
int count = SoeEventBuf.size();
int count = static_cast<int>(SoeEventBuf.size());
if ((count + num) > DiMaxChgNum)
{
for (i = 0; i < num; i++)
@ -1365,10 +1336,8 @@ void CFesRtu::WriteRtuEventBuf(int num,SFesRtuEvent *buffer)
*/
int CFesRtu::GetRxDoCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = RxDoCmdBuf.size();
int num = static_cast<int>(RxDoCmdBuf.size());
return num;
}
@ -1379,10 +1348,8 @@ int CFesRtu::GetRxDoCmdNum()
*/
int CFesRtu::GetRxAoCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = RxAoCmdBuf.size();
int num = static_cast<int>(RxAoCmdBuf.size());
return num;
}
@ -1393,10 +1360,8 @@ int CFesRtu::GetRxAoCmdNum()
*/
int CFesRtu::GetRxMoCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = RxMoCmdBuf.size();
int num = static_cast<int>(RxMoCmdBuf.size());
return num;
}
@ -1407,10 +1372,8 @@ int CFesRtu::GetRxMoCmdNum()
*/
int CFesRtu::GetRxSettingCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = RxSettingCmdBuf.size();
int num = static_cast<int>(RxSettingCmdBuf.size());
return num;
}
@ -1421,10 +1384,8 @@ int CFesRtu::GetRxSettingCmdNum()
*/
int CFesRtu::GetRxDefCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = RxDefCmdBuf.size();
int num = static_cast<int>(RxDefCmdBuf.size());
return num;
}
@ -1628,7 +1589,6 @@ void CFesRtu::WriteTxDefCmdBuf(int num,SFesTxDefCmd *buffer)
}
}
/**
* @brief CFesRtu::WriteTxSettingCmdBuf
* FESSetting命令结果FES发送Setting命令缓存区
@ -1679,7 +1639,7 @@ void CFesRtu::WriteChgAiValue(int num,SFesChgAi *buffer)
int i;
boost::mutex::scoped_lock lock(m_AiChgMutex);
int count = AiChgBuf.size();
int count = static_cast<int>(AiChgBuf.size());
if((count+num)>AiMaxChgNum)
{
LOGERROR("RTU%d AiChgBuf overflow AiMaxChgNum=%d ",m_Param.RtuNo,AiMaxChgNum);
@ -1702,7 +1662,7 @@ void CFesRtu::WriteChgAccValue(int num,SFesChgAcc *buffer)
int i;
boost::mutex::scoped_lock lock(m_AccChgMutex);
int count = AccChgBuf.size();
int count = static_cast<int>(AccChgBuf.size());
if((count+num)>AccMaxChgNum)
{
LOGERROR("RTU%d AccChgBuf overflow AccMaxChgNum=%d ",m_Param.RtuNo,AccMaxChgNum);
@ -1725,7 +1685,7 @@ void CFesRtu::WriteChgMiValue(int num,SFesChgMi *buffer)
int i;
boost::mutex::scoped_lock lock(m_MiChgMutex);
int count = MiChgBuf.size();
int count = static_cast<int>(MiChgBuf.size());
if((count+num)>MiMaxChgNum)
{
LOGERROR("RTU%d MiChgBuf overflow MiMaxChgNum=%d ",m_Param.RtuNo,MiMaxChgNum);
@ -1864,8 +1824,8 @@ void CFesRtu::WriteRtuAccValueAndRetChg(int num,SFesRtuAccValue *buffer,int *ret
{
int i,count;
SFesAcc *pAcc;
uint64 value;
double fdValue;
//uint64 value;
double dvalue;
boost::mutex::scoped_lock lock(m_AccMutex);
count = 0;
@ -1874,9 +1834,10 @@ void CFesRtu::WriteRtuAccValueAndRetChg(int num,SFesRtuAccValue *buffer,int *ret
if(buffer[i].PointNo < m_MaxAccPoints)
{
pAcc = m_pAcc+buffer[i].PointNo;
fdValue = (double)buffer[i].Value*pAcc->Coeff+pAcc->Base;
value = fdValue;
if(((int64)value) != pAcc->Value)
//fdValue = (double)buffer[i].Value*pAcc->Coeff+pAcc->Base;
dvalue = buffer[i].Value*(pAcc->Coeff)+pAcc->Base;
//value = fdValue;
if(dvalue != pAcc->Value)
{
//2019-08-23 thxiao 第一次启动时HMI数据上传慢所以不再判断是否更新过。
//if(pAcc->Status&CN_FesValueUpdate)//更新过的点才能报告变化
@ -1884,14 +1845,14 @@ void CFesRtu::WriteRtuAccValueAndRetChg(int num,SFesRtuAccValue *buffer,int *ret
memcpy(ChgBuffer[count].TableName,pAcc->TableName,CN_FesMaxTableNameSize);
memcpy(ChgBuffer[count].ColumnName,pAcc->ColumnName,CN_FesMaxColumnNameSize);
memcpy(ChgBuffer[count].TagName,pAcc->TagName,CN_FesMaxTagSize);
ChgBuffer[count].Value=value;
ChgBuffer[count].Value=dvalue;
ChgBuffer[count].Status = buffer[i].Status;
ChgBuffer[count].time = buffer[i].time;
ChgBuffer[count].RtuNo = m_Param.RtuNo;
ChgBuffer[count].PointNo = pAcc->PointNo;
count++;
}
pAcc->Value = value;
pAcc->Value = dvalue;
pAcc->Status = buffer[i].Status;
pAcc->time = buffer[i].time;
}
@ -2021,6 +1982,7 @@ void CFesRtu::WriteRtuPointsComStatus(int comStatus)
{
if ((pDi->Status&CN_FesValueComDown) == 0x00)//2021-06-08 thxiao 判断原来的通信状态确实发生了状态变化,才置上全局标志
{
pDi->Status = 0; //置为值未更新状态,防止重连成功时,上一次的值被上传
pDi->Status |= status;
pointCount++;
if (m_Param.ClearDataEnable&CN_Fes_Comdown_Clear)
@ -2063,6 +2025,7 @@ void CFesRtu::WriteRtuPointsComStatus(int comStatus)
{
if ((pAi->Status&CN_FesValueComDown) == 0x00)//2021-06-08 thxiao 判断原来的通信状态确实发生了状态变化,才置上全局标志
{
pAi->Status = 0; //置为值未更新状态,防止重连成功时,上一次的值被上传
pAi->Status |= status;
if (m_Param.ClearDataEnable&CN_Fes_Comdown_Clear)
{
@ -2109,6 +2072,7 @@ void CFesRtu::WriteRtuPointsComStatus(int comStatus)
{
if ((pAcc->Status&CN_FesValueComDown) == 0x00)//2021-06-08 thxiao 有状态变化才置标志
{
pAcc->Status = 0; //置为值未更新状态,防止重连成功时,上一次的值被上传
pAcc->Status |= status;
if (m_Param.ClearDataEnable&CN_Fes_Comdown_Clear)
pAcc->Value = 0;
@ -2149,6 +2113,7 @@ void CFesRtu::WriteRtuPointsComStatus(int comStatus)
{
if ((pMi->Status&CN_FesValueComDown) == 0x00)//2021-06-08 thxiao 有状态变化才置标志
{
pMi->Status = 0; //置为值未更新状态,防止重连成功时,上一次的值被上传
pMi->Status |= status;
if (m_Param.ClearDataEnable&CN_Fes_Comdown_Clear)
pMi->Value = 0;
@ -2250,10 +2215,8 @@ int CFesRtu::ReadFwDoRespCmd(int num, SFesFwDoRespCmd *buffer)
*/
int CFesRtu::GetFwDoRespCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = FwDoRespCmdBuf.size();
int num = static_cast<int>(FwDoRespCmdBuf.size());
return num;
}
@ -2306,7 +2269,7 @@ void CFesRtu::SetAiFwFlag(int PointNo, int MappingIndex, int RemoteNo)
pAi->FwMapNum++;
}
else
LOGERROR("RTU:%d PointNo:%d Di 超出最大转发映射次数映射失败。转发MappingIndex:%d RemoteNo:%d ", m_Param.RtuNo, PointNo, MappingIndex, RemoteNo);
LOGERROR("RTU:%d PointNo:%d Ai 超出最大转发映射次数映射失败。转发MappingIndex:%d RemoteNo:%d ", m_Param.RtuNo, PointNo, MappingIndex, RemoteNo);
}
@ -2367,15 +2330,13 @@ void CFesRtu::SetMiFwFlag(int PointNo, int MappingIndex, int RemoteNo)
* SOE EVENT缓冲区内容
* @param buffer
*/
void CFesRtu::WriteFwSoeEventBuf(SFesFwSoeEvent buffer)
void CFesRtu::WriteFwSoeEventBuf(const SFesFwSoeEvent &buffer)
{
int count;
if (FwSoeChgStop)//有些从站协议不支持变化报告,该标志可以用来控制是否填写对应的变化缓冲区。
return;
boost::mutex::scoped_lock lock(m_EventMutex);
count = FwSoeEventBuf.size();
int count = static_cast<int>(FwSoeEventBuf.size());
if(count>FwDiMaxChgNum)
{
//FwSoeEventBuf.front(); //从头开始读取数据
@ -2384,7 +2345,7 @@ void CFesRtu::WriteFwSoeEventBuf(SFesFwSoeEvent buffer)
}
FwSoeEventBuf.push(buffer);
//2019-09-06 thxiao 方便查找事件,增加记录
LOGINFO("SOE RtuNo:%d RemoteNo=%d value=%d ms=[%" PRId64 "] .", m_Param.RtuNo, buffer.RemoteNo,buffer.Value, buffer.time);
LOGTRACE("SOE RtuNo:%d RemoteNo=%d value=%d ms=[%" PRId64 "] .", m_Param.RtuNo, buffer.RemoteNo,buffer.Value, buffer.time);
}
@ -2393,15 +2354,13 @@ void CFesRtu::WriteFwSoeEventBuf(SFesFwSoeEvent buffer)
* DSOE EVENT缓冲区内容
* @param buffer
*/
void CFesRtu::WriteFwDSoeEventBuf(SFesFwSoeEvent buffer)
void CFesRtu::WriteFwDSoeEventBuf(const SFesFwSoeEvent &buffer)
{
int count;
if (FwDSoeChgStop)//有些从站协议不支持变化报告,该标志可以用来控制是否填写对应的变化缓冲区。
return;
boost::mutex::scoped_lock lock(m_EventMutex);
count = FwDSoeEventBuf.size();
int count = static_cast<int>(FwDSoeEventBuf.size());
if (count>FwDiMaxChgNum)
{
//FwDSoeEventBuf.front(); //从头开始读取数据
@ -2410,7 +2369,7 @@ void CFesRtu::WriteFwDSoeEventBuf(SFesFwSoeEvent buffer)
}
FwDSoeEventBuf.push(buffer);
//2019-09-06 thxiao 方便查找事件,增加记录
LOGINFO("DSOE RtuNo:%d RemoteNo=%d value=%d ms=%ld", m_Param.RtuNo, buffer.RemoteNo, buffer.Value, buffer.time);
LOGTRACE("DSOE RtuNo:%d RemoteNo=%d value=%d ms=%ld", m_Param.RtuNo, buffer.RemoteNo, buffer.Value, buffer.time);
}
@ -2419,15 +2378,13 @@ void CFesRtu::WriteFwDSoeEventBuf(SFesFwSoeEvent buffer)
* DI变化缓冲区内容
* @param buffer
*/
void CFesRtu::WriteFwDiBuf(SFesFwChgDi buffer)
void CFesRtu::WriteFwDiBuf(const SFesFwChgDi &buffer)
{
int count;
if (FwDiChgStop)//有些从站协议不支持变化报告,该标志可以用来控制是否填写对应的变化缓冲区。
return;
boost::mutex::scoped_lock lock(m_DiChgMutex);
count = FwDiChgBuf.size();
int count = static_cast<int>(FwDiChgBuf.size());
if (count>FwDiMaxChgNum)
{
//FwDiChgBuf.front(); //从头开始读取数据
@ -2436,7 +2393,7 @@ void CFesRtu::WriteFwDiBuf(SFesFwChgDi buffer)
}
FwDiChgBuf.push(buffer);
//2019-09-06 thxiao 方便查找事件,增加记录
LOGINFO("转发DI变位 RtuNo:%d RemoteNo=%d value=%d ms=[%" PRId64 "] .", m_Param.RtuNo, buffer.RemoteNo, buffer.Value, buffer.time);
LOGTRACE("转发DI变位 RtuNo:%d RemoteNo=%d value=%d ms=[%" PRId64 "] .", m_Param.RtuNo, buffer.RemoteNo, buffer.Value, buffer.time);
}
@ -2445,15 +2402,13 @@ void CFesRtu::WriteFwDiBuf(SFesFwChgDi buffer)
* DDI变化缓冲区内容
* @param buffer
*/
void CFesRtu::WriteFwDDiBuf(SFesFwChgDi buffer)
void CFesRtu::WriteFwDDiBuf(const SFesFwChgDi &buffer)
{
int count;
if (FwDDiChgStop)//有些从站协议不支持变化报告,该标志可以用来控制是否填写对应的变化缓冲区。
return;
boost::mutex::scoped_lock lock(m_DiChgMutex);
count = FwDDiChgBuf.size();
int count = static_cast<int>(FwDDiChgBuf.size());
if (count > FwDDiMaxChgNum)
{
//FwDDiChgBuf.front(); //从头开始读取数据
@ -2462,7 +2417,7 @@ void CFesRtu::WriteFwDDiBuf(SFesFwChgDi buffer)
}
FwDDiChgBuf.push(buffer);
//2019-09-06 thxiao 方便查找事件,增加记录
LOGINFO("转发DDI变位 RtuNo:%d RemoteNo=%d value=%d ms=%ld", m_Param.RtuNo, buffer.RemoteNo, buffer.Value, buffer.time);
LOGTRACE("转发DDI变位 RtuNo:%d RemoteNo=%d value=%d ms=%ld", m_Param.RtuNo, buffer.RemoteNo, buffer.Value, buffer.time);
}
@ -2471,15 +2426,13 @@ void CFesRtu::WriteFwDDiBuf(SFesFwChgDi buffer)
* Ai变化缓冲区内容
* @param buffer
*/
void CFesRtu::WriteFwAiBuf(SFesFwChgAi buffer)
void CFesRtu::WriteFwAiBuf(const SFesFwChgAi &buffer)
{
int count;
if (FwAiChgStop)//有些从站协议不支持变化报告,该标志可以用来控制是否填写对应的变化缓冲区。
return;
boost::mutex::scoped_lock lock(m_AiChgMutex);
count = FwAiChgBuf.size();
int count = static_cast<int>(FwAiChgBuf.size());
if (count > FwAiMaxChgNum)
{
//FwAiChgBuf.front(); //从头开始读取数据
@ -2494,15 +2447,13 @@ void CFesRtu::WriteFwAiBuf(SFesFwChgAi buffer)
* Acc变化缓冲区内容
* @param buffer
*/
void CFesRtu::WriteFwAccBuf(SFesFwChgAcc buffer)
void CFesRtu::WriteFwAccBuf(const SFesFwChgAcc &buffer)
{
int count;
if (FwAccChgStop)//有些从站协议不支持变化报告,该标志可以用来控制是否填写对应的变化缓冲区。
return;
boost::mutex::scoped_lock lock(m_AccChgMutex);
count = FwAccChgBuf.size();
int count = static_cast<int>(FwAccChgBuf.size());
if (count > FwAccMaxChgNum)
{
//FwAccChgBuf.front(); //从头开始读取数据
@ -2518,15 +2469,13 @@ void CFesRtu::WriteFwAccBuf(SFesFwChgAcc buffer)
* Mi变化缓冲区内容
* @param buffer
*/
void CFesRtu::WriteFwMiBuf(SFesFwChgMi buffer)
void CFesRtu::WriteFwMiBuf(const SFesFwChgMi &buffer)
{
int count;
if (FwMiChgStop)//有些从站协议不支持变化报告,该标志可以用来控制是否填写对应的变化缓冲区。
return;
boost::mutex::scoped_lock lock(m_MiChgMutex);
count = FwMiChgBuf.size();
int count = static_cast<int>(FwMiChgBuf.size());
if (count > FwMiMaxChgNum)
{
//FwMiChgBuf.front(); //从头开始读取数据
@ -2544,10 +2493,8 @@ void CFesRtu::WriteFwMiBuf(SFesFwChgMi buffer)
*/
int CFesRtu::GetFwSOEEventNum()
{
int num;
boost::mutex::scoped_lock lock(m_EventMutex);
num = FwSoeEventBuf.size();
int num = static_cast<int>(FwSoeEventBuf.size());
return num;
}
@ -2626,10 +2573,8 @@ int CFesRtu::ReadFwAoRespCmd(int num, SFesFwAoRespCmd *buffer)
*/
int CFesRtu::GetFwAoRespCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = FwAoRespCmdBuf.size();
int num = static_cast<int>(FwAoRespCmdBuf.size());
return num;
}
@ -2683,10 +2628,8 @@ int CFesRtu::ReadFwMoRespCmd(int num,SFesFwMoRespCmd *buffer)
*/
int CFesRtu::GetFwMoRespCmdNum()
{
int num;
boost::mutex::scoped_lock lock(m_CmdMutex);
num = FwMoRespCmdBuf.size();
int num = static_cast<int>(FwMoRespCmdBuf.size());
return num;
}
@ -2819,10 +2762,8 @@ void CFesRtu::ClearBuf()
*/
int CFesRtu::GetFwChgAiNum()
{
int num;
boost::mutex::scoped_lock lock(m_AiChgMutex);
num = FwAiChgBuf.size();
int num = static_cast<int>(FwAiChgBuf.size());
return num;
}
@ -2857,10 +2798,8 @@ int CFesRtu::ReadFwChgAi(int num, SFesFwChgAi *buffer)
*/
int CFesRtu::GetFwChgDiNum()
{
int num;
boost::mutex::scoped_lock lock(m_DiChgMutex);
num = FwDiChgBuf.size();
int num = static_cast<int>(FwDiChgBuf.size());
return num;
}
@ -2895,10 +2834,8 @@ int CFesRtu::ReadFwChgDi(int num, SFesFwChgDi *buffer)
*/
int CFesRtu::GetFwChgDDiNum()
{
int num;
boost::mutex::scoped_lock lock(m_DiChgMutex);
num = FwDDiChgBuf.size();
int num = static_cast<int>(FwDDiChgBuf.size());
return num;
}
@ -2934,10 +2871,8 @@ int CFesRtu::ReadFwChgDDi(int num, SFesFwChgDi *buffer)
*/
int CFesRtu::GetFwChgAccNum()
{
int num;
boost::mutex::scoped_lock lock(m_AccChgMutex);
num = FwAccChgBuf.size();
int num = static_cast<int>(FwAccChgBuf.size());
return num;
}
@ -2972,10 +2907,8 @@ int CFesRtu::ReadFwChgAcc(int num, SFesFwChgAcc *buffer)
*/
int CFesRtu::GetFwChgMiNum()
{
int num;
boost::mutex::scoped_lock lock(m_MiChgMutex);
num = FwMiChgBuf.size();
int num = static_cast<int>(FwMiChgBuf.size());
return num;
}
@ -3011,10 +2944,8 @@ int CFesRtu::ReadFwChgMi(int num, SFesFwChgMi *buffer)
*/
int CFesRtu::GetFwDSOEEventNum()
{
int num;
boost::mutex::scoped_lock lock(m_EventMutex);
num = FwDSoeEventBuf.size();
int num = static_cast<int>(FwDSoeEventBuf.size());
return num;
}
@ -3051,7 +2982,7 @@ int CFesRtu::ReadFwDSOEEvent(int num, SFesFwSoeEvent *buffer)
*
* @return true: false:
*/
bool CFesRtu::UpdataFwDiValue(SFesFwChgDi DiValue,int updateMode)
bool CFesRtu::UpdataFwDiValue(const SFesFwChgDi &DiValue,int updateMode)
{
SFesFwDi *pDi;
@ -3105,7 +3036,7 @@ int CFesRtu::ReadFwDSOEEvent(int num, SFesFwSoeEvent *buffer)
* @return true: false:
*/
bool CFesRtu::UpdataFwDDiValue(SFesFwChgDi DiValue, int updateMode)
bool CFesRtu::UpdataFwDDiValue(const SFesFwChgDi &DiValue, int updateMode)
{
SFesFwDi *pDi;
@ -3158,50 +3089,39 @@ int CFesRtu::ReadFwDSOEEvent(int num, SFesFwSoeEvent *buffer)
* @param updateMode 1(DP to FES) 0(FES to FES)
* @return true: false:
*/
bool CFesRtu::UpdataFwAiValue(SFesFwChgAi AiValue,int updateMode)
bool CFesRtu::UpdataFwAiValue(const SFesFwChgAi &AiValue, float &fNewValue,EnumUpdateFwCacheMode eUpdateMode)
{
SFesFwAi *pAi;
int changeFlag = 0;
if(AiValue.RemoteNo >= m_MaxFwAiPoints || AiValue.RemoteNo < 0)
{
return false;
}
//boost::mutex::scoped_lock lock(m_AiChgMutex);
boost::mutex::scoped_lock lock(m_AiMutex);//2023-02-15 thxiao 转发数据读写时使用同一个锁所以改为m_AiMutex
if ((AiValue.RemoteNo < m_MaxFwAiPoints) && (AiValue.RemoteNo >= 0))
{
pAi = m_pFwAi + AiValue.RemoteNo;
if (updateMode)
{
if ((fabs(pAi->Value) < CN_FesFloatCompare) && (fabs(AiValue.Value) < CN_FesFloatCompare))
return false;
SFesFwAi *pAi = m_pFwAi + AiValue.RemoteNo;
//< 强制更新模式直接更新,不进行系数和死区判断
if(eUpdateMode == eDirectUpdate)
{
pAi->Value = AiValue.Value;
pAi->Status = AiValue.Status;
pAi->time = AiValue.time;
return true;
}
if (fabs(pAi->Value*AiValue.Value) < CN_FesFloatCompare)
changeFlag = 1;
else if ((fabs(pAi->Value / AiValue.Value) < (1 - CN_FesFwAIChangeScale))
||(fabs(pAi->Value / AiValue.Value) > (1 + CN_FesFwAIChangeScale)))
changeFlag = 1;
if (changeFlag)
{
pAi->Value = AiValue.Value;
pAi->Status = AiValue.Status;
pAi->time = AiValue.time;
return true;
}
else
{
return false;
}
}
else
{
pAi->Value = AiValue.Value;
pAi->Status = AiValue.Status;
pAi->time = AiValue.time;
return true;
}
}
else
return false;
//< 超过5分钟或者超过死区更新一次
fNewValue = static_cast<float>(AiValue.Value * pAi->Coeff + pAi->Base); //< 进行基值和K值变换
if( eUpdateMode == eWithoutDeadbandUpdate ||
fabs(pAi->Value - fNewValue) >= pAi->RealDeadBandValue ||
(AiValue.time - pAi->time) > 5 * SEC_PER_MIN * MSEC_PER_SEC )
{
pAi->Value = fNewValue;
pAi->Status = AiValue.Status;
pAi->time = AiValue.time;
return true;
}
else
{
return false;
}
}
/**
@ -3211,37 +3131,33 @@ int CFesRtu::ReadFwDSOEEvent(int num, SFesFwSoeEvent *buffer)
* @param updateMode 1(DP to FES) 0(FES to FES)
* @return true: false:
*/
bool CFesRtu::UpdataFwAccValue(SFesFwChgAcc AccValue, int updateMode)
bool CFesRtu::UpdataFwAccValue(const SFesFwChgAcc &AccValue, double &dNewValue,EnumUpdateFwCacheMode eUpdateMode)
{
SFesFwAcc *pAcc;
if(AccValue.RemoteNo >= m_MaxFwAccPoints || AccValue.RemoteNo < 0)
{
return false;
}
//boost::mutex::scoped_lock lock(m_AccChgMutex);
boost::mutex::scoped_lock lock(m_AccMutex);//2023-02-15 thxiao 转发数据读写时使用同一个锁所以改为m_AccMutex
if ((AccValue.RemoteNo < m_MaxFwAccPoints) && (AccValue.RemoteNo >= 0))
{
pAcc = m_pFwAcc + AccValue.RemoteNo;
if (updateMode)
{
if (pAcc->Value != AccValue.Value)
{
pAcc->Value = AccValue.Value;
pAcc->Status = AccValue.Status;
pAcc->time = AccValue.time;
return true;
}
else
return false;
}
else
{
pAcc->Value = AccValue.Value;
pAcc->Status = AccValue.Status;
pAcc->time = AccValue.time;
return true;
}
}
else
return false;
SFesFwAcc *pAcc = m_pFwAcc + AccValue.RemoteNo;
if(eUpdateMode == eDirectUpdate)
{
pAcc->Value = AccValue.Value;
pAcc->Status = AccValue.Status;
pAcc->time = AccValue.time;
return true;
}
dNewValue = AccValue.Value * pAcc->Coeff + pAcc->Base;
if( fabs(dNewValue - pAcc->Value) >= CN_FesFloatCompare )
{
pAcc->Value = dNewValue;
pAcc->Status = AccValue.Status;
pAcc->time = AccValue.time;
return true;
}
return false;
}
/**
@ -3251,37 +3167,33 @@ int CFesRtu::ReadFwDSOEEvent(int num, SFesFwSoeEvent *buffer)
* @param updateMode 1(DP to FES) 0(FES to FES)
* @return true: false:
*/
bool CFesRtu::UpdataFwMiValue(SFesFwChgMi MiValue,int updateMode)
bool CFesRtu::UpdataFwMiValue(const SFesFwChgMi &MiValue,int &nNewValue, EnumUpdateFwCacheMode eUpdateMode)
{
SFesFwMi *pMi;
if(MiValue.RemoteNo >= m_MaxFwMiPoints || MiValue.RemoteNo < 0)
{
return false;
}
//boost::mutex::scoped_lock lock(m_MiChgMutex);
boost::mutex::scoped_lock lock(m_MiMutex);//2023-02-15 thxiao 转发数据读写时使用同一个锁所以改为m_MiMutex
if ((MiValue.RemoteNo < m_MaxFwMiPoints) && (MiValue.RemoteNo >= 0))
{
pMi = m_pFwMi + MiValue.RemoteNo;
if (updateMode)
{
if (pMi->Value != MiValue.Value)
{
pMi->Value = MiValue.Value;
pMi->Status = MiValue.Status;
pMi->time = MiValue.time;
return true;
}
else
return false;
}
else
{
pMi->Value = MiValue.Value;
pMi->Status = MiValue.Status;
pMi->time = MiValue.time;
return true;
}
}
else
return false;
SFesFwMi *pMi = m_pFwMi + MiValue.RemoteNo;
if(eUpdateMode == eDirectUpdate)
{
pMi->Value = MiValue.Value;
pMi->Status = MiValue.Status;
pMi->time = MiValue.time;
return true;
}
nNewValue = static_cast<int>(MiValue.Value * pMi->Coeff + pMi->Base);
if (pMi->Value != nNewValue)
{
pMi->Value = nNewValue;
pMi->Status = MiValue.Status;
pMi->time = MiValue.time;
return true;
}
return false;
}
@ -3737,7 +3649,7 @@ void CFesRtu::ClearFwDSoeEventBuf()
* @brief CFesRtu::WriteVirtualValue
*
*/
void CFesRtu::WriteVirtualValue(SFesVirtualValue Value)
void CFesRtu::WriteVirtualValue(const SFesVirtualValue &Value)
{
boost::mutex::scoped_lock lock(m_CmdMutex);
VirtualValueBuf.push(Value);
@ -3876,10 +3788,8 @@ int CFesRtu::GetMiPointNoByDevId(int DevId, std::vector<int>& PointNo)
*/
int CFesRtu::GetSoeStrEventNum()
{
int num;
boost::mutex::scoped_lock lock(m_EventMutex);
num = SoeStrEventBuf.size();
int num = static_cast<int>(SoeStrEventBuf.size());
return num;
}
@ -3997,5 +3907,59 @@ void CFesRtu::WriteRtuPointsComDown()
}
if (pointCount > 0)
m_MiStatusChangeReportFlag = 1;
}
}
}
void CFesRtu::writeJsonFormatReqCmd(const rapidjson::Value &jsonCmd)
{
//<rapidjson中基本都是浅拷贝比如赋值都会造成原值失效一定注意
RapidJsonDocPtr ptrDoc = boost::make_shared<rapidjson::Document>();
ptrDoc->CopyFrom(jsonCmd,ptrDoc->GetAllocator());
boost::mutex::scoped_lock lock(m_CmdMutex);
if(m_jsonFormatReqCmdBuf.size() > CN_Fes_MaxCmdBufSize)
{
m_jsonFormatReqCmdBuf.pop();
}
m_jsonFormatReqCmdBuf.push(ptrDoc);
}
void CFesRtu::readJsonFormatReqCmd(std::queue<RapidJsonDocPtr> &dequeJsonCmd)
{
boost::mutex::scoped_lock lock(m_CmdMutex);
dequeJsonCmd.swap(m_jsonFormatReqCmdBuf);
}
size_t CFesRtu::getJsonFormatReqCmdSize()
{
boost::mutex::scoped_lock lock(m_CmdMutex);
return m_jsonFormatReqCmdBuf.size();
}
void CFesRtu::clearJsonFormatReqCmdBuf()
{
std::queue<RapidJsonDocPtr> dequeJsonCmd;
boost::mutex::scoped_lock lock(m_CmdMutex);
m_jsonFormatReqCmdBuf.swap(dequeJsonCmd);
}
void CFesRtu::writeJsonFormatReplayCmd(const std::string &strCmd)
{
boost::mutex::scoped_lock lock(m_CmdMutex);
if(m_jsonFormatReplayCmdBuf.size() > CN_Fes_MaxCmdBufSize)
{
m_jsonFormatReplayCmdBuf.pop();
}
m_jsonFormatReplayCmdBuf.push(strCmd);
}
/**
* @brief CFesRtu::ReadStringFormatRespCmd
*
* @param dequeStrCmd
*/
void CFesRtu::readJsonFormatReplayCmd(std::queue<std::string> &strCmds)
{
boost::mutex::scoped_lock lock(m_CmdMutex);
strCmds.swap(m_jsonFormatReplayCmdBuf);
}

View File

@ -9,14 +9,15 @@
*/
#include "FesRxControlCmdThread.h"
#include "MessageChannel.h"
#include "FesMessage.pb.h"
using namespace iot_net;
using namespace iot_public;
using namespace iot_idl;
#define CN_JSON_KEY_RTUNAME "rtu_name"
CFesRxControlCmdThread::CFesRxControlCmdThread(int iDomainID, int iAppID ,void* FesBaseAddr):
CTimerThreadBase("FesRxControlCmdThread",20)
CTimerThreadBase("FesRxControlCmdThread",0)
{
m_ptrRxCommunicator = new CMbCommunicator("FesRxControlCmdThread");
m_pRxData = NULL;
@ -63,41 +64,53 @@ int CFesRxControlCmdThread::beforeExecute()
*/
void CFesRxControlCmdThread::execute()
{
std::string RecvStr;
if(m_ptrRxCommunicator==NULL)
if(m_ptrRxCommunicator==NULL)
{
m_nRunPeriodMsec = 100; //<防止异常时线程死循环
LOGERROR("CFesRxControlCmdThread::execute m_ptrRxCommunicator is null");
return;
}
//接收消息
CMbMessage msgRcv;
int nMsgType;
if (m_ptrRxCommunicator->recvMsg(msgRcv))
if (m_ptrRxCommunicator->recvMsg(msgRcv,100)) //< 通过接收消息超时防止线程空转
{
//std::string RecvStr;
nMsgType = msgRcv.getMsgType();
LOGDEBUG("Received a message: nMsgType=%d\n",nMsgType);
RecvStr.resize(msgRcv.getDataSize()+1);
memcpy((void*)RecvStr.c_str(),(void *)msgRcv.getDataPtr(),msgRcv.getDataSize());
LOGTRACE("Received a message: nMsgType=%d\n",nMsgType);
//RecvStr.resize(msgRcv.getDataSize()+1);
//((void*)RecvStr.c_str(),(void *)msgRcv.getDataPtr(),msgRcv.getDataSize());
switch (nMsgType)
{
case MT_FES_DO_SELECT:
case MT_FES_DO_EXECUTE:
case MT_FES_DO_CANCEL:
case MT_FES_DO_PREVENT:
RxDoControl(RecvStr,nMsgType);
RxDoControl(msgRcv.getDataPtr(), msgRcv.getDataSize(),nMsgType);
break;
case MT_FES_AO_EXECUTE:
RxAoControl(RecvStr,nMsgType);
RxAoControl(msgRcv.getDataPtr(), msgRcv.getDataSize(),nMsgType);
break;
case MT_FES_MO_SELECT:
case MT_FES_MO_EXECUTE:
RxMoControl(RecvStr,nMsgType);
case MT_FES_MO_CANCEL:
RxMoControl(msgRcv.getDataPtr(), msgRcv.getDataSize(),nMsgType);
break;
case MT_FES_SETTING_READ:
case MT_FES_SETTING_DOWN:
case MT_FES_SETTING_ACK:
RxSettingControl(RecvStr,nMsgType);
RxSettingControl(msgRcv.getDataPtr(), msgRcv.getDataSize(),nMsgType);
break;
case MT_FES_DEFINE_CMD:
RxDefCmdControl(RecvStr);
RxDefCmdControl(msgRcv.getDataPtr(), msgRcv.getDataSize());
break;
case MT_FES_BATCH_PNT_CMD:
RxBatchPntCmd(msgRcv.getDataPtr(), msgRcv.getDataSize());
break;
case MT_FES_JSON_RTU_CMD_REQ:
handleJsonFormatRtuCmd(msgRcv);
break;
default:
LOGERROR("CFesRxControlCmdThread::execute() Error message type:%d \n",nMsgType);
@ -126,73 +139,23 @@ void CFesRxControlCmdThread::afterExecute()
* @param RecvStr
* @param msgType
*/
void CFesRxControlCmdThread::RxDoControl(const std::string &RecvStr,const int &msgType)
void CFesRxControlCmdThread::RxDoControl(const void* data,size_t dataSize,const int &msgType)
{
SFesRxDoCmd cmd;
CFesRtuPtr ptrCFesRtu;
SFesDoRequestPkg DoReqPkg;
boost::ignore_unused_variable_warning(msgType);
if(m_ptrCFesBase==NULL)
{
return;
// get protocbuf data
memset(&cmd,0,sizeof(SFesRxDoCmd));
DoReqPkg.ParseFromString(RecvStr);
strcpy(cmd.TableName,(const char *)DoReqPkg.strapptablename().c_str());
strcpy(cmd.ColumnName,(const char *)DoReqPkg.strappcolumnname().c_str());
strcpy(cmd.TagName,(const char *)DoReqPkg.strapptagname().c_str());
strcpy(cmd.RtuName,(const char *)DoReqPkg.strrtuname().c_str());
cmd.PointID = DoReqPkg.norder();
cmd.iValue = DoReqPkg.naction();
switch(msgType)
{
case MT_FES_DO_SELECT:
cmd.CtrlActType = CN_ControlSelect;
break;
case MT_FES_DO_CANCEL:
cmd.CtrlActType = CN_ControlAbort;
break;
case MT_FES_DO_PREVENT:
cmd.CtrlActType = CN_ControlPrevent;
break;
case MT_FES_DO_EXECUTE:
cmd.CtrlActType = CN_ControlExecute;
break;
default:
LOGERROR("CFesRxControlCmdThread::RxDoControl invaild msgType:%d ",msgType);
break;
break;
}
cmd.TagtState = DoReqPkg.niftagtstate();
if(DoReqPkg.has_lpara1()==true)
cmd.Param1 = DoReqPkg.lpara1();
if(DoReqPkg.has_lpara2()==true)
cmd.Param2 = DoReqPkg.lpara2();
if(DoReqPkg.has_fpara()==true)
cmd.Param1 = DoReqPkg.fpara();
if(DoReqPkg.has_strpara()==true)
SFesDoRequestPkg DoReqPkg;
if(!DoReqPkg.ParseFromArray(data,static_cast<int>(dataSize)))
{
int strLen;
if(DoReqPkg.strpara().size()>(CN_FesControlStrParamSize-1))
strLen = CN_FesControlStrParamSize-1;
else
strLen = DoReqPkg.strpara().size();
memcpy(cmd.strParam,(const char *)DoReqPkg.strpara().c_str(),strLen);
}
ptrCFesRtu = m_ptrCFesBase->GetRtuDataByRtuTag(cmd.RtuName);
if(ptrCFesRtu!=NULL)
{
cmd.RtuNo = ptrCFesRtu->m_Param.RtuNo;//2019-3-4 thxiao 转发规约需要RtuNo,所以此处加上。
LOGDEBUG("RxDoControl() RTUNo:%d PointNo:%d CtrlActType:%d iValue:%d",cmd.RtuNo,cmd.PointID,cmd.CtrlActType,cmd.iValue);
ptrCFesRtu->WriteRxDoCmdBuf(1,&cmd);
}
else
{
LOGERROR("RxDoControl() can not find RTU:%s",cmd.RtuName);
LOGERROR("CFesRxControlCmdThread::RxDoControl parse recv msg failed");
return;
}
addDoControl(DoReqPkg);
}
/**
@ -200,63 +163,23 @@ void CFesRxControlCmdThread::RxDoControl(const std::string &RecvStr,const int &m
* AO控制命令RTU对应的命令缓存区
* @param RecvStr
*/
void CFesRxControlCmdThread::RxAoControl(const std::string &RecvStr,const int &msgType)
void CFesRxControlCmdThread::RxAoControl(const void* data,size_t dataSize,const int &msgType)
{
CFesRtuPtr ptrCFesRtu;
SFesRxAoCmd cmd;
SFesAoRequestPkg AoReqPkg;
boost::ignore_unused_variable_warning(msgType);
if(m_ptrCFesBase==NULL)
{
return;
// get protocbuf data
memset(&cmd,0,sizeof(SFesRxAoCmd));
AoReqPkg.ParseFromString(RecvStr);
strcpy(cmd.TableName,(const char *)AoReqPkg.strapptablename().c_str());
strcpy(cmd.ColumnName,(const char *)AoReqPkg.strappcolumnname().c_str());
strcpy(cmd.TagName,(const char *)AoReqPkg.strapptagname().c_str());
strcpy(cmd.RtuName,(const char *)AoReqPkg.strrtuname().c_str());
cmd.PointID = AoReqPkg.norder();
cmd.fValue = AoReqPkg.fvalue();
//cmd.CtrlActType = AoReqPkg.nctrltype();
switch(msgType)
{
case MT_FES_AO_EXECUTE:
cmd.CtrlActType = CN_ControlExecute;
break;
default:
LOGERROR("CFesRxControlCmdThread::RxDoControl invaild msgType:%d ",msgType);
break;
}
cmd.TagtState = AoReqPkg.niftagtstate();
if(AoReqPkg.has_lpara1()==true)
cmd.Param1 = AoReqPkg.lpara1();
if(AoReqPkg.has_lpara2()==true)
cmd.Param2 = AoReqPkg.lpara2();
if(AoReqPkg.has_fpara()==true)
cmd.Param1 = AoReqPkg.fpara();
if(AoReqPkg.has_strpara()==true)
SFesAoRequestPkg AoReqPkg;
if(!AoReqPkg.ParseFromArray(data,static_cast<int>(dataSize)))
{
int strLen;
if(AoReqPkg.strpara().size()>(CN_FesControlStrParamSize-1))
strLen = CN_FesControlStrParamSize-1;
else
strLen = AoReqPkg.strpara().size();
memcpy(cmd.strParam,(const char *)AoReqPkg.strpara().c_str(),strLen);
LOGERROR("CFesRxControlCmdThread::RxAoControl parse recv msg failed");
return;
}
ptrCFesRtu = m_ptrCFesBase->GetRtuDataByRtuTag(cmd.RtuName);
if(ptrCFesRtu!=NULL)
{
cmd.RtuNo = ptrCFesRtu->m_Param.RtuNo;//2019-03-18 thxiao 转发规约需要RtuNo,所以此处加上。
ptrCFesRtu->WriteRxAoCmdBuf(1,&cmd);
}
else
{
LOGERROR("CFesRxControlCmdThread::RxAoControl can not find RTU:%s",cmd.RtuName);
}
addAoControl(AoReqPkg);
}
/**
@ -264,71 +187,23 @@ void CFesRxControlCmdThread::RxAoControl(const std::string &RecvStr,const int &m
* MO控制命令RTU对应的命令缓存区
* @param RecvStr
*/
void CFesRxControlCmdThread::RxMoControl(const std::string &RecvStr,const int &msgType)
void CFesRxControlCmdThread::RxMoControl(const void* data,size_t dataSize,const int &msgType)
{
CFesRtuPtr ptrCFesRtu;
SFesRxMoCmd cmd;
SFesMoRequestPkg MoReqPkg;
boost::ignore_unused_variable_warning(msgType);
if(m_ptrCFesBase==NULL)
{
return;
// get protocbuf data
memset(&cmd,0,sizeof(cmd));
MoReqPkg.ParseFromString(RecvStr);
strcpy(cmd.TableName,(const char *)MoReqPkg.strapptablename().c_str());
strcpy(cmd.ColumnName,(const char *)MoReqPkg.strappcolumnname().c_str());
strcpy(cmd.TagName,(const char *)MoReqPkg.strapptagname().c_str());
strcpy(cmd.RtuName,(const char *)MoReqPkg.strrtuname().c_str());
cmd.PointID = MoReqPkg.norder();
cmd.iValue = MoReqPkg.nvalue();
//cmd.CtrlActType = MoReqPkg.nctrltype();
switch(msgType)
{
case MT_FES_MO_SELECT:
cmd.CtrlActType = CN_ControlSelect;
break;
case MT_FES_MO_CANCEL:
cmd.CtrlActType = CN_ControlAbort;
break;
case MT_FES_MO_PREVENT:
cmd.CtrlActType = CN_ControlPrevent;
break;
case MT_FES_MO_EXECUTE:
cmd.CtrlActType = CN_ControlExecute;
break;
default:
LOGERROR("CFesRxControlCmdThread::RxDoControl invaild msgType:%d ",msgType);
break;
}
cmd.TagtState = MoReqPkg.niftagtstate();
if(MoReqPkg.has_lpara1()==true)
cmd.Param1 = MoReqPkg.lpara1();
if(MoReqPkg.has_lpara2()==true)
cmd.Param2 = MoReqPkg.lpara2();
if(MoReqPkg.has_fpara()==true)
cmd.Param1 = MoReqPkg.fpara();
if(MoReqPkg.has_strpara()==true)
SFesMoRequestPkg MoReqPkg;
if(!MoReqPkg.ParseFromArray(data,static_cast<int>(dataSize)))
{
int strLen;
if(MoReqPkg.strpara().size()>(CN_FesControlStrParamSize-1))
strLen = CN_FesControlStrParamSize-1;
else
strLen = MoReqPkg.strpara().size();
memcpy(cmd.strParam,(const char *)MoReqPkg.strpara().c_str(),strLen);
}
ptrCFesRtu = m_ptrCFesBase->GetRtuDataByRtuTag(cmd.RtuName);
if(ptrCFesRtu!=NULL)
{
cmd.RtuNo = ptrCFesRtu->m_Param.RtuNo;//2019-03-18 thxiao 转发规约需要RtuNo,所以此处加上。
ptrCFesRtu->WriteRxMoCmdBuf(1,&cmd);
}
else
{
LOGERROR("CFesRxControlCmdThread::RxMoControl can not find RTU:%s",cmd.RtuName);
LOGERROR("CFesRxControlCmdThread::RxMoControl parse recv msg failed");
return;
}
addMoControl(MoReqPkg);
}
/**
@ -339,7 +214,7 @@ void CFesRxControlCmdThread::RxMoControl(const std::string &RecvStr,const int &m
* @param pData
* @param DataSize
*/
void CFesRxControlCmdThread::RxSettingControl(const std::string &RecvStr,const int &msgType)
void CFesRxControlCmdThread::RxSettingControl(const void* data,size_t dataSize,const int &msgType)
{
int j;
SFesRxSettingCmd cmd;
@ -351,7 +226,7 @@ void CFesRxControlCmdThread::RxSettingControl(const std::string &RecvStr,const i
// get protocbuf data
memset(&cmd,0,sizeof(SFesRxSettingCmd));
SettingPkg.ParseFromString(RecvStr);
SettingPkg.ParseFromArray(data,static_cast<int>(dataSize));
cmd.RtuNo = SettingPkg.nrtuno();
cmd.DevId = SettingPkg.ndevid();
@ -406,7 +281,7 @@ void CFesRxControlCmdThread::RxSettingControl(const std::string &RecvStr,const i
* @param pData
* @param DataSize
*/
void CFesRxControlCmdThread::RxDefCmdControl(const std::string &RecvStr)
void CFesRxControlCmdThread::RxDefCmdControl(const void* data,size_t dataSize)
{
int i,count;
SFesRxDefCmd cmd;
@ -418,7 +293,7 @@ void CFesRxControlCmdThread::RxDefCmdControl(const std::string &RecvStr)
// get protocbuf data
//memset(&cmd,0,sizeof(SFesRxDefCmd));
CmddefPkg.ParseFromString(RecvStr);
CmddefPkg.ParseFromArray(data,static_cast<int>(dataSize));
strcpy(cmd.TableName,(const char *)CmddefPkg.strapptablename().c_str());
strcpy(cmd.ColumnName,(const char *)CmddefPkg.strappcolumnname().c_str());
strcpy(cmd.TagName,(const char *)CmddefPkg.strapptagname().c_str());
@ -449,6 +324,284 @@ void CFesRxControlCmdThread::RxDefCmdControl(const std::string &RecvStr)
}
void CFesRxControlCmdThread::RxBatchPntCmd(const void* data,size_t dataSize)
{
if(m_ptrCFesBase==NULL)
{
return;
}
SFesCtrlRequestSeq vecReq;
if(!vecReq.ParseFromArray(data,static_cast<int>(dataSize)))
{
LOGERROR("CFesRxControlCmdThread::RxBatchPntCmd parse recv msg failed");
return;
}
for(int nAo = 0; nAo < vecReq.ao_seq_size(); nAo++)
{
addAoControl(vecReq.ao_seq(nAo));
}
}
void CFesRxControlCmdThread::addDoControl(const SFesDoRequestPkg &doReq)
{
SFesRxDoCmd cmd;
strcpy(cmd.TableName,(const char *)doReq.strapptablename().c_str());
strcpy(cmd.ColumnName,(const char *)doReq.strappcolumnname().c_str());
strcpy(cmd.TagName,(const char *)doReq.strapptagname().c_str());
strcpy(cmd.RtuName,(const char *)doReq.strrtuname().c_str());
cmd.PointID = doReq.norder();
cmd.iValue = doReq.naction();
//DoReqPkg.nctrltype()的值与msgType一致
switch(doReq.nctrltype())
{
case MT_FES_DO_SELECT:
cmd.CtrlActType = CN_ControlSelect;
break;
case MT_FES_DO_CANCEL:
cmd.CtrlActType = CN_ControlAbort;
break;
case MT_FES_DO_PREVENT:
cmd.CtrlActType = CN_ControlPrevent;
break;
case MT_FES_DO_EXECUTE:
cmd.CtrlActType = CN_ControlExecute;
break;
default:
LOGERROR("CFesRxControlCmdThread::addDoControl invaild msgType:%d ",doReq.nctrltype());
return;
}
cmd.TagtState = doReq.niftagtstate();
if(doReq.has_lpara1())
{
cmd.Param1 = doReq.lpara1();
}
if(doReq.has_lpara2())
{
cmd.Param2 = doReq.lpara2();
}
if(doReq.has_fpara())
{
cmd.fParam = doReq.fpara();
}
if(doReq.has_strpara())
{
int strLen;
if(doReq.strpara().size()>(CN_FesControlStrParamSize-1))
strLen = CN_FesControlStrParamSize-1;
else
strLen = static_cast<int>(doReq.strpara().size());
memcpy(cmd.strParam,(const char *)doReq.strpara().c_str(),strLen);
}
CFesRtuPtr ptrCFesRtu = m_ptrCFesBase->GetRtuDataByRtuTag(cmd.RtuName);
if(ptrCFesRtu!=NULL)
{
cmd.RtuNo = ptrCFesRtu->m_Param.RtuNo;//2019-3-4 thxiao 转发规约需要RtuNo,所以此处加上。
LOGTRACE("addDoControl() RTUNo:%d PointNo:%d CtrlActType:%d iValue:%d",cmd.RtuNo,cmd.PointID,cmd.CtrlActType,cmd.iValue);
ptrCFesRtu->WriteRxDoCmdBuf(1,&cmd);
}
else
{
LOGERROR("addDoControl() can not find RTU:%s",cmd.RtuName);
}
}
void CFesRxControlCmdThread::addAoControl(const iot_idl::SFesAoRequestPkg &aoReq)
{
SFesRxAoCmd cmd;
strcpy(cmd.TableName,(const char *)aoReq.strapptablename().c_str());
strcpy(cmd.ColumnName,(const char *)aoReq.strappcolumnname().c_str());
strcpy(cmd.TagName,(const char *)aoReq.strapptagname().c_str());
strcpy(cmd.RtuName,(const char *)aoReq.strrtuname().c_str());
cmd.PointID = aoReq.norder();
cmd.fValue = aoReq.fvalue();
//aoReq.nctrltype(); //控制类型:选择、执行、取消,与消息类型一致
switch(aoReq.nctrltype())
{
case MT_FES_AO_EXECUTE:
cmd.CtrlActType = CN_ControlExecute;
break;
default:
LOGERROR("CFesRxControlCmdThread::addAoControl invaild msgType:%d ",aoReq.nctrltype());
return;
}
cmd.TagtState = aoReq.niftagtstate();
if(aoReq.has_lpara1())
{
cmd.Param1 = aoReq.lpara1();
}
if(aoReq.has_lpara2())
{
cmd.Param2 = aoReq.lpara2();
}
if(aoReq.has_fpara())
{
cmd.fParam = aoReq.fpara();
}
if(aoReq.has_strpara())
{
int strLen;
if(aoReq.strpara().size()>(CN_FesControlStrParamSize-1))
strLen = CN_FesControlStrParamSize-1;
else
strLen = static_cast<int>(aoReq.strpara().size());
memcpy(cmd.strParam,(const char *)aoReq.strpara().c_str(),strLen);
}
CFesRtuPtr ptrCFesRtu = m_ptrCFesBase->GetRtuDataByRtuTag(cmd.RtuName);
if(ptrCFesRtu != NULL)
{
cmd.RtuNo = ptrCFesRtu->m_Param.RtuNo;//2019-03-18 thxiao 转发规约需要RtuNo,所以此处加上。
ptrCFesRtu->WriteRxAoCmdBuf(1,&cmd);
}
else
{
LOGERROR("CFesRxControlCmdThread::addAoControl can not find RTU:%s",cmd.RtuName);
}
}
void CFesRxControlCmdThread::addMoControl(const SFesMoRequestPkg &moReq)
{
SFesRxMoCmd cmd;
strcpy(cmd.TableName,(const char *)moReq.strapptablename().c_str());
strcpy(cmd.ColumnName,(const char *)moReq.strappcolumnname().c_str());
strcpy(cmd.TagName,(const char *)moReq.strapptagname().c_str());
strcpy(cmd.RtuName,(const char *)moReq.strrtuname().c_str());
cmd.PointID = moReq.norder();
cmd.iValue = moReq.nvalue();
//< moReq.nctrltype() 与消息类型一致
switch(moReq.nctrltype())
{
case MT_FES_MO_SELECT:
cmd.CtrlActType = CN_ControlSelect;
break;
case MT_FES_MO_CANCEL:
cmd.CtrlActType = CN_ControlAbort;
break;
case MT_FES_MO_PREVENT:
cmd.CtrlActType = CN_ControlPrevent;
break;
case MT_FES_MO_EXECUTE:
cmd.CtrlActType = CN_ControlExecute;
break;
default:
LOGERROR("CFesRxControlCmdThread::RxDoControl invaild msgType:%d ",moReq.nctrltype());
return;
}
cmd.TagtState = moReq.niftagtstate();
if(moReq.has_lpara1())
{
cmd.Param1 = moReq.lpara1();
}
if(moReq.has_lpara2())
{
cmd.Param2 = moReq.lpara2();
}
if(moReq.has_fpara())
{
cmd.fParam = moReq.fpara();
}
if(moReq.has_strpara())
{
int strLen;
if(moReq.strpara().size()>(CN_FesControlStrParamSize-1))
strLen = CN_FesControlStrParamSize-1;
else
strLen = static_cast<int>(moReq.strpara().size());
memcpy(cmd.strParam,(const char *)moReq.strpara().c_str(),strLen);
}
CFesRtuPtr ptrCFesRtu = m_ptrCFesBase->GetRtuDataByRtuTag(cmd.RtuName);
if(ptrCFesRtu!=NULL)
{
cmd.RtuNo = ptrCFesRtu->m_Param.RtuNo;//2019-03-18 thxiao 转发规约需要RtuNo,所以此处加上。
ptrCFesRtu->WriteRxMoCmdBuf(1,&cmd);
}
else
{
LOGERROR("CFesRxControlCmdThread::addMoControl can not find RTU:%s",cmd.RtuName);
}
}
void CFesRxControlCmdThread::handleJsonFormatRtuCmd(const CMbMessage &stMsg)
{
LOGTRACE("handleJsonFormatRtuCmd: recv json cmd=%s",stMsg.printInfoToStr().c_str());
if(m_ptrCFesBase==NULL)
{
LOGERROR("m_ptrCFesBase is null");
return;
}
rapidjson::Document doc;
if( doc.Parse((const char *)stMsg.getDataPtr(),stMsg.getDataSize()).HasParseError() )
{
string strMsg((const char*)stMsg.getDataPtr(),stMsg.getDataSize());
LOGERROR("handleJsonFormatCmd: parse json cmd failed ,error=%d. cmd=\n%s",
doc.GetParseError(),strMsg.c_str());
return;
}
if(doc.IsObject())
{
addJsonFormatRtuCmd(doc);
}
else if(doc.IsArray())
{
for(size_t i = 0; i < doc.Size();i++)
{
const rapidjson::Value& arrValue = doc[i];
if(arrValue.IsObject())
{
addJsonFormatRtuCmd(arrValue);
}
else
{
LOGERROR("handleJsonFormatCmd: the element is not object format.");
}
}
}
else
{
string strMsg((const char *)stMsg.getDataPtr(),stMsg.getDataSize());
LOGERROR("handleJsonFormatCmd: invalid json format.str=\n%s",strMsg.c_str());
}
}
void CFesRxControlCmdThread::addJsonFormatRtuCmd(const rapidjson::Value &value)
{
const rapidjson::Value::ConstMemberIterator &iterInfo = value.FindMember(CN_JSON_KEY_RTUNAME);
if(iterInfo == value.MemberEnd())
{
LOGERROR("addJsonFormatRtuCmd: has not key : %s",CN_JSON_KEY_RTUNAME);
return;
}
const rapidjson::Value& rtuValue = iterInfo->value;
if(!rtuValue.IsString())
{
LOGERROR("addJsonFormatRtuCmd: rtu_name is not a string. type=%d",rtuValue.GetType());
return;
}
string strRtuName = rtuValue.GetString();
CFesRtuPtr ptrCFesRtu = m_ptrCFesBase->GetRtuDataByRtuTag(const_cast<char*>(strRtuName.c_str()));
if(ptrCFesRtu != NULL)
{
LOGDEBUG("addJsonFormatRtuCmd: recv json cmd. rtu_name=%s",strRtuName.c_str());
ptrCFesRtu->writeJsonFormatReqCmd(value);
}
else
{
LOGERROR("addJsonFormatRtuCmd can not find RTU:%s",strRtuName.c_str());
}
}
//订阅消息通道
int CFesRxControlCmdThread::subMessage()

View File

@ -3,8 +3,18 @@
#include "FesDef.h"
#include "FesBase.h"
#include "net/net_msg_bus_api/MsgBusApi.h"
#include "FesMessage.pb.h"
using namespace iot_net;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4003)
#endif
#include "rapidjson/document.h"
#ifdef _MSC_VER
#pragma warning(pop)
#endif
class CFesRxControlCmdThread : public iot_public::CTimerThreadBase
{
@ -31,19 +41,26 @@ public:
int unsubMessage();
private:
CMbCommunicator *m_ptrRxCommunicator;
iot_net::CMbCommunicator *m_ptrRxCommunicator;
byte *m_pRxData;
int m_iDomainID;
int m_iAppID;
int m_iChannelID;
CFesBase *m_ptrCFesBase;
void RxDoControl(const std::string &RecvStr,const int &msgType);
void RxAoControl(const std::string &RecvStr,const int &msgType);
void RxMoControl(const std::string &RecvStr,const int &msgType);
void RxSettingControl(const std::string &RecvStr,const int &msgType);
void RxDefCmdControl(const std::string &RecvStr);
void RxDoControl(const void* data,size_t dataSize,const int &msgType);
void RxAoControl(const void* data,size_t dataSize,const int &msgType);
void RxMoControl(const void* data,size_t dataSize,const int &msgType);
void RxSettingControl(const void* data,size_t dataSize,const int &msgType);
void RxDefCmdControl(const void* data,size_t dataSize);
void RxBatchPntCmd(const void* data,size_t dataSize);
void addDoControl(const iot_idl::SFesDoRequestPkg &doReq);
void addAoControl(const iot_idl::SFesAoRequestPkg &aoReq);
void addMoControl(const iot_idl::SFesMoRequestPkg &moReq);
void handleJsonFormatRtuCmd(const iot_net::CMbMessage &stMsg);
void addJsonFormatRtuCmd(const rapidjson::Value &value);
};
typedef boost::shared_ptr<CFesRxControlCmdThread> CFesRxControlCmdThreadPtr;

View File

@ -13,7 +13,7 @@ using namespace iot_idl;
using namespace iot_service;
CFesRxDPDataThread::CFesRxDPDataThread(int iDomainID, int iAppID ,void* FesBaseAddr):
CTimerThreadBase("FesRxDPDataThread",30)
CTimerThreadBase("FesRxDPDataThread",0)
{
m_ptrRxCommunicator = new CMbCommunicator("FesRxDPDataThread");
m_iDomainID = iDomainID;
@ -132,7 +132,6 @@ int CFesRxDPDataThread::unsubMessage()
*/
int CFesRxDPDataThread::readFromBus()
{
std::string RecvStr;
CMbMessage msgRcv;
if (m_ptrRxCommunicator == NULL)
@ -140,14 +139,14 @@ int CFesRxDPDataThread::readFromBus()
//1.从消息总线接收消息没有消息返回FALSE
//====================================================================================
if (m_ptrRxCommunicator->recvMsg(msgRcv))
if (m_ptrRxCommunicator->recvMsg(msgRcv,100))
{
int nMessageType = msgRcv.getMsgType();
//LOGDEBUG("readFromBus nMessageType=%d ", nMessageType);
if (nMessageType == MT_DP_CHANGE_DATA)
{
SRealTimeDataPkg ChangeDataPkg;
if (true == ChangeDataPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize()))
if (true == ChangeDataPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) ))
{
if (iotFailed == RxDiChangeData(ChangeDataPkg))
{
@ -200,12 +199,10 @@ int CFesRxDPDataThread::RxDiChangeData(const SRealTimeDataPkg & ChangeDataPkg)
if (nChangeNum > 0)
{
mSec = getUTCTimeMsec();
SDiRealTimeData diStru;
std::string strTagName = "";
for (i = 0; i < nChangeNum; i++)
{
diStru = ChangeDataPkg.stdirtd(i);
strTagName = diStru.strtagname();
const SDiRealTimeData &diStru = ChangeDataPkg.stdirtd(i);
const std::string &strTagName = diStru.strtagname();
if ((pPubDi = m_ptrCFesBase->GetFesFwPubDpDi(strTagName)) == NULL)
continue;
@ -282,56 +279,45 @@ int CFesRxDPDataThread::RxDiChangeData(const SRealTimeDataPkg & ChangeDataPkg)
*/
int CFesRxDPDataThread::RxAiChangeData(const SRealTimeDataPkg & ChangeDataPkg)
{
int i,j;
CFesRtuPtr ptrFwRtu;
SFesFwChgAi ChangeInfo;
SFesFwPubAi *pPubAi = NULL;
uint64 mSec;
try
{
int nChangeNum = ChangeDataPkg.stairtd_size();
if (nChangeNum > 0)
{
mSec = getUTCTimeMsec();
::iot_idl::SAiRealTimeData aiStru;
std::string strTagName = "";
for (i = 0; i < nChangeNum; i++)
{
aiStru = ChangeDataPkg.stairtd(i);
strTagName = aiStru.strtagname();
uint64 mSec = getUTCTimeMsec();
std::string strTagName = "";
if ((pPubAi = m_ptrCFesBase->GetFesFwPubDpAi(strTagName)) == NULL)
continue;
int nChangeNum = ChangeDataPkg.stairtd_size();
for (int i = 0; i < nChangeNum; i++)
{
const iot_idl::SAiRealTimeData &aiStru = ChangeDataPkg.stairtd(i);
strTagName = aiStru.strtagname();
if ((pPubAi = m_ptrCFesBase->GetFesFwPubDpAi(strTagName)) == NULL)
continue;
pPubAi->Value = aiStru.fvalue();
pPubAi->Status = aiStru.ustatus();
pPubAi->time = mSec;
ChangeInfo.RtuNo = pPubAi->FesRtuNo;
ChangeInfo.PointNo = pPubAi->SrcPointNo;
ChangeInfo.Status = pPubAi->Status;
ChangeInfo.time = pPubAi->time;
float fNewValue = 0.0f;
for (int j = 0; j < pPubAi->FwMapNum; j++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubAi->FwMapping[j].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubAi->FwMapping[j].RemoteNo;
ChangeInfo.Value = pPubAi->Value; //< 每次要设置为原始值因为ChangeInfo在下面可能会被修改
if(ptrFwRtu->UpdataFwAiValue(ChangeInfo,fNewValue,eNormalUpdate)) //< fNewValue值会被更新
{
ChangeInfo.Value = fNewValue;
ptrFwRtu->WriteFwAiBuf(ChangeInfo);
}
}
}
pPubAi->Value = aiStru.fvalue();
pPubAi->Status = aiStru.ustatus();
pPubAi->time = mSec;
ChangeInfo.RtuNo = pPubAi->FesRtuNo;
ChangeInfo.PointNo = pPubAi->SrcPointNo;
ChangeInfo.Value = pPubAi->Value;
ChangeInfo.Status = pPubAi->Status;
ChangeInfo.time = pPubAi->time;
for (j = 0; j < pPubAi->FwMapNum; j++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubAi->FwMapping[j].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubAi->FwMapping[j].RemoteNo;
if(ptrFwRtu->UpdataFwAiValue(ChangeInfo,1))
ptrFwRtu->WriteFwAiBuf(ChangeInfo);
}
}
}
}
catch (std::exception &ex)
{
LOGERROR("RxAiChangeData Fail,errNo=%s",ex.what());
return iotFailed;
}
catch (...)
{
return iotFailed;
}
return iotSuccess;
}
@ -348,54 +334,42 @@ int CFesRxDPDataThread::RxAccChangeData(const SRealTimeDataPkg & ChangeDataPkg)
CFesRtuPtr ptrFwRtu;
SFesFwChgAcc ChangeInfo;
SFesFwPubAcc *pPubAcc = NULL;
uint64 mSec;
try
{
int nChangeNum = ChangeDataPkg.stpirtd_size();
if (nChangeNum > 0)
{
::iot_idl::SPiRealTimeData piStru;
std::string strTagName = "";
mSec = getUTCTimeMsec();
for (i = 0; i < nChangeNum; i++)
{
piStru = ChangeDataPkg.stpirtd(i);
strTagName = piStru.strtagname();
uint64 mSec = getUTCTimeMsec();
if ((pPubAcc = m_ptrCFesBase->GetFesFwPubDpAcc(strTagName)) == NULL)
continue;
int nChangeNum = ChangeDataPkg.stpirtd_size();
for (i = 0; i < nChangeNum; i++)
{
const iot_idl::SPiRealTimeData &piStru = ChangeDataPkg.stpirtd(i);
const std::string &strTagName = piStru.strtagname();
if ((pPubAcc = m_ptrCFesBase->GetFesFwPubDpAcc(strTagName)) == NULL)
continue;
pPubAcc->Value = piStru.dvalue();
pPubAcc->Status = piStru.ustatus();
pPubAcc->time = mSec;
ChangeInfo.RtuNo = pPubAcc->FesRtuNo;
ChangeInfo.PointNo = pPubAcc->SrcPointNo;
ChangeInfo.Status = pPubAcc->Status;
ChangeInfo.time = pPubAcc->time;
double dNewValue = 0.0;
for (j = 0; j < pPubAcc->FwMapNum; j++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubAcc->FwMapping[j].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubAcc->FwMapping[j].RemoteNo;
ChangeInfo.Value = pPubAcc->Value; //< 每次要重新赋值
if(ptrFwRtu->UpdataFwAccValue(ChangeInfo,dNewValue,eNormalUpdate))
{
ChangeInfo.Value = dNewValue;
ptrFwRtu->WriteFwAccBuf(ChangeInfo);
}
}
}
pPubAcc->Value = piStru.dvalue();
pPubAcc->Status = piStru.ustatus();
pPubAcc->time = mSec;
ChangeInfo.RtuNo = pPubAcc->FesRtuNo;
ChangeInfo.PointNo = pPubAcc->SrcPointNo;
ChangeInfo.Value = pPubAcc->Value;
ChangeInfo.Status = pPubAcc->Status;
ChangeInfo.time = pPubAcc->time;
for (j = 0; j < pPubAcc->FwMapNum; j++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubAcc->FwMapping[j].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubAcc->FwMapping[j].RemoteNo;
if(ptrFwRtu->UpdataFwAccValue(ChangeInfo,1))
ptrFwRtu->WriteFwAccBuf(ChangeInfo);
}
}
}
}
catch (std::exception &ex)
{
LOGERROR("RxAccChangeData Fail,errNo=%s",ex.what());
return iotFailed;
}
catch (...)
{
return iotFailed;
}
return iotSuccess;
}
/**
@ -407,55 +381,43 @@ int CFesRxDPDataThread::RxAccChangeData(const SRealTimeDataPkg & ChangeDataPkg)
*/
int CFesRxDPDataThread::RxMiChangeData(const SRealTimeDataPkg & ChangeDataPkg)
{
int j;
CFesRtuPtr ptrFwRtu;
SFesFwChgMi ChangeInfo;
SFesFwPubMi *pPubMi = NULL;
uint64 mSec;
uint64 mSec = getUTCTimeMsec();
try
{
int nChangeNum = ChangeDataPkg.stmirtd_size();
if (nChangeNum > 0)
{
::iot_idl::SMiRealTimeData miStru;
std::string strTagName = "";
mSec = getUTCTimeMsec();
for (int i = 0; i < nChangeNum; i++)
{
miStru = ChangeDataPkg.stmirtd(i);
strTagName = miStru.strtagname();
if ((pPubMi = m_ptrCFesBase->GetFesFwPubDpMi(strTagName)) == NULL)
continue;
int nChangeNum = ChangeDataPkg.stmirtd_size();
for (int i = 0; i < nChangeNum; i++)
{
const iot_idl::SMiRealTimeData &miStru = ChangeDataPkg.stmirtd(i);
const std::string &strTagName = miStru.strtagname();
if ((pPubMi = m_ptrCFesBase->GetFesFwPubDpMi(strTagName)) == NULL)
continue;
pPubMi->Value = miStru.nvalue();
pPubMi->Status = miStru.ustatus();
pPubMi->time = mSec;
ChangeInfo.RtuNo = pPubMi->FesRtuNo;
ChangeInfo.PointNo = pPubMi->SrcPointNo;
ChangeInfo.Status = pPubMi->Status;
ChangeInfo.time = pPubMi->time;
int nNewValue = 0;
for (int j = 0; j < pPubMi->FwMapNum; j++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubMi->FwMapping[j].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubMi->FwMapping[j].RemoteNo;
ChangeInfo.Value = pPubMi->Value;
if(ptrFwRtu->UpdataFwMiValue(ChangeInfo,nNewValue,eNormalUpdate))
{
ChangeInfo.Value = nNewValue;
ptrFwRtu->WriteFwMiBuf(ChangeInfo);
}
}
}
pPubMi->Value = miStru.nvalue();
pPubMi->Status = miStru.ustatus();
pPubMi->time = mSec;
ChangeInfo.RtuNo = pPubMi->FesRtuNo;
ChangeInfo.PointNo = pPubMi->SrcPointNo;
ChangeInfo.Value = pPubMi->Value;
ChangeInfo.Status = pPubMi->Status;
ChangeInfo.time = pPubMi->time;
for (j = 0; j < pPubMi->FwMapNum; j++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubMi->FwMapping[j].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubMi->FwMapping[j].RemoteNo;
if(ptrFwRtu->UpdataFwMiValue(ChangeInfo,1))
ptrFwRtu->WriteFwMiBuf(ChangeInfo);
}
}
}
}
catch (std::exception &ex)
{
LOGERROR("RxMiChangeData Fail,errNo=%s",ex.what());
return iotFailed;
}
catch (...)
{
return iotFailed;
}
return iotSuccess;
}

View File

@ -289,7 +289,7 @@ void CFesRxDataUpDateThread::DiAllResp()
continue;
memset(m_pDiValue, 0, ptrCFesRtu->m_MaxDiPoints * sizeof(SFesAllDi));//2023-02-22 thxiao 清除内存,避免点标签赋值不正确
retNum = ptrCFesRtu->ReadDiValue(ptrCFesRtu->m_MaxDiPoints,m_pDiValue);
retNum = ptrCFesRtu->ReadDiValue(ptrCFesRtu->m_MaxDiPoints,m_pDiValue);
//fill the protobuf data
//LOGDEBUG("CFesRxDataUpDateThread::DiAllResp num=%d",retNum);
for(j=0;j<retNum;j++)
@ -463,7 +463,7 @@ void CFesRxDataUpDateThread::AccAllResp()
continue;
memset(m_pAccValue, 0, ptrCFesRtu->m_MaxAccPoints * sizeof(SFesAllAcc));//2023-02-22 thxiao 清除内存,避免点标签赋值不正确
retNum = ptrCFesRtu->ReadAccValue(ptrCFesRtu->m_MaxAccPoints,m_pAccValue);
retNum = ptrCFesRtu->ReadAccValue(ptrCFesRtu->m_MaxAccPoints,m_pAccValue);
//fill the protobuf data
for(j=0;j<retNum;j++)
{
@ -476,7 +476,7 @@ void CFesRxDataUpDateThread::AccAllResp()
pAccWithoutTm->set_strappcolumnname(pAcc->ColumnName);
pAccWithoutTm->set_strapptagname(pAcc->TagName);
pAccWithoutTm->set_ustatus(pAcc->Status);
pAccWithoutTm->set_nvalue(pAcc->Value);
pAccWithoutTm->set_dvalue(pAcc->Value);
count++;
}
@ -944,7 +944,7 @@ void CFesRxDataUpDateThread::AccChangeStatusReport()
pAccWithoutTm->set_strappcolumnname(pAcc->ColumnName);
pAccWithoutTm->set_strapptagname(pAcc->TagName);
pAccWithoutTm->set_ustatus(pAcc->Status);
pAccWithoutTm->set_nvalue(pAcc->Value);
pAccWithoutTm->set_dvalue(pAcc->Value);
count++;
}

View File

@ -3,10 +3,6 @@
@brief FES的AI\DI\ACC\MI数据
@author thxiao
2023-11-25 tthxiao
PSCADA把数据转发到PSCADA1
线
*/
#include "FesRxFesDataThread.h"
#include "MessageChannel.h"
@ -15,21 +11,21 @@ using namespace iot_net;
using namespace iot_public;
using namespace iot_idl;
CFesRxFesDataThread::CFesRxFesDataThread(int iDomainID, int iAppID ,void* FesBaseAddr, CPacketQueuePtr ptrPacketQueue):
CTimerThreadBase("FesRxFesDataThread",0)
CFesRxFesDataThread::CFesRxFesDataThread(int iDomainID, int iAppID ,void* FesBaseAddr):
CTimerThreadBase("FesRxFesDataThread",30)
{
m_ptrRxCommunicator = new CMbCommunicator("FesRxFesDataThread");
m_iDomainID = iDomainID;
m_iAppID= iAppID;
m_ptrCFesBase = (CFesBase*)FesBaseAddr;
m_ptrPacketQueue = ptrPacketQueue;
}
CFesRxFesDataThread::~CFesRxFesDataThread()
{
delete m_ptrRxCommunicator;
m_ptrRxCommunicator = NULL;
m_ptrPacketQueue.reset();
}
/**
@ -132,143 +128,585 @@ bool CFesRxFesDataThread::readFromBus()
{
std::string RecvStr;
CMbMessage msgRcv;
int nMsgType,count;
bool bRetCode = false;
int nMsgType;
if (m_ptrRxCommunicator == NULL)
return false;
count = 0;
while (count < 20)
//1.从消息总线接收消息没有消息返回FALSE
//====================================================================================
if (m_ptrRxCommunicator->recvMsg(msgRcv))
{
count++;
//1.从消息总线接收消息没有消息返回FALSE
if (m_ptrRxCommunicator->recvMsg(msgRcv, 50) == false)
{
continue;
}
nMsgType = msgRcv.getMsgType();
switch (nMsgType)
switch(nMsgType)
{
case MT_FES_DI_CHANGE:
{
SFesChangeDiPkg ChangeDiPkg;
bRetCode = ChangeDiPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize());
if (!bRetCode)
{
LOGDEBUG("readFromBus::ChangeDiPkg解析错误");
break;
}
m_ptrPacketQueue->addFesChangeDigPkg(ChangeDiPkg);
break;
ChangeDiPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) );
RxDiChangeData(ChangeDiPkg);
}
break;
case MT_FES_DI_UPDATE:
{
SFesUpdateDiPkg UpdateDiPkg;
bRetCode = UpdateDiPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize());
if (!bRetCode)
{
LOGDEBUG("readFromBus::UpdateDiPkg解析错误");
break;
}
m_ptrPacketQueue->addFesUpdateDigPkg(UpdateDiPkg);
break;
UpdateDiPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) );
RxDiUpdataData(UpdateDiPkg);
}
break;
case MT_FES_SOE_EVENT:
{
SFesSoeEventPkg SoePkg;
bRetCode = SoePkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize());
if (!bRetCode)
{
LOGDEBUG("readFromBus::SoePkg解析错误");
break;
}
m_ptrPacketQueue->addFesSoeEventPkg(SoePkg);
break;
SoePkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) );
RxSOEData(SoePkg);
}
break;
case MT_FES_AI_CHANGE:
{
SFesChangeAiPkg ChangeAiPkg;
bRetCode = ChangeAiPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize());
if (!bRetCode)
{
LOGDEBUG("readFromBus::ChangeAiPkg解析错误");
break;
}
m_ptrPacketQueue->addFesChangeAnaPkg(ChangeAiPkg);
break;
ChangeAiPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) );
RxAiChangeData(ChangeAiPkg);
}
break;
case MT_FES_AI_UPDATE:
{
SFesUpdateAiPkg UpdateAiPkg;
UpdateAiPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize());
if (!bRetCode)
{
LOGDEBUG("readFromBus::UpdateAiPkg解析错误");
break;
}
m_ptrPacketQueue->addFesUpdateAnaPkg(UpdateAiPkg);
break;
UpdateAiPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) );
RxAiUpdataData(UpdateAiPkg);
}
break;
case MT_FES_PI_CHANGE:
{
SFesChangePiPkg ChangeAccPkg;
bRetCode = ChangeAccPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize());
if (!bRetCode)
{
LOGDEBUG("parseFesPackage::ChangeAccPkg解析错误");
break;
}
m_ptrPacketQueue->addFesChangeAccPkg(ChangeAccPkg);
break;
SFesChangePiPkg ChanageAccPkg;
ChanageAccPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) );
RxAccChangeData(ChanageAccPkg);
}
break;
case MT_FES_PI_UPDATE:
{
SFesUpdatePiPkg UpdateAccPkg;
bRetCode = UpdateAccPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize());
if (!bRetCode)
{
LOGDEBUG("readFromBus::UpdateAccPkg解析错误");
break;
}
m_ptrPacketQueue->addFesUpdateAccPkg(UpdateAccPkg);
break;
UpdateAccPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) );
RxAccUpdataData(UpdateAccPkg);
}
break;
case MT_FES_MI_CHANGE:
{
SFesChangeMiPkg ChangeMiPkg;
bRetCode = ChangeMiPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize());
if (!bRetCode)
{
LOGDEBUG("readFromBus::ChangeMiPkg解析错误");
break;
}
m_ptrPacketQueue->addFesChangeMixPkg(ChangeMiPkg);
break;
SFesChangeMiPkg ChangeMiPkg;
ChangeMiPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) );
RxMiChangeData(ChangeMiPkg);
}
break;
case MT_FES_MI_UPDATE:
{
SFesUpdateMiPkg UpdateMiPkg;
bRetCode = UpdateMiPkg.ParseFromArray(msgRcv.getDataPtr(), msgRcv.getDataSize());
if (!bRetCode)
{
LOGDEBUG("readFromBus::UpdateMiPkg解析错误");
break;
}
m_ptrPacketQueue->addFesUpdateMixPkg(UpdateMiPkg);
break;
SFesUpdateMiPkg UpdateMiPkg;
UpdateMiPkg.ParseFromArray(msgRcv.getDataPtr(), static_cast<int>(msgRcv.getDataSize()) );
RxMiUpdataData(UpdateMiPkg);
}
break;
default:
{
// LOGDEBUG("readFromBus::MsgType = %d 消息类型不支持!", nMsgType);
break;
}
return true;
}
return false;
}
/**
* @brief CFesRxFesDataThread::RxDiChangeData
* DI变化数据
*
* @param stChangeDiPkg
* @return
*/
void CFesRxFesDataThread::RxDiChangeData(const SFesChangeDiPkg &ChangeDiPkg)
{
int nChangeNum;
int nLoop = 0;
int i;
CFesRtuPtr ptrFwRtu;
SFesFwChgDi ChangeInfo;
nChangeNum = ChangeDiPkg.stdidata_size();
if (nChangeNum > 0)
{
LOGDEBUG("RxDiChangeData:收到变化数据报文,数目[%d],时间[%" PRId64 "].", nChangeNum, (int64)ChangeDiPkg.stdidata(0).ultime());
}
for (nLoop = 0; nLoop < nChangeNum; nLoop++)
{
SFesFwPubDi *pPubDi = NULL;
const SFesDiDataWithTm &stDiData = ChangeDiPkg.stdidata(nLoop);
const std::string &TagName = stDiData.strapptagname();
if ((pPubDi = m_ptrCFesBase->GetFesFwPubFesDi(TagName)) == NULL)
continue;
if ((int64)stDiData.ultime() < 0)
{
LOGERROR("tag_name = %s, times = [%" PRId64 "] < 0 error!", TagName.c_str(), stDiData.ultime());
continue;
}
pPubDi->Value = 0x01 & stDiData.nvalue();
pPubDi->Status = 0xffff & stDiData.ustatus();
pPubDi->time = stDiData.ultime();
ChangeInfo.RtuNo = pPubDi->FesRtuNo;
ChangeInfo.PointNo = pPubDi->SrcPointNo;
ChangeInfo.Value = pPubDi->Value;
ChangeInfo.Status = pPubDi->Status;
ChangeInfo.time = pPubDi->time;
for (i = 0; i < pPubDi->FwMapNum; i++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubDi->FwMapping[i].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubDi->FwMapping[i].RemoteNo;
ptrFwRtu->WriteFwDiBuf(ChangeInfo);
ptrFwRtu->UpdataFwDiValue(ChangeInfo);
}
}
}
/**
* @brief CFesRxFesDataThread::RxSOEData
* DI变化数据
*
* @param SFesSoeEventPkg
* @return
*/
void CFesRxFesDataThread::RxSOEData(const SFesSoeEventPkg &SOEPkg)
{
int nChangeNum;
int nLoop = 0;
int i;
CFesRtuPtr ptrFwRtu;
SFesFwSoeEvent ChangeInfo;
nChangeNum = SOEPkg.stsoeevent_size();
if (nChangeNum > 0)
{
LOGDEBUG("RxSOEData:收到变化数据报文,数目[%d],时间[%" PRId64 "].", nChangeNum, (int64)SOEPkg.stsoeevent(0).ultime());
}
for (nLoop = 0; nLoop < nChangeNum; nLoop++)
{
SFesFwPubDi *pPubDi = NULL;
const SFesSoeEventInfo &stSoeEvent = SOEPkg.stsoeevent(nLoop);
const std::string &TagName = stSoeEvent.strapptagname();
if ((pPubDi = m_ptrCFesBase->GetFesFwPubFesDi(TagName)) == NULL)
continue;
if ((int64)stSoeEvent.ultime() < 0)
{
LOGERROR("tag_name = %s, times = [%" PRId64 "] < 0 error!", TagName.c_str(), stSoeEvent.ultime());
continue;
}
ChangeInfo.RtuNo = pPubDi->FesRtuNo;
ChangeInfo.PointNo = pPubDi->SrcPointNo;
ChangeInfo.Value = 0x01 & stSoeEvent.nvalue();
ChangeInfo.Status = 0xffff & stSoeEvent.ustatus();
ChangeInfo.time = stSoeEvent.ultime();
//SOE事件故障描述忽略不处理
for (i = 0; i < pPubDi->FwMapNum; i++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubDi->FwMapping[i].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubDi->FwMapping[i].RemoteNo;
ptrFwRtu->WriteFwSoeEventBuf(ChangeInfo);
}
}
}
/**
* @brief CFesRxFesDataThread::RxAiChangeData
* AI变化数据
*
* @param stChangeAiPkg
* @return
*/
void CFesRxFesDataThread::RxAiChangeData(const SFesChangeAiPkg &ChangeAiPkg)
{
int nChangeNum;
int nLoop = 0;
int i;
CFesRtuPtr ptrFwRtu;
SFesFwChgAi ChangeInfo;
nChangeNum = ChangeAiPkg.staidata_size();
if (nChangeNum > 0)
{
LOGTRACE("RxAiChangeData:收到变化数据报文,数目[%d],时间[%" PRId64 "].", nChangeNum, (int64)ChangeAiPkg.staidata(0).ultime());
}
for (nLoop = 0; nLoop < nChangeNum; nLoop++)
{
SFesFwPubAi *pPubAi = NULL;
const SFesAiDataWithTm &stAiData = ChangeAiPkg.staidata(nLoop);
const std::string &TagName = stAiData.strapptagname();
if ((pPubAi = m_ptrCFesBase->GetFesFwPubFesAi(TagName)) == NULL)
continue;
if ((int64)stAiData.ultime() < 0)
{
LOGERROR("tag_name = %s, times = [%" PRId64 "]< 0 error!", TagName.c_str(), stAiData.ultime());
continue;
}
pPubAi->Value = stAiData.fvalue();
pPubAi->Status = stAiData.ustatus();
pPubAi->time = stAiData.ultime();
ChangeInfo.RtuNo = pPubAi->FesRtuNo;
ChangeInfo.PointNo = pPubAi->SrcPointNo;
ChangeInfo.Status = pPubAi->Status;
ChangeInfo.time = pPubAi->time;
float fNewValue = 0.0f;
for (i = 0; i < pPubAi->FwMapNum; i++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubAi->FwMapping[i].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubAi->FwMapping[i].RemoteNo;
ChangeInfo.Value = pPubAi->Value; //< 每次必须重新赋值因为ChangeInfo的Value会被更新
if(ptrFwRtu->UpdataFwAiValue(ChangeInfo,fNewValue,eNormalUpdate)) //< fNewValue值会被更新
{
ChangeInfo.Value = fNewValue;
ptrFwRtu->WriteFwAiBuf(ChangeInfo);
}
}
}
return true;
}
/**
* @brief CFesRxFesDataThread::RxAccChangeData
* ACC变化数据
*
* @param stChangePiPkg
* @return
*/
void CFesRxFesDataThread::RxAccChangeData(const SFesChangePiPkg &ChangeAccPkg)
{
int nChangeNum;
int nLoop = 0;
int i;
CFesRtuPtr ptrFwRtu;
SFesFwChgAcc ChangeInfo;
nChangeNum = ChangeAccPkg.stpidata_size();
if (nChangeNum > 0)
{
LOGTRACE("RxAccChangeData:收到变化数据报文,数目[%d],时间[%" PRId64 "].", nChangeNum, (int64)ChangeAccPkg.stpidata(0).ultime());
}
for (nLoop = 0; nLoop < nChangeNum; nLoop++)
{
SFesFwPubAcc *pPubAcc = NULL;
const SFesPiDataWithTm &stAccData = ChangeAccPkg.stpidata(nLoop);
const std::string &TagName = stAccData.strapptagname();
if ((pPubAcc = m_ptrCFesBase->GetFesFwPubFesAcc(TagName)) == NULL)
continue;
if ((int64)stAccData.ultime() < 0)
{
LOGERROR("tag_name = %s, times = [%" PRId64 "] < 0 error!", TagName.c_str(), stAccData.ultime());
continue;
}
pPubAcc->Value = stAccData.dvalue();
pPubAcc->Status = stAccData.ustatus();
pPubAcc->time = stAccData.ultime();
ChangeInfo.RtuNo = pPubAcc->FesRtuNo;
ChangeInfo.PointNo = pPubAcc->SrcPointNo;
ChangeInfo.Status = pPubAcc->Status;
ChangeInfo.time = pPubAcc->time;
double dNewValue = 0.0;
for (i = 0; i < pPubAcc->FwMapNum; i++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubAcc->FwMapping[i].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubAcc->FwMapping[i].RemoteNo;
ChangeInfo.Value = pPubAcc->Value; //< 每次要重新赋值
if(ptrFwRtu->UpdataFwAccValue(ChangeInfo,dNewValue,eNormalUpdate))
{
ChangeInfo.Value = dNewValue;
ptrFwRtu->WriteFwAccBuf(ChangeInfo);
}
}
}
}
/**
* @brief CFesRxFesDataThread::RxMiChangeData
* MI变化数据
*
* @param stChangeMiPkg
* @return
*/
void CFesRxFesDataThread::RxMiChangeData(const SFesChangeMiPkg &ChangeMiPkg)
{
int nChangeNum;
int nLoop = 0;
int i;
CFesRtuPtr ptrFwRtu;
SFesFwChgMi ChangeInfo;
nChangeNum = ChangeMiPkg.stmidata_size();
if (nChangeNum > 0)
{
LOGTRACE("RxMiChangeData:收到变化数据报文,数目[%d],时间[%" PRId64 "].", nChangeNum, (int64)ChangeMiPkg.stmidata(0).ultime());
}
for (nLoop = 0; nLoop < nChangeNum; nLoop++)
{
SFesFwPubMi *pPubMi = NULL;
const SFesMiDataWithTm &MiData = ChangeMiPkg.stmidata(nLoop);
const std::string &TagName = MiData.strapptagname();
if ((pPubMi = m_ptrCFesBase->GetFesFwPubFesMi(TagName)) == NULL)
continue;
if ((int64)MiData.ultime() < 0)
{
LOGERROR("tag_name = %s, times = [%" PRId64 "] < 0 error!", TagName.c_str(), MiData.ultime());
continue;
}
pPubMi->Value = MiData.nvalue();
pPubMi->Status = MiData.ustatus();
pPubMi->time = MiData.ultime();
ChangeInfo.RtuNo = pPubMi->FesRtuNo;
ChangeInfo.PointNo = pPubMi->SrcPointNo;
ChangeInfo.Status = pPubMi->Status;
ChangeInfo.time = pPubMi->time;
int nNewValue = 0;
for (i = 0; i < pPubMi->FwMapNum; i++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubMi->FwMapping[i].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubMi->FwMapping[i].RemoteNo;
ChangeInfo.Value = pPubMi->Value; //< 每次要重新赋值
if(ptrFwRtu->UpdataFwMiValue(ChangeInfo,nNewValue,eNormalUpdate))
{
ChangeInfo.Value = nNewValue;
ptrFwRtu->WriteFwMiBuf(ChangeInfo);
}
}
}
}
/**
* @brief CFesRxFesDataThread::RxDiUpdataData
* DI全数据
*
* @param UpdateDiPkg
* @return
*/
void CFesRxFesDataThread::RxDiUpdataData(const SFesUpdateDiPkg &UpdateDiPkg)
{
int nNum;
int nLoop = 0;
int i;
CFesRtuPtr ptrFwRtu;
SFesFwChgDi ChangeInfo;
uint64 mSec;
nNum = UpdateDiPkg.stdidata_size();
if (nNum > 0)
{
LOGDEBUG("RxDiChangeData:收到全数据报文,数目[%d]", nNum);
}
mSec = getUTCTimeMsec();
for (nLoop = 0; nLoop < nNum; nLoop++)
{
SFesFwPubDi *pPubDi = NULL;
const SFesDiDataWithoutTm &DiData = UpdateDiPkg.stdidata(nLoop);
const std::string &strTagName = DiData.strapptagname();
if ((pPubDi = m_ptrCFesBase->GetFesFwPubFesDi(strTagName)) == NULL)
continue;
pPubDi->Value = 0x01 & DiData.nvalue();
pPubDi->Status = DiData.ustatus();
pPubDi->time = mSec;
ChangeInfo.Value = pPubDi->Value;
ChangeInfo.Status = pPubDi->Status;
ChangeInfo.time = pPubDi->time;
for (i = 0; i < pPubDi->FwMapNum; i++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubDi->FwMapping[i].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubDi->FwMapping[i].RemoteNo;
ptrFwRtu->UpdataFwDiValue(ChangeInfo);
}
}
}
/**
* @brief CFesRxFesDataThread::RxAiUpdataData
* Ai全数据
*
* @param UpdateAiPkg
* @return
*/
void CFesRxFesDataThread::RxAiUpdataData(const SFesUpdateAiPkg &UpdateAiPkg)
{
int nNum;
int nLoop = 0;
int i;
CFesRtuPtr ptrFwRtu;
SFesFwChgAi ChangeInfo;
uint64 mSec;
nNum = UpdateAiPkg.staidata_size();
if (nNum > 0)
{
LOGTRACE("RxAiChangeData:收到全数据报文,数目[%d]", nNum);
}
mSec = getUTCTimeMsec();
for (nLoop = 0; nLoop < nNum; nLoop++)
{
SFesFwPubAi *pPubAi = NULL;
const SFesAiDataWithoutTm &AiData = UpdateAiPkg.staidata(nLoop);
const std::string &TagName = AiData.strapptagname();
if ((pPubAi = m_ptrCFesBase->GetFesFwPubFesAi(TagName)) == NULL)
continue;
pPubAi->Value = AiData.fvalue();
pPubAi->Status = AiData.ustatus();
pPubAi->time = mSec;
ChangeInfo.Value = pPubAi->Value;
ChangeInfo.Status = pPubAi->Status;
ChangeInfo.time = pPubAi->time;
float fNewValue = 0.0f;
for (i = 0; i < pPubAi->FwMapNum; i++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubAi->FwMapping[i].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubAi->FwMapping[i].RemoteNo;
ptrFwRtu->UpdataFwAiValue(ChangeInfo,fNewValue,eWithoutDeadbandUpdate); //< fNewValue的值会被更新
}
}
}
/**
* @brief CFesRxFesDataThread::RxAccUpdataData
* ACC全数据
*
* @param UpdateAccPkg
* @return
*/
void CFesRxFesDataThread::RxAccUpdataData(const SFesUpdatePiPkg &UpdateAccPkg)
{
int nNum;
int nLoop = 0;
int i;
CFesRtuPtr ptrFwRtu;
SFesFwChgAcc ChangeInfo;
uint64 mSec;
nNum = UpdateAccPkg.stpidata_size();
if (nNum > 0)
{
LOGTRACE("RxAccChangeData:收到全数据报文,数目[%d]", nNum);
}
mSec = getUTCTimeMsec();
for (nLoop = 0; nLoop < nNum; nLoop++)
{
SFesFwPubAcc *pPubAcc = NULL;
const SFesPiDataWithoutTm &AccData = UpdateAccPkg.stpidata(nLoop);
const std::string &TagName = AccData.strapptagname();
if ((pPubAcc = m_ptrCFesBase->GetFesFwPubFesAcc(TagName)) == NULL)
continue;
pPubAcc->Value = AccData.dvalue();
pPubAcc->Status = AccData.ustatus();
pPubAcc->time = mSec;
ChangeInfo.Value = pPubAcc->Value;
ChangeInfo.Status = pPubAcc->Status;
ChangeInfo.time = pPubAcc->time;
double dNewValue = 0.0;
for (i = 0; i < pPubAcc->FwMapNum; i++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubAcc->FwMapping[i].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubAcc->FwMapping[i].RemoteNo;
ptrFwRtu->UpdataFwAccValue(ChangeInfo,dNewValue,eWithoutDeadbandUpdate);
}
}
}
/**
* @brief CFesRxFesDataThread::RxMiUpdataData
* Mi全数据
*
* @param UpdateMiPkg
* @return
*/
void CFesRxFesDataThread::RxMiUpdataData(const SFesUpdateMiPkg &UpdateMiPkg)
{
int nNum;
int nLoop = 0;
int i;
CFesRtuPtr ptrFwRtu;
SFesFwChgMi ChangeInfo;
uint64 mSec;
nNum = UpdateMiPkg.stmidata_size();
if (nNum > 0)
{
LOGTRACE("RxMiChangeData:收到全数据报文,数目[%d]", nNum);
}
mSec = getUTCTimeMsec();
for (nLoop = 0; nLoop < nNum; nLoop++)
{
SFesFwPubMi *pPubMi = NULL;
const SFesMiDataWithoutTm &MiData = UpdateMiPkg.stmidata(nLoop);
const std::string &TagName = MiData.strapptagname();
if ((pPubMi = m_ptrCFesBase->GetFesFwPubFesMi(TagName)) == NULL)
continue;
pPubMi->Value = MiData.nvalue();
pPubMi->Status = MiData.ustatus();
pPubMi->time = mSec;
ChangeInfo.Value = pPubMi->Value;
ChangeInfo.Status = pPubMi->Status;
ChangeInfo.time = pPubMi->time;
int nNewValue = 0;
for (i = 0; i < pPubMi->FwMapNum; i++)
{
if ((ptrFwRtu = m_ptrCFesBase->GetFwRtuByMappingIndex(pPubMi->FwMapping[i].MappingIndex)) == NULL)
continue;
ChangeInfo.RemoteNo = pPubMi->FwMapping[i].RemoteNo;
ptrFwRtu->UpdataFwMiValue(ChangeInfo,nNewValue,eWithoutDeadbandUpdate);
}
}
}
//设置为主
@ -284,146 +722,3 @@ int CFesRxFesDataThread::setSlave()
unsubMessage();
return iotSuccess;
}
/**
@brief ///SOE/
@param
@return
@retval
*/
int CFesRxFesDataThread::parseFesPackage(const iot_net::CMbMessage &objRecvMsg)
{
//int64 t1,t2;
bool bRetCode = false;
int nMessageType = objRecvMsg.getMsgType();
LOGDEBUG("parseFesPackage, Recv a Message Type=%d ", nMessageType);
switch (nMessageType)
{
case MT_FES_DI_CHANGE://DI Change Data
{
SFesChangeDiPkg objFesChanageDiPkg;
//t1 = getUTCTimeMsec() ;
bRetCode = objFesChanageDiPkg.ParseFromArray(objRecvMsg.getDataPtr(), objRecvMsg.getDataSize());
//t2 = getUTCTimeMsec() ;
//LOGINFO("parseFesPackage:解析变化数字量 num=%d用时=%d(ms)",objFesChanageDiPkg.stdidata_size(),t2-t1);
if (!bRetCode)
{
LOGWARN("parseFesPackage::objFesChanageDiPkg解析错误");
return -1;
}
m_ptrPacketQueue->addFesChangeDigPkg(objFesChanageDiPkg);
break;
}
case MT_FES_DI_UPDATE://DI UPDATE Data
{
SFesUpdateDiPkg objFesUpdateDiPkg;
//t1 = getUTCTimeMsec() ;
bRetCode = objFesUpdateDiPkg.ParseFromArray(objRecvMsg.getDataPtr(), objRecvMsg.getDataSize());
//t2 = getUTCTimeMsec() ;
//LOGINFO("parseFesPackage:解析数字量全数据 num=%d用时=%d(ms)",objFesUpdateDiPkg.stdidata_size(),t2-t1);
if (!bRetCode)
{
LOGWARN("parseFesPackage::objFesUpdateDiPkg解析错误");
return -1;
}
m_ptrPacketQueue->addFesUpdateDigPkg(objFesUpdateDiPkg);
break;
}
case MT_FES_AI_CHANGE://AI Change Data
{
SFesChangeAiPkg objFesChanageAiPkg;
bRetCode = objFesChanageAiPkg.ParseFromArray(objRecvMsg.getDataPtr(), objRecvMsg.getDataSize());
if (!bRetCode)
{
LOGWARN("parseFesPackage::objFesChanageAiPkg解析错误");
return -1;
}
m_ptrPacketQueue->addFesChangeAnaPkg(objFesChanageAiPkg);
break;
}
case MT_FES_AI_UPDATE://AI UPDATE Data
{
SFesUpdateAiPkg objFesUpdateAiPkg;
bRetCode = objFesUpdateAiPkg.ParseFromArray(objRecvMsg.getDataPtr(), objRecvMsg.getDataSize());
if (!bRetCode)
{
LOGWARN("parseFesPackage::objFesUpdateAiPkg解析错误");
return -1;
}
m_ptrPacketQueue->addFesUpdateAnaPkg(objFesUpdateAiPkg);
break;
}
case MT_FES_MI_CHANGE://MI Change Data
{
SFesChangeMiPkg objFesChanageMiPkg;
bRetCode = objFesChanageMiPkg.ParseFromArray(objRecvMsg.getDataPtr(), objRecvMsg.getDataSize());
if (!bRetCode)
{
LOGWARN("parseFesPackage::objFesChanageMiPkg解析错误");
return -1;
}
m_ptrPacketQueue->addFesChangeMixPkg(objFesChanageMiPkg);
break;
}
case MT_FES_MI_UPDATE://MI UPDATE Data
{
SFesUpdateMiPkg objFesUpdateMiPkg;
bRetCode = objFesUpdateMiPkg.ParseFromArray(objRecvMsg.getDataPtr(), objRecvMsg.getDataSize());
if (!bRetCode)
{
LOGWARN("parseFesPackage::objFesUpdateMiPkg解析错误");
return -1;
}
m_ptrPacketQueue->addFesUpdateMixPkg(objFesUpdateMiPkg);
break;
}
case MT_FES_PI_CHANGE://PI Change Data
{
SFesChangePiPkg objFesChangePiPkg;
bRetCode = objFesChangePiPkg.ParseFromArray(objRecvMsg.getDataPtr(), objRecvMsg.getDataSize());
if (!bRetCode)
{
LOGWARN("parseFesPackage::objFesChangePiPkg解析错误");
return -1;
}
m_ptrPacketQueue->addFesChangeAccPkg(objFesChangePiPkg);
break;
}
case MT_FES_PI_UPDATE://PI UPDATE Data
{
SFesUpdatePiPkg objFesUpdatePiPkg;
bRetCode = objFesUpdatePiPkg.ParseFromArray(objRecvMsg.getDataPtr(), objRecvMsg.getDataSize());
if (!bRetCode)
{
LOGWARN("parseFesPackage::objFesUpdatePiPkg解析错误");
return -1;
}
m_ptrPacketQueue->addFesUpdateAccPkg(objFesUpdatePiPkg);
break;
}
case MT_FES_SOE_EVENT: //SOE事件信息
{
SFesSoeEventPkg objFesSoeEventPkg;
bRetCode = objFesSoeEventPkg.ParseFromArray(objRecvMsg.getDataPtr(), objRecvMsg.getDataSize());
if (!bRetCode)
{
LOGWARN("parseFesPackage::objFesSoeEventPkg解析错误");
return -1;
}
m_ptrPacketQueue->addFesSoeEventPkg(objFesSoeEventPkg);
break;
}
default:
{
LOGWARN("parseFesPackage::MsgType = %d 消息类型不支持!", nMessageType);
return -1;
}
}// end switch
return 1;
}

View File

@ -4,8 +4,6 @@
#include "FesBase.h"
#include "net/net_msg_bus_api/MsgBusApi.h"
#include "FesMessage.pb.h"
#include "PacketQueue.h"
#include <queue>
using namespace iot_net;
using namespace iot_idl;
@ -13,7 +11,7 @@ using namespace iot_idl;
class CFesRxFesDataThread : public iot_public::CTimerThreadBase
{
public:
CFesRxFesDataThread(int iDomainID, int iAppID, void* BaseDataAddr, CPacketQueuePtr ptrPacketQueue);
CFesRxFesDataThread(int iDomainID, int iAppID, void* BaseDataAddr);
virtual ~CFesRxFesDataThread();
/*
@ -44,12 +42,15 @@ private:
CFesBase *m_ptrCFesBase;
bool readFromBus();
CPacketQueuePtr m_ptrPacketQueue; //消息缓存类
int parseFesPackage(const iot_net::CMbMessage &objRecvMsg);
void RxDiChangeData(const iot_idl::SFesChangeDiPkg &stChangeDiPkg);
void RxAiChangeData(const iot_idl::SFesChangeAiPkg &stChangeAiPkg);
void RxAccChangeData(const iot_idl::SFesChangePiPkg &stChangeAccPkg);
void RxMiChangeData(const iot_idl::SFesChangeMiPkg &stChangeMiPkg);
void RxDiUpdataData(const SFesUpdateDiPkg &UpdateDiPkg);
void RxAiUpdataData(const SFesUpdateAiPkg &UpdateAiPkg);
void RxAccUpdataData(const SFesUpdatePiPkg &UpdateAccPkg);
void RxMiUpdataData(const SFesUpdateMiPkg &UpdateMiPkg);
void RxSOEData(const SFesSoeEventPkg &SOEPkg);
};

View File

@ -404,7 +404,7 @@ int CFesSimServerThread::RxData(unsigned char *Data,int MaxLen)
TcpClose(m_AcceptSocket);
m_AcceptSocket = SOCKET_ERROR;
}
if (FD_ISSET(m_AcceptSocket, &fdSet))
if (SOCKET_ERROR != m_AcceptSocket && INVALID_SOCKET != m_AcceptSocket && FD_ISSET(m_AcceptSocket, &fdSet))
{
len = ::recv(m_AcceptSocket , (char *)Data , MaxLen , 0);
if (len > 0)
@ -1796,6 +1796,7 @@ int CFesSimServerThread::AccDataResp(unsigned char *Data,int FrameNo)
SFesAcc *pAcc;
int writex,count,structLen,maxCount,RtuNo;
int i,StartIndex,EndIndex;
unsigned char* pTemp;
if(m_ptrCFesBase==NULL)
return 0;
@ -1886,14 +1887,23 @@ int CFesSimServerThread::AccDataResp(unsigned char *Data,int FrameNo)
Data[writex++] = (pAcc->PointNo>>8)&0xff;
Data[writex++] = (pAcc->PointNo>>16)&0xff;
Data[writex++] = (pAcc->PointNo>>24)&0xff;
Data[writex++]=pAcc->Value&0xff;
Data[writex++]=(pAcc->Value>>8)&0xff;
Data[writex++]=(pAcc->Value>>16)&0xff;
Data[writex++]=(pAcc->Value>>24)&0xff;
Data[writex++]=(pAcc->Value>>32)&0xff;
Data[writex++]=(pAcc->Value>>40)&0xff;
Data[writex++]=(pAcc->Value>>48)&0xff;
Data[writex++]=(pAcc->Value>>56)&0xff;
// Data[writex++]=pAcc->Value&0xff;
// Data[writex++]=(pAcc->Value>>8)&0xff;
// Data[writex++]=(pAcc->Value>>16)&0xff;
// Data[writex++]=(pAcc->Value>>24)&0xff;
// Data[writex++]=(pAcc->Value>>32)&0xff;
// Data[writex++]=(pAcc->Value>>40)&0xff;
// Data[writex++]=(pAcc->Value>>48)&0xff;
// Data[writex++]=(pAcc->Value>>56)&0xff;
pTemp = (unsigned char*)&pAcc->Value;
Data[writex++]=*pTemp;
Data[writex++]=*(pTemp+1);
Data[writex++]=*(pTemp+2);
Data[writex++]=*(pTemp+3);
Data[writex++]=*(pTemp+4);
Data[writex++]=*(pTemp+5);
Data[writex++]=*(pTemp+6);
Data[writex++]=*(pTemp+7);
Data[writex++]=pAcc->Status&0xff;
Data[writex++]=(pAcc->Status>>8)&0xff;
Data[writex++]=(pAcc->Status>>16)&0xff;
@ -2869,7 +2879,7 @@ void CFesSimServerThread::SimAiSetValue()
{
AiValue.PointNo=m_SimAi.PointNo;
AiValue.Status=CN_FesValueUpdate;
AiValue.Value=rand()%10000;
AiValue.Value = static_cast<float>(rand()%10000);
AiValue.time = getUTCTimeMsec();
ChgAiValue.Status = AiValue.Status;
//ChgAiValue.Value = AiValue.Value;
@ -2908,7 +2918,7 @@ void CFesSimServerThread::SimAiSetValue()
if((pAi=pRtu->GetAiByPointNo(i))!=NULL)
{
AiValue.PointNo = i;
AiValue.Value=rand()%10000;
AiValue.Value = static_cast<float>(rand()%10000);
//ChgAiValue.Value = AiValue.Value;
memcpy(ChgAiValue.TableName,pAi->TableName,CN_FesMaxTableNameSize);
memcpy(ChgAiValue.ColumnName,pAi->ColumnName,CN_FesMaxColumnNameSize);
@ -2946,7 +2956,7 @@ void CFesSimServerThread::SimAiSetValue()
if((pAi=pRtu->GetAiByPointNo(j))!=NULL)
{
AiValue.PointNo = j;
AiValue.Value=rand()%10000;
AiValue.Value= static_cast<float>(rand()%10000);
//ChgAiValue.Value = AiValue.Value;
memcpy(ChgAiValue.TableName,pAi->TableName,CN_FesMaxTableNameSize);
memcpy(ChgAiValue.ColumnName,pAi->ColumnName,CN_FesMaxColumnNameSize);
@ -3540,30 +3550,55 @@ int CFesSimServerThread::SimAccStartResp(unsigned char *Data,int /*FrameNo*/)
m_SimAcc.Period |= (short)m_RecvBuf[readx++]<<8;
m_SimAccLastmSec = getMonotonicMsec();
m_SimAcc.SetValue = (uint64)m_RecvBuf[readx++];
m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<8;
m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<16;
m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<24;
m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<32;
m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<40;
m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<48;
m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<56;
// m_SimAcc.SetValue = (uint64)m_RecvBuf[readx++];
// m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<8;
// m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<16;
// m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<24;
// m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<32;
// m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<40;
// m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<48;
// m_SimAcc.SetValue |= (uint64)m_RecvBuf[readx++]<<56;
unsigned char *pTemp= (unsigned char*)&m_SimAcc.SetValue;
*pTemp = m_RecvBuf[readx++];
*(pTemp+1) = m_RecvBuf[readx++];
*(pTemp+2) = m_RecvBuf[readx++];
*(pTemp+3) = m_RecvBuf[readx++];
*(pTemp+4) = m_RecvBuf[readx++];
*(pTemp+5) = m_RecvBuf[readx++];
*(pTemp+6) = m_RecvBuf[readx++];
*(pTemp+7) = m_RecvBuf[readx++];
m_SimAcc.Status = (uint32)m_RecvBuf[readx++];
m_SimAcc.Status |= (uint32)m_RecvBuf[readx++]<<8;
m_SimAcc.Status |= (uint32)m_RecvBuf[readx++]<<16;
m_SimAcc.Status |= (uint32)m_RecvBuf[readx++]<<24;
m_SimAcc.MinValue = (int)m_RecvBuf[readx++];
m_SimAcc.MinValue |= (int)m_RecvBuf[readx++]<<8;
m_SimAcc.MinValue |= (int)m_RecvBuf[readx++]<<16;
m_SimAcc.MinValue |= (int)m_RecvBuf[readx++]<<24;
m_SimAcc.MaxValue = (int)m_RecvBuf[readx++];
m_SimAcc.MaxValue |= (int)m_RecvBuf[readx++]<<8;
m_SimAcc.MaxValue |= (int)m_RecvBuf[readx++]<<16;
m_SimAcc.MaxValue |= (int)m_RecvBuf[readx++]<<24;
m_SimAcc.StepValue = (int)m_RecvBuf[readx++];
m_SimAcc.StepValue |= (int)m_RecvBuf[readx++]<<8;
m_SimAcc.StepValue |= (int)m_RecvBuf[readx++]<<16;
m_SimAcc.StepValue |= (int)m_RecvBuf[readx++]<<24;
// m_SimAcc.MinValue = (int)m_RecvBuf[readx++];
// m_SimAcc.MinValue |= (int)m_RecvBuf[readx++]<<8;
// m_SimAcc.MinValue |= (int)m_RecvBuf[readx++]<<16;
// m_SimAcc.MinValue |= (int)m_RecvBuf[readx++]<<24;
// m_SimAcc.MaxValue = (int)m_RecvBuf[readx++];
// m_SimAcc.MaxValue |= (int)m_RecvBuf[readx++]<<8;
// m_SimAcc.MaxValue |= (int)m_RecvBuf[readx++]<<16;
// m_SimAcc.MaxValue |= (int)m_RecvBuf[readx++]<<24;
// m_SimAcc.StepValue = (int)m_RecvBuf[readx++];
// m_SimAcc.StepValue |= (int)m_RecvBuf[readx++]<<8;
// m_SimAcc.StepValue |= (int)m_RecvBuf[readx++]<<16;
// m_SimAcc.StepValue |= (int)m_RecvBuf[readx++]<<24;
pTemp = (unsigned char*)&m_SimAcc.MinValue;
*pTemp = m_RecvBuf[readx++];
*(pTemp+1) = m_RecvBuf[readx++];
*(pTemp+2) = m_RecvBuf[readx++];
*(pTemp+3) = m_RecvBuf[readx++];
pTemp = (unsigned char*)&m_SimAcc.MaxValue;
*pTemp = m_RecvBuf[readx++];
*(pTemp+1) = m_RecvBuf[readx++];
*(pTemp+2) = m_RecvBuf[readx++];
*(pTemp+3) = m_RecvBuf[readx++];
pTemp = (unsigned char*)&m_SimAcc.StepValue;
*pTemp = m_RecvBuf[readx++];
*(pTemp+1) = m_RecvBuf[readx++];
*(pTemp+2) = m_RecvBuf[readx++];
*(pTemp+3) = m_RecvBuf[readx++];
m_SimAcc.RtuNo = (int)m_RecvBuf[readx++];
@ -3579,7 +3614,8 @@ int CFesSimServerThread::SimAccStartResp(unsigned char *Data,int /*FrameNo*/)
m_SimAccStart = 1;
m_SimAccChangeCountReset = m_SimAcc.Period*1000/50; //50ms polling;
m_SimAccChangeCount = 0;
m_SimAccValue = m_SimAcc.MinValue;
//m_SimAccValue = m_SimAcc.MinValue;
m_SimAccValue = (double)m_SimAcc.MinValue;
m_SimAccValueSigned = 1;
Data[6] = CN_SFesSimAccStartResp; //命令码
@ -6828,6 +6864,7 @@ int CFesSimServerThread::FwAccDataResp(unsigned char *Data, int FrameNo)
SFesFwAcc *pFwAcc;
int writex, count, structLen, maxCount, RtuNo;
int i, StartIndex, EndIndex;
unsigned char* pTemp;
if (m_ptrCFesBase == NULL)
return 0;
@ -6916,14 +6953,23 @@ int CFesSimServerThread::FwAccDataResp(unsigned char *Data, int FrameNo)
Data[writex++] = (pFwAcc->RemoteNo >> 8) & 0xff;
Data[writex++] = (pFwAcc->RemoteNo >> 16) & 0xff;
Data[writex++] = (pFwAcc->RemoteNo >> 24) & 0xff;
Data[writex++] = pFwAcc->Value & 0xff;
Data[writex++] = (pFwAcc->Value >> 8) & 0xff;
Data[writex++] = (pFwAcc->Value >> 16) & 0xff;
Data[writex++] = (pFwAcc->Value >> 24) & 0xff;
Data[writex++] = (pFwAcc->Value >> 32) & 0xff;
Data[writex++] = (pFwAcc->Value >> 40) & 0xff;
Data[writex++] = (pFwAcc->Value >> 48) & 0xff;
Data[writex++] = (pFwAcc->Value >> 56) & 0xff;
// Data[writex++] = pFwAcc->Value & 0xff;
// Data[writex++] = (pFwAcc->Value >> 8) & 0xff;
// Data[writex++] = (pFwAcc->Value >> 16) & 0xff;
// Data[writex++] = (pFwAcc->Value >> 24) & 0xff;
// Data[writex++] = (pFwAcc->Value >> 32) & 0xff;
// Data[writex++] = (pFwAcc->Value >> 40) & 0xff;
// Data[writex++] = (pFwAcc->Value >> 48) & 0xff;
// Data[writex++] = (pFwAcc->Value >> 56) & 0xff;
pTemp = (unsigned char*)&pFwAcc->Value;
Data[writex++] = *pTemp;
Data[writex++] = *(pTemp + 1);
Data[writex++] = *(pTemp + 2);
Data[writex++] = *(pTemp + 3);
Data[writex++] = *(pTemp + 4);
Data[writex++] = *(pTemp + 5);
Data[writex++] = *(pTemp + 6);
Data[writex++] = *(pTemp + 7);
Data[writex++] = pFwAcc->Status & 0xff;
Data[writex++] = (pFwAcc->Status >> 8) & 0xff;
Data[writex++] = (pFwAcc->Status >> 16) & 0xff;
@ -7589,6 +7635,7 @@ int CFesSimServerThread::SpecifiedAccDataResp(unsigned char *Data, int FrameNo)
SFesAcc *pAcc;
int writex, count, structLen, maxCount, RtuNo;
int i;
unsigned char* pTemp;
if (m_ptrCFesBase == NULL)
return 0;
@ -7673,14 +7720,23 @@ int CFesSimServerThread::SpecifiedAccDataResp(unsigned char *Data, int FrameNo)
Data[writex++] = (pAcc->PointNo >> 8) & 0xff;
Data[writex++] = (pAcc->PointNo >> 16) & 0xff;
Data[writex++] = (pAcc->PointNo >> 24) & 0xff;
Data[writex++] = pAcc->Value & 0xff;
Data[writex++] = (pAcc->Value >> 8) & 0xff;
Data[writex++] = (pAcc->Value >> 16) & 0xff;
Data[writex++] = (pAcc->Value >> 24) & 0xff;
Data[writex++] = (pAcc->Value >> 32) & 0xff;
Data[writex++] = (pAcc->Value >> 40) & 0xff;
Data[writex++] = (pAcc->Value >> 48) & 0xff;
Data[writex++] = (pAcc->Value >> 56) & 0xff;
// Data[writex++] = pAcc->Value & 0xff;
// Data[writex++] = (pAcc->Value >> 8) & 0xff;
// Data[writex++] = (pAcc->Value >> 16) & 0xff;
// Data[writex++] = (pAcc->Value >> 24) & 0xff;
// Data[writex++] = (pAcc->Value >> 32) & 0xff;
// Data[writex++] = (pAcc->Value >> 40) & 0xff;
// Data[writex++] = (pAcc->Value >> 48) & 0xff;
// Data[writex++] = (pAcc->Value >> 56) & 0xff;
pTemp = (unsigned char*)&pAcc->Value;
Data[writex++] = *pTemp;
Data[writex++] = *(pTemp + 1);
Data[writex++] = *(pTemp + 2);
Data[writex++] = *(pTemp + 3);
Data[writex++] = *(pTemp + 4);
Data[writex++] = *(pTemp + 5);
Data[writex++] = *(pTemp + 6);
Data[writex++] = *(pTemp + 7);
Data[writex++] = pAcc->Status & 0xff;
Data[writex++] = (pAcc->Status >> 8) & 0xff;
Data[writex++] = (pAcc->Status >> 16) & 0xff;

View File

@ -101,7 +101,8 @@ private:
SFesSimAccStartReq m_SimAcc;
int m_SimAccChangeCount;
int m_SimAccChangeCountReset;
int64 m_SimAccValue;
//int64 m_SimAccValue;
double m_SimAccValue;
int m_SimAccValueSigned; //增加的方向 (1)+ else(-)
int64 m_SimAccLastmSec; //2022-01-10

View File

@ -61,7 +61,7 @@ void CFesTxControlCmdThread::execute()
if(m_ptrTxCommunicator==NULL)
return;
//发送控制消息
//发送控制反馈消息
int retNum,msgType;
for (size_t i = 0; i < m_ptrCFesBase->m_vectCFesRtuPtr.size(); i++)
{
@ -203,7 +203,7 @@ void CFesTxControlCmdThread::execute()
CmdReplyPkg.set_nstatus(TxDefCmd.retStatus);
CmdReplyPkg.set_ndevid(TxDefCmd.DevId);
CmdReplyPkg.set_ndatalen(TxDefCmd.CmdNum);
int count = TxDefCmd.VecCmd.size();
int count = static_cast<int>(TxDefCmd.VecCmd.size());
for(int k=0;k<count;k++)
{
SFesCustCmdQueue *cmdQueue;

View File

@ -12,7 +12,6 @@
2021-05-25 thxiao SFesSoeStrEvent
2021-06-04 thxiao ChanEventResp()base结构m_ChanEventBuf发出
2021-06-07 thxiao getUTCTimeMsec()getMonotonicMsec()
2023-11-25 thxiao MiChangeResp()SFesChangeDiPkg变为SFesChangeMiPkg
*/
#include "FesTxDataChangeThread.h"
@ -464,7 +463,7 @@ int CFesTxDataChangeThread::DiChangeResp()
if (i >= m_ptrCFesBase->m_vectCFesRtuPtr.size())
m_ptrCFesBase->m_LastRtuIndx.iDiChgRtu = 0;
else
m_ptrCFesBase->m_LastRtuIndx.iDiChgRtu = i;
m_ptrCFesBase->m_LastRtuIndx.iDiChgRtu = static_cast<int>(i);
return iotSuccess;
}
@ -560,7 +559,7 @@ int CFesTxDataChangeThread::AiChangeResp()
if(i>=m_ptrCFesBase->m_vectCFesRtuPtr.size())
m_ptrCFesBase->m_LastRtuIndx.iAiChgRtu=0;
else
m_ptrCFesBase->m_LastRtuIndx.iAiChgRtu=i;
m_ptrCFesBase->m_LastRtuIndx.iAiChgRtu=static_cast<int>(i);
//LOGINFO("AiChangeResp end %lld",mSec);
@ -614,7 +613,7 @@ int CFesTxDataChangeThread::AccChangeResp()
pAccWithTm->set_strappcolumnname(pChgAcc->ColumnName);
pAccWithTm->set_strapptagname(pChgAcc->TagName);
pAccWithTm->set_ustatus(pChgAcc->Status);
pAccWithTm->set_nvalue(pChgAcc->Value);
pAccWithTm->set_dvalue(pChgAcc->Value);
pAccWithTm->set_ultime(pChgAcc->time);
count++;
}
@ -653,7 +652,7 @@ int CFesTxDataChangeThread::AccChangeResp()
if(i>=m_ptrCFesBase->m_vectCFesRtuPtr.size())
m_ptrCFesBase->m_LastRtuIndx.iAccChgRtu=0;
else
m_ptrCFesBase->m_LastRtuIndx.iAccChgRtu=i;
m_ptrCFesBase->m_LastRtuIndx.iAccChgRtu=static_cast<int>(i);
return iotSuccess;
}
@ -670,8 +669,8 @@ int CFesTxDataChangeThread::MiChangeResp()
int j,startIndex;
CFesRtuPtr ptrCFesRtu;
int num,retNum,count;
SFesChangeMiPkg ChgMiPkg;
SFesMiDataWithTm *pMiWithTm;
SFesChangeDiPkg ChgMiPkg;
SFesDiDataWithTm *pMiWithTm;
SFesChgMi *pChgMi;
if(m_ptrCFesBase==NULL)
@ -701,7 +700,7 @@ int CFesTxDataChangeThread::MiChangeResp()
pChgMi = m_pChgMiData+j;
if(strlen(pChgMi->TagName)<1)//TagName 内容<1表明后台配置无效不需送数据
continue;
pMiWithTm = ChgMiPkg.add_stmidata();
pMiWithTm = ChgMiPkg.add_stdidata();
pMiWithTm->set_strapptablename(pChgMi->TableName);
pMiWithTm->set_strappcolumnname(pChgMi->ColumnName);
pMiWithTm->set_strapptagname(pChgMi->TagName);
@ -747,7 +746,7 @@ int CFesTxDataChangeThread::MiChangeResp()
if(i>=m_ptrCFesBase->m_vectCFesRtuPtr.size())
m_ptrCFesBase->m_LastRtuIndx.iMiChgRtu=0;
else
m_ptrCFesBase->m_LastRtuIndx.iMiChgRtu=i;
m_ptrCFesBase->m_LastRtuIndx.iMiChgRtu=static_cast<int>(i);
return iotSuccess;
}
@ -852,7 +851,7 @@ int CFesTxDataChangeThread::SoeEventResp()
if (i >= m_ptrCFesBase->m_vectCFesRtuPtr.size())
m_ptrCFesBase->m_LastRtuIndx.iSoeEventRtu=0;
else
m_ptrCFesBase->m_LastRtuIndx.iSoeEventRtu=i;
m_ptrCFesBase->m_LastRtuIndx.iSoeEventRtu=static_cast<int>(i);
return iotSuccess;
}
@ -1132,7 +1131,7 @@ int CFesTxDataChangeThread::SoeStrEventResp()
if (i >= m_ptrCFesBase->m_vectCFesRtuPtr.size())
m_ptrCFesBase->m_LastRtuIndx.iSoeStrEventRtu = 0;
else
m_ptrCFesBase->m_LastRtuIndx.iSoeStrEventRtu = i;
m_ptrCFesBase->m_LastRtuIndx.iSoeStrEventRtu = static_cast<int>(i);
return iotSuccess;
}

View File

@ -99,7 +99,7 @@ std::set<std::string> FesWaveRecord::getDevGroupTagList(CFesRtuPtr rtuPtr,int fe
retNum = rtuPtr->GetDiPointNoByDevId(fesDevId, VetPointNo);
std::set<string> devGroupList;
SFesDi* pFesDi;
int diCount = VetPointNo.size();
int diCount = static_cast<int>(VetPointNo.size());
string pointTagName;
string devGroupTag;
for (int i = 0; i < diCount; i++)
@ -165,8 +165,7 @@ bool FesWaveCfgFile::openFile(std::string& file)
m_startTime = 0;
m_endTime = 0;
CFileUtil fu;
std::string dataPath = fu.getCurModuleDir();
std::string dataPath = CFileUtil::getCurModuleDir();
//file path
filesystem::path fpath = dataPath;

View File

@ -19,20 +19,16 @@ SOURCES += main.cpp \
FesChan.cpp \
FesRedundantManage.cpp \
FesRtu.cpp \
FesSimServerThread.cpp \
FesWaveFormThread.cpp \
FesDataPublish.cpp \
FesForwardConfig.cpp \
FesRxFesDataThread.cpp \
FesRxDPDataThread.cpp \
FesFwRxControlCmdThread.cpp \
FesRxFesDataThread.cpp \
FesRxDPDataThread.cpp \
FesFwRxControlCmdThread.cpp \
FesFwTxControlCmdThread.cpp \
FesWaveRecord.cpp \
AnaWorkThread.cpp \
DigWorkThread.cpp \
AccWorkThread.cpp \
MixWorkThread.cpp \
PacketQueue.cpp
DebugThread.cpp \
DebugMbCommunicator.cpp
HEADERS += \
FesApp.h \
@ -51,28 +47,26 @@ HEADERS += \
../include/FesRdbStruct.h \
FesChanManageThread.h \
FesRedundantManage.h \
FesSimServerThread.h \
FesWaveFormThread.h \
FesDataPublish.h \
FesForwardConfig.h \
FesRxFesDataThread.h \
FesRxDPDataThread.h \
FesFwRxControlCmdThread.h \
FesFwTxControlCmdThread.h \
FesRxFesDataThread.h \
FesRxDPDataThread.h \
FesFwRxControlCmdThread.h \
FesFwTxControlCmdThread.h \
../../idl_files/FesMessage.pb.h \
../../idl_files/FesDataMessage.pb.h \
../../idl_files/FesFwMessage.pb.h \
FesWaveRecord.h \
AnaWorkThread.h \
DigWorkThread.h \
AccWorkThread.h \
MixWorkThread.h \
PacketQueue.h
DebugThread.h \
DebugMbCommunicator.h \
DebugSimParam.h
INCLUDEPATH += ../include/
INCLUDEPATH += ../fes_idl_files/
LIBS += -lboost_system -lboost_thread -lboost_chrono -lboost_program_options -lboost_date_time -lboost_filesystem -lboost_locale -lboost_regex
LIBS += -lpub_utility_api -lpub_logger_api -lnet_msg_bus_api -lpub_sysinfo_api -llog4cplus -lsys_dog_auth_api
LIBS += -lpub_utility_api -lpub_logger_api -lnet_msg_bus_api -lpub_sysinfo_api -llog4cplus
LIBS += -lrdb_api
LIBS += -lprotobuf
LIBS += -lsys_node_mng_api
@ -80,10 +74,12 @@ LIBS += -lsys_proc_mng_api
LIBS += -lalarm_server_api
LIBS += -ldp_chg_data_api
LIBS += -lsys_file_sync_api
LIBS += -lzmq -lczmq
DEFINES += PROTOCOLBASE_API_EXPORTS
include($$PWD/../../idl_files/idl_files.pri)
include($$PWD/../fes_idl_files/fes_idl_files.pri)
#-------------------------------------------------------------------
COMMON_PRI=$$PWD/../../common.pri