UtilBase.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #if !defined(_UTILLBASE_HPP_)
  2. #define _UTILLBASE_HPP_
  3. #include <iostream>
  4. #include <ctime>
  5. #include <memory>
  6. #include <vector>
  7. #include "SendDevice.h"
  8. #include "NonCopyAble.hpp"
  9. namespace gsd{
  10. /**
  11. * @brief 控制设备基础
  12. *
  13. */
  14. class ContorlGear:private NonCopyAble
  15. {
  16. public:
  17. struct ControlerMsg
  18. {
  19. int deviceId;
  20. uint8_t msgId;
  21. uint8_t data;
  22. };
  23. enum DeviceTools{
  24. serial = 0,
  25. http = 1,
  26. tcp = 2
  27. };
  28. protected:
  29. std::string deviceId;
  30. std::string DeviceInfo = "";
  31. enum DeviceTools tool = DeviceTools::serial;
  32. public:
  33. ContorlGear(){}
  34. ~ContorlGear(){}
  35. /**
  36. * @description: 序列化
  37. * @return {*}
  38. */
  39. virtual bool serialization(){
  40. return true;
  41. }
  42. /**
  43. * @description: 反序列化
  44. * @return {*}
  45. */
  46. virtual bool deserialization(){
  47. return true;
  48. }
  49. /**
  50. * @description: 消费数据
  51. * @param {uint8_t} *data
  52. * @param {int} len
  53. * @param {int} &msg_id
  54. * @return {*}
  55. */
  56. virtual bool Consumer(uint8_t *data, int len, int &msg_id){
  57. return true;
  58. }
  59. /**
  60. * @description: 设备响应码是否为状态码
  61. * @param {int} &msg_id
  62. * @return {*}
  63. */
  64. virtual bool getStatusMsg(int &msg_id){
  65. return false;
  66. };
  67. /**
  68. * @description: 构建设备信息
  69. * @param {SendDevice&} sendDevice
  70. * @return {*}
  71. */
  72. virtual void BuildDeviceInfo(SendDevice& sendDevice) {};
  73. /**
  74. * @description: 常规控制
  75. * @param {string} _deviceId 设备Id
  76. * @param {uint8_t*} data 数据
  77. * @param {int&} length 数据长度
  78. * @return {*}
  79. */
  80. virtual int8_t Open(std::string _deviceId,uint8_t* data, int& length){return 0;};
  81. virtual int8_t Close(std::string _deviceId, uint8_t* data, int&length){return 0;};
  82. virtual int8_t Fire(std::string _deviceId, uint8_t* data, int& length){return 0;};
  83. virtual int8_t Status(std::string _deviceId, uint8_t* data, int& length){return 0;};
  84. /**
  85. * @description: 设置设备ID
  86. * @param {string} DeviceId
  87. * @return {*}
  88. */
  89. void setDeviceId(std::string DeviceId){
  90. deviceId = DeviceId;
  91. }
  92. /**
  93. * @description: 获取设备ID
  94. * @return {*}
  95. */
  96. std::string getDeviceId(){
  97. return deviceId;
  98. }
  99. /**
  100. * @description: 获取设备工具
  101. * @return {*}
  102. */
  103. enum DeviceTools getDeviceTool(){
  104. return tool;
  105. }
  106. /**
  107. * @description: 获取数据信息
  108. * @return {*}
  109. */
  110. std::string getDeviceInfo(){
  111. return DeviceInfo;
  112. }
  113. };
  114. /**
  115. * @brief 串口工具
  116. *
  117. */
  118. class ContorlSerialBase:public ContorlGear
  119. {
  120. protected:
  121. int baudRate;
  122. public:
  123. ContorlSerialBase(){}
  124. ~ContorlSerialBase(){}
  125. /**
  126. * @description: 获取波特率
  127. * @return {*}
  128. */
  129. int getBaudRate(){
  130. return this->baudRate;
  131. }
  132. };
  133. /**
  134. * @brief ContorlHttplBase
  135. *
  136. */
  137. class ContorlHttplBase: public ContorlGear
  138. {
  139. protected:
  140. std::string serverIP;
  141. int port;
  142. std::string serverCname;
  143. std::string serverCpwd;
  144. public:
  145. ContorlHttplBase(){}
  146. ~ContorlHttplBase(){}
  147. void setServerIP(std::string _serverIP){
  148. serverIP = _serverIP;
  149. }
  150. void setServerCname(std::string _serverCname){
  151. serverCname = _serverCname;
  152. }
  153. void setServerCpwd(std::string _serverCpwd){
  154. serverCpwd = _serverCpwd;
  155. }
  156. };
  157. /**
  158. * @brief ModuleBase
  159. *
  160. */
  161. class ModuleBase: private NonCopyAble
  162. {
  163. public:
  164. ModuleBase(){}
  165. ~ModuleBase(){}
  166. /**
  167. * @description: 初始化
  168. * @return {*}
  169. */
  170. virtual bool Init() = 0;
  171. /**
  172. * @description: 释放
  173. * @return {*}
  174. */
  175. virtual void Destroy() = 0;
  176. };
  177. /**
  178. * @brief PlginsBase
  179. *
  180. */
  181. class PluginBase: private ModuleBase
  182. {
  183. private:
  184. /* data */
  185. public:
  186. PluginBase(){}
  187. ~PluginBase(){}
  188. /**
  189. * @description: StartTask
  190. * @return {*}
  191. */
  192. virtual bool StartTask() = 0;
  193. /**
  194. * @description: Alive
  195. * @return {*}
  196. */
  197. virtual bool Alive() = 0;
  198. };
  199. };
  200. #endif // _UTILLBASE_HPP_