141 lines
4.5 KiB
C++
141 lines
4.5 KiB
C++
#ifndef _RY_H_
|
|
#define _RY_H_
|
|
|
|
#include <fstream>
|
|
#include <string>
|
|
#include <map>
|
|
#include <unordered_map>
|
|
|
|
#include <libgen.h>
|
|
#include <dirent.h>
|
|
#include <fnmatch.h>
|
|
#include <signal.h>
|
|
|
|
#include <nopoll.h>
|
|
#include <nopoll_decl.h>
|
|
|
|
#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"
|
|
|
|
#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;
|
|
|
|
typedef struct {
|
|
std::string name;
|
|
Json::Value value;
|
|
int highSpeed;
|
|
} struct_attr;
|
|
typedef std::vector<struct_attr> attrvector;
|
|
|
|
class CRYDevice
|
|
{
|
|
public:
|
|
CRYDevice();
|
|
~CRYDevice();
|
|
|
|
BOOLEAN ry_init(const char*, const int, const char*, const char*);
|
|
void ry_destroy(void);
|
|
bool ry_run(void);
|
|
private:
|
|
uid2pidmap uid2pid_map;
|
|
unitname2servicemap unitname2service_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:
|
|
noPollCtx *ctx;
|
|
noPollConn *conn;
|
|
DWORD last_connect_sec = 0;
|
|
int status;
|
|
|
|
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:
|
|
std::vector<std::string> split(const std::string &s, char delimiter);
|
|
|
|
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);
|
|
float GetUnitYCReal(int uid, int order);
|
|
float GetUnitYCRealFromValue(int uid, int order, long value);
|
|
float GetUnitYMReal(int uid, int order);
|
|
BYTE GetUnitYX(int uid, int point);
|
|
int GetUnitYXBW(int& uid, BOOLEAN& value, BYTE& qds, int& type, unionCP56Time& st);
|
|
int GetUnitSOE(int& uid, BOOLEAN& value, BYTE& qds, unionCP56Time& st);
|
|
int GetUnitYCBW(int& uid, LONG& value, BYTE& qds, 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 uid, int& order, DWORD& value, BYTE& act, BYTE& result);
|
|
void SetUnitYT(int uid, int order, DWORD value, BYTE act, BYTE result);
|
|
int MakeYKFrame(noPollConn* conn, int uid);
|
|
int MakeYTFrame(noPollConn* conn, int uid);
|
|
bool OnReceivedDeviceCommand(const Json::Value jsonRoot);
|
|
BOOLEAN processUartParam(const Json::Value jsonRoot, int ord);
|
|
BOOLEAN processNetworkParam(const Json::Value jsonRoot, int pid);
|
|
BOOLEAN processHostIEC104ProcessParam(const Json::Value jsonRoot, int pid);
|
|
BOOLEAN processModbusPointParam(const Json::Value jsonRoot, int uid, int point, int type);
|
|
bool dealConfigFile(const Json::Value jsonRoot);
|
|
bool OnReceivedSystemAction(noPollConn* conn, const std::string cmdId, const std::string cmd, const Json::Value data);
|
|
void on_message(noPollConn* conn, const char *msg, const int size);
|
|
|
|
void heart_beat(noPollConn* conn, int status);
|
|
bool publishinitDeviceData(noPollConn* conn, int uid);
|
|
bool publishAnalogData(noPollConn* conn, int uid);
|
|
bool publishStateData(noPollConn* conn, int uid);
|
|
bool publishHistoryAnalogData(noPollConn* conn, int uid);
|
|
bool publishHistoryStateData(noPollConn* conn, int uid);
|
|
|
|
BOOLEAN websocket_msg_join(noPollMsg **msg, int msg_count, BYTE* &buffer, int &buffer_size);
|
|
int websocket_write(noPollConn* conn, const char * buffer, int buffer_len);
|
|
bool publish_sensor_data(noPollConn* conn, const std::string traceId, const char* command, const Json::Value payload);
|
|
};
|
|
#endif //_RY_H_
|