user_app.h 6.4 KB

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