Expel.hpp 4.7 KB

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