user_app.h 7.3 KB

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