user_app.h 7.1 KB

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