123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- #if !defined(_UTILLBASE_HPP_)
- #define _UTILLBASE_HPP_
- #include <iostream>
- #include <ctime>
- #include <memory>
- #include <vector>
- #include <typeinfo>
- #include <cxxabi.h>
- #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
- {
- protected:
- bool PluginAlive = false;
- public:
- PluginBase(){}
- ~PluginBase(){}
- /**
- * @description: StartTask
- * @return {*}
- */
- virtual bool StartTask() = 0;
-
- /**
- * @description: Alive
- * @return {*}
- */
- virtual bool Alive() = 0;
- /**
- * @description: Rest
- * @return {*}
- */
- virtual bool RestPlugin() = 0;
- };
- };
- #endif // _UTILLBASE_HPP_
|