user_app.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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-12-27 13:55:40
  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 "recorder.h"
  49. #include <httplib.h>
  50. using namespace toolkit;
  51. using namespace mediakit;
  52. using namespace inifile;
  53. using namespace std;
  54. namespace MIVA
  55. {
  56. class UserApp
  57. {
  58. public:
  59. /**
  60. * @description: 创建对象
  61. * @param {*}
  62. * @return {std::shared_ptr<UserApp>} 智能指针
  63. * @author: lishengyin
  64. */
  65. static std::shared_ptr<UserApp> CreateNew();
  66. UserApp();
  67. ~UserApp();
  68. /**
  69. * @description: 模块初始化
  70. * @param {string} appName 应用名
  71. * @return {int} 是否成功
  72. * @author: lishengyin
  73. */
  74. int32_t Init(std::string appName);
  75. /**
  76. * @description: 释放数据
  77. * @param {*}
  78. * @return {*}
  79. * @author: lishengyin
  80. */
  81. void Destroy();
  82. /**
  83. * @description: 启动任务
  84. * @param {*}
  85. * @return {*}
  86. * @author: lishengyin
  87. */
  88. void StartTask();
  89. /**
  90. * @description: 获取数据
  91. * @param {*}
  92. * @return {*}
  93. */
  94. int32_t GetNettyDatas();
  95. /**
  96. * @description: 赋值struct sockaddr
  97. * @param {sockaddr} *out
  98. * @param {char} *ip
  99. * @param {uint16_t} port
  100. * @return {*}
  101. * @author: lishengyin
  102. */
  103. static void makeAddr(struct sockaddr *out,const char *ip,uint16_t port);
  104. /**
  105. * @description: 最终的结果运算
  106. * @param {uint32_t} noLoad 空载车厢载荷
  107. * @param {uint32_t} dynamicLoad 动态车厢载荷
  108. * @param {int} num 推理结果
  109. * @return {uint32_t} 运算结构
  110. * @author: lishengyin
  111. */
  112. static uint32_t DataCalculation(uint32_t noLoad, uint32_t dynamicLoad, int num);
  113. /**
  114. * @description: 拥挤成都判定
  115. * @param {int} num 识别结果
  116. * @return {uint8_t} 拥挤程度 1-4
  117. * @author: lishengyin
  118. */
  119. static uint8_t GradeDetermination(int num);
  120. private:
  121. IniFile m_ini;
  122. std::string m_appName;
  123. const std::string m_configSrc = "../config/config.ini";
  124. private:
  125. // Natty
  126. std::string Netty_ip;
  127. int32_t Netty_port;
  128. std::string Netty_idName;
  129. // PIS
  130. std::string PIS_ip;
  131. int32_t PIS_port;
  132. std::string PIS_IdName;
  133. // Mysql
  134. std::string sql_ip;
  135. int32_t sql_port;
  136. std::string user;
  137. std::string password;
  138. std::string character;
  139. // Http
  140. std::string account;
  141. std::string pwd;
  142. std::string uri;
  143. std::string port;
  144. int device_id;
  145. bool play = false;
  146. bool start = true;
  147. private:
  148. std::shared_ptr<TCPClient> m_tcpClient = NULL;
  149. std::shared_ptr<Inference> m_Infer = NULL;
  150. std::shared_ptr<HttpClient> m_httpClient = NULL;
  151. std::shared_ptr<recorder> m_recorder = nullptr;
  152. Socket::Ptr m_udpClient = NULL;
  153. std::shared_ptr<InferInfo> m_InferInfo = NULL;
  154. Timer::Ptr m_timer0;
  155. Timer::Ptr m_timer1;
  156. Timer::Ptr m_timer2;
  157. Timer::Ptr m_timer3;
  158. Timer::Ptr m_timer4;
  159. Timer::Ptr m_timer5;
  160. private:
  161. /**
  162. * @description: 监听推理模块广播
  163. * @param {int} Source_id 数据源ID
  164. * @param {int} num 推理结果
  165. * @return {*}
  166. * @author: lishengyin
  167. */
  168. void ListenInfer(int Source_id, int num);
  169. /**
  170. * @description: 监听Netty下发的数据
  171. * @param {Ptr} &pBuf 接受到的数据
  172. * @return {*}
  173. * @author: lishengyin
  174. */
  175. void ListenNettyData(const Buffer::Ptr &pBuf);
  176. /**
  177. * @description: 监听PIS系统的数据
  178. * @param {Ptr} &buf 接受到的数据
  179. * @param {sockaddr} *addr socker信息
  180. * @return {*}
  181. * @author: lishengyin
  182. */
  183. void ListenPISData(const Buffer::Ptr &buf, struct sockaddr *addr);
  184. /**
  185. * @description: 监听车厢关门广播
  186. * @param {*}
  187. * @return {*}
  188. * @author: lishengyin
  189. */
  190. void ListenClosed();
  191. /**
  192. * @description: 监听重启识别广播
  193. * @param {*}
  194. * @return {*}
  195. * @author: lishengyin
  196. */
  197. void ListenRelease();
  198. /**
  199. * @description: 监听推理数据广播
  200. * @param {*}
  201. * @return {*}
  202. * @author: lishengyin
  203. */
  204. void ListenInferData();
  205. /**
  206. * @description: 监听推理完成
  207. * @param {*}
  208. * @return {*}
  209. */
  210. void ListenInferPer();
  211. /**
  212. * @description: 连接Netty
  213. * @param {*}
  214. * @return {*}
  215. * @author: lishengyin
  216. */
  217. void ConnectNetty();
  218. /**
  219. * @description: 上报数据到PIS
  220. * @param {*}
  221. * @return {*}
  222. * @author: lishengyin
  223. */
  224. void ReportData();
  225. /**
  226. * 上报推理数据到Netty
  227. * @param {*}
  228. * @return {*}
  229. */
  230. void ReportInferData();
  231. /**
  232. * 监听数据
  233. * @param {*}
  234. * @return {*}
  235. */
  236. void MonitorData();
  237. };
  238. }