expel.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /***** (C) Copyright, Shenzhen SUNWIN Intelligent Co.,Ltd. ******header file****
  2. * File name : expel.h
  3. * Author : Jinliang Yang
  4. * Brief :
  5. ********************************************************************************
  6. * modify
  7. * Version Date Author Described
  8. * V2.00 2020/04/8 ShengYin Li Created
  9. *******************************************************************************/
  10. #ifndef expel_h
  11. #define expel_h
  12. #pragma once
  13. #include <iostream>
  14. #include <stdlib.h>
  15. #include <time.h>
  16. #include <stdio.h>
  17. #include <sys/types.h>
  18. #include <stdint.h>
  19. #include "md5.h"
  20. #include <sys/socket.h>
  21. #include <sys/mman.h>
  22. #include <sys/shm.h>
  23. #include <sys/stat.h>
  24. #include <sys/un.h>
  25. #include <sys/wait.h>
  26. #include <netinet/in.h>
  27. #include <arpa/inet.h>
  28. #include <errno.h>
  29. #include <fcntl.h>
  30. #include <unistd.h>
  31. #include <iostream>
  32. #include <memory>
  33. #include <string>
  34. #include <vector>
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <list>
  38. #include <thread>
  39. #include <rapidjson/document.h>
  40. #include <rapidjson/rapidjson.h>
  41. #include <rapidjson/stringbuffer.h>
  42. #include <rapidjson/writer.h>
  43. #include "SerialPort.h"
  44. #include "Util/util.h"
  45. #include "Util/logger.h"
  46. #include "Network/Socket.h"
  47. #include "Util/TimeTicker.h"
  48. #include "Poller/Timer.h"
  49. #include "Util/NoticeCenter.h"
  50. #include "Network/TcpClient.h"
  51. //dataType
  52. #include "NettyClientCommandEnum.h"
  53. #include "NettyServerCommandEnum.h"
  54. #include "NettyClientResultMsg.h"
  55. #include "NettyServerResultMsg.h"
  56. #include "RecDeviceCommand.h"
  57. #include "SendBird.h"
  58. #include "SendDevice.h"
  59. #include "SendHeartBeat.h"
  60. #include "Notices.h"
  61. #include "httplib.h"
  62. #include "ExpelDevice.h"
  63. #include <mutex>
  64. #include "uuid.hpp"
  65. using namespace std;
  66. using namespace itas109;
  67. using namespace toolkit;
  68. using namespace utility;
  69. class Expel
  70. {
  71. public:
  72. Expel();
  73. ~Expel();
  74. /**
  75. * @description: 初始化
  76. * @param {*}
  77. * @return {*}
  78. */
  79. void Init();
  80. /**
  81. * @description: 获取Ptr
  82. * @return {*}
  83. */
  84. static std::shared_ptr<Expel> getPtr();
  85. /**
  86. * @description: 设备命令的回调函数
  87. * @param {NettyServerResultMsg<RecDeviceCommand>} &nettyServerResultMsg
  88. * @return {*}
  89. */
  90. void sendDeviceMsgCallback(NettyServerResultMsg<RecDeviceCommand> &nettyServerResultMsg, ExpelDevice expelDevice);
  91. /**
  92. * @description: 全部打开
  93. * @param {*}
  94. * @return {*}
  95. */
  96. int32_t AllOpen();
  97. /**
  98. * @description:
  99. * @param {*}
  100. * @return {*}
  101. */
  102. int32_t AllClose();
  103. /**
  104. * @description: 全部开炮
  105. * @param {*}
  106. * @return {*}
  107. */
  108. int32_t AllFire();
  109. /**
  110. * @description: 获取设备列表
  111. * @param {*}
  112. * @return {*}
  113. */
  114. int32_t UpdateDeviceList(vector<vector<std::string>>& datas);
  115. /**
  116. * @description: 数组转为json
  117. * @param {uint8_t*} bytes
  118. * @param {int} length
  119. * @return {*}
  120. */
  121. static std::string bytesToHexString(const uint8_t* bytes,const int length);
  122. /**
  123. * @description: 获取驱鸟设备数量
  124. * @return {*}
  125. */
  126. int32_t getExpelSize();
  127. /**
  128. * @description: 全部驱鸟设备的控制器
  129. * @return {*}
  130. */
  131. int32_t Controler(std::string commandCode);
  132. list<int> m_deviceIdList;
  133. list<ExpelDevice> m_deviceLists;
  134. mutex m_mutex;
  135. private:
  136. /**
  137. * @description: 获取控制器
  138. * @param {*}
  139. * @return {*}
  140. */
  141. std::shared_ptr<deviceBase> getControl(ExpelDevice& expelDevice);
  142. /**
  143. * @description: 启动
  144. * @param {int} deivceId
  145. * @return {*}
  146. */
  147. int32_t Open(ExpelDevice& expelDevice);
  148. /**
  149. * @description: 关闭
  150. * @param {int} deivceId
  151. * @return {*}
  152. */
  153. int32_t Close(ExpelDevice& expelDevice);
  154. /**
  155. * @description: 开火
  156. * @param {int} deivceId
  157. * @return {*}
  158. */
  159. int32_t Fire(ExpelDevice& expelDevice);
  160. /**
  161. * @description: 状态
  162. * @param {int} deivceId
  163. * @param {string&} json
  164. * @return {*}
  165. */
  166. int32_t Status(ExpelDevice& expelDevice);
  167. /**
  168. * @description: 串口数据接收
  169. * @param {*}
  170. * @return {*}
  171. */
  172. bool SerialReceive(CSerialPort& ser, std::shared_ptr<deviceBase>& deviceControl);
  173. /**
  174. * @description: Control
  175. * @param {*}
  176. * @return {*}
  177. */
  178. int32_t Control(std::shared_ptr<deviceBase>& deviceControl, ExpelDevice& expelDevice, uint8_t* data, int& length, int type);
  179. };
  180. #endif
  181. /******** (C) Copyright, Shenzhen SUNWIN Intelligent Co.,Ltd. ******** End *****/