map/das-dn/cmg/ry.h

196 lines
5.9 KiB
C
Raw Normal View History

2024-12-03 10:36:06 +08:00
#ifndef _ISS_RY_H_
#define _ISS_RY_H_
2024-10-14 20:26:21 +08:00
#include <fstream>
#include <string>
#include <map>
#include <unordered_map>
#include <libgen.h>
#include <dirent.h>
#include <fnmatch.h>
#include <signal.h>
2024-12-03 10:36:06 +08:00
#ifndef USE_NOPOLL_WEBSOCKET
2024-11-27 11:56:30 +08:00
#include <easywsclient.hpp>
using easywsclient::WebSocket;
#else
#include <nopoll.h>
#include <nopoll_decl.h>
#endif
2024-10-14 20:26:21 +08:00
#include <json.h>
#include <md5.h>
#include <base64.h>
#include <mbedtls/aes.h>
#include <mbedtls/error.h>
#include "soe.h"
#include "yxbw.h"
#include "ycbw.h"
#include "yklog.h"
#include "ytlog.h"
#include "public.h"
2024-11-27 11:56:30 +08:00
2024-10-14 20:26:21 +08:00
#define MAX_MSG_COUNT 4096
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;
2024-11-15 16:12:14 +08:00
typedef std::unordered_map<std::string, std::string> unitserviceName2cmdIdmap;
2024-10-14 20:26:21 +08:00
typedef struct {
std::string name;
2024-11-25 10:59:23 +08:00
Json::Value params;
int highSpeed;
int order;
2024-10-14 20:26:21 +08:00
} struct_attr;
typedef std::vector<struct_attr> attrvector;
2024-11-25 10:59:23 +08:00
//设备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;
2024-11-27 11:56:30 +08:00
#include <queue>
#include <string>
#include <stack>
2024-10-14 20:26:21 +08:00
class CRYDevice
{
public:
CRYDevice();
~CRYDevice();
2024-10-21 10:53:15 +08:00
BOOLEAN ry_init(const char*, const int, const char*, const char*);
2024-10-14 20:26:21 +08:00
void ry_destroy(void);
bool ry_run(void);
2024-11-27 11:56:30 +08:00
int sendMsg(std::string);
int recvMsg(std::string);
void handle_message(const std::string & message);
2024-10-14 20:26:21 +08:00
private:
uid2pidmap uid2pid_map;
unitname2servicemap unitname2service_map;
2024-11-15 16:12:14 +08:00
unitserviceName2cmdIdmap unitserviceName2cmdId_map;
2024-10-14 20:26:21 +08:00
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:
2024-12-03 10:36:06 +08:00
#ifndef USE_NOPOLL_WEBSOCKET
2024-11-27 11:56:30 +08:00
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
2024-10-14 20:26:21 +08:00
noPollCtx *ctx;
noPollConn *conn;
2024-11-21 09:06:36 +08:00
noPollMsg *msg[2048];
2024-11-27 11:56:30 +08:00
int msg_count = 0;
#endif
2024-10-29 12:52:52 +08:00
2024-11-27 11:56:30 +08:00
DWORD last_connect_sec = 0;
int status;
bool m_dataAcquisitionReload = false;
2024-10-14 20:26:21 +08:00
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);
void releaseAllUnits(void);
int GetUnitYXCount(int uid);
int GetUnitYCCount(int uid);
int GetUnitYMCount(int uid);
2024-10-29 12:52:52 +08:00
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;
float GetUnitYCLimitReal(int uid, int order, int type = 1) const;
2024-10-14 20:26:21 +08:00
float GetUnitYMReal(int uid, int order);
BYTE GetUnitYX(int uid, int point);
2024-10-29 12:52:52 +08:00
int GetUnitYXBW(int& uid, BOOLEAN& value, unionCP56Time& st);
2024-10-14 20:26:21 +08:00
int GetUnitSOE(int& uid, BOOLEAN& value, BYTE& qds, unionCP56Time& st);
2024-10-29 12:52:52 +08:00
int GetUnitYCBW(int& uid, LONG& value, int& type, unionCP56Time& st);
2024-10-14 20:26:21 +08:00
BOOLEAN GetUnitYK(int uid, int& order, BYTE& value, BYTE& act, BYTE& result);
void SetUnitYK(int uid, int order, BYTE value, BYTE act, BYTE result);
2024-11-15 16:12:14 +08:00
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);
2024-11-21 16:09:38 +08:00
BOOLEAN processHostModbustcpParam(const Json::Value, int);
BOOLEAN processSubModbustcpParam(const Json::Value, int);
2024-11-15 16:12:14 +08:00
BOOLEAN processRymodbustcpParam(const Json::Value, int);
BOOLEAN processRyFTP2MinioParam(const Json::Value, int);
2024-12-03 10:36:06 +08:00
BOOLEAN processRyADSParam(const Json::Value, int);
2024-11-20 17:28:24 +08:00
BOOLEAN processHostIEC104ProcessParam(const Json::Value, int);
BOOLEAN processSubIEC104ProcessParam(const Json::Value, int);
2024-11-21 16:09:38 +08:00
BOOLEAN processHostModbusPointParam(const Json::Value, int, int, int);
BOOLEAN processSubModbusPointParam(const Json::Value, int, int, int);
2024-12-03 10:36:06 +08:00
BOOLEAN processHostADSPointParam(const Json::Value, int, int, int);
2024-11-15 16:12:14 +08:00
bool dealConfigFile(const Json::Value);
bool OnReceivedSystemAction(const std::string, const std::string, const Json::Value);
void on_message(const char*, const int);
2024-10-29 12:52:52 +08:00
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);
2024-12-03 10:36:06 +08:00
#ifdef USE_NOPOLL_WEBSOCKET
2024-10-14 20:26:21 +08:00
BOOLEAN websocket_msg_join(noPollMsg **msg, int msg_count, BYTE* &buffer, int &buffer_size);
2024-10-29 12:52:52 +08:00
int websocket_write(const char * buffer, int buffer_len);
2024-11-27 11:56:30 +08:00
#endif
2024-10-29 12:52:52 +08:00
bool publish_sensor_data(const std::string traceId, const char* command, const Json::Value payload);
2024-10-14 20:26:21 +08:00
};
2024-12-03 10:36:06 +08:00
#endif //_ISS_RY_H_