Expel.hpp 4.6 KB

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