#if !defined(_UTILLBASE_HPP_) #define _UTILLBASE_HPP_ #include #include #include #include #include "SendDevice.h" #include "NonCopyAble.hpp" #include "httplib.h" namespace gsd{ /** * @brief 控制设备基础 * */ class ContorlGear:private NonCopyAble { public: struct ControlerMsg { int deviceId; uint8_t msgId; uint8_t data; }; enum DeviceTools{ serial = 0, http = 1, tcp = 2 }; enum CommmandCodeGear{ _STATUS, _OPEN, _CLOSE, _FIRE }; protected: std::string deviceId; std::string DeviceInfo = ""; enum DeviceTools tool = DeviceTools::serial; enum CommmandCodeGear code = CommmandCodeGear::_OPEN; int TypeId; public: ContorlGear(){} ~ContorlGear(){} /** * @description: 序列化 * @return {*} */ virtual bool serialization(){ return true; } /** * @description: 反序列化 * @return {*} */ virtual bool deserialization(){ return true; } /** * @description: 消费数据 * @param {uint8_t} *data * @param {int} len * @param {int} &msg_id * @return {*} */ virtual bool Consumer(uint8_t *data, int len, int &msg_id){ return true; } /** * @description: 设备响应码是否为状态码 * @param {int} &msg_id * @return {*} */ virtual bool getStatusMsg(int &msg_id){ return false; }; /** * @description: 构建设备信息 * @param {SendDevice&} sendDevice * @return {*} */ virtual void BuildDeviceInfo(SendDevice& sendDevice) {}; /** * @description: 常规控制 * @param {string} _deviceId 设备Id * @param {uint8_t*} data 数据 * @param {int&} length 数据长度 * @return {*} */ virtual int8_t Open(std::string _deviceId,uint8_t* data, int& length){return 0;}; virtual int8_t Close(std::string _deviceId, uint8_t* data, int&length){return 0;}; virtual int8_t Fire(std::string _deviceId, uint8_t* data, int& length){return 0;}; virtual int8_t Status(std::string _deviceId, uint8_t* data, int& length){return 0;}; /** * @description: 设置设备ID * @param {string} DeviceId * @return {*} */ void setDeviceId(std::string DeviceId){ deviceId = DeviceId; } /** * @description: 获取设备ID * @return {*} */ std::string getDeviceId(){ return deviceId; } /** * @description: 获取设备工具 * @return {*} */ enum DeviceTools getDeviceTool(){ return tool; } /** * @description: 获取数据信息 * @return {*} */ std::string getDeviceInfo(){ return DeviceInfo; } /** * @description: 获取类型 * @return {*} */ int getTypeId(){ return TypeId; } /** * @description: 设置类型 * @param {int} typeId * @return {*} */ void setTypeId(int typeId){ this->TypeId = typeId; } }; /** * @brief 串口工具 * */ class ContorlSerialBase:public ContorlGear { protected: int baudRate; public: ContorlSerialBase(){} ~ContorlSerialBase(){} /** * @description: 获取波特率 * @return {*} */ int getBaudRate(){ return this->baudRate; } }; /** * @brief ContorlHttplBase * */ class ContorlHttplBase: public ContorlGear { protected: std::string serverIP; int port; std::string serverCname; std::string serverCpwd; int commandCode = 0; public: ContorlHttplBase(){} ~ContorlHttplBase(){} void setServerIP(std::string _serverIP){ serverIP = _serverIP; } void setServerCname(std::string _serverCname){ serverCname = _serverCname; } void setServerCpwd(std::string _serverCpwd){ serverCpwd = _serverCpwd; } httplib::Params getParms(){ httplib::Params parms; return parms; } httplib::Headers getHeaders(){ httplib::Headers headers; return headers; } std::string getUrl(){ return ""; } }; /** * @brief ContorlTcplBase * */ class ContorlTcplBase: public ContorlGear{ protected: std::string serverIP; int port; public: ContorlTcplBase(){}; ~ContorlTcplBase(){}; void setServerIP(std::string _serverIP){ serverIP = _serverIP; } void setPort(int _port){ this->port = _port; } }; /** * @brief ModuleBase * */ class ModuleBase: private NonCopyAble { public: ModuleBase(){} ~ModuleBase(){} /** * @description: 初始化 * @return {*} */ virtual bool Init() = 0; /** * @description: 释放 * @return {*} */ virtual void Destroy() = 0; }; /** * @brief PlginsBase * */ class PluginBase: private ModuleBase { private: /* data */ public: PluginBase(){} ~PluginBase(){} /** * @description: StartTask * @return {*} */ virtual bool StartTask() = 0; /** * @description: Alive * @return {*} */ virtual bool Alive() = 0; }; }; #endif // _UTILLBASE_HPP_