Expel.hpp 4.1 KB

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