197 lines
6.1 KiB
C++
197 lines
6.1 KiB
C++
#ifndef _ISS_RY_H_
|
|
#define _ISS_RY_H_
|
|
|
|
#include <fstream>
|
|
#include <string>
|
|
#include <map>
|
|
#include <unordered_map>
|
|
|
|
#include <libgen.h>
|
|
#include <dirent.h>
|
|
#include <fnmatch.h>
|
|
#include <signal.h>
|
|
|
|
#ifndef USE_NOPOLL_WEBSOCKET
|
|
#include <queue>
|
|
#include <string>
|
|
#include <stack>
|
|
#include <easywsclient.hpp>
|
|
using easywsclient::WebSocket;
|
|
#else
|
|
#include <nopoll.h>
|
|
#include <nopoll_decl.h>
|
|
#define MAX_MSG_COUNT 4096
|
|
#endif
|
|
|
|
#include <json.h>
|
|
#if 0
|
|
#include <md5.h>
|
|
#include <base64.h>
|
|
#include <mbedtls/aes.h>
|
|
#include <mbedtls/error.h>
|
|
#endif
|
|
|
|
#include "soe.h"
|
|
#include "yxbw.h"
|
|
#include "ycbw.h"
|
|
#include "yklog.h"
|
|
#include "ytlog.h"
|
|
#include "public.h"
|
|
|
|
|
|
typedef std::unordered_map<std::string, short> uid2pidmap;
|
|
|
|
#define CMD_CONTROL_OPERATION 0
|
|
#define CMD_CONTROL_SETTING 1
|
|
typedef struct {
|
|
int uid;
|
|
int point;
|
|
int order;
|
|
int type;
|
|
} struct_service_item;
|
|
|
|
typedef std::unordered_map<std::string, struct_service_item> name2servicemap;
|
|
typedef std::unordered_map<std::string, name2servicemap> unitname2servicemap;
|
|
typedef std::unordered_map<std::string, std::string> unitserviceName2cmdIdmap;
|
|
|
|
typedef struct {
|
|
std::string name;
|
|
std::string deviceId;
|
|
Json::Value params;
|
|
int highSpeed;
|
|
int order;
|
|
} struct_attr;
|
|
typedef std::vector<struct_attr> attrvector;
|
|
|
|
//设备id和attrs/services名称对应的测点序号
|
|
typedef std::unordered_map<std::string, int> string2intmap;
|
|
|
|
//设备unit和attrvector对应的关系
|
|
typedef struct {
|
|
attrvector yxs;
|
|
attrvector ycs;
|
|
attrvector yms;
|
|
attrvector yks;
|
|
attrvector yts;
|
|
} attrvectorGroup;
|
|
typedef std::unordered_map<int, attrvectorGroup> pid2attrvectormap;
|
|
|
|
class CRYDevice
|
|
{
|
|
public:
|
|
CRYDevice();
|
|
~CRYDevice();
|
|
|
|
BOOLEAN ry_init(const char*, const int, const char*, const char*);
|
|
void ry_destroy(void);
|
|
bool ry_run(void);
|
|
int sendMsg(std::string);
|
|
int recvMsg(std::string);
|
|
|
|
void handle_message(const std::string & message);
|
|
private:
|
|
string2intmap uid2pid_map;
|
|
unitname2servicemap unitname2service_map;
|
|
unitserviceName2cmdIdmap unitserviceName2cmdId_map;
|
|
std::string m_traceId;
|
|
|
|
LONG m_soeload = 0;
|
|
LONG m_yxbwload = 0;
|
|
LONG m_ycbwload = 0;
|
|
|
|
struSystem config_system32;
|
|
struConfig config_config;
|
|
struDatabase config_database;
|
|
struNodeOption config_nodes;
|
|
struUnitStatic config_static_units[UNIT_NUM];
|
|
|
|
private:
|
|
#ifndef USE_NOPOLL_WEBSOCKET
|
|
std::queue<std::string> m_SendQueue;
|
|
std::queue<std::string> m_recvMsgQueue;
|
|
pthread_mutex_t m_SendQueueMutex;
|
|
pthread_mutex_t m_RecvQueueMutex;
|
|
|
|
WebSocket::pointer m_ws;
|
|
#else
|
|
noPollCtx *ctx;
|
|
noPollConn *conn;
|
|
noPollMsg *msg[2048];
|
|
int msg_count = 0;
|
|
#endif
|
|
|
|
DWORD last_connect_sec = 0;
|
|
int m_status;
|
|
int m_nCurUnit;
|
|
|
|
bool m_dataAcquisitionReload = false;
|
|
|
|
char m_host[256] = {"127.0.0.1"};
|
|
int m_port = 7790;
|
|
char m_nodeId[128] = {"runyang_dn"};
|
|
char m_version[128] = {"v1.0"};
|
|
|
|
time_t last_sec;
|
|
private:
|
|
bool configInitializeMemory(void);
|
|
bool configWriteSystemCFG(void);
|
|
bool configWriteNodeCFG(void);
|
|
bool configWriteHardwareCFG(void);
|
|
bool configWriteProcessCFG(void);
|
|
bool configWriteUnitCFG(void);
|
|
bool configWriteStaticUnitCFG(void);
|
|
bool configWriteDatabaseCFG(void);
|
|
|
|
int GetUnitYXCount(int uid);
|
|
int GetUnitYCCount(int uid);
|
|
int GetUnitYMCount(int uid);
|
|
LONG GetUnitYC(int uid, int order) const;
|
|
float GetUnitYCReal(int uid, int order) const;
|
|
float GetUnitYCRealFromValue(int uid, int order, long value) const;
|
|
BOOLEAN GetUnitYCIsFloat(int uid, int order) const;
|
|
BOOLEAN GetUnitYCIsForceArchive(int uid, int order) const;
|
|
float GetUnitYCLimitReal(int uid, int order, int type = 1) const;
|
|
float GetUnitYMReal(int uid, int order);
|
|
BYTE GetUnitYX(int uid, int point);
|
|
BOOLEAN GetUnitYXIsForceArchive(int uid, int order) const;
|
|
int GetUnitYXBW(int& uid, BOOLEAN& value, unionCP56Time& st);
|
|
int GetUnitSOE(int& uid, BOOLEAN& value, BYTE& qds, unionCP56Time& st);
|
|
int GetUnitYCBW(int& uid, LONG& value, int& type, unionCP56Time& st);
|
|
BOOLEAN GetUnitYK(int uid, int& order, BYTE& value, BYTE& act, BYTE& result);
|
|
void SetUnitYK(int uid, int order, BYTE value, BYTE act, BYTE result);
|
|
BOOLEAN GetUnitYT(int, int& order, DWORD& value, BYTE& act, BYTE& result);
|
|
void SetUnitYT(int, int order, DWORD value, BYTE act, BYTE result);
|
|
int MakeYKFrame(int);
|
|
int MakeYTFrame(int);
|
|
bool OnReceivedDeviceCommand(const Json::Value);
|
|
BOOLEAN processUartParam(const Json::Value, int);
|
|
BOOLEAN processHostModbustcpParam(const Json::Value, int);
|
|
BOOLEAN processSubModbustcpParam(const Json::Value, int);
|
|
BOOLEAN processRymodbustcpParam(const Json::Value, int);
|
|
BOOLEAN processRyFTP2MinioParam(const Json::Value, int);
|
|
BOOLEAN processRyADSParam(const Json::Value, int);
|
|
BOOLEAN processHostIEC104ProcessParam(const Json::Value, int);
|
|
BOOLEAN processSubIEC104ProcessParam(const Json::Value, int);
|
|
BOOLEAN processHostModbusPointParam(const Json::Value, int, int, int);
|
|
BOOLEAN processSubModbusPointParam(const Json::Value, int, int, int);
|
|
BOOLEAN processHostADSPointParam(const Json::Value, int, int, int);
|
|
bool dealConfigFile(const Json::Value);
|
|
bool OnReceivedSystemAction(const std::string, const std::string, const Json::Value);
|
|
void on_message(const char*, const int);
|
|
|
|
void heart_beat(int status);
|
|
bool publishinitDeviceData(int uid);
|
|
bool publishAnalogData(int uid);
|
|
bool publishStateData(int uid);
|
|
bool publishHistoryAnalogData(int uid);
|
|
bool publishHistoryStateData(int uid);
|
|
bool publishdeviceEventData(void);
|
|
BOOLEAN publishYXBWData(int uid);
|
|
BOOLEAN publishYCBWData(int uid);
|
|
#ifdef USE_NOPOLL_WEBSOCKET
|
|
BOOLEAN websocket_msg_join(noPollMsg **msg, int msg_count, BYTE* &buffer, int &buffer_size);
|
|
int websocket_write(const char * buffer, int buffer_len);
|
|
#endif
|
|
bool publish_sensor_data(const std::string traceId, const char* command, const Json::Value payload);
|
|
};
|
|
#endif //_ISS_RY_H_
|