user_app.h 7.0 KB

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