Expel.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #ifndef _EXPEL_HPP_
  2. #define _EXPEL_HPP_
  3. #include "UtilBase.hpp"
  4. #include <mutex>
  5. #include <condition_variable>
  6. #include <future>
  7. #include "Util/logger.h"
  8. #include "Util/NoticeCenter.h"
  9. #include "Network/TcpClient.h"
  10. #include "requests.hpp"
  11. #include "ExpelDevice.h"
  12. #include "httplib.h"
  13. #include "CSerialPort/SerialPort.h"
  14. // dev
  15. #include "DevicePlayerV1.hpp"
  16. #include "DevicePlayerV2.hpp"
  17. #include "DevicePlayerV3.hpp"
  18. #include "DevicePlayerV3.hpp"
  19. #include "DevicePlayerV4.hpp"
  20. #include "DevicePlayerV5.hpp"
  21. #include "DeviceGasV1.hpp"
  22. #include "DeviceGasV2.hpp"
  23. #include "config.hpp"
  24. #include <iostream>
  25. #include "PlayerStatus.h"
  26. #include "uuid.hpp"
  27. #include "Notices.h"
  28. using namespace utility;
  29. using namespace toolkit;
  30. using namespace itas109;
  31. namespace gsd{
  32. class Expel: public std::enable_shared_from_this<Expel>, public ModuleBase
  33. {
  34. private:
  35. Expel(): ModuleBase(){
  36. this->pool = std::make_shared<ThreadPool>(1,ThreadPool::PRIORITY_HIGHEST, false);
  37. InfoL;
  38. }
  39. public:
  40. using Ptr = std::shared_ptr<Expel>;
  41. ~Expel(){
  42. this->Destroy();
  43. }
  44. /**
  45. * @description: 获取Ptr
  46. * @return {*}
  47. */
  48. static std::shared_ptr<Expel> getPtr();
  49. /**
  50. * @description: 初始化
  51. * @return {*}
  52. */
  53. bool Init();
  54. /**
  55. * @description: 释放
  56. * @return {*}
  57. */
  58. void Destroy();
  59. /**
  60. * @description: HttpControler的控制接口
  61. * @param {int} commandCode
  62. * @param {ExpelDevice} expelDevice
  63. * @return {*}
  64. */
  65. void HttpControler(int commandCode, ExpelDevice expelDevice);
  66. /**
  67. * @description: 设备命令的回调函数
  68. * @param {NettyServerResultMsg<RecDeviceCommand>} &nettyServerResultMsg
  69. * @return {*}
  70. */
  71. void sendDeviceMsgCallback(NettyServerResultMsg<RecDeviceCommand> &nettyServerResultMsg, ExpelDevice expelDevice);
  72. /**
  73. * @description: 全部打开
  74. * @param {*}
  75. * @return {*}
  76. */
  77. int32_t AllOpen();
  78. /**
  79. * @description:
  80. * @param {*}
  81. * @return {*}
  82. */
  83. int32_t AllClose();
  84. /**
  85. * @description: 全部开炮
  86. * @param {*}
  87. * @return {*}
  88. */
  89. int32_t AllFire();
  90. /**
  91. * @description: 获取设备列表
  92. * @param {*}
  93. * @return {*}
  94. */
  95. int32_t UpdateDeviceList(vector<vector<std::string>>& datas);
  96. /**
  97. * @description: 数组转为json
  98. * @param {uint8_t*} bytes
  99. * @param {int} length
  100. * @return {*}
  101. */
  102. static std::string bytesToHexString(const uint8_t* bytes,const int length);
  103. /**
  104. * @description: 获取驱鸟设备数量
  105. * @return {*}
  106. */
  107. int32_t getExpelSize();
  108. /**
  109. * @description: 全部驱鸟设备的控制器
  110. * @return {*}
  111. */
  112. int32_t Controler(std::string commandCode);
  113. /**
  114. * @description: getExpelInfo
  115. * @return {*}
  116. */
  117. std::string getExpelInfo();
  118. list<int> m_deviceIdList;
  119. list<ExpelDevice> m_deviceLists;
  120. private:
  121. /**
  122. * @description: 获取控制器
  123. * @param {*}
  124. * @return {*}
  125. */
  126. std::shared_ptr<ContorlGear> getControl(ExpelDevice& expelDevice);
  127. /**
  128. * @description: 启动
  129. * @param {int} deivceId
  130. * @return {*}
  131. */
  132. int32_t Open(ExpelDevice& expelDevice);
  133. /**
  134. * @description: 关闭
  135. * @param {int} deivceId
  136. * @return {*}
  137. */
  138. int32_t Close(ExpelDevice& expelDevice);
  139. /**
  140. * @description: 开火
  141. * @param {int} deivceId
  142. * @return {*}
  143. */
  144. int32_t Fire(ExpelDevice& expelDevice);
  145. /**
  146. * @description: 状态
  147. * @param {int} deivceId
  148. * @param {string&} json
  149. * @return {*}
  150. */
  151. int32_t Status(ExpelDevice& expelDevice);
  152. /**
  153. * @description: 串口数据接收
  154. * @param {*}
  155. * @return {*}
  156. */
  157. bool SerialReceive(CSerialPort& ser, std::shared_ptr<ContorlGear>& deviceControl);
  158. /**
  159. * @description: Control
  160. * @param {*}
  161. * @return {*}
  162. */
  163. int32_t Control(std::shared_ptr<ContorlGear>& deviceControl, ExpelDevice& expelDevice, uint8_t* data, int& length, int type);
  164. protected:
  165. mutex m_mutex;
  166. std::shared_ptr<ThreadPool> pool = nullptr;
  167. };
  168. };
  169. #endif