[ref]同步711

This commit is contained in:
shi_jq 2025-03-13 16:20:05 +08:00
parent 622341b73e
commit 5aeaaf5548
1120 changed files with 346423 additions and 8757 deletions

View File

@ -63,3 +63,6 @@ LIBS += -L$$SRC_ROOT_PATH/../$$ISCS6000_OS$$DIR_DEBUG_RELEASE/
QMAKE_RPATHLINKDIR += $$PWD/../../platform/$$ISCS6000_OS$$DIR_DEBUG_RELEASE/
QMAKE_RPATHLINKDIR += $$SRC_ROOT_PATH/../$$ISCS6000_OS$$DIR_DEBUG_RELEASE/
TR_EXCLUDE += $$SRC_ROOT_PATH/3rd/* \
$$PWD/../../platform/src/3rd/*

View File

@ -0,0 +1,324 @@
/*
@file KBD511SInfo.cpp
@brief R80
APP加入WIFI连接后
HOSTNAME,IP,MASK,MAC,
@author thxiao
@history
*/
#include "net/net_msg_bus_api/MsgBusApi.h"
#include "common/Common.h"
#include "boost/program_options.hpp"
#include "pub_utility_api/SingleProcInstance.h"
#include "pub_utility_api/CommonConfigParse.h"
#include "net_msg_bus_api/MsgBusApi.h"
#include "pub_logger_api/logger.h"
#include "pub_utility_api/I18N.h"
#include "boost/dll/shared_library.hpp"
#include "pub_utility_api/FileUtil.h"
#include "KBD511SInfoRedundantManage.h"
#include "KBD511SInfo.h"
#define OPT_DESC_APP "app"
#define OPT_DESC_HELP "help"
#define PROCESS_NAME_CMD_PROCESS "KBD511SInfo"
using namespace std;
using namespace iot_sys;
using namespace iot_public;
bool g_IsMainKBD511SInfo =false;
bool g_IsMainKBD511SInfoOld=false;
CKBD511SInfo::CKBD511SInfo()
{
//iot_public::initI18N("/fes/translate", "fes");
m_ptrProcManage = NULL;
m_ptrReduSwitchManage = NULL;
m_ptrRedundantMng = NULL;
}
CKBD511SInfo::~CKBD511SInfo()
{
stop();
}
/*
@brief boost
@return truefalse
*/
bool CKBD511SInfo::parseCommandLine(int argc, char *argv[])
{
for (int i = 1; i < argc; ++i)
{
if (i != 1)
{
m_strStartArgs += " ";
}
m_strStartArgs += argv[i];
}
namespace po = boost::program_options;
po::options_description desc("usage");
po::variables_map vm;
try
{
desc.add_options()
(OPT_DESC_APP",a", po::value<std::string>()->required(), "app name")
(OPT_DESC_HELP",h", "\t""帮助");
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if(vm.count(OPT_DESC_HELP))
{
std::cout << desc << std::endl;
return false;
}
m_strAppLabel = vm[OPT_DESC_APP].as<std::string>();
}
catch (std::exception &ex)
{
std::cerr << ex.what() << std::endl;
std::cout << desc << endl;
return false;
}
catch (...)
{
std::cerr << "未知错误" << std::endl;
std::cout << desc << std::endl;
return false;
}
return true;
}
bool CKBD511SInfo::isAlreadyRunning()
{
m_strInstName = PROCESS_NAME_CMD_PROCESS;
m_strInstName += " -s " + m_strAppLabel;
return iot_public::CSingleProcInstance::hasInstanceRunning(m_strInstName);
}
/*
@brief
@return truefalse
*/
bool CKBD511SInfo::start(int argc, char *argv[], int &/*nStatus*/)
{
string strProcessName = "KBD511SInfo";//进程名,固定为"KBD511SInfo"
//1、解析系统启动进程传入的参数具体为"应用名"
//================================================================================
if(!parseCommandLine(argc, argv))//获取应用名
{
LOGERROR("CKBD511SInfo::start(), Get application name fail!\n");
return false;
}
//2、日志系统初始
//================================================================================
StartLogSystem(m_strAppLabel.c_str(),strProcessName.c_str() );
LOGDEBUG("CKBD511SInfo::start(), Get application name ok!\n");
if(isAlreadyRunning())
{
LOGERROR("ICKBD511SInfo::start(), Inst isAlreadyRunning, fail!\n");
return false;
}
LOGDEBUG("ICKBD511SInfo::start(), Inst isAlreadyRunning, ok!\n");
//3、获取进程相关参数包括应用名进程名,节点信息等
//================================================================================
//SRunAppInfo stRunAppInfo;
CSysInfoInterfacePtr sysInfoPtr;
if(createSysInfoInstance(sysInfoPtr) == false)
{
LOGERROR("InstName=%s ,CKBD511SInfo::start(), createSysInfoInstance fail!\n", m_strInstName.c_str());
return false;
}
if(sysInfoPtr == NULL)
{
LOGERROR("InstName=%s ,CKBD511SInfo::start(), Get System Info fail!\n", m_strInstName.c_str());
return false;
}
sysInfoPtr->getLocalRunAppInfoByName(m_strAppLabel,m_stRunAppInfo);
m_ProcessInfo.nAppId = m_stRunAppInfo.nAppId;
m_ProcessInfo.nDomainId = m_stRunAppInfo.nDomainId;
m_ProcessInfo.strNodeName = m_stRunAppInfo.strLocalNodeName;
m_ProcessInfo.strProcName = strProcessName;
m_ProcessInfo.strProcParam = m_strStartArgs;
//4、进程注册消息总线注册实时库注册等
//================================================================================
m_ptrProcManage = getProcMngInstance(m_ProcessInfo);//进程注册
if(m_ptrProcManage== NULL)
{
LOGERROR("InstName=%s ,CKBD511SInfo::start(), getProcMngInstance fail!\n", m_strInstName.c_str());
return false;
}
m_ptrProcManage->setCallback(this);
//5、WINSOCK注册
//================================================================================
InitWinsock();
//读取系统配置文件
ReadConfigParam();
//8、业务线程初始化
//================================================================================
InitThread();
//9、创建主备用管理实例
//================================================================================
m_ptrReduSwitchManage = boost::make_shared<CKBD511SInfoRedundantManage>(m_ptrProcManage);//
if (m_ptrReduSwitchManage == NULL)
{
LOGERROR("InstName=%s ,CKBD511SInfo::start(), Start digital data process thread fail!\n", m_strInstName.c_str());
return false;
}
//初始化冗余切换管理模块的数据
SRedundantManageThreadParam Param;
Param.ptrKBD511SInfoDataThread = m_ptrKBD511SInfoDataThread;
/******转发相关线程*************************************************/
m_ptrReduSwitchManage->Init(Param);
m_ptrRedundantMng = getRedundantMngInstance(m_ProcessInfo.nDomainId,m_ProcessInfo.nAppId,m_ProcessInfo.strNodeName);
if(m_ptrRedundantMng == NULL)
{
LOGERROR("InstName=%s ,CKBD511SInfo::start(), get RedundantMngInstance fail!\n", m_strInstName.c_str());
return false;
}
m_ptrRedundantMng->setCallback(m_ptrReduSwitchManage);
m_ptrProcManage->updateProcessInfo(true,false,false);
return true;
}
/*
* @brief stop()
* @return
*/
bool CKBD511SInfo::stop()
{
/* @brief 进行进程退出前的资源清理 */
if (m_ptrRedundantMng != NULL)
{
m_ptrRedundantMng->unsetCallback();
m_ptrRedundantMng.reset();
}
m_ptrReduSwitchManage.reset();
//8、业务线程停止
//================================================================================
LOGDEBUG("StopThread().......... start.");
StopThread();
LOGDEBUG("StopThread().......... end.");
//5、WINSOCK注消
//================================================================================
//4、关闭日志系统
//================================================================================
LOGDEBUG("StopLogSystem().......... start.");
StopLogSystem();
return true;
}
/*
@brief 退service::shutdown()
@return
*/
int CKBD511SInfo::toQuit()
{
shutdown();
return iotSuccess;
}
/**
* @brief CKBD511SInfo::InitThread
* 线线线
*/
bool CKBD511SInfo::InitThread()
{
m_ptrKBD511SInfoDataThread = boost::make_shared<CKBD511SInfoDataThread>();
if (m_ptrKBD511SInfoDataThread == NULL)
{
LOGERROR("m_ptrKBD511SInfoDataThread 创建失败");
return false;
}
m_ptrKBD511SInfoDataThread->resume();
LOGINFO("InitThread() 创建成功!");
return true;
}
/**
* @brief CKBD511SInfo::StopThread
*/
void CKBD511SInfo::StopThread()
{
if (m_ptrKBD511SInfoDataThread != NULL)
{
m_ptrKBD511SInfoDataThread->quit();
m_ptrKBD511SInfoDataThread.reset();
LOGDEBUG("CKBD511SInfo::StopThread m_ptrKBD511SInfoDataThread");
}
}
/**
* @brief CKBD511SInfo::InitWinsock
*
* Windows系统下网络库初始化
* @return
*/
bool CKBD511SInfo::InitWinsock()
{
#ifdef WIN32
WSADATA wsdata;
WORD wVersion = MAKEWORD(2, 2);
if ((WSAStartup(wVersion, &wsdata)) != 0)
{
LOGERROR("WSAStartup() ERROR, errno:%d ", WSAGetLastError());
return false;
}
return true;
#else
return true;
#endif
}
/**
* @brief CKBD511SInfo::ReadConfigParam
* FESSYS配置文件
* @return iotSuccessiotFailed
*/
int CKBD511SInfo::ReadConfigParam()
{
return iotSuccess;
}

View File

@ -0,0 +1,71 @@
#pragma once
#include "pub_utility_api/BaseService.h"
#include "sys_proc_mng_api/ProcMngInterface.h"
#include "sys_node_mng_api/NodeMngInterface.h"
#include "pub_sysinfo_api/SysInfoApi.h"
#include "KBD511SInfoRedundantManage.h"
#include "FesDef.h"
#include "KBD511SInfoDataThread.h"
class CKBD511SInfo:public iot_public::CBaseService,iot_sys::CProcessQuitInterface
{
public:
CKBD511SInfo();
~CKBD511SInfo();
/*
@brief CMsgQueueBuffer;
@return
*/
bool parseCommandLine(int argc, char* argv[]);
/*
@brief
@return
*/
bool isAlreadyRunning();
virtual bool start(int argc, char *argv[], int &nStatus);
/*
@brief main()true
@return truefalse
*/
virtual bool stop();
/*
@brief 退service::shutdown()
@return
*/
virtual int toQuit();
private:
std::string m_strAppLabel; //应用名: pscada\bus....
std::string m_strInstName; //实例名: 进程名+"-s"+应用名。进程名固定为"fes"
std::string m_strStartArgs;
iot_sys::SProcessInfoKey m_ProcessInfo;//进程信息
iot_public::SRunAppInfo m_stRunAppInfo;
iot_sys::CProcMngInterfacePtr m_ptrProcManage;
iot_sys::CRedundantMngInterfacePtr m_ptrRedundantMng;
CKBD511SInfoRedundantManagePtr m_ptrReduSwitchManage;
CKBD511SInfoDataThreadPtr m_ptrKBD511SInfoDataThread;
bool InitWinsock();
/**
* @brief CKBD511SInfo::InitThread
* 线线线
*/
bool InitThread();
void StopThread();
void Restart();
int ReadConfigParam();
};

View File

@ -0,0 +1,40 @@
QT -= core gui
CONFIG -= qt
TEMPLATE = app
TARGET = KBD511SInfo
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp \
KBD511SInfo.cpp \
KBD511SInfoRedundantManage.cpp \
KBD511SInfoDataThread.cpp
HEADERS += \
KBD511SInfo.h \
KBD511SInfoRedundantManage.h \
KBD511SInfoDataThread.h
INCLUDEPATH += ../include/
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
LIBS += -lrdb_api
LIBS += -lprotobuf
LIBS += -lsys_node_mng_api
LIBS += -lsys_proc_mng_api
DEFINES += PROTOCOLBASE_API_EXPORTS
include($$PWD/../../idl_files/idl_files.pri)
#-------------------------------------------------------------------
COMMON_PRI=$$PWD/../../common.pri
exists($$COMMON_PRI) {
include($$COMMON_PRI)
}else {
error("FATAL error: can not find common.pri")
}

View File

@ -0,0 +1,519 @@
/*
@file KBD511SInfoDataThread.cpp
@brief APP加入WIFI连接后
WIN10上调试
@author thxiao
*/
#ifdef OS_WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <ws2tcpip.h>
#include <windows.h>
#include <winsock2.h>
#include <Iphlpapi.h>
#include <iostream>
using namespace std;
#pragma comment(lib,"ws2_32.lib")
#pragma comment(lib,"Iphlpapi.lib") //需要添加Iphlpapi.lib库
#else
#include <net/if.h>
#endif
#include "KBD511SInfoDataThread.h"
using namespace iot_public;
char g_KBD511SInfoMultIpAddr[] = "239.0.0.11"; //组播地址
const int g_KBD511SInfoSendPort = 6664; //组播信息发送的端口号
const int g_KBD511SInfoRcvPort = 6662; //组播信息接收的端口号
CKBD511SInfoDataThread::CKBD511SInfoDataThread():
CTimerThreadBase("KBD511SInfoDataThread",100)
{
memset(m_HostName, 0, CN_KBD511SInfoEthDescMaxSize);
memset(&m_LocalEthInfo[0], 0, CN_KBD511SInfoEthMaxNum * sizeof(SKBD511SInfoETH));
memset(&m_defaultGW, 0, CN_KBD511SInfoEthDescMaxSize);
m_LocalEthNum = 0;
m_Socket = INVALID_SOCKET;
}
CKBD511SInfoDataThread::~CKBD511SInfoDataThread()
{
}
/**
* @brief CKBD511SInfoDataThread::beforeExecute
* 线
*/
int CKBD511SInfoDataThread::beforeExecute()
{
ReadInfo();
SocketInit();
return iotSuccess;
}
/*
@brief CKBD511SInfoDataThread::execute
线
*/
void CKBD511SInfoDataThread::execute()
{
RecvNetData();
return;
}
/*
@brief execute函数后的处理
*/
void CKBD511SInfoDataThread::afterExecute()
{
}
/*
@brief
*/
void CKBD511SInfoDataThread::ReadInfo()
{
#ifdef OS_WINDOWS
winGetHostname(m_HostName); //读出本机的机器名
winGeEthParam(); //获取本机网口参数信息ip地址、掩码、MAC
#else
gethostname(m_HostName, sizeof(m_HostName)); //读出本机配置的机器名
//获取本机网卡信息
memset(&m_LocalEthInfo[0], 0, CN_KBD511SInfoEthMaxNum * sizeof(SKBD511SInfoETH));
m_LocalEthNum = 0;
KBD511S_GetEthParam("eth", 2); //获取有线网口参数
KBD511S_GetEthParam("wlan", 1); //获取WIFI参数
#endif
LOGDEBUG("HostName=%s", m_HostName);
}
/*
* @brief CKBD511SInfoDataThread::ExeCmmdScript
*
*/
bool CKBD511SInfoDataThread::ExeCmmdScript(char *cmdStr, char *retCmdInfo, int infoLen)
{
bool ret = false;
if ((cmdStr == NULL) || (retCmdInfo == NULL))
return ret;
retCmdInfo[0] = '\0';
#ifndef OS_WINDOWS
FILE *fp;
LOGDEBUG("%s ",cmdStr);
if ((fp = popen(cmdStr, "r")) == NULL)
{
LOGDEBUG("%s exe error!", cmdStr);
exit(1);//退出当前shell
return ret;
}
ret = fread(retCmdInfo, sizeof(char), infoLen, fp);
LOGDEBUG("%s",retCmdInfo);
pclose(fp);
#endif
return ret;
}
//获取网口参数
void CKBD511SInfoDataThread::KBD511S_GetEthParam(char* ethName, int ethNum)
{
int i, ethFlag;
char buf[4096], cmd[128];
char *spli_1;
for (i = 0; i<ethNum; i++)
{
ethFlag = 0;
memset(&m_LocalEthInfo[m_LocalEthNum], 0, sizeof(SKBD511SInfoETH));
//IP
memset(cmd, 0, sizeof(cmd));
sprintf(cmd, "ifconfig %s%d |grep inet | awk '{print $2}'", ethName, i);
memset(buf, 0, sizeof(buf));
if (ExeCmmdScript(cmd, buf, sizeof(buf) - 1))
{
ethFlag = 1;
spli_1 = strtok(buf, "\n");
if (spli_1 != NULL)
strcpy(m_LocalEthInfo[m_LocalEthNum].IpAddr, spli_1);
else
strcpy(m_LocalEthInfo[m_LocalEthNum].IpAddr, buf);
//掩码
memset(cmd, 0, sizeof(cmd));
sprintf(cmd, "ifconfig %s%d |grep inet | awk '{print $4}'", ethName, i);
memset(buf, 0, sizeof(buf));
if (ExeCmmdScript(cmd, buf, sizeof(buf) - 1))
{
spli_1 = strtok(buf, "\n");
if (spli_1 != NULL)
strcpy(m_LocalEthInfo[m_LocalEthNum].Mask, spli_1);
else
strcpy(m_LocalEthInfo[m_LocalEthNum].Mask, buf);
}
//广播地址
memset(cmd, 0, sizeof(cmd));
sprintf(cmd, "ifconfig %s%d |grep inet | awk '{print $6}'", ethName, i);
memset(buf, 0, sizeof(buf));
if (ExeCmmdScript(cmd, buf, sizeof(buf) - 1))
{
spli_1 = strtok(buf, "\n");
if (spli_1 != NULL)
strcpy(m_LocalEthInfo[m_LocalEthNum].Bcast, spli_1);
else
strcpy(m_LocalEthInfo[m_LocalEthNum].Bcast, buf);
}
}
//mac
memset(cmd, 0, sizeof(cmd));
sprintf(cmd, "ifconfig %s%d |grep ether | awk '{print $2}'", ethName, i);
memset(buf, 0, sizeof(buf));
if (ExeCmmdScript(cmd, buf, sizeof(buf) - 1))
{
ethFlag = 1;
spli_1 = strtok(buf, "\n");
if (spli_1 != NULL)
strcpy(m_LocalEthInfo[m_LocalEthNum].Mac, spli_1);
else
strcpy(m_LocalEthInfo[m_LocalEthNum].Mac, buf);
}
if (ethFlag)
{
sprintf(m_LocalEthInfo[m_LocalEthNum].EthName, "%s%d", ethName, i);
m_LocalEthNum++;
}
}
}
int CKBD511SInfoDataThread::SocketInit()
{
int ret;
struct sockaddr_in localSin;
//struct ip_mreq n1;
m_Socket = (int)socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (m_Socket == INVALID_SOCKET)
{
#ifdef OS_WINDOWS
LOGERROR("unable to create socket, errno:%d ", WSAGetLastError());
#else
LOGERROR("unable to create socket, errno:%d <%s>\n", errno, strerror(errno));
#endif
return iotFailed;
}
// struct sockaddr_in local;
memset(&localSin, 0, sizeof(localSin));
localSin.sin_family = AF_INET;
localSin.sin_port = htons(g_KBD511SInfoRcvPort);
localSin.sin_addr.s_addr = htonl(INADDR_ANY);
//inet_pton(AF_INET, "0.0.0.0", &localSin.sin_addr.s_addr);
ret = ::bind(m_Socket, (struct sockaddr *)&localSin, sizeof(localSin));
if (ret == SOCKET_ERROR)
{
#ifdef OS_WINDOWS
LOGERROR("UDP bind(%d) failed, errno:%d ", m_Socket, WSAGetLastError());
#else
LOGERROR("UDP bind(%d) failed, errno:%d <%s>", m_Socket, errno, strerror(errno));
#endif
SocketClose();
return iotFailed;
}
/* //设置组播
#ifdef OS_WINDOWS
n1.imr_multiaddr.s_addr = inet_addr(g_KBD511SInfoMultIpAddr);
n1.imr_interface.s_addr = htonl(INADDR_ANY);
//inet_pton(AF_INET, g_KBD511SInfoMultIpAddr, &n1.imr_multiaddr.s_addr);
//inet_pton(AF_INET, "0.0.0.0", &n1.imr_interface.s_addr);
if(setsockopt(m_Socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&n1, sizeof(n1))<0)
#else
n1.imr_multiaddr.s_addr = inet_addr(g_KBD511SInfoMultIpAddr);
n1.imr_interface.s_addr = htonl(INADDR_ANY);
//inet_pton(AF_INET, g_KBD511SInfoMultIpAddr, &n1.imr_multiaddr.s_addr);
//inet_pton(AF_INET, "0.0.0.0", &n1.imr_address.s_addr);
//n1.imr_ifindex = if_nametoindex("eth0");
if(setsockopt(m_Socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &n1, sizeof(n1))<0)
#endif
{
LOGERROR("Usetsockopt m_Socket IP_ADD_MEMBERSHIP\n");
//return iotFailed;
}*/
//设置套接字为非阻塞模式
#ifdef OS_WINDOWS
u_long argp = 1;
if (ioctlsocket(m_Socket, FIONBIO, &argp) == SOCKET_ERROR)
#else
int flags;
flags = fcntl(m_Socket, F_GETFL, 0);
if (fcntl(m_Socket, F_SETFL, flags | O_NONBLOCK) < 0) //O_NDELAY
#endif
{
#ifdef OS_WINDOWS
LOGERROR("ioctlsocket(sock:%d) set FIONBIO error, errno:%d \n", m_Socket, WSAGetLastError());
#else
LOGERROR("fcntl(sock:%d) set O_NONBLOCK error, errno:%d <%s>\n", m_Socket, errno, strerror(errno));
#endif
return iotFailed;
}
return iotSuccess;
}
void CKBD511SInfoDataThread::SocketClose()
{
if (m_Socket != INVALID_SOCKET)
{
closesocket(m_Socket);
m_Socket = INVALID_SOCKET;
LOGDEBUG("closesocket m_Socket =%d", m_Socket);
}
}
int CKBD511SInfoDataThread::RxData(char *retData, int MaxDataLen)
{
int len, fromlen;
fd_set fdSet;
sockaddr_in fromaddr;
struct timeval tv;
char fromIP[64];
if (m_Socket == SOCKET_ERROR)
return -1;
//add 判断soket是否可读
FD_ZERO(&fdSet);
FD_SET(m_Socket, &fdSet);
tv.tv_sec = 0;
tv.tv_usec = 20 * 1000;
len = select((int)(m_Socket + 1), &fdSet, 0, 0, &tv);
if (len < 0)
{
#ifdef OS_WINDOWS
LOGWARN("select(sock+1:%d) error, errno:%d ", m_Socket + 1, WSAGetLastError());
#else
LOGWARN("select(sock+1:%d) error, errno:%d <%s>", m_Socket, errno, strerror(errno));
#endif
}
else
if (len > 0)
{
fromlen = sizeof(fromaddr);
#ifdef OS_WINDOWS
len = ::recvfrom(m_Socket, retData, MaxDataLen, 0, (struct sockaddr *)&fromaddr, &fromlen);
#else
len = ::recvfrom(m_Socket, retData, MaxDataLen, 0, (struct sockaddr *)&fromaddr, (socklen_t*)&fromlen);
#endif
if (len > 0)
{
memset(fromIP, 0, sizeof(fromIP));
strcpy(fromIP, inet_ntoa(fromaddr.sin_addr));
LOGDEBUG("Recv from %s len=%d", fromIP, len);
strcpy(g_KBD511SInfoMultIpAddr, fromIP);
}
}
return len;
}
int CKBD511SInfoDataThread::TxData(char *Data, int DataLen)
{
struct sockaddr_in client;
int ret;
ret = -1;
if (m_Socket == SOCKET_ERROR)
return ret;
memset(&client, 0, sizeof(client));
client.sin_family = AF_INET;
client.sin_port = htons(g_KBD511SInfoSendPort);
client.sin_addr.s_addr = inet_addr(g_KBD511SInfoMultIpAddr);
//inet_pton(AF_INET, g_KBD511SInfoMultIpAddr, &client.sin_addr.s_addr);
ret = sendto(m_Socket, Data, DataLen, 0, (struct sockaddr *)&client, sizeof(client));
if (ret < 0)
{
#ifdef OS_WINDOWS
LOGDEBUG("sendto(sock:%d) error, errno:%d ", m_Socket, WSAGetLastError());
#else
LOGDEBUG("sendto(sock:%d) error, errno:%d <%s>", m_Socket, errno, strerror(errno));
#endif
}
else
LOGDEBUG("sendto(%s:%d) len=%d ", g_KBD511SInfoMultIpAddr,g_KBD511SInfoSendPort,ret);
return ret;
}
//windows获取主机名
void CKBD511SInfoDataThread::winGetHostname(char* hostname)
{
#ifdef OS_WINDOWS
WCHAR PCname[255];
DWORD bufSizeP = 255;
memset(PCname, 0, 255);
GetComputerName(PCname, &bufSizeP);
bufSizeP = WideCharToMultiByte(CP_ACP,0, PCname,-1,NULL,0,NULL,NULL);
WideCharToMultiByte(CP_ACP, 0, PCname, -1, hostname, bufSizeP, NULL, NULL);
#endif
}
//windows获取网卡信息
void CKBD511SInfoDataThread::winGeEthParam()
{
#ifdef OS_WINDOWS
//PIP_ADAPTER_INFO结构体指针存储本机网卡信息
PIP_ADAPTER_INFO pIpAdapterInfo = new IP_ADAPTER_INFO();
//得到结构体大小,用于GetAdaptersInfo参数
unsigned long stSize = sizeof(IP_ADAPTER_INFO);
//调用GetAdaptersInfo函数,填充pIpAdapterInfo指针变量;其中stSize参数既是一个输入量也是一个输出量
int nRel = GetAdaptersInfo(pIpAdapterInfo, &stSize);
//记录网卡数量
int netCardNum = 0;
//记录每张网卡上的IP地址数量
//int IPnumPerNetCard = 0;
memset(&m_LocalEthInfo[0], 0, CN_KBD511SInfoEthMaxNum * sizeof(SKBD511SInfoETH));
m_LocalEthNum = 0;
if (ERROR_BUFFER_OVERFLOW == nRel)
{
//如果函数返回的是ERROR_BUFFER_OVERFLOW
//则说明GetAdaptersInfo参数传递的内存空间不够,同时其传出stSize,表示需要的空间大小
//这也是说明为什么stSize既是一个输入量也是一个输出量
//释放原来的内存空间
delete pIpAdapterInfo;
//重新申请内存空间用来存储所有网卡信息
pIpAdapterInfo = (PIP_ADAPTER_INFO)new BYTE[stSize];
//再次调用GetAdaptersInfo函数,填充pIpAdapterInfo指针变量
nRel = GetAdaptersInfo(pIpAdapterInfo, &stSize);
}
if (ERROR_SUCCESS == nRel)
{
//输出网卡信息
//可能有多网卡,因此通过循环去判断
while (pIpAdapterInfo)
{
//网卡名称
strcpy(m_LocalEthInfo[netCardNum].EthName, pIpAdapterInfo->Description);
//网卡描述
//strcpy(m_LocalEthInfo[netCardNum].EthName, pIpAdapterInfo->Description);
//网卡类型
m_LocalEthInfo[netCardNum].Type = pIpAdapterInfo->Type;
/*switch (pIpAdapterInfo->Type)
{
case MIB_IF_TYPE_OTHER:
cout << "网卡类型:" << "OTHER" << endl;
break;
case MIB_IF_TYPE_ETHERNET:
cout << "网卡类型:" << "ETHERNET" << endl;
break;
case MIB_IF_TYPE_TOKENRING:
cout << "网卡类型:" << "TOKENRING" << endl;
break;
case MIB_IF_TYPE_FDDI:
cout << "网卡类型:" << "FDDI" << endl;
break;
case MIB_IF_TYPE_PPP:
cout << "网卡类型:" << "PPP" << endl;
break;
case MIB_IF_TYPE_LOOPBACK:
cout << "网卡类型:" << "LOOPBACK" << endl;
break;
case MIB_IF_TYPE_SLIP:
cout << "网卡类型:" << "SLIP" << endl;
break;
default:
break;
}*/
//网卡MAC地址
for (unsigned int i = 0; i < pIpAdapterInfo->AddressLength; i++)
{
if (i < pIpAdapterInfo->AddressLength - 1)
sprintf(&m_LocalEthInfo[netCardNum].Mac[i*3],"%02X-", pIpAdapterInfo->Address[i]);
else
sprintf(&m_LocalEthInfo[netCardNum].Mac[i * 3],"%02X", pIpAdapterInfo->Address[i]);
}
//可能网卡有多IP,因此通过循环去判断
IP_ADDR_STRING *pIpAddrString = &(pIpAdapterInfo->IpAddressList);
/*do {
cout << "该网卡上的IP数量" << ++IPnumPerNetCard << endl;
cout << "IP 地址:" << pIpAddrString->IpAddress.String << endl;
cout << "子网地址:" << pIpAddrString->IpMask.String << endl;
cout << "网关地址:" << pIpAdapterInfo->GatewayList.IpAddress.String << endl;
pIpAddrString = pIpAddrString->Next;
} while (pIpAddrString);*/
//网卡第一个IP地址
strcpy(m_LocalEthInfo[netCardNum].IpAddr, pIpAddrString->IpAddress.String);
//掩码
strcpy(m_LocalEthInfo[netCardNum].Mask, pIpAddrString->IpMask.String);
//网关
strcpy(m_LocalEthInfo[netCardNum].Gateway, pIpAdapterInfo->GatewayList.IpAddress.String);
pIpAdapterInfo = pIpAdapterInfo->Next;
netCardNum++;
}
m_LocalEthNum = netCardNum;
}
//释放内存空间
if (pIpAdapterInfo)
delete pIpAdapterInfo;
#endif
}
void CKBD511SInfoDataThread::RecvNetData()
{
char recvBuf[100];
int maxRecvSize;
int retLen;
memset(recvBuf,0,100);
maxRecvSize = sizeof(recvBuf);
retLen = RxData(recvBuf, maxRecvSize);
if (retLen > 0)
{
LOGDEBUG("recv(%s:%d) %s ", g_KBD511SInfoMultIpAddr,g_KBD511SInfoSendPort,recvBuf);
if (strcmp(recvBuf, "APP") == 0)
RecvDataProcess();
}
}
int CKBD511SInfoDataThread::RecvDataProcess()
{
char sendData[1024];
char temStr[500];
int sendLen,ret;
LOGDEBUG("recv(%s:%d) APP sendInfo ", g_KBD511SInfoMultIpAddr,g_KBD511SInfoSendPort);
sprintf(sendData, "hostname:%s,\n", m_HostName);
for (int i = 0; i < m_LocalEthNum; i++)
{
memset(temStr, 0, 500);
sprintf(temStr, "%s IP:%s\nMAC:%s\nMask:%s,\n", m_LocalEthInfo[i].EthName, m_LocalEthInfo[i].IpAddr, m_LocalEthInfo[i].Mac, m_LocalEthInfo[i].Mask);
strcat(sendData, temStr);
}
sendLen = (int)strlen(sendData);
ret = TxData(sendData, sendLen);
return ret;
}

View File

@ -0,0 +1,73 @@
#pragma once
#include "FesDef.h"
//本机网口信息
const int CN_KBD511SInfoEthMaxNum = 8;
const int CN_KBD511SInfoEthDescMaxSize = 100;
typedef struct _SKBD511SInfoETH{
char EthName[CN_KBD511SInfoEthDescMaxSize]; //ETH名
char IpAddr[CN_KBD511SInfoEthDescMaxSize]; //IP
char Mask[CN_KBD511SInfoEthDescMaxSize]; //掩码
char Mac[CN_KBD511SInfoEthDescMaxSize]; //MAC
char Bcast[CN_KBD511SInfoEthDescMaxSize];
char Gateway[CN_KBD511SInfoEthDescMaxSize]; //网关
unsigned int Type; //网卡类型
_SKBD511SInfoETH() {
memset(EthName, 0, CN_KBD511SInfoEthDescMaxSize);
memset(IpAddr, 0, CN_KBD511SInfoEthDescMaxSize);
memset(Mask, 0, CN_KBD511SInfoEthDescMaxSize);
memset(Mac, 0, CN_KBD511SInfoEthDescMaxSize);
memset(Bcast, 0, CN_KBD511SInfoEthDescMaxSize);
memset(Gateway, 0, CN_KBD511SInfoEthDescMaxSize);
Type = 0;
}
}SKBD511SInfoETH;
class CKBD511SInfoDataThread : public iot_public::CTimerThreadBase
{
public:
CKBD511SInfoDataThread();
virtual ~CKBD511SInfoDataThread();
/*
@brief execute函数前的处理
*/
virtual int beforeExecute();
/*
@brief
*/
virtual void execute();
/*
@brief execute函数后的处理
*/
virtual void afterExecute();
private:
char m_HostName[CN_KBD511SInfoEthDescMaxSize];
SKBD511SInfoETH m_LocalEthInfo[CN_KBD511SInfoEthMaxNum];
int m_LocalEthNum;
char m_defaultGW[CN_KBD511SInfoEthDescMaxSize];
int m_Socket;
bool ExeCmmdScript(char *cmdStr, char *retCmdInfo, int infoLen);
void ReadInfo();
void SocketClose();
int RxData(char *retData, int MaxDataLen);
int TxData(char *Data, int DataLen);
void RecvNetData();
int RecvDataProcess();
int SocketInit();
void winGetHostname(char* hostname);
void winGeEthParam();
void KBD511S_GetEthParam(char* ethName, int ethNum);
};
typedef boost::shared_ptr<CKBD511SInfoDataThread> CKBD511SInfoDataThreadPtr;

View File

@ -0,0 +1,115 @@
/*
@file KBD511SInfoRedundantManage.c
@brief redundantSwitch实现
@author thxiao
@history
*/
#include "KBD511SInfoRedundantManage.h"
#include "KBD511SInfo.h"
using namespace iot_sys;
extern bool g_IsMainKBD511SInfo;
extern bool g_IsMainKBD511SInfoOld;
CKBD511SInfoRedundantManage::CKBD511SInfoRedundantManage(iot_sys::CProcMngInterfacePtr ptrProc)
{
m_ptrProcManage = ptrProc;
m_bMaster = false;
m_bSlave = false;
m_startThreadFlag = false;
}
CKBD511SInfoRedundantManage::~CKBD511SInfoRedundantManage(void)
{
}
/*
@brief
@param bool bMaster
@param bool bSlave
@return
@retval
*/
int CKBD511SInfoRedundantManage::redundantSwitch(bool bMaster, bool bSlave)
{
if (m_startThreadFlag == false)
{
m_startThreadFlag = true;
LOGINFO("bMaster = [%d] bSlave = [%d] 启动永不挂起线程", bMaster, bSlave);
//StartThread();//部分线程需要一直开启
}
if((true == bMaster) && (false == bSlave) ) //主状态,启动部分线程
{
g_IsMainKBD511SInfo = true;
LOGINFO(" bMaster=[%d] bSlave=[%d] g_IsMainKBD511SInfo = true", bMaster, bSlave);
//ResumeThread();
}
else if((false == bMaster) && (true == bSlave)) //备用状态,停止部分线程
{
g_IsMainKBD511SInfo = false;
LOGINFO(" bMaster=[%d] bSlave=[%d] g_IsMainKBD511SInfo = false", bMaster, bSlave);
//SuspendThread();
}
else
{
//在非主非备的情况下(开门狗叫),按备机方式处理
g_IsMainKBD511SInfo = false;
LOGINFO("非主非备不确定状态 bMaster=[%d] bSlave=[%d] g_IsMainKBD511SInfo = false", bMaster, bSlave);
//SuspendThread();
}
m_bMaster = bMaster;
m_bSlave = bSlave;
m_ptrProcManage->updateProcessInfo(true,m_bMaster,m_bSlave);
return iotSuccess;
}
/*
@brief
@param SRedundantManageThreadParam &Param 线
@return
@retval
*/
void CKBD511SInfoRedundantManage::Init(SRedundantManageThreadParam &Param )
{
m_ptrKBD511SInfoDataThread =Param.ptrKBD511SInfoDataThread;
}
/*
@brief FES状态下resume thread
@param
@return
@retval
*/
void CKBD511SInfoRedundantManage::ResumeThread()
{
}
/*
@brief thread
@param
@return
@retval
*/
void CKBD511SInfoRedundantManage::StartThread()
{
}
/*
@brief FES状态下suspend thread
@param CKBD511SInfoApp *pApp
@return
@retval
*/
void CKBD511SInfoRedundantManage::SuspendThread()
{
}

View File

@ -0,0 +1,73 @@
/*
@file KBD511SInfoRedundantManage.h
@brief redundantSwitch实现
@author thxiao
*/
#pragma once
#include "sys_node_mng_api/NodeMngInterface.h"
#include "sys_proc_mng_api/ProcMngInterface.h"
#include "KBD511SInfoDataThread.h"
typedef struct{
CKBD511SInfoDataThreadPtr ptrKBD511SInfoDataThread;
}SRedundantManageThreadParam;
class CKBD511SInfoRedundantManage :
public ::iot_sys::CRedundantSwitchInterface
{
public:
CKBD511SInfoRedundantManage(iot_sys::CProcMngInterfacePtr ptrProc);
~CKBD511SInfoRedundantManage(void);
/*
@brief
@param bool bMaster
@param bool bSlave
@return
@retval
*/
virtual int redundantSwitch(bool bMaster, bool bSlave);
/*
@brief
@param SRedundantManageThreadParam &Param 线
@return
@retval
*/
void Init(SRedundantManageThreadParam &Param);
/*
@brief FES状态下resume thread
@param CKBD511SInfoApp *pApp
@return
@retval
*/
void ResumeThread();
/*
@brief FES状态下suspend thread
@param CKBD511SInfoApp *pApp
@return
@retval
*/
void SuspendThread();
/*
@brief thread
@param
@return
@retval
*/
void StartThread();
private:
bool m_bMaster;
bool m_bSlave;
bool m_startThreadFlag;
iot_sys::CProcMngInterfacePtr m_ptrProcManage;
CKBD511SInfoDataThreadPtr m_ptrKBD511SInfoDataThread;
};
typedef boost::shared_ptr<CKBD511SInfoRedundantManage> CKBD511SInfoRedundantManagePtr;

View File

@ -0,0 +1,12 @@
#include <iostream>
#include "KBD511SInfo.h"
using namespace std;
int main(int argc, char *argv[])
{
CKBD511SInfo objApp;
return objApp.main(argc, argv);
}

View File

@ -3,6 +3,10 @@
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += iec61850 protocol fes fesSim
SUBDIRS += \
fes_pub \
# iec61850 \
protocol \
fes \
# fesSim

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -591,10 +591,11 @@ void FwAccMonDlg::OnRecvPiDataResp(int CmdCode,QByteArray Data,int DataLen)
return;
int readx,count;
float fvalue;
double dvalue;
unsigned char* pTemp;
count = 0;
readx = 16;
pTemp = (unsigned char*)&fvalue;
pTemp = (unsigned char*)&dvalue;
while(readx<DataLen)
{
piData.PointNo = RecvData[readx++];
@ -602,14 +603,24 @@ void FwAccMonDlg::OnRecvPiDataResp(int CmdCode,QByteArray Data,int DataLen)
piData.PointNo |= RecvData[readx++]<<16;
piData.PointNo |= RecvData[readx++]<<24;
piData.Value = (uint64)RecvData[readx++];
piData.Value |= (uint64)RecvData[readx++]<<8;
piData.Value |= (uint64)RecvData[readx++]<<16;
piData.Value |= (uint64)RecvData[readx++]<<24;
piData.Value |= (uint64)RecvData[readx++]<<32;
piData.Value |= (uint64)RecvData[readx++]<<40;
piData.Value |= (uint64)RecvData[readx++]<<48;
piData.Value |= (uint64)RecvData[readx++]<<56;
// piData.Value = (uint64)RecvData[readx++];
// piData.Value |= (uint64)RecvData[readx++]<<8;
// piData.Value |= (uint64)RecvData[readx++]<<16;
// piData.Value |= (uint64)RecvData[readx++]<<24;
// piData.Value |= (uint64)RecvData[readx++]<<32;
// piData.Value |= (uint64)RecvData[readx++]<<40;
// piData.Value |= (uint64)RecvData[readx++]<<48;
// piData.Value |= (uint64)RecvData[readx++]<<56;
pTemp = (unsigned char*)&dvalue;
*pTemp = RecvData[readx++];
*(pTemp+1) = RecvData[readx++];
*(pTemp+2) = RecvData[readx++];
*(pTemp+3) = RecvData[readx++];
*(pTemp+4) = RecvData[readx++];
*(pTemp+5) = RecvData[readx++];
*(pTemp+6) = RecvData[readx++];
*(pTemp+7) = RecvData[readx++];
piData.Value = dvalue;
piData.Status = (uint32)RecvData[readx++];
piData.Status |= (uint32)RecvData[readx++]<<8;
piData.Status |= (uint32)RecvData[readx++]<<16;

View File

@ -582,10 +582,11 @@ void PiMonDlg::OnRecvPiDataResp(int CmdCode,QByteArray Data,int DataLen)
return;
int readx,count;
float fvalue;
double dvalue;
unsigned char* pTemp;
count = 0;
readx = 16;
pTemp = (unsigned char*)&fvalue;
pTemp = (unsigned char*)&dvalue;
while(readx<DataLen)
{
piData.PointNo = RecvData[readx++];
@ -593,14 +594,24 @@ void PiMonDlg::OnRecvPiDataResp(int CmdCode,QByteArray Data,int DataLen)
piData.PointNo |= RecvData[readx++]<<16;
piData.PointNo |= RecvData[readx++]<<24;
piData.Value = (uint64)RecvData[readx++];
piData.Value |= (uint64)RecvData[readx++]<<8;
piData.Value |= (uint64)RecvData[readx++]<<16;
piData.Value |= (uint64)RecvData[readx++]<<24;
piData.Value |= (uint64)RecvData[readx++]<<32;
piData.Value |= (uint64)RecvData[readx++]<<40;
piData.Value |= (uint64)RecvData[readx++]<<48;
piData.Value |= (uint64)RecvData[readx++]<<56;
// piData.Value = (uint64)RecvData[readx++];
// piData.Value |= (uint64)RecvData[readx++]<<8;
// piData.Value |= (uint64)RecvData[readx++]<<16;
// piData.Value |= (uint64)RecvData[readx++]<<24;
// piData.Value |= (uint64)RecvData[readx++]<<32;
// piData.Value |= (uint64)RecvData[readx++]<<40;
// piData.Value |= (uint64)RecvData[readx++]<<48;
// piData.Value |= (uint64)RecvData[readx++]<<56;
*pTemp = RecvData[readx++];
*(pTemp+1) = RecvData[readx++];
*(pTemp+2) = RecvData[readx++];
*(pTemp+3) = RecvData[readx++];
*(pTemp+4) = RecvData[readx++];
*(pTemp+5) = RecvData[readx++];
*(pTemp+6) = RecvData[readx++];
*(pTemp+7) = RecvData[readx++];
piData.Value = dvalue;
piData.Status = (uint32)RecvData[readx++];
piData.Status |= (uint32)RecvData[readx++]<<8;
piData.Status |= (uint32)RecvData[readx++]<<16;

View File

@ -601,10 +601,11 @@ void SimPiDlg::OnRecvPiDataResp(int CmdCode,QByteArray Data,int DataLen)
return;
int readx,count;
float fvalue;
double dvalue;
unsigned char* pTemp;
count = 0;
readx = 16;
pTemp = (unsigned char*)&fvalue;
pTemp = (unsigned char*)&dvalue;
while(readx<DataLen)
{
piData.PointNo = RecvData[readx++];
@ -612,14 +613,24 @@ void SimPiDlg::OnRecvPiDataResp(int CmdCode,QByteArray Data,int DataLen)
piData.PointNo |= RecvData[readx++]<<16;
piData.PointNo |= RecvData[readx++]<<24;
piData.Value = (uint64)RecvData[readx++];
piData.Value |= (uint64)RecvData[readx++]<<8;
piData.Value |= (uint64)RecvData[readx++]<<16;
piData.Value |= (uint64)RecvData[readx++]<<24;
piData.Value |= (uint64)RecvData[readx++]<<32;
piData.Value |= (uint64)RecvData[readx++]<<40;
piData.Value |= (uint64)RecvData[readx++]<<48;
piData.Value |= (uint64)RecvData[readx++]<<56;
// piData.Value = (uint64)RecvData[readx++];
// piData.Value |= (uint64)RecvData[readx++]<<8;
// piData.Value |= (uint64)RecvData[readx++]<<16;
// piData.Value |= (uint64)RecvData[readx++]<<24;
// piData.Value |= (uint64)RecvData[readx++]<<32;
// piData.Value |= (uint64)RecvData[readx++]<<40;
// piData.Value |= (uint64)RecvData[readx++]<<48;
// piData.Value |= (uint64)RecvData[readx++]<<56;
pTemp = (unsigned char*)&dvalue;
*pTemp = RecvData[readx++];
*(pTemp+1) = RecvData[readx++];
*(pTemp+2) = RecvData[readx++];
*(pTemp+3) = RecvData[readx++];
*(pTemp+4) = RecvData[readx++];
*(pTemp+5) = RecvData[readx++];
*(pTemp+6) = RecvData[readx++];
*(pTemp+7) = RecvData[readx++];
piData.Value = dvalue;
piData.Status = (uint32)RecvData[readx++];
piData.Status |= (uint32)RecvData[readx++]<<8;
piData.Status |= (uint32)RecvData[readx++]<<16;
@ -755,7 +766,8 @@ void SimPiDlg::OnSetValue()
bool ok;
str = ui->ValueEdit->text();
m_PiValue = str.toLong(&ok,10);
//m_PiValue = str.toLong(&ok,10);
m_PiValue = str.toDouble(&ok);
str = ui->StatusEdit->text();
m_PiStatus = str.toInt(&ok,10);
@ -781,14 +793,24 @@ void SimPiDlg::OnSetValue()
data[writex++] = m_PiFlag;
data[writex++] = 0x00;
data[writex++] = 0x00;
data[writex++] = m_PiValue&0xff;
data[writex++] = (m_PiValue>>8)&0xff;
data[writex++] = (m_PiValue>>16)&0xff;
data[writex++] = (m_PiValue>>24)&0xff;
data[writex++] = (m_PiValue>>32)&0xff;
data[writex++] = (m_PiValue>>40)&0xff;
data[writex++] = (m_PiValue>>48)&0xff;
data[writex++] = (m_PiValue>>56)&0xff;
// data[writex++] = m_PiValue&0xff;
// data[writex++] = (m_PiValue>>8)&0xff;
// data[writex++] = (m_PiValue>>16)&0xff;
// data[writex++] = (m_PiValue>>24)&0xff;
// data[writex++] = (m_PiValue>>32)&0xff;
// data[writex++] = (m_PiValue>>40)&0xff;
// data[writex++] = (m_PiValue>>48)&0xff;
// data[writex++] = (m_PiValue>>56)&0xff;
pTemp = (unsigned char*)&m_PiValue;
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++] = m_PiStatus&0xff;
data[writex++] = (m_PiStatus>>8)&0xff;
data[writex++] = (m_PiStatus>>16)&0xff;
@ -838,6 +860,7 @@ void SimPiDlg::OnLineSet()
{
unsigned char data[50];
int SetMode,writex;
unsigned char *pTemp;
//if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。
// return;
@ -877,11 +900,14 @@ void SimPiDlg::OnLineSet()
*/
str = ui->MinValueEdit->text();
m_MinValue = str.toInt(&ok,10);
//m_MinValue = str.toInt(&ok,10);
m_MinValue = str.toDouble(&ok);
str = ui->MaxValueEdit->text();
m_MaxValue = str.toInt(&ok,10);
//m_MaxValue = str.toInt(&ok,10);
m_MaxValue = str.toDouble(&ok);
str = ui->StepValueEdit->text();
m_StepValue = str.toInt(&ok,10);
// m_StepValue = str.toInt(&ok,10);
m_StepValue = str.toDouble(&ok);
str = ui->ChangeTimeEdit->text();
m_ChangeTime = str.toInt(&ok,10);
@ -905,18 +931,34 @@ void SimPiDlg::OnLineSet()
data[writex++] = (m_ChangeTime>>8)&0xff;
memset(&data[writex],0,12);
writex+=12;
data[writex++] = m_MinValue&0xff;
data[writex++] = (m_MinValue>>8)&0xff;
data[writex++] = (m_MinValue>>16)&0xff;
data[writex++] = (m_MinValue>>24)&0xff;
data[writex++] = m_MaxValue&0xff;
data[writex++] = (m_MaxValue>>8)&0xff;
data[writex++] = (m_MaxValue>>16)&0xff;
data[writex++] = (m_MaxValue>>24)&0xff;
data[writex++] = m_StepValue&0xff;
data[writex++] = (m_StepValue>>8)&0xff;
data[writex++] = (m_StepValue>>16)&0xff;
data[writex++] = (m_StepValue>>24)&0xff;
// data[writex++] = m_MinValue&0xff;
// data[writex++] = (m_MinValue>>8)&0xff;
// data[writex++] = (m_MinValue>>16)&0xff;
// data[writex++] = (m_MinValue>>24)&0xff;
// data[writex++] = m_MaxValue&0xff;
// data[writex++] = (m_MaxValue>>8)&0xff;
// data[writex++] = (m_MaxValue>>16)&0xff;
// data[writex++] = (m_MaxValue>>24)&0xff;
// data[writex++] = m_StepValue&0xff;
// data[writex++] = (m_StepValue>>8)&0xff;
// data[writex++] = (m_StepValue>>16)&0xff;
// data[writex++] = (m_StepValue>>24)&0xff;
pTemp = (unsigned char*)&m_MinValue;
data[writex++] = *pTemp;
data[writex++] = *(pTemp+1);
data[writex++] = *(pTemp+2);
data[writex++] = *(pTemp+3);
pTemp = (unsigned char*)&m_MaxValue;
data[writex++] = *pTemp;
data[writex++] = *(pTemp+1);
data[writex++] = *(pTemp+2);
data[writex++] = *(pTemp+3);
pTemp = (unsigned char*)&m_StepValue;
data[writex++] = *pTemp;
data[writex++] = *(pTemp+1);
data[writex++] = *(pTemp+2);
data[writex++] = *(pTemp+3);
data[writex++] = m_CurrentRtuNo&0xff;
data[writex++] = (m_CurrentRtuNo>>8)&0xff;
data[writex++] = (m_CurrentRtuNo>>16)&0xff;

View File

@ -73,12 +73,16 @@ private:
bool m_AllPiFlag;
int m_PiFlag;
long m_MaxValue;
long m_MinValue;
long m_StepValue;
// long m_MaxValue;
// long m_MinValue;
// long m_StepValue;
float m_MaxValue;
float m_MinValue;
float m_StepValue;
int m_ChangeTime; //unit:1s
uint64 m_PiValue;
double m_PiValue;
int m_PiStatus;
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,465 @@
//======================================================================================
// @file FesDebugTool.proto
// @brief debug_tool与fes交互
// @author caodingfa
//======================================================================================
syntax="proto2";
package iot_idl;
//========================================================================================
//
//========================================================================================
enum enFesDebugMsgType
{
MT_FESDBG_HeartBeat = 0;
MT_FESDBG_CONNECT = 1;
MT_FESDBG_DISCONNECT = 2;
MT_FESDBG_ChanParam = 5;
MT_FESDBG_RtuParam = 6;
MT_FESDBG_AI_RtuInfo = 10;
MT_FESDBG_AI_Param = 11;
MT_FESDBG_AI_Value = 12;
MT_FESDBG_DI_RtuInfo = 20;
MT_FESDBG_DI_Param = 21;
MT_FESDBG_DI_Value = 22;
MT_FESDBG_ACC_RtuInfo = 30;
MT_FESDBG_ACC_Param = 31;
MT_FESDBG_ACC_Value = 32;
MT_FESDBG_MI_RtuInfo = 40;
MT_FESDBG_MI_Param = 41;
MT_FESDBG_MI_Value = 42;
MT_FESDBG_SimAI_RtuInfo = 50;
MT_FESDBG_SimAI_Param = 51;
MT_FESDBG_SimAI_Value = 52;
MT_FESDBG_SimAI_StartSim = 53;
MT_FESDBG_SimAI_StopSim = 54;
MT_FESDBG_SimDI_RtuInfo = 60;
MT_FESDBG_SimDI_Param = 61;
MT_FESDBG_SimDI_Value = 62;
MT_FESDBG_SimDI_StartSim = 63;
MT_FESDBG_SimDI_StopSim = 64;
MT_FESDBG_SimMI_RtuInfo = 70;
MT_FESDBG_SimMI_Param = 71;
MT_FESDBG_SimMI_Value = 72;
MT_FESDBG_SimMI_StartSim = 73;
MT_FESDBG_SimMI_StopSim = 74;
MT_FESDBG_SimACC_RtuInfo = 80;
MT_FESDBG_SimACC_Param = 81;
MT_FESDBG_SimACC_Value = 82;
MT_FESDBG_SimACC_StartSim = 83;
MT_FESDBG_SimACC_StopSim = 84;
MT_FESDBG_SimEvent_RtuInfo = 90;
MT_FESDBG_SimEvent_DiParam = 91;
MT_FESDBG_SimEvent_Create = 92;
MT_FESDBG_SimAO_RtuInfo = 100;
MT_FESDBG_SimAO_Param = 101;
MT_FESDBG_SimAO_Control = 102;
MT_FESDBG_SimDO_RtuInfo = 110;
MT_FESDBG_SimDO_Param = 111;
MT_FESDBG_SimDO_Control = 112;
MT_FESDBG_SimMO_RtuInfo = 120;
MT_FESDBG_SimMO_Param = 121;
MT_FESDBG_SimMO_Control = 122;
MT_FESDBG_SimDefCmd_RtuInfo = 130;
MT_FESDBG_SimDefCmd_Control = 131;
MT_FESDBG_FWAI_RtuInfo = 140;
MT_FESDBG_FWAI_Param = 141;
MT_FESDBG_FWAI_Value = 142;
MT_FESDBG_FWDI_RtuInfo = 150;
MT_FESDBG_FWDI_Param = 151;
MT_FESDBG_FWDI_Value = 152;
MT_FESDBG_FWDDI_RtuInfo = 160;
MT_FESDBG_FWDDI_Param = 161;
MT_FESDBG_FWDDI_Value = 162;
MT_FESDBG_FWMI_RtuInfo = 170;
MT_FESDBG_FWMI_Param = 171;
MT_FESDBG_FWMI_Value = 172;
MT_FESDBG_FWACC_RtuInfo = 180;
MT_FESDBG_FWACC_Param = 181;
MT_FESDBG_FWACC_Value = 182;
MT_FESDBG_Event_SOE = 190;
MT_FESDBG_Event_Channel = 191;
MT_FESDBG_Event_SOEMemory = 192;
MT_FESDBG_Mon_ChanStart = 200;
MT_FESDBG_Mon_ChanStop = 201;
MT_FESDBG_Mon_ChanClear = 202;
MT_FESDBG_Mon_ChanInfo = 203;
}
message FesDebugToolReqMsg
{
required enFesDebugMsgType type = 1; //
optional string body = 2; //
}
message FesDebugToolRepMsg
{
required bool success = 1;
optional string err_msg = 2;
required enFesDebugMsgType type = 3; //
optional string body = 4; //
}
message FesDebugToolNetRoute
{
required string desc = 1;
required int32 port_no = 2;
}
message FesDebugToolChanParam
{
required int32 chan_no = 1;
required string tag_name = 2;
required string chan_name = 3;
required int32 used = 4;
required int32 chan_status = 5;
required int32 comm_type = 6;
required int32 chan_mode = 7;
required int32 protocol_id = 8;
repeated FesDebugToolNetRoute net_route = 9;
required int32 connect_wait_sec = 10;
required int32 connect_timeout = 11;
required int32 retry_times = 12;
required int32 recv_timeout = 13;
required int32 resp_timeout = 14;
required int32 max_rx_size = 15;
required int32 max_tx_size = 16;
required float err_rate_limit = 17;
repeated int32 backup_chan_no = 18;
}
message FesDebugToolChanParamRepMsg
{
repeated FesDebugToolChanParam chan_param = 1;
}
message FesDebugToolRtuParam
{
required int32 rtu_no = 1;
required string rtu_desc = 2;
required string rtu_name = 3;
required int32 used = 4;
required int32 rtu_status = 5;
required int32 rtu_addr = 6;
required int32 chan_no = 7;
required int32 max_ai_num = 8;
required int32 max_di_num = 9;
required int32 max_acc_num = 10;
required int32 recv_fail_limit = 11;
}
message FesDebugToolRtuParamRepMsg
{
repeated FesDebugToolRtuParam rtu_param = 1;
}
message FesDebugToolRtuInfo
{
required int32 rtu_no = 1;
required int32 used = 2;
// required int32 max_pnt_num = 3;
required string rtu_desc = 3;
}
message FesDebugToolRtuInfoRepMsg
{
repeated FesDebugToolRtuInfo rtu_info = 1;
}
// -
message FesDebugToolPntParamReqMsg
{
required int32 rtu_no = 1;
}
message FesDebugToolPntParam
{
required int32 pnt_no = 1;
required int32 used = 2;
required string pnt_desc = 3;
}
message FesDebugToolPntParamRepMsg
{
required int32 rtu_no = 1;
required int32 max_pnt_num = 2;
repeated FesDebugToolPntParam pnt_param = 3;
}
// -
message FesDebugToolPntValueReqMsg
{
required int32 rtu_no = 1;
required int32 start_index = 2;
required int32 end_index = 3;
}
// - -
message FesDebugToolIntPntValue
{
required int32 pnt_no = 1;
required sint32 value = 2;
required uint32 status = 3;
required uint64 time = 4;
}
// - -
message FesDebugToolFloatPntValue
{
required int32 pnt_no = 1;
required float value = 2;
required uint32 status = 3;
required uint64 time = 4;
}
// - -
message FesDebugToolDoublePntValue
{
required int32 pnt_no = 1;
required double value = 2;
required uint32 status = 3;
required uint64 time = 4;
}
message FesDebugToolPntValueRepMsg
{
required int32 rtu_no = 1;
repeated FesDebugToolIntPntValue int_values = 2;
repeated FesDebugToolFloatPntValue float_values = 3;
repeated FesDebugToolDoublePntValue double_values = 4;
}
//仿
//仿 - 仿
enum enFesDebugSimMode
{
MT_FESDBG_SM_ValueSet = 1; //
MT_FESDBG_SM_LineSet = 2; //线
MT_FESDBG_SM_RandSet = 3; //
// MT_FESDBG_SM_PeriodSet = 4; //
}
//仿 - 仿
enum enFesDebugSimRangeType
{
MT_FESDBG_RT_SinglePoint = 1; //
MT_FESDBG_RT_RtuPoint = 2; //RTU测点
MT_FESDBG_RT_AllPoint = 3; //
}
//仿 -
enum enFesDebugEventSimType
{
MT_FESDBG_EST_RtuSoe = 1; //RTUSOE事件
MT_FESDBG_EST_FepSoe = 2; //FEPSOE事件
}
message FesDebugToolValueVariant
{
optional int32 int_value = 1;
optional float float_value = 2;
optional double double_value = 3;
}
//仿
message FesDebugToolValueSetSimParam
{
required double value = 1;
}
// 线
message FesDebugToolLineSetSimParam
{
required double min_value = 1;
required double max_value = 2;
required double step_value = 3;
required int32 period = 4; //
}
//
message FesDebugToolRandSetSimParam
{
optional double min_value = 1;
optional double max_value = 2;
required int32 period = 3; //
}
//仿
message FesDebugToolValueSimSetReqMsg
{
required enFesDebugSimMode sim_mode = 1;
required enFesDebugSimRangeType sim_range = 2;
optional int32 rtu_no = 3;
optional int32 pnt_no = 4;
optional uint32 status = 5;
optional FesDebugToolValueSetSimParam value_set_param = 6;
optional FesDebugToolLineSetSimParam line_set_param = 7;
optional FesDebugToolRandSetSimParam rand_set_param = 8;
}
//仿
message FesDebugToolValueSimSetRepMsg
{
required enFesDebugSimMode sim_mode = 1;
optional string body = 2;
}
//仿-仿
message FesDebugToolSimEventRtuSoe
{
required int32 event_source = 1;
required int32 rtu_no = 2;
required int32 pnt_no = 3;
required int32 value = 4;
required uint32 status = 5;
required int32 fault_num = 6;
repeated int32 fault_type = 7;
repeated float fault_value = 8;
}
message FesDebugToolSimEventCreateReqMsg
{
required enFesDebugEventSimType event_type = 1;
optional FesDebugToolSimEventRtuSoe event = 2;
}
message FesDebugToolSimEventCreateRepMsg
{
required enFesDebugEventSimType event_type = 1;
optional string body = 2;
}
//仿
message FesDebugToolSimControlReqMsg
{
required int32 ctrl_type = 1;
required int64 seq_no = 2;
required int32 rtu_no = 3;
required int32 pnt_no = 4;
optional float float_value = 5;
optional int32 int_value = 6;
}
message FesDebugToolSimControlRepMsg
{
required int32 ctrl_type = 1;
required int64 seq_no = 2;
required bool success = 3;
optional string err_msg = 4;
}
message FesDebugToolSimDefCmdReqMsg
{
required int32 rtu_no = 1;
required int32 dev_id = 2;
repeated string keys = 3;
repeated string values = 4;
}
//
message FesDebugToolFwPntParam
{
required int32 pnt_no = 1;
required int32 used = 2;
required int32 fes_rtu_no = 3;
required int32 fes_pnt_no = 4;
required string pnt_desc = 5;
}
message FesDebugToolFwPntParamRepMsg
{
required int32 rtu_no = 1;
required int32 max_pnt_num = 2;
repeated FesDebugToolFwPntParam pnt_param = 3;
}
//
message FesDebugToolSoeEvent
{
required string table_name = 1;
required string col_name = 2;
required string tag_name = 3;
required uint32 status = 4;
required int32 value = 5;
required uint64 time = 6;
required int32 fault_num = 7;
repeated int32 fault_type = 8;
repeated float fault_value = 9;
//required int32 rtu_no = 10;
//required int32 pnt_no = 11;
}
message FesDebugToolSoeEventRepMsg
{
required int32 over_flow = 1;
repeated FesDebugToolSoeEvent event = 2;
}
message FesDebugToolChanEvent
{
required string tag_name = 1;
required uint32 status = 2;
required float err_rate = 3;
required uint64 time = 4;
}
message FesDebugToolChanEventRepMsg
{
required int32 over_flow = 1;
repeated FesDebugToolChanEvent event = 2;
}
message FesDebugToolChanMonCmdReqMsg
{
required int32 chan_no = 1;
}
message FesDebugToolChanMonCmdRepMsg
{
required int32 chan_no = 1;
optional int32 rx_num = 2;
optional int32 tx_num = 3;
optional int32 err_num = 4;
}
message FesDebugToolChanMonFrame
{
required int32 frame_type = 1;
required int32 data_type = 2;
required uint64 time = 3;
required bytes data = 4;
}
message FesDebugToolChanMonInfoMsg
{
required int32 chan_no = 1;
required int32 rx_num = 2;
required int32 tx_num = 3;
required int32 err_num = 4;
required int32 over_flow = 5;
repeated FesDebugToolChanMonFrame frame = 6;
}

View File

@ -0,0 +1,25 @@
@echo off
::协议文件路径
set SOURCE_FOLDER=.
::cpp编译器路径
set CPP_COMPILER_PATH=.\protoc.exe
::cpp文件生成路径
set CPP_TARGET_PATH=.
::删除之前创建的文件
del %CPP_TARGET_PATH%\*.h /f /s /q
del %CPP_TARGET_PATH%\*.cc /f /s /q
::遍历所有文件
for /f "delims=" %%i in ('dir /b "%SOURCE_FOLDER%\*.proto"') do (
::生成 cpp 代码
echo %CPP_COMPILER_PATH% --cpp_out=dllexport_decl=IDL_FILES_EXPORT:%CPP_TARGET_PATH% %%i
%CPP_COMPILER_PATH% --cpp_out=dllexport_decl=IDL_FILES_EXPORT:%CPP_TARGET_PATH% %%i
)
echo gen finish
pause

View File

@ -0,0 +1,11 @@
win32 {
DEFINES += IDL_FILES_EXPORT=__declspec(dllimport)
#暂时禁用警告
QMAKE_CXXFLAGS += /wd"4251"
QMAKE_CXXFLAGS += /wd"4275"
} else {
DEFINES += IDL_FILES_EXPORT=
}
LIBS += -lfes_idl_files

View File

@ -0,0 +1,37 @@
QT -= core gui
#平台的库保持原名
#产品的库名已改为 idl_files_product
TARGET = fes_idl_files
TEMPLATE = lib
#暂时禁用警告
win32{
QMAKE_CXXFLAGS += /wd"4251"
QMAKE_CXXFLAGS += /wd"4275"
QMAKE_CXXFLAGS += /wd"4267"
QMAKE_CXXFLAGS += /wd"4100"
contains (QMAKE_CXXFLAGS_WARN_ON, -w34100) : QMAKE_CXXFLAGS_WARN_ON -= -w34100
}
HEADERS += \
FesDebugTool.pb.h
SOURCES += \
FesDebugTool.pb.cc
win32 {
DEFINES += IDL_FILES_EXPORT=__declspec(dllexport)
} else {
DEFINES += IDL_FILES_EXPORT=\'__attribute__((visibility(\"default\")))\'
}
LIBS += -lprotobuf
COMMON_PRI=$$PWD/../../common.pri
exists($$COMMON_PRI) {
include($$COMMON_PRI)
}else {
error("FATAL error: can not find common.pri")
}

Binary file not shown.

View File

@ -0,0 +1,295 @@
/**
@file Ping.cpp
@brief ping操作类
@author
*/
#include "Ping.h"
#include "common/Common.h"
#include "pub_logger_api/logger.h"
using namespace std;
#ifdef OS_WINDOWS
using boost::asio::ip::icmp;
#endif
#ifdef OS_LINUX
using boost::asio::ip::icmp_nonroot;
#endif
using boost::asio::deadline_timer;
namespace posix_time = boost::posix_time;
using namespace iot_public;
using namespace iot_fes;
iot_fes::CPinger::CPinger(boost::asio::io_service& ioService,
const std::string &strDstIP,
const int nChannelNo,
const int nIpIdx,
const size_t nInitSequenceNum,
const size_t nSequenceStep,
const CPingResultCachePtr &ptrPingCache)
: m_bIsExit(false),
m_strDstIP(strDstIP),
m_nChannelNo(nChannelNo),
m_nIpIdx(nIpIdx),
m_dwInitSequenceNum(static_cast<uint16>(nInitSequenceNum)),
m_dwSequenceNum(static_cast<uint16>(nInitSequenceNum)),
m_nSequenceStep(static_cast<int>(nSequenceStep)),
m_nReplyNum(0),
m_nFailTime(0),
m_bLastNetworkState(false),
m_nTimeoutMsec(1000),
m_nCheckInterval(500),
m_nPingRetryTime(3),
m_ptrPingCache(ptrPingCache),
m_objResolver(ioService),
#ifdef OS_WINDOWS
m_objSocket(ioService, icmp::v4()),
#endif
#ifdef OS_LINUX
m_objSocket(ioService, icmp_nonroot::v4()),
#endif
m_objTimer(ioService)
{
}
iot_fes::CPinger::~CPinger()
{
m_bIsExit = true;
boost::system::error_code ec;
m_objTimer.cancel(ec);
//m_ptrNetworkTable.reset();
m_objSocket.close();
}
/* @brief 初始化 */
int iot_fes::CPinger::initialize()
{
//m_nTimeoutMsec = CNetworkCfgParam::getPingTimeoutMsec(); //< ping超时时间
//m_nCheckInterval = CNetworkCfgParam::getPingCheckIntervalMsec(); //< ping检查周期
//m_nPingRetryTime = CNetworkCfgParam::getPingRetryTime(); //< ping失败重试次数超过重试次数才认为失败
m_nTimeoutMsec = 2000; //< ping超时时间
m_nCheckInterval = 1000; //< ping检查周期
m_nPingRetryTime = 3; //< ping失败重试次数超过重试次数才认为失败
#ifdef OS_WINDOWS
icmp::resolver::query objQuery(icmp::v4(), m_strDstIP, "",
icmp::resolver::query::resolver_query_base::all_matching);
try
{
m_objEndpoint = *m_objResolver.resolve(objQuery);
}
catch (std::exception& ex)
{
LOGERROR("创建endpoint失败.IP=[%s].error=[%s]", m_strDstIP.c_str(), ex.what());
return iotFailed;
}
#endif
#ifdef OS_LINUX
m_objEndpoint = icmp_nonroot::endpoint( boost::asio::ip::address::from_string( m_strDstIP ), 0 );
#endif
startSend();
startReceive();
return iotSuccess;
}
/* @brief 启动发送 */
void iot_fes::CPinger::startSend()
{
if (m_bIsExit) //< 退出
{
LOGINFO("接收到退出命令,停止Ping");
return;
}
#ifdef OS_WINDOWS
std::string strBody = "ping " + m_strDstIP;
#endif
#ifdef OS_LINUX
std::string strBody( "iscs_ping" );
#endif
// Create an ICMP header for an echo request.
icmp_header objRequest;
objRequest.type(icmp_header::echo_request);
objRequest.code(0);
#ifdef OS_WINDOWS
objRequest.identifier(getIdentifier());
#endif
uint16_t lastSeqNum = m_dwSequenceNum;
m_dwSequenceNum += m_nSequenceStep;
if(m_dwSequenceNum < lastSeqNum)
{
m_dwSequenceNum = m_dwInitSequenceNum;
}
objRequest.sequence_number(m_dwSequenceNum);
#ifdef OS_WINDOWS
compute_checksum(objRequest, strBody.begin(), strBody.end());
#endif
// Encode the request packet.
boost::asio::streambuf request_buffer;
std::ostream os(&request_buffer);
os << objRequest << strBody;
// Send the request.
m_sendTime = posix_time::microsec_clock::universal_time();
try
{
if(m_ptrPingCache->isEnablePing(m_nChannelNo))
{
m_objSocket.send_to(request_buffer.data(), m_objEndpoint);
}
}
catch (const std::exception& ex)
{
if (m_bLastNetworkState && m_nFailTime <= m_nPingRetryTime) /* @brief 防止网络异常时频繁打印日志 */
{
LOGERROR("消息发送失败.err=[%s]", ex.what());
}
}
// Wait up to five seconds for a reply.
m_nReplyNum = 0;
m_objTimer.expires_from_now(/*time_sent_ +*/ posix_time::millisec(m_nTimeoutMsec));
m_objTimer.async_wait(boost::bind(&CPinger::handleTimeout, this));
}
/* @brief 超时处理 */
void iot_fes::CPinger::handleTimeout()
{
if (m_bIsExit) //< 退出
{
LOGINFO("接收到退出命令,停止Ping");
return;
}
bool bNetworkNormal = false;
if (m_nReplyNum == 0)
{
/* @brief 超时 */
++m_nFailTime;
}
else
{
m_nFailTime = 0;
bNetworkNormal = true; //< 网络正常
}
//if (m_bLastNetworkState != bNetworkNormal)
{
bool bUpdateTable = false;
if (bNetworkNormal)
{
bUpdateTable = true;
LOGTRACE("%s网络正常",m_strDstIP.c_str());
}
else
{
if (m_nFailTime >= m_nPingRetryTime) //< 超过指定次数才认为失败
{
bUpdateTable = true;
LOGTRACE("%s网络故障",m_strDstIP.c_str());
}
}
if (bUpdateTable)
{
m_bLastNetworkState = bNetworkNormal;
m_ptrPingCache->setPingResult(m_nChannelNo,m_nIpIdx,bNetworkNormal);
}
}
if (m_nFailTime >= m_nPingRetryTime) //< 失败后复位计数
{
m_nFailTime = 0;
}
/* @brief 设置ping的周期如果上一次失败则不需要等待直接再次ping */
int nTimeoutMsec = m_nCheckInterval;
if (m_nFailTime > 0)
{
nTimeoutMsec = 0;
}
// Requests must be sent no less than one second apart.
m_objTimer.expires_from_now(/*time_sent_ +*/ posix_time::millisec(nTimeoutMsec));
m_objTimer.async_wait(boost::bind(&CPinger::startSend, this));
}
/* @brief 启动接收 */
void iot_fes::CPinger::startReceive()
{
// Discard any data already in the buffer.
m_objReplyBuf.consume(m_objReplyBuf.size());
// Wait for a reply. We prepare the buffer to receive up to 64KB.
m_objSocket.async_receive(m_objReplyBuf.prepare(65536), boost::bind(&CPinger::handleReceive, this, _2));
}
void iot_fes::CPinger::handleReceive(std::size_t ulLength)
{
// The actual number of bytes received is committed to the buffer so that we
// can extract it using a std::istream object.
m_objReplyBuf.commit(ulLength);
// Decode the reply packet.
std::istream is(&m_objReplyBuf);
ipv4_header ipv4_hdr;
icmp_header icmp_hdr;
#if OS_WINDOWS
is >> ipv4_hdr >> icmp_hdr;
#endif
#ifdef OS_LINUX
is >> icmp_hdr;
#endif
// We can receive all ICMP packets received by the host, so we need to
// filter out only the echo replies that match the our identifier and
// expected sequence number.
if (is && icmp_hdr.type() == icmp_header::echo_reply
#ifdef OS_WINDOWS
&& icmp_hdr.identifier() == getIdentifier()
#endif
&& icmp_hdr.sequence_number() == m_dwSequenceNum)
{
// If this is the first reply, interrupt the five second timeout.
if (m_nReplyNum++ == 0)
{
m_objTimer.cancel(); //< 调用后会调用注册的handle
}
// Print out some information about the reply packet.
posix_time::ptime now = posix_time::microsec_clock::universal_time();
int64 lIntervalMsec = (now - m_sendTime).total_milliseconds();
if (lIntervalMsec > 50) //< 大于100ms时记录一下
{
LOGWARN("[%" PRIu64 "] bytes from [%s] : icmp_seq=[%u],ttl=[%u],time=[%" PRId64 "]ms",
ulLength, ipv4_hdr.source_address().to_string().c_str(),
icmp_hdr.sequence_number(), ipv4_hdr.time_to_live(), lIntervalMsec);
}
}
startReceive();
}
/* @brief 用来生成唯一索引 */
uint16 iot_fes::CPinger::getIdentifier()
{
#if defined(BOOST_ASIO_WINDOWS)
return static_cast<unsigned short>(::GetCurrentProcessId());
#else
return static_cast<unsigned short>(::getpid());
#endif
}

View File

@ -0,0 +1,94 @@
/**
@file Ping.h
@brief ping操作类
@author
*/
#pragma once
#include "boost/asio.hpp"
#ifdef OS_LINUX
#include "asio_icmp_nonroot.hpp"
#endif
#include "boost/bind.hpp"
//#include "common/DataType.h"
#include "icmp_header.hpp"
#include "ipv4_header.hpp"
#include "fes_ping_api/PingResultCache.h"
namespace iot_fes
{
class CPinger
{
public:
/**
@brief
@param boost::asio::io_service & ioService asio服务
@param const std::string & strDstIP ping的IP地址
@param const int nChannelNo
@param const int nIpIdx IP
@param const size_t nInitSequenceNum
@param const size_t nSequenceStep
@param const CPingResultCachePtr & ptrPingCache Ping结果缓存
*/
CPinger(boost::asio::io_service& ioService,
const std::string &strDstIP,
const int nChannelNo,
const int nIpIdx,
const size_t nInitSequenceNum,
const size_t nSequenceStep,
const CPingResultCachePtr &ptrPingCache);
virtual ~CPinger();
/**
@brief
@return iotSuccess,iotFailed
*/
int initialize();
private:
/* @brief 启动发送 */
void startSend();
/* @brief 超时处理 */
void handleTimeout();
/* @brief 启动接收 */
void startReceive();
/* @brief 收到反馈时的处理 */
void handleReceive(std::size_t length);
/**
@brief
@return
*/
static uint16_t getIdentifier();
private:
bool m_bIsExit; //< 是否退出
std::string m_strDstIP; //< 要ping的IP地址
int m_nChannelNo; //< 通道号
int m_nIpIdx; //< 本通道下第几个IP
uint16_t m_dwInitSequenceNum; //初始发送序号
uint16_t m_dwSequenceNum; //< 发送序号
int m_nSequenceStep; //< 序号增长步长
std::size_t m_nReplyNum; //< 接收到的反馈数目
int m_nFailTime; //< ping失败次数
bool m_bLastNetworkState; //< 上一次网络状态
int m_nTimeoutMsec; //< ping超时时间
int m_nCheckInterval; //< ping检查周期
int m_nPingRetryTime; //< ping失败重试次数超过重试次数才认为失败
CPingResultCachePtr m_ptrPingCache; //保存Ping结果
#ifdef OS_WINDOWS
boost::asio::ip::icmp::resolver m_objResolver;
boost::asio::ip::icmp::endpoint m_objEndpoint;
boost::asio::ip::icmp::socket m_objSocket;
#endif
#ifdef OS_LINUX
boost::asio::ip::icmp_nonroot::resolver m_objResolver;
boost::asio::ip::icmp_nonroot::endpoint m_objEndpoint;
boost::asio::ip::icmp_nonroot::socket m_objSocket;
#endif
boost::asio::deadline_timer m_objTimer; //< 定时器
boost::posix_time::ptime m_sendTime; //< ping发送时间
boost::asio::streambuf m_objReplyBuf;
};
typedef boost::shared_ptr<CPinger> CPingerPtr;
} //namespace iot_fes

View File

@ -0,0 +1,158 @@
/**
@file NetworkCheckImpl.cpp
@brief 访
@author
*/
#include "common/Common.h"
#include "PingImpl.h"
#include "pub_logger_api/logger.h"
using namespace iot_fes;
iot_fes::CPingImpl::CPingImpl() : m_pThread(nullptr),m_ptrPingCache(NULL)
{
}
iot_fes::CPingImpl::~CPingImpl()
{
stop();
}
/* @brief 获取当前网络是否正常 */
int iot_fes::CPingImpl::start()
{
if(m_vecPingInfo.empty())
{
LOGINFO("没有配置需要Ping的地址");
return iotSuccess;
}
if(iotSuccess != initPinger())
{
return iotFailed;
}
m_pThread = new boost::thread( boost::bind(&iot_fes::CPingImpl::startListen,this));
if ( nullptr == m_pThread )
{
LOGERROR("创建Ping监听线程失败");
return iotFailed;
}
return iotSuccess;
}
int iot_fes::CPingImpl::stop()
{
m_objIOService.stop();
if(m_pThread != nullptr)
{
if(m_pThread->joinable())
{
LOGINFO("开始停止Ping线程");
m_pThread->join();
LOGINFO("Ping线程停止成功");
}
delete m_pThread;
m_pThread = nullptr;
}
for (size_t i = 0; i < m_vecPingerPtr.size(); ++i)
{
m_vecPingerPtr[i].reset();
}
m_vecPingerPtr.clear();
return iotSuccess;
}
/* @brief 初始化本类资源,主要打开内存表 */
int iot_fes::CPingImpl::initialize()
{
m_ptrPingCache = boost::make_shared<CPingResultCache>();
if(m_ptrPingCache == NULL)
{
LOGERROR("创建PingCache失败,不启用Ping功能");
return iotFailed;
}
return iotSuccess;
}
void iot_fes::CPingImpl::startListen()
{
LOGINFO("运行Ping监听服务");
m_objIOService.run();
LOGINFO("停止Ping监听服务");
}
void iot_fes::CPingImpl::addAddress(const int nChannelNo, const int nIpIdx, const std::string &strIp)
{
SPingAddrInfo stInfo(nChannelNo,nIpIdx,strIp);
m_vecPingInfo.push_back(stInfo);
}
bool iot_fes::CPingImpl::getPingResult(const int nChannelNo)
{
return m_ptrPingCache->getPingResult(nChannelNo);
}
int CPingImpl::getPingOkIpIndex(const int nChannelNo)
{
return m_ptrPingCache->getPingOkIpIndex(nChannelNo);
}
void iot_fes::CPingImpl::enablePing(const int nChannelNo)
{
m_ptrPingCache->enablePing(nChannelNo);
}
void iot_fes::CPingImpl::disablePing(const int nChannelNo)
{
m_ptrPingCache->disablePing(nChannelNo);
}
int iot_fes::CPingImpl::initPinger()
{
try
{
/* @brief 每个网关IP创建一个CPinger,每个Pinger检测一个网关的网络状况 */
for (size_t i = 0; i < m_vecPingInfo.size(); ++i)
{
CPingerPtr ptrPinger = boost::make_shared<CPinger>(m_objIOService,
m_vecPingInfo[i].strIp,
m_vecPingInfo[i].nChNo,
m_vecPingInfo[i].nIdx,
i,
m_vecPingInfo.size(),
m_ptrPingCache);
if (ptrPinger == NULL)
{
LOGERROR("创建pinger失败.ChNo=%d,ip=%s",m_vecPingInfo[i].nChNo,m_vecPingInfo[i].strIp.c_str());
return iotFailed;
}
else
{
if (iotSuccess != ptrPinger->initialize())
{
return iotFailed;
}
else
{
m_vecPingerPtr.push_back(ptrPinger);
//先默认认为网络正常
m_ptrPingCache->setPingResult(m_vecPingInfo[i].nChNo,m_vecPingInfo[i].nIdx,true);
}
}
}
}
catch (std::exception& ex)
{
LOGERROR("创建Pinger失败.error=[%s]", ex.what());
return iotFailed;
}
return iotSuccess;
}

View File

@ -0,0 +1,83 @@
/**
@file NetworkCheckImpl.h
@brief 访
@author
*/
#pragma once
#include "boost/thread.hpp"
#include "fes_ping_api/PingInterface.h"
#include "Ping.h"
namespace iot_fes
{
typedef struct _SPingAddrInfo
{
_SPingAddrInfo(const int nChannelNo,const int nIpIdx,const std::string &strPingIp)
:nChNo(nChannelNo),nIdx(nIpIdx),strIp(strPingIp)
{}
int nChNo; //通道号
int nIdx; //本通道下第几个IP从0开始
std::string strIp; //Ip地址
}SPingAddrInfo,*PSPingAddrInfo;
typedef std::vector<SPingAddrInfo> SPingAddrInfoSeq;
class CPingImpl : public CPingInterface
{
public:
CPingImpl();
~CPingImpl();
/**
@brief Ping
@return iotSuccess
*/
virtual int start();
//停止Ping
virtual int stop();
/**
@brief Ping结果缓存
@return iotSuccess
@retval
*/
int initialize();
//启动网络监听服务
void startListen();
/**
@brief Ping的信息start执行执行
@param const int nChannelNo
@param const int nIpIdx IP
@param const std::string & strDstIP ping的IP地址
*/
void addAddress(const int nChannelNo,const int nIpIdx,const std::string &strIp);
//获取指定通道的Ping结果
bool getPingResult(const int nChannelNo);
//获取指定通道的Ping结果返回是ping的ip的索引找不到返回-1
int getPingOkIpIndex(const int nChannelNo);
//启用指定通道的Ping功能
void enablePing(const int nChannelNo);
//禁用指定通道的Ping功能
void disablePing(const int nChannelNo);
private:
//每个IP创建一个Ping实例
int initPinger();
private:
boost::thread *m_pThread; //网络监听线程
boost::asio::io_service m_objIOService; //< asio服务类
SPingAddrInfoSeq m_vecPingInfo; //IP地址信息
CPingResultCachePtr m_ptrPingCache; //存放ping结果
std::vector<CPingerPtr> m_vecPingerPtr; //< 需要ping的IP类列表
};
typedef boost::shared_ptr<CPingImpl> CPingImplPtr;
} //namespace iot_sys

View File

@ -0,0 +1,24 @@
/**
@file NetworkCheckInterface.cpp
@brief
@author
*/
#include "fes_ping_api/PingInterface.h"
#include "PingImpl.h"
#include "common/Common.h"
using namespace iot_fes;
FES_PING_API CPingInterfacePtr iot_fes::getPingInstance()
{
CPingImplPtr ptrNetworkCheck = boost::make_shared<CPingImpl>();
if (ptrNetworkCheck != NULL)
{
if (iotSuccess != ptrNetworkCheck->initialize())
{
ptrNetworkCheck.reset();
}
}
return ptrNetworkCheck;
}

View File

@ -0,0 +1,103 @@
/**
@file NetworkCheckImpl.cpp
@brief 访
@author
*/
#include "common/Common.h"
#include "fes_ping_api/PingResultCache.h"
#include "pub_logger_api/logger.h"
using namespace iot_fes;
iot_fes::CPingResultCache::CPingResultCache()
{
}
iot_fes::CPingResultCache::~CPingResultCache()
{
}
bool iot_fes::CPingResultCache::getPingResult(const int nChannelNo)
{
boost::mutex::scoped_lock lock(m_objMutex);
Chan2ConnStatMAP::const_iterator pIter = m_mapChToPingResult.find(nChannelNo);
if(pIter == m_mapChToPingResult.end())
{
return true; //找不到,走默认逻辑,认为需要重连
}
return pIter->second.any();
}
int CPingResultCache::getPingOkIpIndex(const int nChannelNo)
{
boost::mutex::scoped_lock lock(m_objMutex);
Chan2ConnStatMAP::const_iterator pIter = m_mapChToPingResult.find(nChannelNo);
if(pIter == m_mapChToPingResult.end())
{
return -1; //找不到,走默认逻辑,认为需要重连
}
if(pIter->second.test(0) && pIter->second.test(1))
{
return -1; //如果2个都能ping通返回-1防止设备能ping通但是端口未开的情况
}
if(pIter->second.test(0))
{
return 0;
}
else if(pIter->second.test(1))
{
return 1;
}
return -1;
}
void iot_fes::CPingResultCache::setPingResult(const int nChNo, const int nIdx,const bool bRet)
{
boost::mutex::scoped_lock lock(m_objMutex);
m_mapChToPingResult[nChNo].set(nIdx,bRet);
}
bool iot_fes::CPingResultCache::isEnablePing(const int nChannelNo)
{
boost::mutex::scoped_lock lock(m_objMutex);
Chan2ConnStatMAP::const_iterator pIter = m_mapChToPingResult.find(nChannelNo);
if(pIter == m_mapChToPingResult.end())
{
return true; //找不到走默认逻辑认为需要Ping
}
if(pIter->second.test(CONST_MAX_PING_NUM - 1)) //如果最高位设置为1表示当前网络正常可以暂停ping
{
return false;
}
return true;
}
void iot_fes::CPingResultCache::enablePing(const int nChannelNo)
{
boost::mutex::scoped_lock lock(m_objMutex);
Chan2ConnStatMAP::iterator pIter = m_mapChToPingResult.find(nChannelNo);
if(pIter != m_mapChToPingResult.end())
{
LOGINFO("启用通道Ping功能.ChannelNo=%d",nChannelNo);
pIter->second.reset(CONST_MAX_PING_NUM - 1);
}
}
void CPingResultCache::disablePing(const int nChannelNo)
{
boost::mutex::scoped_lock lock(m_objMutex);
Chan2ConnStatMAP::iterator pIter = m_mapChToPingResult.find(nChannelNo);
if(pIter != m_mapChToPingResult.end())
{
LOGINFO("禁用通道Ping功能.ChannelNo=%d",nChannelNo);
pIter->second.set(CONST_MAX_PING_NUM - 1,true);
}
}

View File

@ -0,0 +1,106 @@
/**
* @brief root权限发送icmp包boost/asio/ip/icmp.hpp修改而来
* @author yikenan
*/
# pragma once
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/basic_raw_socket.hpp>
#include <boost/asio/ip/basic_endpoint.hpp>
#include <boost/asio/ip/basic_resolver.hpp>
#include <boost/asio/ip/basic_resolver_iterator.hpp>
#include <boost/asio/ip/basic_resolver_query.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost
{
namespace asio
{
namespace ip
{
/**
* @brief root权限发送icmp包boost/asio/ip/icmp.hpp修改而来
*/
class icmp_nonroot
{
public:
/// The type of a ICMP endpoint.
typedef basic_endpoint <icmp_nonroot> endpoint;
/// Construct to represent the IPv4 ICMP protocol.
static icmp_nonroot v4()
{
return icmp_nonroot( BOOST_ASIO_OS_DEF( IPPROTO_ICMP ),
BOOST_ASIO_OS_DEF( AF_INET ) );
}
/// Construct to represent the IPv6 ICMP protocol.
static icmp_nonroot v6()
{
return icmp_nonroot( BOOST_ASIO_OS_DEF( IPPROTO_ICMPV6 ),
BOOST_ASIO_OS_DEF( AF_INET6 ) );
}
/// Obtain an identifier for the type of the protocol.
int type() const
{
//< yikenan
// return BOOST_ASIO_OS_DEF(SOCK_RAW);
return BOOST_ASIO_OS_DEF( SOCK_DGRAM );
}
/// Obtain an identifier for the protocol.
int protocol() const
{
return protocol_;
}
/// Obtain an identifier for the protocol family.
int family() const
{
return family_;
}
/// The ICMP socket type.
//< yikenan
//typedef basic_raw_socket <icmp_nonroot> socket;
typedef basic_datagram_socket <icmp_nonroot> socket;
/// The ICMP resolver type.
typedef basic_resolver <icmp_nonroot> resolver;
/// Compare two protocols for equality.
friend bool operator==( const icmp_nonroot &p1, const icmp_nonroot &p2 )
{
return p1.protocol_ == p2.protocol_ && p1.family_ == p2.family_;
}
/// Compare two protocols for inequality.
friend bool operator!=( const icmp_nonroot &p1, const icmp_nonroot &p2 )
{
return p1.protocol_ != p2.protocol_ || p1.family_ != p2.family_;
}
private:
// Construct with a specific family.
explicit icmp_nonroot( int protocol_id, int protocol_family )
: protocol_( protocol_id ),
family_( protocol_family )
{
}
int protocol_;
int family_;
};
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>

View File

@ -0,0 +1,43 @@
QT -= core gui
CONFIG -= qt
TEMPLATE = lib
TARGET = fes_ping_api
DEFINES += FES_PING_EXPORTS
# Input
HEADERS += \
PingImpl.h \
icmp_header.hpp \
ipv4_header.hpp \
Ping.h \
../../include/fes_ping_api/PingApiCommon.h \
../../include/fes_ping_api/PingInterface.h \
../../include/fes_ping_api/PingResultCache.h
linux-g++* {
HEADERS += asio_icmp_nonroot.hpp
}
SOURCES += \
PingImpl.cpp \
PingResultCache.cpp \
PingInterface.cpp \
Ping.cpp
INCLUDEPATH += ../../include/
#LIBS += -lboost_filesystem -lboost_system -lboost_thread
LIBS += -lboost_date_time -lboost_thread
LIBS += -lboost_system -llog4cplus
LIBS += -lpub_utility_api -lpub_logger_api -lrdb_api
#-------------------------------------------------------------------
COMMON_PRI=$$PWD/../../../common.pri
exists($$COMMON_PRI) {
include($$COMMON_PRI)
}else {
error("FATAL error: can not find common.pri")
}

View File

@ -0,0 +1,94 @@
//
// icmp_header.hpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ICMP_HEADER_HPP
#define ICMP_HEADER_HPP
#include <istream>
#include <ostream>
#include <algorithm>
// ICMP header for both IPv4 and IPv6.
//
// The wire format of an ICMP header is:
//
// 0 8 16 31
// +---------------+---------------+------------------------------+ ---
// | | | | ^
// | type | code | checksum | |
// | | | | |
// +---------------+---------------+------------------------------+ 8 bytes
// | | | |
// | identifier | sequence number | |
// | | | v
// +-------------------------------+------------------------------+ ---
class icmp_header
{
public:
enum { echo_reply = 0, destination_unreachable = 3, source_quench = 4,
redirect = 5, echo_request = 8, time_exceeded = 11, parameter_problem = 12,
timestamp_request = 13, timestamp_reply = 14, info_request = 15,
info_reply = 16, address_request = 17, address_reply = 18 };
icmp_header() { std::fill(rep_, rep_ + sizeof(rep_), 0); }
unsigned char type() const { return rep_[0]; }
unsigned char code() const { return rep_[1]; }
unsigned short checksum() const { return decode(2, 3); }
unsigned short identifier() const { return decode(4, 5); }
unsigned short sequence_number() const { return decode(6, 7); }
void type(unsigned char n) { rep_[0] = n; }
void code(unsigned char n) { rep_[1] = n; }
void checksum(unsigned short n) { encode(2, 3, n); }
void identifier(unsigned short n) { encode(4, 5, n); }
void sequence_number(unsigned short n) { encode(6, 7, n); }
friend std::istream& operator>>(std::istream& is, icmp_header& header)
{ return is.read(reinterpret_cast<char*>(header.rep_), 8); }
friend std::ostream& operator<<(std::ostream& os, const icmp_header& header)
{ return os.write(reinterpret_cast<const char*>(header.rep_), 8); }
private:
unsigned short decode(int a, int b) const
{ return (rep_[a] << 8) + rep_[b]; }
void encode(int a, int b, unsigned short n)
{
rep_[a] = static_cast<unsigned char>(n >> 8);
rep_[b] = static_cast<unsigned char>(n & 0xFF);
}
unsigned char rep_[8];
};
template <typename Iterator>
void compute_checksum(icmp_header& header,
Iterator body_begin, Iterator body_end)
{
unsigned int sum = (header.type() << 8) + header.code()
+ header.identifier() + header.sequence_number();
Iterator body_iter = body_begin;
while (body_iter != body_end)
{
sum += (static_cast<unsigned char>(*body_iter++) << 8);
if (body_iter != body_end)
sum += static_cast<unsigned char>(*body_iter++);
}
sum = (sum >> 16) + (sum & 0xFFFF);
sum += (sum >> 16);
header.checksum(static_cast<unsigned short>(~sum));
}
#endif // ICMP_HEADER_HPP

View File

@ -0,0 +1,102 @@
//
// ipv4_header.hpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef IPV4_HEADER_HPP
#define IPV4_HEADER_HPP
#include <algorithm>
#include <boost/asio/ip/address_v4.hpp>
// Packet header for IPv4.
//
// The wire format of an IPv4 header is:
//
// 0 8 16 31
// +-------+-------+---------------+------------------------------+ ---
// | | | | | ^
// |version|header | type of | total length in bytes | |
// | (4) | length| service | | |
// +-------+-------+---------------+-+-+-+------------------------+ |
// | | | | | | |
// | identification |0|D|M| fragment offset | |
// | | |F|F| | |
// +---------------+---------------+-+-+-+------------------------+ |
// | | | | |
// | time to live | protocol | header checksum | 20 bytes
// | | | | |
// +---------------+---------------+------------------------------+ |
// | | |
// | source IPv4 address | |
// | | |
// +--------------------------------------------------------------+ |
// | | |
// | destination IPv4 address | |
// | | v
// +--------------------------------------------------------------+ ---
// | | ^
// | | |
// / options (if any) / 0 - 40
// / / bytes
// | | |
// | | v
// +--------------------------------------------------------------+ ---
class ipv4_header
{
public:
ipv4_header() { std::fill(rep_, rep_ + sizeof(rep_), 0); }
unsigned char version() const { return (rep_[0] >> 4) & 0xF; }
unsigned short header_length() const { return (rep_[0] & 0xF) * 4; }
unsigned char type_of_service() const { return rep_[1]; }
unsigned short total_length() const { return decode(2, 3); }
unsigned short identification() const { return decode(4, 5); }
bool dont_fragment() const { return (rep_[6] & 0x40) != 0; }
bool more_fragments() const { return (rep_[6] & 0x20) != 0; }
unsigned short fragment_offset() const { return decode(6, 7) & 0x1FFF; }
unsigned int time_to_live() const { return rep_[8]; }
unsigned char protocol() const { return rep_[9]; }
unsigned short header_checksum() const { return decode(10, 11); }
boost::asio::ip::address_v4 source_address() const
{
boost::asio::ip::address_v4::bytes_type bytes
= { { rep_[12], rep_[13], rep_[14], rep_[15] } };
return boost::asio::ip::address_v4(bytes);
}
boost::asio::ip::address_v4 destination_address() const
{
boost::asio::ip::address_v4::bytes_type bytes
= { { rep_[16], rep_[17], rep_[18], rep_[19] } };
return boost::asio::ip::address_v4(bytes);
}
friend std::istream& operator>>(std::istream& is, ipv4_header& header)
{
is.read(reinterpret_cast<char*>(header.rep_), 20);
if (header.version() != 4)
is.setstate(std::ios::failbit);
std::streamsize options_length = header.header_length() - 20;
if (options_length < 0 || options_length > 40)
is.setstate(std::ios::failbit);
else
is.read(reinterpret_cast<char*>(header.rep_) + 20, options_length);
return is;
}
private:
unsigned short decode(int a, int b) const
{ return (rep_[a] << 8) + rep_[b]; }
unsigned char rep_[60];
};
#endif // IPV4_HEADER_HPP

View File

@ -0,0 +1,9 @@
#各子工程按书写顺序编译,清注意各子工程的依赖关系,被依赖的库应写在前面
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += \
#fes_ping_api

View File

@ -0,0 +1,72 @@
/*
@file SerialPortThread.h
@brief SerialPortThread类
@author thxiao
*/
#pragma once
#include "FesDef.h"
#include "FesBase.h"
#ifdef WIN32 //无效句柄定义,返回类型定义
#define HINVALID NULL
#define HVALID(x) (HANDLE)x
#define DEVTYPE HANDLE
#else
#define HINVALID -1
#define HVALID(x) x
#define DEVTYPE int
#endif
#define COM_NOPARITY 0
#define COM_EVENPARITY 2
#define COM_ODDPARITY 3
#define COM_SPACEPARITY 4
#define COM_MARKPARITY 5
#define COM_ONESTOPBIT 0
#define COM_ONE5STOPBITS 1
#define COM_TWOSTOPBITS 2
using namespace iot_public;
class CComSerialPort
{
public:
CComSerialPort(CFesChanPtr ptrCFesChan);
virtual ~CComSerialPort();
void TxComData(CFesChanPtr ptrCFesChan,int dateLen, byte *pData);
void RxComData(CFesChanPtr ptrCFesChan);
int GetComStatus();
CFesChanPtr m_ptrCFesChan; //主通道数据区。如果存在备通道,每次发送接收数据时需要得到当前使用的通道数据
CFesChanPtr m_ptrCurrentChan; //当前使用通道数据区。如果存在备通,每次发送接收数据时需要得到当前使用的通道数据
int m_timerCount;
int m_timerCountReset;
bool OpenChan(CFesChanPtr ptrCFesChan);
void CloseChan(CFesChanPtr ptrCFesChan);
void SetChan(CFesChanPtr ptrCFesChan);
private:
DEVTYPE m_devId;
int m_comIndex;//1~24(P1,P2........)
int errSendCount;
int errRecvCount;
int openCount;
#ifdef WIN32
BOOL cfgWrite(HANDLE hPortHandle, BYTE bReg, BYTE bValue);
BOOL cfgRead(HANDLE hPortHandle, BYTE bReg, BYTE *pbValue);
void ComModeSet(HANDLE hPortHandle, unsigned int Mode, unsigned int num);
void ComReset(HANDLE hPortHandle, unsigned int Mode, unsigned int num);
#else
int ComModeSet(int fd, unsigned int Mode,unsigned int num);
#endif
};
typedef boost::shared_ptr<CComSerialPort> CComSerialPortPtr;

View File

@ -394,56 +394,56 @@ public:
* TagNameFES转发点SFesFwPubAi
* @param TagName TagName
*/
SFesFwPubAi* GetFesFwPubFesAi(std::string TagName);
SFesFwPubAi* GetFesFwPubFesAi(const std::string &TagName);
/**
* @brief CFesBase::GetFesFwDpAi
* TagNameDP转发点SFesFwDpAi
* @param TagName TagName
*/
SFesFwPubAi* GetFesFwPubDpAi(std::string TagName);
SFesFwPubAi* GetFesFwPubDpAi(const std::string &TagName);
/**
* @brief CFesBase::GetFesFwPubDi
* TagNameFES转发点SFesFwPubDi
* @param TagName TagName
*/
SFesFwPubDi* GetFesFwPubFesDi(std::string TagName);
SFesFwPubDi* GetFesFwPubFesDi(const std::string &TagName);
/**
* @brief CFesBase::GetFesFwPubDi
* TagNameDP转发点SFesFwPubDi
* @param TagName TagName
*/
SFesFwPubDi* GetFesFwPubDpDi(std::string TagName);
SFesFwPubDi* GetFesFwPubDpDi(const std::string &TagName);
/**
* @brief CFesBase::GetFesFwPubAcc
* TagNameFES转发点SFesFwPubAcc
* @param TagName TagName
*/
SFesFwPubAcc* GetFesFwPubFesAcc(std::string TagName);
SFesFwPubAcc* GetFesFwPubFesAcc(const std::string &TagName);
/**
* @brief CFesBase::GetFesFwPubDpAcc
* TagNameDP转发点SFesFwPubAcc
* @param TagName TagName
*/
SFesFwPubAcc* GetFesFwPubDpAcc(std::string TagName);
SFesFwPubAcc* GetFesFwPubDpAcc(const std::string &TagName);
/**
* @brief CFesBase::GetFesFwPubFesMi
* TagNameFES转发点SFesFwPubMi
* @param TagName TagName
*/
SFesFwPubMi* GetFesFwPubFesMi(std::string TagName);
SFesFwPubMi* GetFesFwPubFesMi(const std::string &TagName);
/**
* @brief CFesBase::GetFesFwPubDpMi
* TagNameDP转发点SFesFwPubMi
* @param TagName TagName
*/
SFesFwPubMi* GetFesFwPubDpMi(std::string TagName);
SFesFwPubMi* GetFesFwPubDpMi(const std::string &TagName);
/**
* @brief CFesBase::WriteSoeEventBuf

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,19 @@
#include "FesDef.h"
#include <queue>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4003)
#endif
#include "rapidjson/document.h"
#ifdef _MSC_VER
#pragma warning(pop)
#endif
typedef boost::shared_ptr<rapidjson::Document> RapidJsonDocPtr;
class PROTOCOLBASE_API CFesRtu
{
public:
@ -47,6 +60,7 @@ public:
int m_MaxDiIndex; //实际数字量最大个数=最大PonitNo+1
int m_MaxAccIndex; //实际整形量最大个数=最大PonitNo+1
int m_MaxMiIndex; //实际混合量最大个数=最大PonitNo+1
int m_MinMiIndex; //实际混合量最小索引即规约参数1最小值,-1表示没有或者无效
int m_MaxAoIndex; //=最大PonitNo+1
int m_MaxDoIndex; //=最大PonitNo+1
int m_MaxMoIndex; //=最大PonitNo+1
@ -77,11 +91,11 @@ public:
int m_FwAoPointsNum; //实际转发遥调量个数
int m_FwDoPointsNum;
int m_FwMoPointsNum;
SFesFwAi *m_pFwAi; //转发点值为源数据的原始值,转发时需要乘上系数。
SFesFwAi *m_pFwAi; //转发点值为源数据的原始值,已经乘上系数。
SFesFwDi *m_pFwDi;
SFesFwDi *m_pFwDDi;
SFesFwAcc *m_pFwAcc; //转发点值为源数据的原始值,转发时需要乘上系数。
SFesFwMi *m_pFwMi; //转发点值为源数据的原始值,转发时需要乘上系数。
SFesFwAcc *m_pFwAcc; //转发点值为源数据的原始值,已经乘上系数。
SFesFwMi *m_pFwMi; //转发点值为源数据的原始值,已经乘上系数。
SFesFwAo *m_pFwAo;
SFesFwDo *m_pFwDo;
SFesFwMo *m_pFwMo;
@ -138,6 +152,7 @@ public:
std::queue<SFesRxMoCmd> RxMoCmdBuf;
std::queue<SFesRxSettingCmd> RxSettingCmdBuf;
std::queue<SFesRxDefCmd> RxDefCmdBuf;
std::queue<RapidJsonDocPtr> m_jsonFormatReqCmdBuf; //< 自定义命令用于存放json格式的自定义命令
//对于FES采集来说控制响应消息分成1、HMI消息发送 2、本FES转发协议内部交互 3、非本FES转发协议消息发送
//FES外部HMI控制响应队列
@ -146,6 +161,7 @@ public:
std::queue<SFesTxMoCmd> TxMoCmdBuf;
std::queue<SFesTxSettingCmd> TxSettingCmdBuf;
std::queue<SFesTxDefCmd> TxDefCmdBuf;
std::queue<std::string> m_jsonFormatReplayCmdBuf; //< 自定义命令反馈对应m_jsonFormatReqCmdBuf
//对于FES转发控制响应队列内部交互
std::queue<SFesFwDoRespCmd> FwDoRespCmdBuf;
@ -906,35 +922,35 @@ public:
* SOE EVENT缓冲区内容
* @param buffer
*/
void WriteFwSoeEventBuf(SFesFwSoeEvent buffer);
void WriteFwSoeEventBuf(const SFesFwSoeEvent &buffer);
/**
* @brief CFesRtu::WriteFwDiBuf
* DI变化缓冲区内容
* @param buffer
*/
void WriteFwDiBuf(SFesFwChgDi buffer);
void WriteFwDiBuf(const SFesFwChgDi &buffer);
/**
* @brief CFesRtu::WriteFwAiBuf
* Ai变化缓冲区内容
* @param buffer
*/
void WriteFwAiBuf(SFesFwChgAi buffer);
void WriteFwAiBuf(const SFesFwChgAi &buffer);
/**
* @brief CFesRtu::WriteFwAccBuf
* Acc变化缓冲区内容
* @param buffer
*/
void WriteFwAccBuf(SFesFwChgAcc buffer);
void WriteFwAccBuf(const SFesFwChgAcc &buffer);
/**
* @brief CFesRtu::WriteFwMiBuf
* Mi变化缓冲区内容
* @param buffer
*/
void WriteFwMiBuf(SFesFwChgMi buffer);
void WriteFwMiBuf(const SFesFwChgMi &buffer);
/**
* @brief CFesRtu::GetFwSOEEventNum
@ -1130,14 +1146,14 @@ public:
* DDI变化缓冲区内容
* @param buffer
*/
void WriteFwDDiBuf(SFesFwChgDi buffer);
void WriteFwDDiBuf(const SFesFwChgDi &buffer);
/**
* @brief CFesRtu::WriteFwDSoeEventBuf
* DSOE EVENT缓冲区内容
* @param buffer
*/
void WriteFwDSoeEventBuf(SFesFwSoeEvent buffer);
void WriteFwDSoeEventBuf(const SFesFwSoeEvent &buffer);
/**
* @brief CFesRtu::GetFwDSOEEventNum
@ -1162,7 +1178,7 @@ public:
* @param updateMode 1(DP to FES) 0(FES to FES)
* @return true: false:
*/
bool UpdataFwDiValue(SFesFwChgDi DiValue, int updateMode = 0);
bool UpdataFwDiValue(const SFesFwChgDi &DiValue, int updateMode = 0);
/**
* @brief CFesRtu::UpdataFwDiValue
@ -1171,16 +1187,16 @@ public:
* @param updateMode 1(DP to FES) 0(FES to FES)
* @return true: false:
*/
bool UpdataFwDDiValue(SFesFwChgDi DiValue, int updateMode = 0);
bool UpdataFwDDiValue(const SFesFwChgDi &DiValue, int updateMode = 0);
/**
* @brief CFesRtu::UpdataFwAiValue
* RTU AI数据
* RTU AI数据K值变换
* @param SFesFwChgAi
* @param updateMode 1(DP to FES) 0(FES to FES)
* @return true: false:
*/
bool UpdataFwAiValue(SFesFwChgAi AiValue, int updateMode = 0);
bool UpdataFwAiValue(const SFesFwChgAi &AiValue, float &fNewValue,EnumUpdateFwCacheMode eUpdateMode);
/**
* @brief CFesRtu::UpdataFwAccValue
@ -1189,7 +1205,7 @@ public:
* @param updateMode 1(DP to FES) 0(FES to FES)
* @return true: false:
*/
bool UpdataFwAccValue(SFesFwChgAcc AccValue, int updateMode = 0);
bool UpdataFwAccValue(const SFesFwChgAcc &AccValue, double &dNewValue,EnumUpdateFwCacheMode eUpdateMode);
/**
* @brief CFesRtu::UpdataFwMiValue
@ -1198,7 +1214,7 @@ public:
* @param updateMode 1(DP to FES) 0(FES to FES)
* @return true: false:
*/
bool UpdataFwMiValue(SFesFwChgMi MiValue, int updateMode = 0);
bool UpdataFwMiValue(const SFesFwChgMi &MiValue,int &nNewValue, EnumUpdateFwCacheMode eUpdateMode);
void ClearFwDiBuf();
void ClearFwDDiBuf();
@ -1325,7 +1341,7 @@ public:
void ClearComStatusInit();
void WriteVirtualValue(SFesVirtualValue Value);
void WriteVirtualValue(const SFesVirtualValue &Value);
int ReadVirtualValue(SFesVirtualValue *Value);
@ -1366,14 +1382,42 @@ public:
*/
int ReadSoeStrEvent(int num, SFesSoeStrEvent *buffer);
/**
/**
* @brief CFesRtu::WriteRtuPointsComDown
*
* @param comStatus RTU通信状态
*/
void WriteRtuPointsComDown();
/**
* @brief CFesRtu::writeStringFormatReqCmd
* FES自定义命令缓存区json
* @param strCmd
*/
void writeJsonFormatReqCmd(const rapidjson::Value &jsonCmd);
/**
* @brief CFesRtu::readStringFormatReqCmd
*
* @param dequeStrCmd
*/
void readJsonFormatReqCmd(std::queue<RapidJsonDocPtr> &dequeJsonCmd);
size_t getJsonFormatReqCmdSize();
void clearJsonFormatReqCmdBuf();
/**
* @brief CFesRtu::writeJsonFormatReplayCmd
* FES自定义命令反馈缓存区json
* @param strCmd
*/
void writeJsonFormatReplayCmd(const std::string &strCmd);
/**
* @brief CFesRtu::readJsonFormatReplayCmd
*
* @param dequeStrCmd
*/
void readJsonFormatReplayCmd(std::queue<std::string> &dequeStrCmd);
};
#ifndef FESSIM

View File

@ -421,7 +421,7 @@ typedef struct{
//整形量数值响应
typedef struct {
uint32 PointNo;
uint64 Value;
double Value;
uint32 Status;
uint64 time; //1970-01-01 00:00 至今的毫秒数
}SFesSimAccData;
@ -621,16 +621,16 @@ typedef struct{
}SFesSimDiStopResp;
//整形量仿真启动请求==================================
//累积量仿真启动请求==================================
typedef struct{
char SetMode; //设置方式 1固定设置 2线性设置 3随机设置
char Range; //设置范围 1当前模拟量 2当前RTU 3所有RTU
short Period; //变化周期,单位:秒
int64 SetValue; //设置值
double SetValue; //设置值
uint32 Status; //设值点状态
int MinValue; //设置值最小值
int MaxValue; //设置值最大值
int StepValue; //设置值步长
float MinValue; //设置值最小值
float MaxValue; //设置值最大值
float StepValue; //设置值步长
int RtuNo; // RTU号 -1 所有RTU 其他对应RTU号
int PointNo; //点号, -1RTU所有点 其他:对应点号
}SFesSimAccStartReq;

View File

@ -0,0 +1,15 @@
/**
@file PingApiCommon.h
@brief
@author
*/
#pragma once
#include <string>
#include "Export.h"
#ifdef FES_PING_EXPORTS
#define FES_PING_API G_DECL_EXPORT
#else
#define FES_PING_API G_DECL_IMPORT
#endif

View File

@ -0,0 +1,56 @@
/**
@file NetworkCheckInterface.h
@brief
@author
*/
#pragma once
#include <string>
#include "boost/shared_ptr.hpp"
#include "boost/make_shared.hpp"
#include "PingApiCommon.h"
#include "PingResultCache.h"
namespace iot_fes
{
/**
@brief
*/
class CPingInterface
{
public:
/**
@brief Ping
@return iotSuccess
*/
virtual int start() = 0;
//停止Ping
virtual int stop() = 0;
/**
@brief Ping的信息start执行执行
@param const int nChannelNo
@param const int nIpIdx IP
@param const std::string & strDstIP ping的IP地址
*/
virtual void addAddress(const int nChannelNo,const int nIpIdx,const std::string &strIp) = 0;
//获取指定通道的Ping结果
virtual bool getPingResult(const int nChannelNo) = 0;
//获取指定通道的Ping结果返回是ping的ip的索引找不到返回-1
virtual int getPingOkIpIndex(const int nChannelNo) = 0;
//启用指定通道的Ping功能
virtual void enablePing(const int nChannelNo) = 0;
//禁用指定通道的Ping功能
virtual void disablePing(const int nChannelNo) = 0;
};
typedef boost::shared_ptr<CPingInterface> CPingInterfacePtr;
/* @brief 创建网络检测访问库实例 */
FES_PING_API CPingInterfacePtr getPingInstance();
} //namespace iot_fes

View File

@ -0,0 +1,51 @@
/**
@file SysRunNetworkInfoTable.h
@brief sys_network_info对应的结构
@author
*/
#pragma once
#include <map>
#include <bitset>
#include <set>
#include <boost/thread.hpp>
#include "fes_ping_api/PingApiCommon.h"
namespace iot_fes
{
//每个通道最大Ip数量
//最高位用来标记启用Ping功能用于实现设备通信正常时关闭Ping功能通信异常时重新启用Ping
const int CONST_MAX_PING_NUM = 3;
typedef std::map<int,std::bitset<CONST_MAX_PING_NUM> > Chan2ConnStatMAP;
class CPingResultCache
{
public:
CPingResultCache();
~CPingResultCache();
//查询指定通道的Ping结果查询不到返回true认为网络OK
bool getPingResult(const int nChannelNo);
//获取指定通道的Ping结果返回是ping的ip的索引找不到返回-1
int getPingOkIpIndex(const int nChannelNo);
//设置通道Ip的Ping结果
void setPingResult(const int nChNo,const int nIdx,const bool bRet);
//查询指定通道是否启用如果找不到走默认逻辑认为需要Ping
//如果最高位设置为1表示当前网络正常可以暂停ping所以认为禁用返回false
bool isEnablePing(const int nChannelNo);
//启用Ping功能
void enablePing(const int nChannelNo);
//禁用Ping功能
void disablePing(const int nChannelNo);
private:
Chan2ConnStatMAP m_mapChToPingResult;
boost::mutex m_objMutex; //< 互斥量
};
typedef boost::shared_ptr<CPingResultCache> CPingResultCachePtr;
} //namespace iot_fes

View File

@ -0,0 +1,60 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_CONSOLELOGGER_H
#define OPENDNP3_CONSOLELOGGER_H
#include "opendnp3/logging/ILogHandler.h"
#include "opendnp3/util/Uncopyable.h"
#include <memory>
#include <mutex>
namespace opendnp3
{
/**
* LogHandler that prints all log messages to the console
*/
class ConsoleLogger final : public opendnp3::ILogHandler, private Uncopyable
{
public:
void log(opendnp3::ModuleId module,
const char* id,
opendnp3::LogLevel level,
char const* location,
char const* message) final;
static std::shared_ptr<opendnp3::ILogHandler> Create(bool printLocation = false)
{
return std::make_shared<ConsoleLogger>(printLocation);
};
ConsoleLogger(bool printLocation) : printLocation(printLocation) {}
private:
bool printLocation;
std::mutex mutex;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,217 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_DNP3MANAGER_H
#define OPENDNP3_DNP3MANAGER_H
#include "opendnp3/ErrorCodes.h"
#include "opendnp3/channel/ChannelRetry.h"
#include "opendnp3/channel/IChannel.h"
#include "opendnp3/channel/IChannelListener.h"
#include "opendnp3/channel/IListener.h"
#include "opendnp3/channel/IPEndpoint.h"
#include "opendnp3/channel/SerialSettings.h"
#include "opendnp3/channel/TLSConfig.h"
#include "opendnp3/gen/ChannelState.h"
#include "opendnp3/gen/ServerAcceptMode.h"
#include "opendnp3/logging/ILogHandler.h"
#include "opendnp3/logging/LogLevels.h"
#include "opendnp3/master/IListenCallbacks.h"
#include "opendnp3/util/TimeDuration.h"
#include <memory>
#include <system_error>
#include <vector>
namespace opendnp3
{
class DNP3ManagerImpl;
/**
* Root DNP3 object used to create channels and sessions.
*/
class DNP3Manager
{
public:
/**
* Construct a manager
*
* @param concurrencyHint How many threads to allocate in the thread pool
* @param handler Callback interface for log messages
* @param onThreadStart Action to run when a thread pool thread starts
* @param onThreadExit Action to run just before a thread pool thread exits
*/
DNP3Manager(uint32_t concurrencyHint,
std::shared_ptr<opendnp3::ILogHandler> handler = std::shared_ptr<opendnp3::ILogHandler>(),
std::function<void(uint32_t)> onThreadStart = [](uint32_t) {},
std::function<void(uint32_t)> onThreadExit = [](uint32_t) {});
~DNP3Manager();
/**
* Permanently shutdown the manager and all sub-objects that have been created. Stop
* the thead pool.
*/
void Shutdown();
/**
* Add a persistent TCP client channel. Automatically attempts to reconnect.
*
* @param id Alias that will be used for logging purposes with this channel
* @param levels Bitfield that describes the logging level for this channel and associated sessions
* @param retry Retry parameters for failed channels
* @param hosts List of host addresses to use to connect to the remote outstation (i.e. 127.0.0.1 or www.google.com)
* @param local adapter address on which to attempt the connection (use 0.0.0.0 for all adapters)
* @param listener optional callback interface (can be nullptr) for info about the running channel
* @return shared_ptr to a channel interface
*/
std::shared_ptr<IChannel> AddTCPClient(const std::string& id,
const opendnp3::LogLevels& levels,
const ChannelRetry& retry,
const std::vector<IPEndpoint>& hosts,
const std::string& local,
std::shared_ptr<IChannelListener> listener);
/**
* Add a persistent TCP server channel. Only accepts a single connection at a time.
*
* @param id Alias that will be used for logging purposes with this channel
* @param levels Bitfield that describes the logging level for this channel and associated sessions
* @param mode Describes how new connections are treated when another session already exists
* @param endpoint Network adapter to listen on (i.e. 127.0.0.1 or 0.0.0.0) and port
* @param listener optional callback interface (can be nullptr) for info about the running channel
* @throw DNP3Error if the manager was already shutdown or if the server could not be binded properly
* @return shared_ptr to a channel interface
*/
std::shared_ptr<IChannel> AddTCPServer(const std::string& id,
const opendnp3::LogLevels& levels,
ServerAcceptMode mode,
const IPEndpoint& endpoint,
std::shared_ptr<IChannelListener> listener);
/**
* Add a persistent UDP channel.
*
* @param id Alias that will be used for logging purposes with this channel
* @param levels Bitfield that describes the logging level for this channel and associated sessions
* @param retry Retry parameters for failed channels
* @param localEndpoint Local endpoint from which datagrams will be received
* @param remoteEndpoint Remote endpoint where datagrams will be sent to
* @param listener optional callback interface (can be nullptr) for info about the running channel
* @throw DNP3Error if the manager was already shutdown
* @return shared_ptr to a channel interface
*/
std::shared_ptr<IChannel> AddUDPChannel(const std::string& id,
const opendnp3::LogLevels& levels,
const ChannelRetry& retry,
const IPEndpoint& localEndpoint,
const IPEndpoint& remoteEndpoint,
std::shared_ptr<IChannelListener> listener);
/**
* Add a persistent serial channel
*
* @param id Alias that will be used for logging purposes with this channel
* @param levels Bitfield that describes the logging level for this channel and associated sessions
* @param retry Retry parameters for failed channels
* @param settings settings object that fully parameterizes the serial port
* @param listener optional callback interface (can be nullptr) for info about the running channel
* @throw DNP3Error if the manager was already shutdown
* @return shared_ptr to a channel interface
*/
std::shared_ptr<IChannel> AddSerial(const std::string& id,
const opendnp3::LogLevels& levels,
const ChannelRetry& retry,
SerialSettings settings,
std::shared_ptr<IChannelListener> listener);
/**
* Add a TLS client channel
*
* @throw std::system_error Throws underlying ASIO exception of TLS configuration is invalid
*
* @param id Alias that will be used for logging purposes with this channel
* @param levels Bitfield that describes the logging level for this channel and associated sessions
* @param retry Retry parameters for failed channels
* @param hosts IP address of remote outstation (i.e. 127.0.0.1 or www.google.com)
* @param local adapter address on which to attempt the connection (use 0.0.0.0 for all adapters)
* @param config TLS configuration information
* @param listener optional callback interface (can be nullptr) for info about the running channel
* @throw DNP3Error if the manager was already shutdown or if the library was compiled without TLS support
* @return shared_ptr to a channel interface
*/
std::shared_ptr<IChannel> AddTLSClient(const std::string& id,
const opendnp3::LogLevels& levels,
const ChannelRetry& retry,
const std::vector<IPEndpoint>& hosts,
const std::string& local,
const TLSConfig& config,
std::shared_ptr<IChannelListener> listener);
/**
* Add a TLS server channel
*
* @throw std::system_error Throws underlying ASIO exception of TLS configuration is invalid
*
* @param id Alias that will be used for logging purposes with this channel
* @param levels Bitfield that describes the logging level for this channel and associated sessions
* @param mode Describes how new connections are treated when another session already exists
* @param endpoint Network adapter to listen on (i.e. 127.0.0.1 or 0.0.0.0) and port
* @param config TLS configuration information
* @param listener optional callback interface (can be nullptr) for info about the running channel
* @throw DNP3Error if the manager was already shutdown, if the library was compiled without TLS support
* or if the server could not be binded properly
* @return shared_ptr to a channel interface
*/
std::shared_ptr<IChannel> AddTLSServer(const std::string& id,
const opendnp3::LogLevels& levels,
ServerAcceptMode mode,
const IPEndpoint& endpoint,
const TLSConfig& config,
std::shared_ptr<IChannelListener> listener);
/**
* Create a TCP listener that will be used to accept incoming connections
* @throw DNP3Error if the manager was already shutdown or if the server could not be binded properly
*/
std::shared_ptr<IListener> CreateListener(std::string loggerid,
const opendnp3::LogLevels& loglevel,
const IPEndpoint& endpoint,
const std::shared_ptr<IListenCallbacks>& callbacks);
/**
* Create a TLS listener that will be used to accept incoming connections
* @throw DNP3Error if the manager was already shutdown, if the library was compiled without TLS support
* or if the server could not be binded properly
*/
std::shared_ptr<IListener> CreateListener(std::string loggerid,
const opendnp3::LogLevels& loglevel,
const IPEndpoint& endpoint,
const TLSConfig& config,
const std::shared_ptr<IListenCallbacks>& callbacks);
private:
std::unique_ptr<DNP3ManagerImpl> impl;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,66 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_ERRORCODES_H
#define OPENDNP3_ERRORCODES_H
#include <stdexcept>
#include <string>
#include <system_error>
namespace opendnp3
{
enum class Error : int
{
SHUTTING_DOWN,
NO_TLS_SUPPORT,
UNABLE_TO_BIND_SERVER
};
struct ErrorSpec
{
static std::string to_string(Error err)
{
switch (err)
{
case Error::SHUTTING_DOWN:
return "The operation was requested while the resource was shutting down";
case Error::NO_TLS_SUPPORT:
return "Not built with TLS support";
case Error::UNABLE_TO_BIND_SERVER:
return "Unable to bind server to the specified port";
default:
return "unknown error";
};
}
};
class DNP3Error final : public std::runtime_error
{
public:
explicit DNP3Error(Error err) : std::runtime_error(ErrorSpec::to_string(err)) {}
DNP3Error(Error err, std::error_code& ec) : std::runtime_error(ErrorSpec::to_string(err) + ": " + ec.message()) {}
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,39 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_IRESOURCE_H
#define OPENDNP3_IRESOURCE_H
namespace opendnp3
{
/**
* Anything that can be shutdown
*/
struct IResource
{
public:
virtual ~IResource() = default;
virtual void Shutdown() = 0;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,55 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_ISTACK_H
#define OPENDNP3_ISTACK_H
#include "opendnp3/IResource.h"
#include "opendnp3/StackStatistics.h"
namespace opendnp3
{
/**
* Base class for masters or outstations
*/
class IStack : public IResource
{
public:
virtual ~IStack() {}
/**
* Synchronously enable communications
*/
virtual bool Enable() = 0;
/**
* Synchronously disable communications
*/
virtual bool Disable() = 0;
/**
* @return stack statistics counters
*/
virtual StackStatistics GetStackStatistics() = 0;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,91 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_STACKSTATISTICS_H
#define OPENDNP3_STACKSTATISTICS_H
#include <cstdint>
namespace opendnp3
{
/**
* Statistics related to both a master or outstation session
*/
struct StackStatistics
{
struct Link
{
/// number of unexpected frames
uint64_t numUnexpectedFrame = 0;
/// frames received w/ wrong master bit
uint64_t numBadMasterBit = 0;
/// frames received for an unknown destination
uint64_t numUnknownDestination = 0;
/// frames received for an unknown source
uint64_t numUnknownSource = 0;
};
struct Transport
{
struct Rx
{
/// Number of valid TPDU's received
uint64_t numTransportRx = 0;
/// Number of TPDUs dropped due to malformed contents
uint64_t numTransportErrorRx = 0;
/// Number of times received data was too big for reassembly buffer
uint64_t numTransportBufferOverflow = 0;
/// number of times transport buffer is discard due to new FIR
uint64_t numTransportDiscard = 0;
/// number of segments ignored due to bad FIR/FIN or SEQ
uint64_t numTransportIgnore = 0;
};
struct Tx
{
/// Number of TPDUs transmitted
uint64_t numTransportTx = 0;
};
Transport() = default;
Transport(const Rx& rx, const Tx& tx) : rx(rx), tx(tx) {}
Rx rx;
Tx tx;
};
StackStatistics() = default;
StackStatistics(const Link& link, const Transport& transport) : link(link), transport(transport) {}
Link link;
Transport transport;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,50 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_ANALOGCOMMANDEVENT_H
#define OPENDNP3_ANALOGCOMMANDEVENT_H
#include "opendnp3/app/DNPTime.h"
#include "opendnp3/gen/CommandStatus.h"
namespace opendnp3
{
/**
* Occurs when an outstation receives and analog command. Maps to Group43.
*/
class AnalogCommandEvent
{
public:
AnalogCommandEvent();
AnalogCommandEvent(double value, CommandStatus status);
AnalogCommandEvent(double value, CommandStatus status, DNPTime time);
double value;
CommandStatus status;
DNPTime time;
bool operator==(const AnalogCommandEvent& rhs) const;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,108 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_ANALOGOUTPUT_H
#define OPENDNP3_ANALOGOUTPUT_H
#include "opendnp3/gen/CommandStatus.h"
namespace opendnp3
{
/**
* The object to represent a setpoint request from the master. Think of
* this like turning a dial on the front of a machine to desired setting.
*/
template<class T> class AnalogOutput
{
public:
AnalogOutput() : value(0), status(CommandStatus::SUCCESS) {}
AnalogOutput(T value_) : value(value_), status(CommandStatus::SUCCESS) {}
AnalogOutput(T value_, CommandStatus status_) : value(value_), status(status_) {}
bool ValuesEqual(const AnalogOutput<T>& lhs) const
{
return value == lhs.value;
}
T value;
/**
* The status value defaults to CS_SUCCESS for requests
*/
CommandStatus status;
};
/**
* 16-bit signed integer analog output. The underlying serialization is Group41, Variation 2
*/
class AnalogOutputInt16 : public AnalogOutput<int16_t>
{
public:
AnalogOutputInt16();
AnalogOutputInt16(int16_t);
AnalogOutputInt16(int16_t, CommandStatus);
bool operator==(const AnalogOutputInt16& arRHS) const;
};
/**
* 32-bit signed integer analog output. The underlying serialization is Group41, Variation 1
*/
class AnalogOutputInt32 : public AnalogOutput<int32_t>
{
public:
AnalogOutputInt32();
AnalogOutputInt32(int32_t);
AnalogOutputInt32(int32_t, CommandStatus);
bool operator==(const AnalogOutputInt32& arRHS) const;
};
/**
* Single precision analog output. The underlying serialization is Group41, Variation 3
*/
class AnalogOutputFloat32 : public AnalogOutput<float>
{
public:
AnalogOutputFloat32();
AnalogOutputFloat32(float);
AnalogOutputFloat32(float, CommandStatus);
bool operator==(const AnalogOutputFloat32& arRHS) const;
};
/**
* Double precision analog output. The underlying serialization is Group41, Variation 3
*/
class AnalogOutputDouble64 : public AnalogOutput<double>
{
public:
AnalogOutputDouble64();
AnalogOutputDouble64(double);
AnalogOutputDouble64(double, CommandStatus);
bool operator==(const AnalogOutputDouble64& arRHS) const;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,37 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_APPCONSTANTS_H
#define OPENDNP3_APPCONSTANTS_H
#include "opendnp3/util/TimeDuration.h"
#include <cstdint>
namespace opendnp3
{
// the default size for an APDU
const uint32_t DEFAULT_MAX_APDU_SIZE = 2048;
// default timeout for the application layer
const TimeDuration DEFAULT_APP_TIMEOUT = TimeDuration::Seconds(5);
} // namespace opendnp3
#endif

View File

@ -0,0 +1,65 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_BASEMEASUREMENTTYPES_H
#define OPENDNP3_BASEMEASUREMENTTYPES_H
#include "opendnp3/app/DNPTime.h"
#include "opendnp3/app/Flags.h"
#include <cstdint>
namespace opendnp3
{
/**
Base class shared by all of the DataPoint types.
*/
class Measurement
{
public:
Flags flags; // bitfield that stores type specific quality information
DNPTime time; // timestamp associated with the measurement
protected:
Measurement() {}
Measurement(Flags flags) : flags(flags) {}
Measurement(Flags flags, DNPTime time) : flags(flags), time(time) {}
};
/// Common subclass to analogs and counters
template<class T> class TypedMeasurement : public Measurement
{
public:
T value;
typedef T Type;
protected:
TypedMeasurement() : Measurement(), value(0) {}
TypedMeasurement(Flags flags) : Measurement(flags), value(0) {}
TypedMeasurement(T value, Flags flags) : Measurement(flags), value(value) {}
TypedMeasurement(T value, Flags flags, DNPTime time) : Measurement(flags, time), value(value) {}
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,65 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_BINARYCOMMANDEVENT_H
#define OPENDNP3_BINARYCOMMANDEVENT_H
#include "opendnp3/app/DNPTime.h"
#include "opendnp3/app/Flags.h"
#include "opendnp3/gen/CommandStatus.h"
namespace opendnp3
{
/**
Maps to Group13Var1/2
*/
class BinaryCommandEvent
{
public:
BinaryCommandEvent();
BinaryCommandEvent(Flags flags);
BinaryCommandEvent(Flags flags, DNPTime time);
BinaryCommandEvent(bool value, CommandStatus status);
BinaryCommandEvent(bool value, CommandStatus status, DNPTime time);
bool value;
CommandStatus status;
DNPTime time;
Flags GetFlags() const;
bool operator==(const BinaryCommandEvent& rhs) const;
private:
static const uint8_t ValueMask = 0x80;
static const uint8_t StatusMask = 0x7F;
static bool GetValueFromFlags(Flags flags);
static CommandStatus GetStatusFromFlags(Flags flags);
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,91 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_CLASSFIELD_H
#define OPENDNP3_CLASSFIELD_H
#include "opendnp3/app/EventType.h"
#include "opendnp3/gen/PointClass.h"
#include <cstdint>
namespace opendnp3
{
/**
* Specifies a set of event classes e.g. some subset of {0, 1, 2, 3}
*/
class ClassField
{
public:
ClassField();
explicit ClassField(PointClass pc);
explicit ClassField(EventClass ec);
explicit ClassField(uint8_t mask_);
ClassField(bool class0, bool class1, bool class2, bool class3);
bool IsEmpty() const;
bool Intersects(const ClassField& other) const;
uint8_t GetBitfield() const
{
return bitfield;
};
ClassField OnlyEventClasses() const;
void Clear(const ClassField& field);
void Set(const ClassField& field);
void Set(PointClass pc);
static const uint8_t CLASS_0 = static_cast<uint8_t>(PointClass::Class0);
static const uint8_t CLASS_1 = static_cast<uint8_t>(PointClass::Class1);
static const uint8_t CLASS_2 = static_cast<uint8_t>(PointClass::Class2);
static const uint8_t CLASS_3 = static_cast<uint8_t>(PointClass::Class3);
static const uint8_t EVENT_CLASSES = CLASS_1 | CLASS_2 | CLASS_3;
static const uint8_t ALL_CLASSES = EVENT_CLASSES | CLASS_0;
bool HasEventType(EventClass ec) const;
bool HasClass0() const;
bool HasClass1() const;
bool HasClass2() const;
bool HasClass3() const;
bool HasEventClass() const;
bool HasAnyClass() const;
static ClassField None();
static ClassField AllClasses();
static ClassField AllEventClasses();
private:
uint8_t bitfield;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,92 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_CONTROLRELAYOUTPUTBLOCK_H
#define OPENDNP3_CONTROLRELAYOUTPUTBLOCK_H
#include "opendnp3/gen/CommandStatus.h"
#include "opendnp3/gen/OperationType.h"
#include "opendnp3/gen/TripCloseCode.h"
namespace opendnp3
{
/**
* Describes an incoming control request from the master. It is the
* applications responsibility to handle the request and return an
* approiate status code. The PULSE_CLOSE and PULSE_TRIP OperationType
* require setting the mOnTimeMS, mOffTimeMS and mCount variables, otherwise
* just use the defaults.
*/
class ControlRelayOutputBlock
{
public:
// primary constructor where the control code is split by its components
ControlRelayOutputBlock(OperationType opType = OperationType::LATCH_ON,
TripCloseCode tcc = TripCloseCode::NUL,
bool clear = false,
uint8_t count = 1,
uint32_t onTime = 100,
uint32_t offTime = 100,
CommandStatus status = CommandStatus::SUCCESS);
// overloaded constructor that allows the user to set a raw control code for non-standard codes
ControlRelayOutputBlock(uint8_t rawCode,
uint8_t count = 1,
uint32_t onTime = 100,
uint32_t offTime = 100,
CommandStatus status = CommandStatus::SUCCESS);
/// operation type
OperationType opType;
// trip-close code
TripCloseCode tcc;
// clear bit
bool clear;
/// the number of times to repeat the operation
uint8_t count;
/// the 'on' time for the pulse train
uint32_t onTimeMS;
/// the 'off' time for the pulse train
uint32_t offTimeMS;
/// status of the resulting operation
CommandStatus status;
/// The raw code in bytes
uint8_t rawCode;
bool IsQUFlagSet() const
{
return (rawCode & 0x10) != 0;
}
bool ValuesEqual(const ControlRelayOutputBlock& lhs) const
{
return (opType == lhs.opType) && (tcc == lhs.tcc) && (clear == lhs.clear) && (count == lhs.count)
&& (onTimeMS == lhs.onTimeMS) && (offTimeMS == lhs.offTimeMS);
}
bool operator==(const ControlRelayOutputBlock& lhs) const
{
return this->ValuesEqual(lhs) && (this->status == lhs.status);
}
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,47 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_DNPTIME_H
#define OPENDNP3_DNPTIME_H
#include "opendnp3/gen/TimestampQuality.h"
#include <cstdint>
namespace opendnp3
{
struct DNPTime
{
DNPTime() : value(0), quality(TimestampQuality::INVALID) {}
explicit DNPTime(uint64_t value) : value(value), quality(TimestampQuality::SYNCHRONIZED) {}
DNPTime(uint64_t value, TimestampQuality quality) : value(value), quality(quality) {}
bool operator==(const DNPTime& rhs) const
{
return this->value == rhs.value && this->quality == rhs.quality;
}
uint64_t value;
TimestampQuality quality;
};
} // namespace opendnp3
#endif // namespace opendnp3

View File

@ -0,0 +1,70 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_EVENTCELLS_H
#define OPENDNP3_EVENTCELLS_H
#include "opendnp3/app/EventType.h"
#include "opendnp3/gen/PointClass.h"
namespace opendnp3
{
/// A null object for types that have no metadata
struct EmptyEventCell
{
};
/// Base class for different types of event metadata
template<class Spec> struct EventCellBase
{
PointClass clazz;
typename Spec::meas_t lastEvent;
typename Spec::event_variation_t evariation;
void SetEventValue(const typename Spec::meas_t& value)
{
lastEvent = value;
}
protected:
EventCellBase() : clazz(PointClass::Class1), lastEvent(), evariation(Spec::DefaultEventVariation) {}
};
/// Metatype w/o a deadband
template<class Spec> struct SimpleEventCell : EventCellBase<Spec>
{
bool IsEvent(const typename Spec::config_t& config, const typename Spec::meas_t& newValue) const
{
return Spec::IsEvent(this->lastEvent, newValue);
}
};
/// Structure for holding metadata information on points that have support deadbanding
template<class Spec> struct DeadbandEventCell : SimpleEventCell<Spec>
{
bool IsEvent(const typename Spec::config_t& config, const typename Spec::meas_t& newValue) const
{
return Spec::IsEvent(this->lastEvent, newValue, config.deadband);
}
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,45 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_EVENTTRIGGERS_H
#define OPENDNP3_EVENTTRIGGERS_H
#include "opendnp3/app/BaseMeasurementTypes.h"
namespace opendnp3
{
namespace measurements
{
template<class T, class U> bool IsEvent(const T& val1, const T& val2, T deadband)
{
// T can be unsigned data type so std::abs won't work since it only directly supports signed data types
// If one uses std::abs and T is unsigned one will get an ambiguous override error.
U diff = (val2 > val1) ? (static_cast<U>(val2) - static_cast<U>(val1))
: (static_cast<U>(val1) - static_cast<U>(val2));
return diff > deadband;
}
bool IsEvent(const TypedMeasurement<double>& newMeas, const TypedMeasurement<double>& oldMeas, double deadband);
} // namespace measurements
} // namespace opendnp3
#endif

View File

@ -0,0 +1,49 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_EVENTTYPE_H
#define OPENDNP3_EVENTTYPE_H
#include <cstdint>
namespace opendnp3
{
enum class EventType : uint16_t
{
Binary = 0,
Analog = 1,
Counter = 2,
FrozenCounter = 3,
DoubleBitBinary = 4,
BinaryOutputStatus = 5,
AnalogOutputStatus = 6,
OctetString = 7
};
enum class EventClass : uint8_t
{
EC1 = 0,
EC2 = 1,
EC3 = 2
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,118 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_FLAGS_H
#define OPENDNP3_FLAGS_H
#include "opendnp3/gen/AnalogOutputStatusQuality.h"
#include "opendnp3/gen/AnalogQuality.h"
#include "opendnp3/gen/BinaryOutputStatusQuality.h"
#include "opendnp3/gen/BinaryQuality.h"
#include "opendnp3/gen/CounterQuality.h"
#include "opendnp3/gen/DoubleBitBinaryQuality.h"
#include "opendnp3/gen/FrozenCounterQuality.h"
namespace opendnp3
{
/**
Measurement Flags
*/
class Flags
{
public:
Flags() : value(0) {}
explicit Flags(uint8_t value) : value(value) {}
inline bool IsSet(BinaryQuality flag) const
{
return IsSetAny(flag);
}
inline bool IsSet(DoubleBitBinaryQuality flag) const
{
return IsSetAny(flag);
}
inline bool IsSet(AnalogQuality flag) const
{
return IsSetAny(flag);
}
inline bool IsSet(CounterQuality flag) const
{
return IsSetAny(flag);
}
inline bool IsSet(FrozenCounterQuality flag) const
{
return IsSetAny(flag);
}
inline bool IsSet(BinaryOutputStatusQuality flag) const
{
return IsSetAny(flag);
}
inline bool IsSet(AnalogOutputStatusQuality flag) const
{
return IsSetAny(flag);
}
inline void Set(BinaryQuality flag)
{
SetAny(flag);
}
inline void Set(DoubleBitBinaryQuality flag)
{
SetAny(flag);
}
inline void Set(AnalogQuality flag)
{
SetAny(flag);
}
inline void Set(CounterQuality flag)
{
SetAny(flag);
}
inline void Set(FrozenCounterQuality flag)
{
SetAny(flag);
}
inline void Set(BinaryOutputStatusQuality flag)
{
SetAny(flag);
}
inline void Set(AnalogOutputStatusQuality flag)
{
SetAny(flag);
}
uint8_t value;
protected:
template<class T> bool IsSetAny(T flag) const
{
return (value & static_cast<uint8_t>(flag)) != 0;
}
template<class T> void SetAny(T flag)
{
value |= static_cast<uint8_t>(flag);
}
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,41 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_GROUPVARIATIONID_H
#define OPENDNP3_GROUPVARIATIONID_H
#include <cstdint>
namespace opendnp3
{
/// Simple uint8_t/uint8_t tuple for group and variation
struct GroupVariationID
{
GroupVariationID() : group(0xFF), variation(0xFF) {}
GroupVariationID(uint8_t aGroup, uint8_t aVariation) : group(aGroup), variation(aVariation) {}
uint8_t group;
uint8_t variation;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,191 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_IINFIELD_H
#define OPENDNP3_IINFIELD_H
#include <cstdint>
namespace opendnp3
{
enum class IINBit
{
BROADCAST = 0,
CLASS1_EVENTS,
CLASS2_EVENTS,
CLASS3_EVENTS,
NEED_TIME,
LOCAL_CONTROL,
DEVICE_TROUBLE,
DEVICE_RESTART,
FUNC_NOT_SUPPORTED,
OBJECT_UNKNOWN,
PARAM_ERROR,
EVENT_BUFFER_OVERFLOW,
ALREADY_EXECUTING,
CONFIG_CORRUPT,
RESERVED1,
RESERVED2 = 15
};
/** DNP3 two-byte IIN field.
*/
class IINField
{
private:
enum class LSBMask : uint8_t
{
BROADCAST = 0x01,
CLASS1_EVENTS = 0x02,
CLASS2_EVENTS = 0x04,
CLASS3_EVENTS = 0x08,
NEED_TIME = 0x10,
LOCAL_CONTROL = 0x20,
DEVICE_TROUBLE = 0x40,
DEVICE_RESTART = 0x80,
};
enum class MSBMask : uint8_t
{
FUNC_NOT_SUPPORTED = 0x01,
OBJECT_UNKNOWN = 0x02,
PARAM_ERROR = 0x04,
EVENT_BUFFER_OVERFLOW = 0x08,
ALREADY_EXECUTING = 0x10,
CONFIG_CORRUPT = 0x20,
RESERVED1 = 0x40,
RESERVED2 = 0x80,
// special mask that indicates if there was any error processing a request
REQUEST_ERROR_MASK = FUNC_NOT_SUPPORTED | OBJECT_UNKNOWN | PARAM_ERROR
};
public:
static IINField Empty()
{
return IINField(0, 0);
}
IINField(IINBit bit) : LSB(0), MSB(0)
{
this->SetBit(bit);
}
IINField(uint8_t aLSB, uint8_t aMSB) : LSB(aLSB), MSB(aMSB) {}
IINField() : LSB(0), MSB(0) {}
bool IsSet(IINBit bit) const;
bool IsClear(IINBit bit) const
{
return !IsSet(bit);
}
void SetBit(IINBit bit);
void ClearBit(IINBit bit);
void SetBitToValue(IINBit bit, bool value);
bool operator==(const IINField& aRHS) const;
bool Any() const
{
return (LSB | MSB) != 0;
}
void Clear()
{
LSB = MSB = 0;
}
bool HasRequestError() const
{
return Get(MSBMask::REQUEST_ERROR_MASK);
}
IINField operator|(const IINField& aIIN) const
{
return IINField(LSB | aIIN.LSB, MSB | aIIN.MSB);
}
IINField& operator|=(const IINField& aIIN)
{
MSB |= aIIN.MSB;
LSB |= aIIN.LSB;
return *this;
}
IINField operator&(const IINField& aIIN) const
{
return IINField(LSB & aIIN.LSB, MSB & aIIN.MSB);
}
IINField& operator&=(const IINField& aIIN)
{
MSB &= aIIN.MSB;
LSB &= aIIN.LSB;
return *this;
}
IINField operator~() const
{
return IINField(~LSB, ~MSB);
}
uint8_t LSB;
uint8_t MSB;
private:
static const uint8_t REQUEST_ERROR_MASK;
inline bool Get(LSBMask bit) const
{
return (LSB & static_cast<uint8_t>(bit)) != 0;
}
inline bool Get(MSBMask bit) const
{
return (MSB & static_cast<uint8_t>(bit)) != 0;
}
inline void Set(LSBMask bit)
{
LSB |= static_cast<uint8_t>(bit);
}
inline void Set(MSBMask bit)
{
MSB |= static_cast<uint8_t>(bit);
}
inline void Clear(LSBMask bit)
{
LSB &= ~static_cast<uint8_t>(bit);
}
inline void Clear(MSBMask bit)
{
MSB &= ~static_cast<uint8_t>(bit);
}
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,49 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_INDEXED_H
#define OPENDNP3_INDEXED_H
#include <cstdint>
namespace opendnp3
{
/**
* A simple tuple for pairing Values with an index
*/
template<class T> class Indexed
{
public:
Indexed(const T& value_, uint16_t index_) : value(value_), index(index_) {}
Indexed() : value(), index(0) {}
T value;
uint16_t index;
};
template<class T> Indexed<T> WithIndex(const T& value, uint16_t index)
{
return Indexed<T>(value, index);
}
} // namespace opendnp3
#endif

View File

@ -0,0 +1,166 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_MEASUREMENTINFO_H
#define OPENDNP3_MEASUREMENTINFO_H
#include "opendnp3/app/EventType.h"
#include "opendnp3/app/MeasurementTypes.h"
#include "opendnp3/app/OctetString.h"
#include "opendnp3/gen/BinaryQuality.h"
#include "opendnp3/gen/EventAnalogOutputStatusVariation.h"
#include "opendnp3/gen/EventAnalogVariation.h"
#include "opendnp3/gen/EventBinaryOutputStatusVariation.h"
#include "opendnp3/gen/EventBinaryVariation.h"
#include "opendnp3/gen/EventCounterVariation.h"
#include "opendnp3/gen/EventDoubleBinaryVariation.h"
#include "opendnp3/gen/EventFrozenCounterVariation.h"
#include "opendnp3/gen/EventOctetStringVariation.h"
#include "opendnp3/gen/EventSecurityStatVariation.h"
#include "opendnp3/gen/StaticAnalogOutputStatusVariation.h"
#include "opendnp3/gen/StaticAnalogVariation.h"
#include "opendnp3/gen/StaticBinaryOutputStatusVariation.h"
#include "opendnp3/gen/StaticBinaryVariation.h"
#include "opendnp3/gen/StaticCounterVariation.h"
#include "opendnp3/gen/StaticDoubleBinaryVariation.h"
#include "opendnp3/gen/StaticFrozenCounterVariation.h"
#include "opendnp3/gen/StaticOctetStringVariation.h"
#include "opendnp3/gen/StaticSecurityStatVariation.h"
#include "opendnp3/gen/StaticTimeAndIntervalVariation.h"
#include "opendnp3/gen/StaticTypeBitmask.h"
#include "opendnp3/util/StaticOnly.h"
namespace opendnp3
{
struct BinaryInfo : private StaticOnly
{
typedef Binary meas_t;
typedef bool value_t;
typedef EventBinaryVariation event_variation_t;
typedef StaticBinaryVariation static_variation_t;
static const EventType EventTypeEnum;
static const StaticTypeBitmask StaticTypeEnum;
static const event_variation_t DefaultEventVariation;
static const static_variation_t DefaultStaticVariation;
};
struct DoubleBitBinaryInfo : private StaticOnly
{
typedef DoubleBitBinary meas_t;
typedef DoubleBit value_t;
typedef EventDoubleBinaryVariation event_variation_t;
typedef StaticDoubleBinaryVariation static_variation_t;
static const EventType EventTypeEnum;
static const StaticTypeBitmask StaticTypeEnum;
static const event_variation_t DefaultEventVariation;
static const static_variation_t DefaultStaticVariation;
};
struct BinaryOutputStatusInfo : private StaticOnly
{
typedef BinaryOutputStatus meas_t;
typedef bool value_t;
typedef EventBinaryOutputStatusVariation event_variation_t;
typedef StaticBinaryOutputStatusVariation static_variation_t;
static const EventType EventTypeEnum;
static const StaticTypeBitmask StaticTypeEnum;
static const event_variation_t DefaultEventVariation;
static const static_variation_t DefaultStaticVariation;
};
struct AnalogInfo : private StaticOnly
{
typedef Analog meas_t;
typedef double value_t;
typedef EventAnalogVariation event_variation_t;
typedef StaticAnalogVariation static_variation_t;
static const EventType EventTypeEnum;
static const StaticTypeBitmask StaticTypeEnum;
static const event_variation_t DefaultEventVariation;
static const static_variation_t DefaultStaticVariation;
};
struct CounterInfo : private StaticOnly
{
typedef Counter meas_t;
typedef uint32_t value_t;
typedef EventCounterVariation event_variation_t;
typedef StaticCounterVariation static_variation_t;
static const EventType EventTypeEnum;
static const StaticTypeBitmask StaticTypeEnum;
static const event_variation_t DefaultEventVariation;
static const static_variation_t DefaultStaticVariation;
};
struct FrozenCounterInfo : private StaticOnly
{
typedef FrozenCounter meas_t;
typedef uint32_t value_t;
typedef EventFrozenCounterVariation event_variation_t;
typedef StaticFrozenCounterVariation static_variation_t;
static const EventType EventTypeEnum;
static const StaticTypeBitmask StaticTypeEnum;
static const event_variation_t DefaultEventVariation;
static const static_variation_t DefaultStaticVariation;
};
struct AnalogOutputStatusInfo : private StaticOnly
{
typedef AnalogOutputStatus meas_t;
typedef double value_t;
typedef EventAnalogOutputStatusVariation event_variation_t;
typedef StaticAnalogOutputStatusVariation static_variation_t;
static const EventType EventTypeEnum;
static const StaticTypeBitmask StaticTypeEnum;
static const event_variation_t DefaultEventVariation;
static const static_variation_t DefaultStaticVariation;
};
struct OctetStringInfo : private StaticOnly
{
typedef OctetString meas_t;
typedef EventOctetStringVariation event_variation_t;
typedef StaticOctetStringVariation static_variation_t;
static const EventType EventTypeEnum;
static const StaticTypeBitmask StaticTypeEnum;
static const event_variation_t DefaultEventVariation;
static const static_variation_t DefaultStaticVariation;
};
struct TimeAndIntervalInfo : private StaticOnly
{
typedef TimeAndInterval meas_t;
typedef StaticTimeAndIntervalVariation static_variation_t;
static const StaticTypeBitmask StaticTypeEnum;
static const StaticTimeAndIntervalVariation DefaultStaticVariation;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,186 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_MEASUREMENTTYPES_H
#define OPENDNP3_MEASUREMENTTYPES_H
#include "opendnp3/app/BaseMeasurementTypes.h"
#include "opendnp3/gen/DoubleBit.h"
#include "opendnp3/gen/IntervalUnits.h"
namespace opendnp3
{
/**
The Binary data type is for describing on-off (boolean) type values. Good examples of
binaries are alarms, mode settings, enabled/disabled flags etc. Think of it as a status
LED on a piece of equipment.
*/
class Binary : public TypedMeasurement<bool>
{
public:
Binary();
explicit Binary(bool value);
explicit Binary(Flags flags);
Binary(Flags flags, DNPTime time);
Binary(bool value, Flags flags);
Binary(bool value, Flags flags, DNPTime time);
};
/**
The Double-bit Binary data type has two stable states, on and off, and an in transit state. Motor operated switches
or binary valves are good examples.
*/
class DoubleBitBinary : public TypedMeasurement<DoubleBit>
{
public:
DoubleBitBinary();
explicit DoubleBitBinary(DoubleBit value);
explicit DoubleBitBinary(Flags flags);
DoubleBitBinary(Flags flags, DNPTime time);
DoubleBitBinary(DoubleBit value, Flags flags);
DoubleBitBinary(DoubleBit value, Flags flags, DNPTime time);
private:
static const uint8_t ValueMask = 0xC0;
static const uint8_t QualityMask = 0x3F;
static DoubleBit GetValue(Flags flags);
static Flags GetFlags(Flags flags, DoubleBit state);
};
/**
BinaryOutputStatus is used for describing the current state of a control. It is very infrequently
used and many masters don't provide any mechanisms for reading these values so their use is
strongly discouraged, a Binary should be used instead.
*/
class BinaryOutputStatus : public TypedMeasurement<bool>
{
public:
BinaryOutputStatus();
explicit BinaryOutputStatus(bool value);
explicit BinaryOutputStatus(Flags flags);
BinaryOutputStatus(Flags flags, DNPTime time);
BinaryOutputStatus(bool value, Flags flags);
BinaryOutputStatus(bool value, Flags flags, DNPTime time);
};
/**
Analogs are used for variable data points that usually reflect a real world value.
Good examples are current, voltage, sensor readouts, etc. Think of a speedometer guage.
*/
class Analog : public TypedMeasurement<double>
{
public:
Analog();
explicit Analog(double value);
Analog(double value, Flags flags);
Analog(double value, Flags flags, DNPTime time);
};
/**
Counters are used for describing generally increasing values (non-negative!). Good examples are
total power consumed, max voltage. Think odometer on a car.
*/
class Counter : public TypedMeasurement<uint32_t>
{
public:
Counter();
explicit Counter(uint32_t value);
Counter(uint32_t value, Flags flags);
Counter(uint32_t value, Flags flags, DNPTime time);
};
/**
Frozen counters are used to report the value of a counter point captured at the instant when the count is frozen.
*/
class FrozenCounter : public TypedMeasurement<uint32_t>
{
public:
FrozenCounter();
explicit FrozenCounter(uint32_t value);
FrozenCounter(uint32_t value, Flags flags);
FrozenCounter(uint32_t value, Flags flags, DNPTime time);
};
/**
Describes the last set value of the set-point. Like the BinaryOutputStatus data type it is not
well supported and its generally better practice to use an explicit analog.
*/
class AnalogOutputStatus : public TypedMeasurement<double>
{
public:
AnalogOutputStatus();
explicit AnalogOutputStatus(double value);
AnalogOutputStatus(double value, Flags flags);
AnalogOutputStatus(double value, Flags flags, DNPTime time);
};
/**
Maps to Group50Var4
This class is a bit of an outlier as an indexed type and is really only used in the DNP3 PV profile
*/
class TimeAndInterval
{
public:
TimeAndInterval();
TimeAndInterval(DNPTime time, uint32_t interval, uint8_t units);
TimeAndInterval(DNPTime time, uint32_t interval, IntervalUnits units);
IntervalUnits GetUnitsEnum() const;
DNPTime time;
uint32_t interval;
uint8_t units;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,110 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_OCTETDATA_H
#define OPENDNP3_OCTETDATA_H
#include "opendnp3/util/Buffer.h"
#include <array>
#include <cstdint>
namespace opendnp3
{
/**
* A base-class for bitstrings containing up to 255 bytes
*/
class OctetData
{
public:
const static uint8_t MAX_SIZE = 255;
/**
* Construct with a default value of [0x00] (length == 1)
*/
OctetData();
/**
* Construct from a c-style string
*
* strlen() is used internally to determine the length
*
* If the length is 0, the default value of [0x00] is assigned
* If the length is > 255, only the first 255 bytes are copied.
*
* The null terminator is NOT copied as part of buffer
*/
OctetData(const char* input);
/**
* Construct from read-only buffer slice
*
*
* If the length is 0, the default value of [0x00] is assigned
* If the length is > 255, only the first 255 bytes are copied.
*
* The null terminator is NOT copied as part of buffer
*/
OctetData(const Buffer& input);
inline uint8_t Size() const
{
return size;
}
/**
* Set the octet data to the input buffer
*
* If the length is 0, the default value of [0x00] is assigned
* If the length is > 255, only the first 255 bytes are copied
*
* @param input the input data to copy into this object
*
* @return true if the input meets the length requirements, false otherwise
*/
bool Set(const Buffer& input);
/**
* Set the buffer equal to the supplied c-string
*
* If the length is 0, the default value of [0x00] is assigned
* If the length is > 255, only the first 255 bytes are copied
*
* @param input c-style string to copy into this object
*
* @return true if the input meets the length requirements, false otherwise
*/
bool Set(const char* input);
/**
* @return a view of the current data
*/
const Buffer ToBuffer() const;
private:
static const Buffer ToSlice(const char* input);
std::array<uint8_t, MAX_SIZE> buffer = {{0x00}};
uint8_t size;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,62 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_OCTETSTRING_H
#define OPENDNP3_OCTETSTRING_H
#include "opendnp3/app/OctetData.h"
namespace opendnp3
{
/**
* Respresents group 110/111 objects
*/
class OctetString : public OctetData
{
public:
/**
* Construct with a default value of [0x00] (length == 1)
*/
OctetString() : OctetData() {}
/**
* Construct from a c-style string
*
* strlen() is used internally to determine the length
*
* If the length is 0, the default value of [0x00] is assigned
* If the length is > 255, only the first 255 bytes are copied
*
* The null terminator is NOT copied as part of buffer
*/
OctetString(const char* input) : OctetData(input) {}
/**
* Construct from read-only buffer slice
*
* If the length is 0, the default value of [0x00] is assigned
* If the length is > 255, only the first 255 bytes are copied
*/
OctetString(const Buffer& buffer) : OctetData(buffer) {}
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,104 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_ICOLLECTION_H
#define OPENDNP3_ICOLLECTION_H
#include <cstddef>
namespace opendnp3
{
/**
* Abstract way of visiting elements of a collection
*
*/
template<class T> class IVisitor
{
public:
virtual void OnValue(const T& value) = 0;
};
/**
* A visitor implemented as an abstract functor
*
*/
template<class T, class Fun> class FunctorVisitor : public IVisitor<T>
{
public:
FunctorVisitor(const Fun& fun_) : fun(fun_) {}
virtual void OnValue(const T& value) override final
{
fun(value);
}
private:
Fun fun;
};
/**
* An interface representing an abstract immutable collection of things of type T.
*
* The user can only read these values via callback to receive each element.
*/
template<class T> class ICollection
{
public:
/**
* The number of elements in the collection
*/
virtual size_t Count() const = 0;
/**
* Visit all the elements of a collection
*/
virtual void Foreach(IVisitor<T>& visitor) const = 0;
/**
visit all of the elements of a collection
*/
template<class Fun> void ForeachItem(const Fun& fun) const
{
FunctorVisitor<T, Fun> visitor(fun);
this->Foreach(visitor);
}
/**
Retrieve the only value from the collection.
*/
bool ReadOnlyValue(T& value) const
{
if (this->Count() == 1)
{
auto assignValue = [&value](const T& item) { value = item; };
this->ForeachItem(assignValue);
return true;
}
else
{
return false;
}
}
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,67 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_CHANNEL_RETRY_H
#define OPENDNP3_CHANNEL_RETRY_H
#include "opendnp3/channel/IOpenDelayStrategy.h"
#include "opendnp3/util/TimeDuration.h"
namespace opendnp3
{
/// Class used to configure how channel failures are retried
class ChannelRetry
{
public:
/*
* Construct a channel retry config class
*
* @param minOpenRetry minimum connection retry interval on failure
* @param maxOpenRetry maximum connection retry interval on failure
*/
ChannelRetry(TimeDuration minOpenRetry,
TimeDuration maxOpenRetry,
TimeDuration reconnectDelay = TimeDuration::Zero(),
IOpenDelayStrategy& strategy = ExponentialBackoffStrategy::Instance());
/// Return the default configuration of exponential backoff from 1 sec to 1 minute
static ChannelRetry Default();
/// minimum connection retry interval on failure
TimeDuration minOpenRetry;
/// maximum connection retry interval on failure
TimeDuration maxOpenRetry;
/// reconnect delay (defaults to zero)
TimeDuration reconnectDelay;
TimeDuration NextDelay(const TimeDuration& current) const
{
return strategy.GetNextDelay(current, maxOpenRetry);
}
private:
//// Strategy to use (default to exponential backoff)
IOpenDelayStrategy& strategy;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,98 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_ICHANNEL_H
#define OPENDNP3_ICHANNEL_H
#include "opendnp3/IResource.h"
#include "opendnp3/gen/ChannelState.h"
#include "opendnp3/link/LinkStatistics.h"
#include "opendnp3/logging/LogLevels.h"
#include "opendnp3/master/IMaster.h"
#include "opendnp3/master/IMasterApplication.h"
#include "opendnp3/master/ISOEHandler.h"
#include "opendnp3/master/MasterStackConfig.h"
#include "opendnp3/outstation/ICommandHandler.h"
#include "opendnp3/outstation/IOutstation.h"
#include "opendnp3/outstation/IOutstationApplication.h"
#include "opendnp3/outstation/OutstationStackConfig.h"
#include <memory>
namespace opendnp3
{
/**
* Represents a communication channel upon which masters and outstations can be bound.
*/
class IChannel : public IResource
{
public:
virtual ~IChannel() {}
/**
* Synchronously read the channel statistics
*/
virtual LinkStatistics GetStatistics() = 0;
/**
* @return The current logger settings for this channel
*/
virtual opendnp3::LogLevels GetLogFilters() const = 0;
/**
* @param filters Adjust the filters to this value
*/
virtual void SetLogFilters(const opendnp3::LogLevels& filters) = 0;
/**
* Add a master to the channel
*
* @param id An ID that gets used for logging
* @param SOEHandler Callback object for all received measurements
* @param application The master application bound to the master session
* @param config Configuration object that controls how the master behaves
*
* @return shared_ptr to the running master
*/
virtual std::shared_ptr<IMaster> AddMaster(const std::string& id,
std::shared_ptr<ISOEHandler> SOEHandler,
std::shared_ptr<IMasterApplication> application,
const MasterStackConfig& config)
= 0;
/**
* Add an outstation to the channel
*
* @param id An ID that gets used for logging
* @param commandHandler Callback object for handling command requests
* @param application Callback object for user code
* @param config Configuration object that controls how the outstation behaves
* @return shared_ptr to the running outstation
*/
virtual std::shared_ptr<IOutstation> AddOutstation(const std::string& id,
std::shared_ptr<ICommandHandler> commandHandler,
std::shared_ptr<IOutstationApplication> application,
const OutstationStackConfig& config)
= 0;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,44 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_ICHANNELLISTENER_H
#define OPENDNP3_ICHANNELLISTENER_H
#include "opendnp3/gen/ChannelState.h"
namespace opendnp3
{
/**
* Callback interface for receiving information about a running channel
*/
class IChannelListener
{
public:
virtual ~IChannelListener() {}
/*
* Receive callbacks for state transitions on the channels executor
*/
virtual void OnStateChange(ChannelState state) = 0;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,40 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_ILISTENER_H
#define OPENDNP3_ILISTENER_H
#include "opendnp3/IResource.h"
namespace opendnp3
{
/**
* Represents a running TCP or TLS listener that can be shutdown
* so that no new connections are accepted.
*/
class IListener : public IResource
{
public:
virtual ~IListener() {}
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,59 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_IOPENDELAYSTRATEGY_H
#define OPENDNP3_IOPENDELAYSTRATEGY_H
#include "opendnp3/util/TimeDuration.h"
#include "opendnp3/util/Uncopyable.h"
namespace opendnp3
{
/**
* A strategy interface for controlling how connection are retried
*/
class IOpenDelayStrategy
{
public:
virtual ~IOpenDelayStrategy() {}
/**
* The the next delay based on the current and the maximum.
*/
virtual TimeDuration GetNextDelay(const TimeDuration& current, const TimeDuration& max) const = 0;
};
/**
* Implements IOpenDelayStrategy using exponential-backoff.
*/
class ExponentialBackoffStrategy final : public IOpenDelayStrategy, private Uncopyable
{
static ExponentialBackoffStrategy instance;
public:
static IOpenDelayStrategy& Instance();
TimeDuration GetNextDelay(const TimeDuration& current, const TimeDuration& max) const final;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,49 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_IPENDPOINT_H
#define OPENDNP3_IPENDPOINT_H
#include <cstdint>
#include <string>
namespace opendnp3
{
struct IPEndpoint
{
IPEndpoint(const std::string& address, uint16_t port) : address(address), port(port) {}
static IPEndpoint AllAdapters(uint16_t port)
{
return IPEndpoint("0.0.0.0", port);
}
static IPEndpoint Localhost(uint16_t port)
{
return IPEndpoint("127.0.0.1", port);
}
std::string address;
uint16_t port;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,53 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_PRINTINGCHANNELLISTENER_H
#define OPENDNP3_PRINTINGCHANNELLISTENER_H
#include "opendnp3/channel/IChannelListener.h"
#include "opendnp3/util/Uncopyable.h"
#include <iostream>
#include <memory>
namespace opendnp3
{
/**
* Callback interface for receiving information about a running channel
*/
class PrintingChannelListener final : public IChannelListener, private Uncopyable
{
public:
virtual void OnStateChange(ChannelState state) override
{
std::cout << "channel state change: " << ChannelStateSpec::to_human_string(state) << std::endl;
}
static std::shared_ptr<IChannelListener> Create()
{
return std::make_shared<PrintingChannelListener>();
}
PrintingChannelListener() {}
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,72 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_SERIALTYPES_H
#define OPENDNP3_SERIALTYPES_H
#include "opendnp3/gen/FlowControl.h"
#include "opendnp3/gen/Parity.h"
#include "opendnp3/gen/StopBits.h"
#include "opendnp3/util/TimeDuration.h"
#include <string>
namespace opendnp3
{
/// Settings structure for the serial port
struct SerialSettings
{
/// Defaults to the familiar 9600 8/N/1, no flow control
SerialSettings()
: baud(9600),
dataBits(8),
stopBits(StopBits::One),
parity(Parity::None),
flowType(FlowControl::None),
asyncOpenDelay(TimeDuration::Milliseconds(500))
{
}
/// name of the port, i.e. "COM1" or "/dev/tty0"
std::string deviceName;
/// Baud rate of the port, i.e. 9600 or 57600
int baud;
/// Data bits, usually 8
int dataBits;
/// Stop bits, usually set to 1
StopBits stopBits;
/// Parity setting for the port, usually PAR_NONE
Parity parity;
/// Flow control setting, usually FLOW_NONE
FlowControl flowType;
/// Some physical layers need time to "settle" so that the first tx isn't lost
TimeDuration asyncOpenDelay;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,100 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_TLS_CONFIG_H
#define OPENDNP3_TLS_CONFIG_H
#include <string>
namespace opendnp3
{
/**
* TLS configuration information
*/
struct TLSConfig
{
/**
* Construct a TLS configuration
*
* @param peerCertFilePath Certificate file used to verify the peer or server. Can be CA file or a self-signed cert
* provided by other party.
* @param localCertFilePath File that contains the certificate (or certificate chain) that will be presented to the
* remote side of the connection
* @param privateKeyFilePath File that contains the private key corresponding to the local certificate
* @param allowTLSv10 Allow TLS version 1.0 (default false)
* @param allowTLSv11 Allow TLS version 1.1 (default false)
* @param allowTLSv12 Allow TLS version 1.2 (default true)
* @param allowTLSv13 Allow TLS version 1.3 (default true)
* @param cipherList The openssl cipher-list, defaults to "" which does not modify the default cipher list
*
* localCertFilePath and privateKeyFilePath can optionally be the same file, i.e. a PEM that contains both pieces of
* data.
*
*/
TLSConfig(const std::string& peerCertFilePath,
const std::string& localCertFilePath,
const std::string& privateKeyFilePath,
bool allowTLSv10 = false,
bool allowTLSv11 = false,
bool allowTLSv12 = true,
bool allowTLSv13 = true,
const std::string& cipherList = "")
: peerCertFilePath(peerCertFilePath),
localCertFilePath(localCertFilePath),
privateKeyFilePath(privateKeyFilePath),
allowTLSv10(allowTLSv10),
allowTLSv11(allowTLSv11),
allowTLSv12(allowTLSv12),
allowTLSv13(allowTLSv13),
cipherList(cipherList)
{
}
/// Certificate file used to verify the peer or server. Can be CA file or a self-signed cert provided by other
/// party.
std::string peerCertFilePath;
/// File that contains the certificate (or certificate chain) that will be presented to the remote side of the
/// connection
std::string localCertFilePath;
/// File that contains the private key corresponding to the local certificate
std::string privateKeyFilePath;
/// Allow TLS version 1.0 (default false)
bool allowTLSv10;
/// Allow TLS version 1.1 (default false)
bool allowTLSv11;
/// Allow TLS version 1.2 (default true)
bool allowTLSv12;
/// Allow TLS version 1.3 (default true)
bool allowTLSv13;
/// openssl format cipher list
std::string cipherList;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,49 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_DECODER_H
#define OPENDNP3_DECODER_H
#include "opendnp3/decoder/IDecoderCallbacks.h"
#include "opendnp3/logging/Logger.h"
#include "opendnp3/util/Buffer.h"
namespace opendnp3
{
class DecoderImpl;
// stand-alone DNP3 decoder
class Decoder
{
public:
Decoder(IDecoderCallbacks& callbacks, const Logger& logger);
~Decoder();
void DecodeLPDU(const Buffer& data);
void DecodeTPDU(const Buffer& data);
void DecodeAPDU(const Buffer& data);
private:
DecoderImpl* impl;
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,39 @@
/*
* Copyright 2013-2022 Step Function I/O, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
* LLC (https://stepfunc.io) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_IDECODERCALLBACKS_H
#define OPENDNP3_IDECODERCALLBACKS_H
#include "opendnp3/util/Uncopyable.h"
namespace opendnp3
{
class IDecoderCallbacks : Uncopyable
{
friend class Indent;
protected:
virtual void PushIndent(){};
virtual void PopIndent(){};
};
} // namespace opendnp3
#endif

View File

@ -0,0 +1,76 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_ANALOGOUTPUTSTATUSQUALITY_H
#define OPENDNP3_ANALOGOUTPUTSTATUSQUALITY_H
#include <cstdint>
#include <string>
namespace opendnp3 {
/**
Quality field bitmask for analog output status values
*/
enum class AnalogOutputStatusQuality : uint8_t
{
/// set when the data is "good", meaning that rest of the system can trust the value
ONLINE = 0x1,
/// the quality all points get before we have established communication (or populated) the point
RESTART = 0x2,
/// set if communication has been lost with the source of the data (after establishing contact)
COMM_LOST = 0x4,
/// set if the value is being forced to a "fake" value somewhere in the system
REMOTE_FORCED = 0x8,
/// set if the value is being forced to a "fake" value on the original device
LOCAL_FORCED = 0x10,
/// set if a hardware input etc. is out of range and we are using a place holder value
OVERRANGE = 0x20,
/// set if calibration or reference voltage has been lost meaning readings are questionable
REFERENCE_ERR = 0x40,
/// reserved bit
RESERVED = 0x80
};
struct AnalogOutputStatusQualitySpec
{
using enum_type_t = AnalogOutputStatusQuality;
static uint8_t to_type(AnalogOutputStatusQuality arg);
static AnalogOutputStatusQuality from_type(uint8_t arg);
static char const* to_string(AnalogOutputStatusQuality arg);
static char const* to_human_string(AnalogOutputStatusQuality arg);
static AnalogOutputStatusQuality from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,76 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_ANALOGQUALITY_H
#define OPENDNP3_ANALOGQUALITY_H
#include <cstdint>
#include <string>
namespace opendnp3 {
/**
Quality field bitmask for analog values
*/
enum class AnalogQuality : uint8_t
{
/// set when the data is "good", meaning that rest of the system can trust the value
ONLINE = 0x1,
/// the quality all points get before we have established communication (or populated) the point
RESTART = 0x2,
/// set if communication has been lost with the source of the data (after establishing contact)
COMM_LOST = 0x4,
/// set if the value is being forced to a "fake" value somewhere in the system
REMOTE_FORCED = 0x8,
/// set if the value is being forced to a "fake" value on the original device
LOCAL_FORCED = 0x10,
/// set if a hardware input etc. is out of range and we are using a place holder value
OVERRANGE = 0x20,
/// set if calibration or reference voltage has been lost meaning readings are questionable
REFERENCE_ERR = 0x40,
/// reserved bit
RESERVED = 0x80
};
struct AnalogQualitySpec
{
using enum_type_t = AnalogQuality;
static uint8_t to_type(AnalogQuality arg);
static AnalogQuality from_type(uint8_t arg);
static char const* to_string(AnalogQuality arg);
static char const* to_human_string(AnalogQuality arg);
static AnalogQuality from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,67 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_ASSIGNCLASSTYPE_H
#define OPENDNP3_ASSIGNCLASSTYPE_H
#include <cstdint>
#include <string>
namespace opendnp3 {
/**
groups that can be used inconjunction with the ASSIGN_CLASS function code
*/
enum class AssignClassType : uint8_t
{
BinaryInput = 0x0,
DoubleBinaryInput = 0x1,
Counter = 0x2,
FrozenCounter = 0x3,
AnalogInput = 0x4,
BinaryOutputStatus = 0x5,
AnalogOutputStatus = 0x6
};
struct AssignClassTypeSpec
{
using enum_type_t = AssignClassType;
static uint8_t to_type(AssignClassType arg);
static AssignClassType from_type(uint8_t arg);
static char const* to_string(AssignClassType arg);
static char const* to_human_string(AssignClassType arg);
static AssignClassType from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,46 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_ATTRIBUTES_H
#define OPENDNP3_ATTRIBUTES_H
#include "opendnp3/gen/GroupVariation.h"
namespace opendnp3 {
bool HasAbsoluteTime(GroupVariation gv);
bool HasRelativeTime(GroupVariation gv);
bool HasFlags(GroupVariation gv);
bool IsEvent(GroupVariation gv);
}
#endif

View File

@ -0,0 +1,76 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_BINARYOUTPUTSTATUSQUALITY_H
#define OPENDNP3_BINARYOUTPUTSTATUSQUALITY_H
#include <cstdint>
#include <string>
namespace opendnp3 {
/**
Quality field bitmask for binary output status values
*/
enum class BinaryOutputStatusQuality : uint8_t
{
/// set when the data is "good", meaning that rest of the system can trust the value
ONLINE = 0x1,
/// the quality all points get before we have established communication (or populated) the point
RESTART = 0x2,
/// set if communication has been lost with the source of the data (after establishing contact)
COMM_LOST = 0x4,
/// set if the value is being forced to a "fake" value somewhere in the system
REMOTE_FORCED = 0x8,
/// set if the value is being forced to a "fake" value on the original device
LOCAL_FORCED = 0x10,
/// reserved bit 1
RESERVED1 = 0x20,
/// reserved bit 2
RESERVED2 = 0x40,
/// state bit
STATE = 0x80
};
struct BinaryOutputStatusQualitySpec
{
using enum_type_t = BinaryOutputStatusQuality;
static uint8_t to_type(BinaryOutputStatusQuality arg);
static BinaryOutputStatusQuality from_type(uint8_t arg);
static char const* to_string(BinaryOutputStatusQuality arg);
static char const* to_human_string(BinaryOutputStatusQuality arg);
static BinaryOutputStatusQuality from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,76 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_BINARYQUALITY_H
#define OPENDNP3_BINARYQUALITY_H
#include <cstdint>
#include <string>
namespace opendnp3 {
/**
Quality field bitmask for binary values
*/
enum class BinaryQuality : uint8_t
{
/// set when the data is "good", meaning that rest of the system can trust the value
ONLINE = 0x1,
/// the quality all points get before we have established communication (or populated) the point
RESTART = 0x2,
/// set if communication has been lost with the source of the data (after establishing contact)
COMM_LOST = 0x4,
/// set if the value is being forced to a "fake" value somewhere in the system
REMOTE_FORCED = 0x8,
/// set if the value is being forced to a "fake" value on the original device
LOCAL_FORCED = 0x10,
/// set if the value is oscillating very quickly and some events are being suppressed
CHATTER_FILTER = 0x20,
/// reserved bit
RESERVED = 0x40,
/// state bit
STATE = 0x80
};
struct BinaryQualitySpec
{
using enum_type_t = BinaryQuality;
static uint8_t to_type(BinaryQuality arg);
static BinaryQuality from_type(uint8_t arg);
static char const* to_string(BinaryQuality arg);
static char const* to_human_string(BinaryQuality arg);
static BinaryQuality from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,68 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_CHANNELSTATE_H
#define OPENDNP3_CHANNELSTATE_H
#include <cstdint>
#include <string>
namespace opendnp3 {
/**
Enumeration for possible states of a channel
*/
enum class ChannelState : uint8_t
{
/// offline and idle
CLOSED = 0,
/// trying to open
OPENING = 1,
/// open
OPEN = 2,
/// stopped and will never do anything again
SHUTDOWN = 3
};
struct ChannelStateSpec
{
using enum_type_t = ChannelState;
static uint8_t to_type(ChannelState arg);
static ChannelState from_type(uint8_t arg);
static char const* to_string(ChannelState arg);
static char const* to_human_string(ChannelState arg);
static ChannelState from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,72 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_COMMANDPOINTSTATE_H
#define OPENDNP3_COMMANDPOINTSTATE_H
#include <cstdint>
#include <string>
namespace opendnp3 {
/**
List the various states that an individual command object can be in after an SBO or direct operate request
*/
enum class CommandPointState : uint8_t
{
/// No corresponding response was ever received for this command point
INIT = 0,
/// A response to a select request was received and matched, but the operate did not complete
SELECT_SUCCESS = 1,
/// A response to a select operation did not contain the same value that was sent
SELECT_MISMATCH = 2,
/// A response to a select operation contained a command status other than success
SELECT_FAIL = 3,
/// A response to an operate or direct operate did not match the request
OPERATE_FAIL = 4,
/// A matching response was received to the operate
SUCCESS = 5
};
struct CommandPointStateSpec
{
using enum_type_t = CommandPointState;
static uint8_t to_type(CommandPointState arg);
static CommandPointState from_type(uint8_t arg);
static char const* to_string(CommandPointState arg);
static char const* to_human_string(CommandPointState arg);
static CommandPointState from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,103 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_COMMANDSTATUS_H
#define OPENDNP3_COMMANDSTATUS_H
#include <cstdint>
#include <string>
namespace opendnp3 {
/**
An enumeration of result codes received from an outstation in response to command request.
These correspond to those defined in the DNP3 standard
*/
enum class CommandStatus : uint8_t
{
/// command was accepted, initiated, or queued
SUCCESS = 0,
/// command timed out before completing
TIMEOUT = 1,
/// command requires being selected before operate, configuration issue
NO_SELECT = 2,
/// bad control code or timing values
FORMAT_ERROR = 3,
/// command is not implemented
NOT_SUPPORTED = 4,
/// command is all ready in progress or its all ready in that mode
ALREADY_ACTIVE = 5,
/// something is stopping the command, often a local/remote interlock
HARDWARE_ERROR = 6,
/// the function governed by the control is in local only control
LOCAL = 7,
/// the command has been done too often and has been throttled
TOO_MANY_OPS = 8,
/// the command was rejected because the device denied it or an RTU intercepted it
NOT_AUTHORIZED = 9,
/// command not accepted because it was prevented or inhibited by a local automation process, such as interlocking logic or synchrocheck
AUTOMATION_INHIBIT = 10,
/// command not accepted because the device cannot process any more activities than are presently in progress
PROCESSING_LIMITED = 11,
/// command not accepted because the value is outside the acceptable range permitted for this point
OUT_OF_RANGE = 12,
/// command not accepted because the outstation is forwarding the request to another downstream device which reported LOCAL
DOWNSTREAM_LOCAL = 13,
/// command not accepted because the outstation has already completed the requested operation
ALREADY_COMPLETE = 14,
/// command not accepted because the requested function is specifically blocked at the outstation
BLOCKED = 15,
/// command not accepted because the operation was cancelled
CANCELLED = 16,
/// command not accepted because another master is communicating with the outstation and has exclusive rights to operate this control point
BLOCKED_OTHER_MASTER = 17,
/// command not accepted because the outstation is forwarding the request to another downstream device which cannot be reached or is otherwise incapable of performing the request
DOWNSTREAM_FAIL = 18,
/// (deprecated) indicates the outstation shall not issue or perform the control operation
NON_PARTICIPATING = 126,
/// 10 to 126 are currently reserved
UNDEFINED = 127
};
struct CommandStatusSpec
{
using enum_type_t = CommandStatus;
static uint8_t to_type(CommandStatus arg);
static CommandStatus from_type(uint8_t arg);
static char const* to_string(CommandStatus arg);
static char const* to_human_string(CommandStatus arg);
static CommandStatus from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,76 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_COUNTERQUALITY_H
#define OPENDNP3_COUNTERQUALITY_H
#include <cstdint>
#include <string>
namespace opendnp3 {
/**
Quality field bitmask for counter values
*/
enum class CounterQuality : uint8_t
{
/// set when the data is "good", meaning that rest of the system can trust the value
ONLINE = 0x1,
/// the quality all points get before we have established communication (or populated) the point
RESTART = 0x2,
/// set if communication has been lost with the source of the data (after establishing contact)
COMM_LOST = 0x4,
/// set if the value is being forced to a "fake" value somewhere in the system
REMOTE_FORCED = 0x8,
/// set if the value is being forced to a "fake" value on the original device
LOCAL_FORCED = 0x10,
/// Deprecated flag that indicates value has rolled over
ROLLOVER = 0x20,
/// indicates an unusual change in value
DISCONTINUITY = 0x40,
/// reserved bit
RESERVED = 0x80
};
struct CounterQualitySpec
{
using enum_type_t = CounterQuality;
static uint8_t to_type(CounterQuality arg);
static CounterQuality from_type(uint8_t arg);
static char const* to_string(CounterQuality arg);
static char const* to_human_string(CounterQuality arg);
static CounterQuality from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,68 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_DOUBLEBIT_H
#define OPENDNP3_DOUBLEBIT_H
#include <cstdint>
#include <string>
namespace opendnp3 {
/**
Enumeration for possible states of a double bit value
*/
enum class DoubleBit : uint8_t
{
/// Transitioning between end conditions
INTERMEDIATE = 0x0,
/// End condition, determined to be OFF
DETERMINED_OFF = 0x1,
/// End condition, determined to be ON
DETERMINED_ON = 0x2,
/// Abnormal or custom condition
INDETERMINATE = 0x3
};
struct DoubleBitSpec
{
using enum_type_t = DoubleBit;
static uint8_t to_type(DoubleBit arg);
static DoubleBit from_type(uint8_t arg);
static char const* to_string(DoubleBit arg);
static char const* to_human_string(DoubleBit arg);
static DoubleBit from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,76 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_DOUBLEBITBINARYQUALITY_H
#define OPENDNP3_DOUBLEBITBINARYQUALITY_H
#include <cstdint>
#include <string>
namespace opendnp3 {
/**
Quality field bitmask for double bit binary values
*/
enum class DoubleBitBinaryQuality : uint8_t
{
/// set when the data is "good", meaning that rest of the system can trust the value
ONLINE = 0x1,
/// the quality all points get before we have established communication (or populated) the point
RESTART = 0x2,
/// set if communication has been lost with the source of the data (after establishing contact)
COMM_LOST = 0x4,
/// set if the value is being forced to a "fake" value somewhere in the system
REMOTE_FORCED = 0x8,
/// set if the value is being forced to a "fake" value on the original device
LOCAL_FORCED = 0x10,
/// set if the value is oscillating very quickly and some events are being suppressed
CHATTER_FILTER = 0x20,
/// state bit 1
STATE1 = 0x40,
/// state bit 2
STATE2 = 0x80
};
struct DoubleBitBinaryQualitySpec
{
using enum_type_t = DoubleBitBinaryQuality;
static uint8_t to_type(DoubleBitBinaryQuality arg);
static DoubleBitBinaryQuality from_type(uint8_t arg);
static char const* to_string(DoubleBitBinaryQuality arg);
static char const* to_human_string(DoubleBitBinaryQuality arg);
static DoubleBitBinaryQuality from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,65 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_EVENTANALOGOUTPUTSTATUSVARIATION_H
#define OPENDNP3_EVENTANALOGOUTPUTSTATUSVARIATION_H
#include <cstdint>
#include <string>
namespace opendnp3 {
enum class EventAnalogOutputStatusVariation : uint8_t
{
Group42Var1 = 0,
Group42Var2 = 1,
Group42Var3 = 2,
Group42Var4 = 3,
Group42Var5 = 4,
Group42Var6 = 5,
Group42Var7 = 6,
Group42Var8 = 7
};
struct EventAnalogOutputStatusVariationSpec
{
using enum_type_t = EventAnalogOutputStatusVariation;
static uint8_t to_type(EventAnalogOutputStatusVariation arg);
static EventAnalogOutputStatusVariation from_type(uint8_t arg);
static char const* to_string(EventAnalogOutputStatusVariation arg);
static char const* to_human_string(EventAnalogOutputStatusVariation arg);
static EventAnalogOutputStatusVariation from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,65 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_EVENTANALOGVARIATION_H
#define OPENDNP3_EVENTANALOGVARIATION_H
#include <cstdint>
#include <string>
namespace opendnp3 {
enum class EventAnalogVariation : uint8_t
{
Group32Var1 = 0,
Group32Var2 = 1,
Group32Var3 = 2,
Group32Var4 = 3,
Group32Var5 = 4,
Group32Var6 = 5,
Group32Var7 = 6,
Group32Var8 = 7
};
struct EventAnalogVariationSpec
{
using enum_type_t = EventAnalogVariation;
static uint8_t to_type(EventAnalogVariation arg);
static EventAnalogVariation from_type(uint8_t arg);
static char const* to_string(EventAnalogVariation arg);
static char const* to_human_string(EventAnalogVariation arg);
static EventAnalogVariation from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,59 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_EVENTBINARYOUTPUTSTATUSVARIATION_H
#define OPENDNP3_EVENTBINARYOUTPUTSTATUSVARIATION_H
#include <cstdint>
#include <string>
namespace opendnp3 {
enum class EventBinaryOutputStatusVariation : uint8_t
{
Group11Var1 = 0,
Group11Var2 = 1
};
struct EventBinaryOutputStatusVariationSpec
{
using enum_type_t = EventBinaryOutputStatusVariation;
static uint8_t to_type(EventBinaryOutputStatusVariation arg);
static EventBinaryOutputStatusVariation from_type(uint8_t arg);
static char const* to_string(EventBinaryOutputStatusVariation arg);
static char const* to_human_string(EventBinaryOutputStatusVariation arg);
static EventBinaryOutputStatusVariation from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,60 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_EVENTBINARYVARIATION_H
#define OPENDNP3_EVENTBINARYVARIATION_H
#include <cstdint>
#include <string>
namespace opendnp3 {
enum class EventBinaryVariation : uint8_t
{
Group2Var1 = 0,
Group2Var2 = 1,
Group2Var3 = 2
};
struct EventBinaryVariationSpec
{
using enum_type_t = EventBinaryVariation;
static uint8_t to_type(EventBinaryVariation arg);
static EventBinaryVariation from_type(uint8_t arg);
static char const* to_string(EventBinaryVariation arg);
static char const* to_human_string(EventBinaryVariation arg);
static EventBinaryVariation from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,61 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_EVENTCOUNTERVARIATION_H
#define OPENDNP3_EVENTCOUNTERVARIATION_H
#include <cstdint>
#include <string>
namespace opendnp3 {
enum class EventCounterVariation : uint8_t
{
Group22Var1 = 0,
Group22Var2 = 1,
Group22Var5 = 2,
Group22Var6 = 3
};
struct EventCounterVariationSpec
{
using enum_type_t = EventCounterVariation;
static uint8_t to_type(EventCounterVariation arg);
static EventCounterVariation from_type(uint8_t arg);
static char const* to_string(EventCounterVariation arg);
static char const* to_human_string(EventCounterVariation arg);
static EventCounterVariation from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,60 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_EVENTDOUBLEBINARYVARIATION_H
#define OPENDNP3_EVENTDOUBLEBINARYVARIATION_H
#include <cstdint>
#include <string>
namespace opendnp3 {
enum class EventDoubleBinaryVariation : uint8_t
{
Group4Var1 = 0,
Group4Var2 = 1,
Group4Var3 = 2
};
struct EventDoubleBinaryVariationSpec
{
using enum_type_t = EventDoubleBinaryVariation;
static uint8_t to_type(EventDoubleBinaryVariation arg);
static EventDoubleBinaryVariation from_type(uint8_t arg);
static char const* to_string(EventDoubleBinaryVariation arg);
static char const* to_human_string(EventDoubleBinaryVariation arg);
static EventDoubleBinaryVariation from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,61 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_EVENTFROZENCOUNTERVARIATION_H
#define OPENDNP3_EVENTFROZENCOUNTERVARIATION_H
#include <cstdint>
#include <string>
namespace opendnp3 {
enum class EventFrozenCounterVariation : uint8_t
{
Group23Var1 = 0,
Group23Var2 = 1,
Group23Var5 = 2,
Group23Var6 = 3
};
struct EventFrozenCounterVariationSpec
{
using enum_type_t = EventFrozenCounterVariation;
static uint8_t to_type(EventFrozenCounterVariation arg);
static EventFrozenCounterVariation from_type(uint8_t arg);
static char const* to_string(EventFrozenCounterVariation arg);
static char const* to_human_string(EventFrozenCounterVariation arg);
static EventFrozenCounterVariation from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,68 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_EVENTMODE_H
#define OPENDNP3_EVENTMODE_H
#include <cstdint>
#include <string>
namespace opendnp3 {
/**
Describes how a transaction behaves with respect to event generation
*/
enum class EventMode : uint8_t
{
/// Detect events using the specific mechanism for that type
Detect = 0x0,
/// Force the creation of an event bypassing detection mechanism
Force = 0x1,
/// Never produce an event regardless of changes
Suppress = 0x2,
/// Force the creation of an event bypassing detection mechanism, but does not update the static value
EventOnly = 0x3
};
struct EventModeSpec
{
using enum_type_t = EventMode;
static uint8_t to_type(EventMode arg);
static EventMode from_type(uint8_t arg);
static char const* to_string(EventMode arg);
static char const* to_human_string(EventMode arg);
static EventMode from_string(const std::string& arg);
};
}
#endif

View File

@ -0,0 +1,58 @@
//
// _ _ ______ _ _ _ _ _ _ _
// | \ | | | ____| | (_) | (_) | | | |
// | \| | ___ | |__ __| |_| |_ _ _ __ __ _| | | |
// | . ` |/ _ \ | __| / _` | | __| | '_ \ / _` | | | |
// | |\ | (_) | | |___| (_| | | |_| | | | | (_| |_|_|_|
// |_| \_|\___/ |______\__,_|_|\__|_|_| |_|\__, (_|_|_)
// __/ |
// |___/
//
// This file is auto-generated. Do not edit manually
//
// Copyright 2013-2022 Step Function I/O, LLC
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
// LLC (https://stepfunc.io) under one or more contributor license agreements.
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
// this file to you under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may obtain
// a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef OPENDNP3_EVENTOCTETSTRINGVARIATION_H
#define OPENDNP3_EVENTOCTETSTRINGVARIATION_H
#include <cstdint>
#include <string>
namespace opendnp3 {
enum class EventOctetStringVariation : uint8_t
{
Group111Var0 = 0
};
struct EventOctetStringVariationSpec
{
using enum_type_t = EventOctetStringVariation;
static uint8_t to_type(EventOctetStringVariation arg);
static EventOctetStringVariation from_type(uint8_t arg);
static char const* to_string(EventOctetStringVariation arg);
static char const* to_human_string(EventOctetStringVariation arg);
static EventOctetStringVariation from_string(const std::string& arg);
};
}
#endif

Some files were not shown because too many files have changed in this diff Show More