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-10-09 09:54:10
  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 "Util/SqlPool.h"
  17. #include "Network/TcpClient.h"
  18. #include "Poller/Timer.h"
  19. #include "TCPClient.h"
  20. #include "inifile.h"
  21. #include <gst/gst.h>
  22. #include <vector>
  23. #include <map>
  24. #include <time.h>
  25. #include "inference.h"
  26. #include "DataSource.h"
  27. // dataType
  28. #include "SendLogin.h"
  29. #include "NettyServerCommandEnum.h"
  30. #include "NettyServerResultMsg.h"
  31. #include "NettyClientResultMsg.h"
  32. #include "SendLogin.h"
  33. #include "NettyClientCommandEnum.h"
  34. #include "InferData.h"
  35. #include "PIDSClientResultMsg.h"
  36. #include "PIDSServerResultMsg.h"
  37. #include "CrowdednessConfig.h"
  38. #include "CrowdednessTimeConfig.h"
  39. #include "SendPassengerFlow.h"
  40. #include "SendCarData.h"
  41. #include "Notices.h"
  42. #include "HttpClient.h"
  43. #include "recorder.h"
  44. #include "Cleaner.h"
  45. #include "monitor.h"
  46. #include "deviceState.h"
  47. #include "Manager.h"
  48. #include <httplib.h>
  49. #include <mutex>
  50. #include <condition_variable>
  51. using namespace toolkit;
  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. /**
  121. * @description:
  122. * @param {string} Pid
  123. * @return {*}
  124. */
  125. static int GetAddrNum(std::string Pid);
  126. private:
  127. IniFile m_ini;
  128. std::string m_appName;
  129. const std::string m_configSrc = "../config/config.ini";
  130. private:
  131. // Natty
  132. std::string Netty_ip;
  133. int32_t Netty_port;
  134. std::string Netty_idName;
  135. // PIS
  136. std::string PIS_ip;
  137. int32_t PIS_port;
  138. std::string PIS_IdName;
  139. // Mysql
  140. std::string sql_ip;
  141. int32_t sql_port;
  142. std::string user;
  143. std::string password;
  144. std::string character;
  145. // Http
  146. std::string account;
  147. std::string pwd;
  148. std::string uri;
  149. std::string port;
  150. int device_id;
  151. int MemoryThreshold = 1024;
  152. bool play = false;
  153. bool start = true;
  154. bool enable = true;
  155. private:
  156. std::shared_ptr<TCPClient> m_tcpClient = NULL;
  157. std::shared_ptr<Inference> m_Infer = NULL;
  158. std::shared_ptr<HttpClient> m_httpClient = NULL;
  159. std::shared_ptr<recorder> m_recorder = nullptr;
  160. std::shared_ptr<Cleaner> m_Cleaner = nullptr;
  161. std::shared_ptr<monitor> m_monitor = nullptr;
  162. deviceState::Ptr m_deviceState = nullptr;
  163. Manager::Ptr m_manager = nullptr;
  164. Socket::Ptr m_udpClient = NULL;
  165. std::shared_ptr<InferInfo> m_InferInfo = NULL;
  166. Timer::Ptr m_timer0;
  167. Timer::Ptr m_timer1;
  168. Timer::Ptr m_timer2;
  169. Timer::Ptr m_timer3;
  170. Timer::Ptr m_timer4;
  171. Timer::Ptr m_timer5;
  172. Timer::Ptr m_timer6;
  173. std::condition_variable condition;
  174. std::mutex m_mutex;
  175. bool stop = false;
  176. private:
  177. /**
  178. * @description: 监听推理模块广播
  179. * @param {int} Source_id 数据源ID
  180. * @param {int} num 推理结果
  181. * @return {*}
  182. * @author: lishengyin
  183. */
  184. void ListenInfer(int Source_id, int num);
  185. /**
  186. * @description: 监听Netty下发的数据
  187. * @param {Ptr} &pBuf 接受到的数据
  188. * @return {*}
  189. * @author: lishengyin
  190. */
  191. void ListenNettyData(const Buffer::Ptr &pBuf);
  192. /**
  193. * @description: 监听PIS系统的数据
  194. * @param {Ptr} &buf 接受到的数据
  195. * @param {sockaddr} *addr socker信息
  196. * @return {*}
  197. * @author: lishengyin
  198. */
  199. void ListenPISData(const Buffer::Ptr &buf, struct sockaddr *addr);
  200. /**
  201. * @description: 监听车厢关门广播
  202. * @param {*}
  203. * @return {*}
  204. * @author: lishengyin
  205. */
  206. void ListenClosed();
  207. /**
  208. * @description: 监听重启识别广播
  209. * @param {*}
  210. * @return {*}
  211. * @author: lishengyin
  212. */
  213. void ListenRelease();
  214. /**
  215. * @description: 监听推理数据广播
  216. * @param {*}
  217. * @return {*}
  218. * @author: lishengyin
  219. */
  220. void ListenInferData();
  221. /**
  222. * @description: 监听推理完成
  223. * @param {*}
  224. * @return {*}
  225. */
  226. void ListenInferPer();
  227. /**
  228. * @description: 连接Netty
  229. * @param {*}
  230. * @return {*}
  231. * @author: lishengyin
  232. */
  233. void ConnectNetty();
  234. /**
  235. * @description: 上报数据到PIS
  236. * @param {*}
  237. * @return {*}
  238. * @author: lishengyin
  239. */
  240. void ReportData();
  241. /**
  242. * 上报推理数据到Netty
  243. * @param {*}
  244. * @return {*}
  245. */
  246. void ReportInferData();
  247. /**
  248. * 监听数据
  249. * @param {*}
  250. * @return {*}
  251. */
  252. void MonitorData();
  253. /**
  254. * @description: 清理内除
  255. * @param {*}
  256. * @return {*}
  257. */
  258. int32_t ClearMemory();
  259. };
  260. }