user_app.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * @Description: USERAPP
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2021-10-13 09:41:50
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2021-11-24 15:10:59
  8. */
  9. #pragma once
  10. #include <iostream>
  11. #include <signal.h>
  12. // ZLMediaKit
  13. #include "Util/logger.h"
  14. #include "Util/NoticeCenter.h"
  15. #include "Poller/EventPoller.h"
  16. #include "Player/PlayerProxy.h"
  17. #include "Rtmp/RtmpPusher.h"
  18. #include "Common/config.h"
  19. #include "Pusher/MediaPusher.h"
  20. #include "Extension/Frame.h"
  21. #include "Util/SqlPool.h"
  22. #include "Network/TcpClient.h"
  23. #include "Poller/Timer.h"
  24. #include "TCPClient.h"
  25. #include "inifile.h"
  26. #include <gst/gst.h>
  27. #include <vector>
  28. #include <map>
  29. #include <time.h>
  30. #include "inference.h"
  31. #include "DataSource.h"
  32. // dataType
  33. #include "SendLogin.h"
  34. #include "NettyServerCommandEnum.h"
  35. #include "NettyServerResultMsg.h"
  36. #include "NettyClientResultMsg.h"
  37. #include "SendLogin.h"
  38. #include "NettyClientCommandEnum.h"
  39. #include "InferData.h"
  40. #include "PIDSClientResultMsg.h"
  41. #include "PIDSServerResultMsg.h"
  42. #include "CrowdednessConfig.h"
  43. #include "CrowdednessTimeConfig.h"
  44. #include "SendPassengerFlow.h"
  45. #include "SendCarData.h"
  46. #include "Notices.h"
  47. #include "HttpClient.h"
  48. #include <httplib.h>
  49. using namespace toolkit;
  50. using namespace mediakit;
  51. using namespace inifile;
  52. using namespace std;
  53. namespace MIVA
  54. {
  55. class UserApp
  56. {
  57. public:
  58. /**
  59. * @description: 创建对象
  60. * @param {*}
  61. * @return {std::shared_ptr<UserApp>} 智能指针
  62. * @author: lishengyin
  63. */
  64. static std::shared_ptr<UserApp> CreateNew();
  65. UserApp();
  66. ~UserApp();
  67. /**
  68. * @description: 模块初始化
  69. * @param {string} appName 应用名
  70. * @return {int} 是否成功
  71. * @author: lishengyin
  72. */
  73. int32_t Init(std::string appName);
  74. /**
  75. * @description: 释放数据
  76. * @param {*}
  77. * @return {*}
  78. * @author: lishengyin
  79. */
  80. void Destroy();
  81. /**
  82. * @description: 启动任务
  83. * @param {*}
  84. * @return {*}
  85. * @author: lishengyin
  86. */
  87. void StartTask();
  88. /**
  89. * @description: 获取数据
  90. * @param {*}
  91. * @return {*}
  92. */
  93. int32_t GetNettyDatas();
  94. /**
  95. * @description: 赋值struct sockaddr
  96. * @param {sockaddr} *out
  97. * @param {char} *ip
  98. * @param {uint16_t} port
  99. * @return {*}
  100. * @author: lishengyin
  101. */
  102. static void makeAddr(struct sockaddr *out,const char *ip,uint16_t port);
  103. /**
  104. * @description: 最终的结果运算
  105. * @param {uint32_t} noLoad 空载车厢载荷
  106. * @param {uint32_t} dynamicLoad 动态车厢载荷
  107. * @param {int} num 推理结果
  108. * @return {uint32_t} 运算结构
  109. * @author: lishengyin
  110. */
  111. static uint32_t DataCalculation(uint32_t noLoad, uint32_t dynamicLoad, int num);
  112. /**
  113. * @description: 拥挤成都判定
  114. * @param {int} num 识别结果
  115. * @return {uint8_t} 拥挤程度 1-4
  116. * @author: lishengyin
  117. */
  118. static uint8_t GradeDetermination(int num);
  119. private:
  120. IniFile m_ini;
  121. std::string m_appName;
  122. const std::string m_configSrc = "../config/config.ini";
  123. private:
  124. // Natty
  125. std::string Netty_ip;
  126. int32_t Netty_port;
  127. std::string Netty_idName;
  128. // PIS
  129. std::string PIS_ip;
  130. int32_t PIS_port;
  131. std::string PIS_IdName;
  132. // Mysql
  133. std::string sql_ip;
  134. int32_t sql_port;
  135. std::string user;
  136. std::string password;
  137. std::string character;
  138. // Http
  139. std::string account;
  140. std::string pwd;
  141. std::string uri;
  142. std::string port;
  143. int device_id;
  144. bool play = false;
  145. bool start = true;
  146. private:
  147. std::shared_ptr<TCPClient> m_tcpClient = NULL;
  148. std::shared_ptr<Inference> m_Infer = NULL;
  149. std::shared_ptr<HttpClient> m_httpClient = NULL;
  150. Socket::Ptr m_udpClient = NULL;
  151. std::shared_ptr<InferInfo> m_InferInfo = NULL;
  152. Timer::Ptr m_timer0;
  153. Timer::Ptr m_timer1;
  154. Timer::Ptr m_timer2;
  155. Timer::Ptr m_timer3;
  156. Timer::Ptr m_timer4;
  157. private:
  158. /**
  159. * @description: 监听推理模块广播
  160. * @param {int} Source_id 数据源ID
  161. * @param {int} num 推理结果
  162. * @return {*}
  163. * @author: lishengyin
  164. */
  165. void ListenInfer(int Source_id, int num);
  166. /**
  167. * @description: 监听Netty下发的数据
  168. * @param {Ptr} &pBuf 接受到的数据
  169. * @return {*}
  170. * @author: lishengyin
  171. */
  172. void ListenNettyData(const Buffer::Ptr &pBuf);
  173. /**
  174. * @description: 监听PIS系统的数据
  175. * @param {Ptr} &buf 接受到的数据
  176. * @param {sockaddr} *addr socker信息
  177. * @return {*}
  178. * @author: lishengyin
  179. */
  180. void ListenPISData(const Buffer::Ptr &buf, struct sockaddr *addr);
  181. /**
  182. * @description: 监听车厢关门广播
  183. * @param {*}
  184. * @return {*}
  185. * @author: lishengyin
  186. */
  187. void ListenClosed();
  188. /**
  189. * @description: 监听重启识别广播
  190. * @param {*}
  191. * @return {*}
  192. * @author: lishengyin
  193. */
  194. void ListenRelease();
  195. /**
  196. * @description: 监听推理数据广播
  197. * @param {*}
  198. * @return {*}
  199. * @author: lishengyin
  200. */
  201. void ListenInferData();
  202. /**
  203. * @description: 连接Netty
  204. * @param {*}
  205. * @return {*}
  206. * @author: lishengyin
  207. */
  208. void ConnectNetty();
  209. /**
  210. * @description: 上报数据到PIS
  211. * @param {*}
  212. * @return {*}
  213. * @author: lishengyin
  214. */
  215. void ReportData();
  216. /**
  217. * 上报推理数据到Netty
  218. * @param {*}
  219. * @return {*}
  220. */
  221. void ReportInferData();
  222. /**
  223. * 监听数据
  224. * @param {*}
  225. * @return {*}
  226. */
  227. void MonitorData();
  228. };
  229. }