GlobalInfo.cpp 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. #include "GlobalInfo.h"
  2. #include <QSettings>
  3. #include "spdlog/spdlog.h"
  4. /* ====================================================================================
  5. * ******************************* 全局变量定义 **********************************
  6. * ====================================================================================*/
  7. int g_eventTimeVaild = 600; /* 事件时间有效性,单位秒,超过这个时间就认为是无效数据 */
  8. ActionList g_actionList; /* 全局算法列表 */
  9. /* ====================================================================================
  10. * *************************** DeviceInfo成员函数 *******************************
  11. * ====================================================================================*/
  12. /* 对比是否相等 */
  13. bool DeviceInfo::operator==(const DeviceInfo& other)
  14. {
  15. if(DeviceID != other.DeviceID) {
  16. return false;
  17. }
  18. else if(DeviceName != other.DeviceName || DeviceIP != other.DeviceIP) {
  19. return false;
  20. }
  21. else if(DeviceSerial != other.DeviceSerial || DeviceType != other.DeviceType) {
  22. return false;
  23. }
  24. else if(DevicePort != other.DevicePort || UserAccount != other.UserAccount || UserPassword != other.UserPassword) {
  25. return false;
  26. }
  27. return true;
  28. }
  29. /* 对比设备关联的算法信息是否相等 */
  30. bool DeviceInfo::isEqualAlgorithmInfo(const std::vector<AlgorithmInfo>& other)
  31. {
  32. /* 算法数目不相等,直接返回false */
  33. if(vecAlgorithmInfo.size() != other.size()) {
  34. return false;
  35. }else {
  36. /* 算法数目相等,进一步对比算法信息 */
  37. bool isEquality = true;
  38. /* 逐步对比算法信息 */
  39. for(const auto& it0 : vecAlgorithmInfo) {
  40. bool isEq2 = true;
  41. for(const auto& it1 : other) {
  42. if(it0 == it1) {
  43. continue;
  44. }else {
  45. isEq2 = false;
  46. break;
  47. }
  48. }
  49. if(!isEq2) {
  50. isEquality = false;
  51. break;
  52. }
  53. }
  54. if(!isEquality) {
  55. return false;
  56. }
  57. }
  58. return true;
  59. }
  60. /* ====================================================================================
  61. * ************************** AlarmInfo成员函数 ****************************
  62. * ====================================================================================*/
  63. AlarmInfo::AlarmInfo()
  64. {
  65. Is_Alarm = false;
  66. AlarmID = 0;
  67. DeviceID = 0;
  68. RoomID = 0;
  69. ChannelID = 0;
  70. State = 0;
  71. OnWork = 0;
  72. StartTime = "";
  73. EndTime = "";
  74. EventTime = "";
  75. PicUrl = "";
  76. ImageInfo = "";
  77. AppID = "";
  78. ActionID = "";
  79. ActionDes = "";
  80. FaceIDList = "";
  81. FaceNameList = "";
  82. BboxList = "";
  83. }
  84. AlarmInfo::AlarmInfo(const AlarmInfo& other)
  85. {
  86. Is_Alarm = other.Is_Alarm;
  87. AlarmID = other.AlarmID;
  88. DeviceID = other.DeviceID;
  89. RoomID = other.RoomID;
  90. ChannelID = other.ChannelID;
  91. State = other.State;
  92. OnWork = other.OnWork;
  93. StartTime = other.StartTime;
  94. EndTime = other.EndTime;
  95. EventTime = other.EventTime;
  96. PicUrl = other.PicUrl;
  97. ImageInfo = other.ImageInfo;
  98. AppID = other.AppID;
  99. ActionID = other.ActionID;
  100. ActionDes = other.ActionDes;
  101. FaceIDList = other.FaceIDList;
  102. FaceNameList = other.FaceNameList;
  103. BboxList = other.BboxList;
  104. vecPersonInfo = other.vecPersonInfo;
  105. }
  106. AlarmInfo& AlarmInfo::operator=(AlarmInfo& other)
  107. {
  108. if(this != &other)
  109. {
  110. Is_Alarm = other.Is_Alarm;
  111. AlarmID = other.AlarmID;
  112. DeviceID = other.DeviceID;
  113. RoomID = other.RoomID;
  114. ChannelID = other.ChannelID;
  115. State = other.State;
  116. OnWork = other.OnWork;
  117. StartTime = other.StartTime;
  118. EndTime = other.EndTime;
  119. EventTime = other.EventTime;
  120. PicUrl = other.PicUrl;
  121. ImageInfo = other.ImageInfo;
  122. AppID = other.AppID;
  123. ActionID = other.ActionID;
  124. ActionDes = other.ActionDes;
  125. FaceIDList = other.FaceIDList;
  126. FaceNameList = other.FaceNameList;
  127. BboxList = other.BboxList;
  128. vecPersonInfo = other.vecPersonInfo;
  129. }
  130. return *this;
  131. }
  132. /* 清空内容 */
  133. void AlarmInfo::reInit()
  134. {
  135. Is_Alarm = false;
  136. AlarmID = 0;
  137. DeviceID = 0;
  138. RoomID = 0;
  139. ChannelID = 0;
  140. State = 0;
  141. OnWork = 0;
  142. StartTime = "";
  143. EndTime = "";
  144. EventTime = "";
  145. PicUrl = "";
  146. ImageInfo = "";
  147. AppID = "";
  148. ActionID = "";
  149. ActionDes = "";
  150. FaceIDList = "";
  151. FaceNameList = "";
  152. BboxList = "";
  153. }
  154. /**
  155. * @brief 添加报警信息
  156. *
  157. * @param info
  158. * @return true
  159. * @return false
  160. */
  161. bool ListAlarmInfo::addAlarmInfo(AlarmInfo& info)
  162. {
  163. /* 先查找有没有重复的 */
  164. auto p = findAlarmInfo(info);
  165. if(p != nullptr)
  166. {
  167. return false;
  168. }
  169. listAlarmInfo.push_back(info);
  170. return true;
  171. }
  172. /**
  173. * @brief 检查列表中是是否有这个报警信息,这里只检查ChannelID、RoomID、CameraID、ActionID是否相等
  174. *
  175. * @param info
  176. * @return AlarmInfo*
  177. */
  178. AlarmInfo* ListAlarmInfo::findAlarmInfo(AlarmInfo& info)
  179. {
  180. for(auto& it0 : listAlarmInfo)
  181. {
  182. if(it0.ChannelID == info.ChannelID && it0.RoomID == info.RoomID && it0.DeviceID == info.DeviceID && it0.ActionID == info.ActionID)
  183. {
  184. return &it0;
  185. }
  186. }
  187. return nullptr;
  188. }
  189. AlarmRuleInfo::AlarmRuleInfo()
  190. {
  191. LiveMinEnable = false;
  192. LiveMaxEnable = false;
  193. DicMinEnable = false;
  194. DicMaxEnable = false;
  195. LiveDicMinEnable = false;
  196. LiveDicMaxEnable = false;
  197. LiveMin = 0;
  198. LiveMax = 0;
  199. DicMin = 0;
  200. DicMax = 0;
  201. LiveDicMin = 0;
  202. LiveDicMax = 0;
  203. RuleName = "";
  204. }
  205. AlarmRuleInfo& AlarmRuleInfo::operator=(AlarmRuleInfo& other)
  206. {
  207. if(this != &other)
  208. {
  209. LiveMinEnable = other.LiveMinEnable;
  210. LiveMaxEnable = other.LiveMaxEnable;
  211. DicMinEnable = other.DicMinEnable;
  212. DicMaxEnable = other.DicMaxEnable;
  213. LiveDicMinEnable = other.LiveDicMinEnable;
  214. LiveDicMaxEnable = other.LiveDicMaxEnable;
  215. LiveMin = other.LiveMin;
  216. LiveMax = other.LiveMax;
  217. DicMin = other.DicMin;
  218. DicMax = other.DicMax;
  219. LiveDicMin = other.LiveDicMin;
  220. LiveDicMax = other.LiveDicMax;
  221. RuleName = other.RuleName;
  222. }
  223. return *this;
  224. }
  225. /* ====================================================================================
  226. * ************************** ListActionInfo成员函数 ****************************
  227. * ====================================================================================*/
  228. ActionInfo::ActionInfo()
  229. {
  230. RunState = RunTimeState::RUN_STATE_INIT;
  231. ChannelID = -1;
  232. RoomID = -1;
  233. CameraID = -1;
  234. RoomType = -1;
  235. ActionID = "";
  236. strRoomName = "";
  237. strActionName = "";
  238. }
  239. ActionInfo& ActionInfo::operator=(const ActionInfo& other)
  240. {
  241. if (this != &other)
  242. {
  243. ChannelID = other.ChannelID;
  244. RoomID = other.RoomID;
  245. CameraID = other.CameraID;
  246. ActionID = other.ActionID;
  247. strRoomName = other.strRoomName;
  248. RoomType = other.RoomType;
  249. }
  250. return *this;
  251. }
  252. bool ActionInfo::operator==(const ActionInfo& other)
  253. {
  254. if(ChannelID != other.ChannelID) {
  255. return false;
  256. }
  257. if(RoomID != other.RoomID) {
  258. return false;
  259. }
  260. if(CameraID != other.CameraID) {
  261. return false;
  262. }
  263. if(ActionID != other.ActionID) {
  264. return false;
  265. }
  266. if(RoomType != other.RoomType) {
  267. return false;
  268. }
  269. return true;
  270. }
  271. /* 对比除摄像机外的基础信息是否相等 */
  272. bool ActionInfo::isEqualBaseInfo(const ActionInfo& other)
  273. {
  274. if(ChannelID != other.ChannelID) {
  275. return false;
  276. }
  277. if(RoomID != other.RoomID) {
  278. return false;
  279. }
  280. if(ActionID != other.ActionID) {
  281. return false;
  282. }
  283. if(RoomType != other.RoomType) {
  284. return false;
  285. }
  286. return true;
  287. }
  288. /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
  289. bool ListActionInfo::insertActionInfo(ActionInfo* info)
  290. {
  291. /* 先判断是否已经在列表中了 */
  292. if(findActionInList(info) == nullptr)
  293. {
  294. ActionInfo* pActionInfo = new ActionInfo;
  295. *pActionInfo = *info;
  296. listActionInfo.push_back(pActionInfo);
  297. }
  298. return true;
  299. }
  300. /* 删除信息 */
  301. bool ListActionInfo::deleteActionInfo(ActionInfo* info)
  302. {
  303. if(info == nullptr)
  304. {
  305. return false;
  306. }
  307. if(findActionInList(info) != nullptr)
  308. {
  309. listActionInfo.remove(info);
  310. delete info;
  311. info = nullptr;
  312. }
  313. return true;
  314. }
  315. /* 给算法添加摄像机,原有的会被替换掉 */
  316. bool ListActionInfo::addActionCamera(ActionInfo* pInfo)
  317. {
  318. auto pActionInfo = findActionIDInListNoCamera(pInfo);
  319. if(pActionInfo != nullptr)
  320. {
  321. pActionInfo->CameraID = pInfo->CameraID;
  322. }
  323. return true;
  324. }
  325. /* 清空算法中的摄像机信息 */
  326. void ListActionInfo::clearCameraList()
  327. {
  328. for(auto& it0 : listActionInfo)
  329. {
  330. it0->CameraID = -1;
  331. }
  332. }
  333. /* 清空设置成STOP或ERROR的Action */
  334. void ListActionInfo::clearStopAction()
  335. {
  336. for(auto it0 = listActionInfo.begin(); it0 != listActionInfo.end();)
  337. {
  338. if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
  339. {
  340. delete *it0;
  341. it0 = listActionInfo.erase(it0);
  342. }else {
  343. ++it0;
  344. }
  345. }
  346. }
  347. /* 查找算法ID是否已在列表中 */
  348. ActionInfo* ListActionInfo::findActionInList(ActionInfo* pInfo)
  349. {
  350. for(const auto& it0 : listActionInfo)
  351. {
  352. if(*it0 == *pInfo)
  353. {
  354. return it0;
  355. }
  356. }
  357. return nullptr;
  358. }
  359. /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
  360. ActionInfo* ListActionInfo::findActionIDInListNoCamera(ActionInfo* pInfo)
  361. {
  362. for(const auto& it0 : listActionInfo)
  363. {
  364. if(it0->isEqualBaseInfo(*pInfo))
  365. {
  366. return it0;
  367. }
  368. }
  369. return nullptr;
  370. }
  371. /* 清空容器 */
  372. void ListActionInfo::clear()
  373. {
  374. for(auto& it0 : listActionInfo)
  375. {
  376. delete it0;
  377. it0 = nullptr;
  378. }
  379. listActionInfo.clear();
  380. }
  381. /* ====================================================================================
  382. * *********************** ListRoomActionInfo成员函数 ***************************
  383. * ====================================================================================*/
  384. /* 对比频道信息、房间信息、算法ID是否相等 */
  385. bool RoomActionInfo::isEqualBaseInfo(const RoomActionInfo& other)
  386. {
  387. if(ChannelID != other.ChannelID) {
  388. return false;
  389. }
  390. if(RoomID != other.RoomID) {
  391. return false;
  392. }
  393. if(ActionID != other.ActionID) {
  394. return false;
  395. }
  396. if(RoomType != other.RoomType) {
  397. return false;
  398. }
  399. return true;
  400. }
  401. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  402. bool ListRoomActionInfo::insertRoomActionInfo(const RoomActionInfo& info)
  403. {
  404. /* 先判断是否已经在列表中了 */
  405. if(findActionIDInList(info.ChannelID, info.RoomID, info.ActionID) == nullptr)
  406. {
  407. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  408. *pRoomActionInfo = info;
  409. listRoomActionInfo.push_back(pRoomActionInfo);
  410. }
  411. return true;
  412. }
  413. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  414. bool ListRoomActionInfo::insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID)
  415. {
  416. /* 先判断是否已经在列表中了 */
  417. if(findActionIDInList(ChannelID, RoomID, strActionID) == nullptr)
  418. {
  419. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  420. pRoomActionInfo->RoomID = RoomID;
  421. pRoomActionInfo->ActionID = strActionID;
  422. listRoomActionInfo.push_back(pRoomActionInfo);
  423. }
  424. return true;
  425. }
  426. /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
  427. bool ListRoomActionInfo::deleteRoomActionInfo(RoomActionInfo* pInfo)
  428. {
  429. if(pInfo == nullptr)
  430. {
  431. return false;
  432. }
  433. for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end(); ++it0)
  434. {
  435. if(*it0 == pInfo)
  436. {
  437. listRoomActionInfo.erase(it0);
  438. delete pInfo;
  439. pInfo = nullptr;
  440. return true;
  441. }
  442. }
  443. return false;
  444. }
  445. /* 清空容器 */
  446. void ListRoomActionInfo::clear()
  447. {
  448. for(auto& it0 : listRoomActionInfo)
  449. {
  450. delete it0;
  451. it0 = nullptr;
  452. }
  453. listRoomActionInfo.clear();
  454. }
  455. /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
  456. void ListRoomActionInfo::addActionInfo(const ActionInfo& info)
  457. {
  458. auto pRAInfo = findActionIDInList(info.ChannelID, info.RoomID, info.ActionID);
  459. if(pRAInfo != nullptr)
  460. {
  461. pRAInfo->listCameraID.push_back(info.CameraID);
  462. }else {
  463. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  464. pRoomActionInfo->ChannelID = info.ChannelID;
  465. pRoomActionInfo->RoomID = info.RoomID;
  466. pRoomActionInfo->ActionID = info.ActionID;
  467. pRoomActionInfo->RoomType = info.RoomType;
  468. pRoomActionInfo->strRoomName = info.strRoomName;
  469. pRoomActionInfo->listCameraID.push_back(info.CameraID);
  470. listRoomActionInfo.push_back(pRoomActionInfo);
  471. }
  472. }
  473. /* 清空算法对应的摄像机列表 */
  474. void ListRoomActionInfo::clearCameraList()
  475. {
  476. for(auto& it0 : listRoomActionInfo)
  477. {
  478. it0->listCameraID.clear();
  479. }
  480. }
  481. /* 清理设置为STOP或者ERROR的RoomAction */
  482. void ListRoomActionInfo::clearStopRoomAction()
  483. {
  484. for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end();)
  485. {
  486. if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
  487. {
  488. delete *it0;
  489. it0 = listRoomActionInfo.erase(it0);
  490. }else {
  491. ++it0;
  492. }
  493. }
  494. }
  495. /* 查找算法ID是否已在列表中 */
  496. RoomActionInfo* ListRoomActionInfo::findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID)
  497. {
  498. for(const auto& it0 : listRoomActionInfo)
  499. {
  500. if((it0->RoomID == RoomID) && (it0->ActionID == strActionID) && (it0->ChannelID == chnID))
  501. {
  502. return it0;
  503. }
  504. }
  505. return nullptr;
  506. }
  507. FuncActionInfo::FuncActionInfo()
  508. {
  509. ChannelID = -1;
  510. appFunction = AppFunction::APP_NONE;
  511. RunState = RunTimeState::RUN_STATE_NONE;
  512. strFunctionName = "";
  513. StartTime = QDateTime::currentDateTime();
  514. EndTime = QDateTime::currentDateTime();
  515. listRoomCamActInfo.clear();
  516. }
  517. FuncActionInfo& FuncActionInfo::operator=(FuncActionInfo& other)
  518. {
  519. if(this != &other)
  520. {
  521. ChannelID = other.ChannelID;
  522. appFunction = other.appFunction;
  523. RunState = other.RunState;
  524. strFunctionName = other.strFunctionName;
  525. StartTime = other.StartTime;
  526. EndTime = other.EndTime;
  527. listRoomCamActInfo = other.listRoomCamActInfo;
  528. }
  529. return *this;
  530. }
  531. /* 添加算法信息 */
  532. bool FuncActionInfo::addActionInfo(const ActionInfo& info)
  533. {
  534. /* 根据此类的功能,添加算法信息 */
  535. if(appFunction == AppFunction::APP_NONE)
  536. {
  537. return false;
  538. }
  539. /* 将其添加到对应的房间 */
  540. bool isFind = false;
  541. for(auto& it0 : listRoomCamActInfo)
  542. {
  543. if((it0.RoomID == info.RoomID) && (it0.RoomType == info.RoomType))
  544. {
  545. isFind = true;
  546. it0.mapCameraAction.insert(std::make_pair(info.CameraID, info.ActionID));
  547. }
  548. }
  549. /* 没找到这个房间,就创建 */
  550. if(!isFind)
  551. {
  552. RoomCamActInfo roomCamActInfo;
  553. roomCamActInfo.RoomID = info.RoomID;
  554. roomCamActInfo.RoomType = info.RoomType;
  555. roomCamActInfo.mapCameraAction.insert(std::make_pair(info.CameraID, info.ActionID));
  556. listRoomCamActInfo.push_back(roomCamActInfo);
  557. }
  558. return true;
  559. }
  560. /* 清空算法信息 */
  561. void FuncActionInfo::clearActionList()
  562. {
  563. listRoomCamActInfo.clear();
  564. }
  565. /**
  566. * @brief 添加应用信息,一个应用功能在一个频道内只有一个实例
  567. * 这里是添加应用功能和时间段信息
  568. *
  569. * @param func
  570. * @return true
  571. * @return false
  572. */
  573. bool ListFuncActInfo::addFuncActionInfo(const AppAndTimeInfo& func)
  574. {
  575. if(func.AppType == 0)
  576. {
  577. return false;
  578. }
  579. /* 解出这条信息里包含几个App,AppType按位计算,总共8个应用信息 */
  580. for(int i = 0; i < 8; ++i)
  581. {
  582. if(func.AppType & 0x01)
  583. {
  584. /* 查找有没有这个应用 */
  585. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_ONWORK);
  586. if(pFuncActionInfo != nullptr)
  587. {
  588. /* 更新时间信息 */
  589. pFuncActionInfo->StartTime = func.StartTime;
  590. pFuncActionInfo->EndTime = func.EndTime;
  591. continue;
  592. }
  593. FuncActionInfo* fa = new FuncActionInfo;
  594. fa->ChannelID = func.ChannelID;
  595. fa->appFunction = AppFunction::APP_ONWORK;
  596. fa->strFunctionName = "人员在岗识别";
  597. fa->StartTime = func.StartTime;
  598. fa->EndTime = func.EndTime;
  599. listFuncActionInfo.push_back(fa);
  600. }
  601. else if(func.AppType & 0x02)
  602. {
  603. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_CONTRABAND);
  604. if(pFuncActionInfo != nullptr)
  605. {
  606. /* 更新时间信息 */
  607. pFuncActionInfo->StartTime = func.StartTime;
  608. pFuncActionInfo->EndTime = func.EndTime;
  609. continue;
  610. }
  611. FuncActionInfo* fa = new FuncActionInfo;
  612. fa->ChannelID = func.ChannelID;
  613. fa->appFunction = AppFunction::APP_CONTRABAND;
  614. fa->strFunctionName = "违禁品识别";
  615. fa->StartTime = func.StartTime;
  616. fa->EndTime = func.EndTime;
  617. listFuncActionInfo.push_back(fa);
  618. }
  619. else if (func.AppType & 0x04)
  620. {
  621. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_ILLEGAL);
  622. if(pFuncActionInfo != nullptr)
  623. {
  624. /* 更新时间信息 */
  625. pFuncActionInfo->StartTime = func.StartTime;
  626. pFuncActionInfo->EndTime = func.EndTime;
  627. continue;
  628. }
  629. FuncActionInfo* fa = new FuncActionInfo;
  630. fa->ChannelID = func.ChannelID;
  631. fa->appFunction = AppFunction::APP_ILLEGAL;
  632. fa->strFunctionName = "非法入侵检测";
  633. fa->StartTime = func.StartTime;
  634. fa->EndTime = func.EndTime;
  635. listFuncActionInfo.push_back(fa);
  636. }
  637. else if (func.AppType & 0x08)
  638. {
  639. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_FATIGUE);
  640. if(pFuncActionInfo != nullptr)
  641. {
  642. /* 更新时间信息 */
  643. pFuncActionInfo->StartTime = func.StartTime;
  644. pFuncActionInfo->EndTime = func.EndTime;
  645. continue;
  646. }
  647. FuncActionInfo* fa = new FuncActionInfo;
  648. fa->ChannelID = func.ChannelID;
  649. fa->appFunction = AppFunction::APP_FATIGUE;
  650. fa->strFunctionName = "疲劳检测";
  651. fa->StartTime = func.StartTime;
  652. fa->EndTime = func.EndTime;
  653. listFuncActionInfo.push_back(fa);
  654. }
  655. else if (func.AppType & 0x10)
  656. {
  657. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_REGIONAL);
  658. if(pFuncActionInfo != nullptr)
  659. {
  660. /* 更新时间信息 */
  661. pFuncActionInfo->StartTime = func.StartTime;
  662. pFuncActionInfo->EndTime = func.EndTime;
  663. continue;
  664. }
  665. FuncActionInfo* fa = new FuncActionInfo;
  666. fa->ChannelID = func.ChannelID;
  667. fa->appFunction = AppFunction::APP_REGIONAL;
  668. fa->strFunctionName = "区域人员检测";
  669. fa->StartTime = func.StartTime;
  670. fa->EndTime = func.EndTime;
  671. listFuncActionInfo.push_back(fa);
  672. }
  673. else if (func.AppType & 0x20)
  674. {
  675. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_MOUSE);
  676. if(pFuncActionInfo != nullptr)
  677. {
  678. /* 更新时间信息 */
  679. pFuncActionInfo->StartTime = func.StartTime;
  680. pFuncActionInfo->EndTime = func.EndTime;
  681. continue;
  682. }
  683. FuncActionInfo* fa = new FuncActionInfo;
  684. fa->ChannelID = func.ChannelID;
  685. fa->appFunction = AppFunction::APP_MOUSE;
  686. fa->strFunctionName = "老鼠识别";
  687. fa->StartTime = func.StartTime;
  688. fa->EndTime = func.EndTime;
  689. listFuncActionInfo.push_back(fa);
  690. }
  691. else if (func.AppType & 0x40)
  692. {
  693. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_PLAYPHONE);
  694. if(pFuncActionInfo != nullptr)
  695. {
  696. /* 更新时间信息 */
  697. pFuncActionInfo->StartTime = func.StartTime;
  698. pFuncActionInfo->EndTime = func.EndTime;
  699. continue;
  700. }
  701. FuncActionInfo* fa = new FuncActionInfo;
  702. fa->ChannelID = func.ChannelID;
  703. fa->appFunction = AppFunction::APP_PLAYPHONE;
  704. fa->strFunctionName = "玩手机识别";
  705. fa->StartTime = func.StartTime;
  706. fa->EndTime = func.EndTime;
  707. listFuncActionInfo.push_back(fa);
  708. }
  709. else if (func.AppType & 0x80)
  710. {
  711. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_NOMASK);
  712. if(pFuncActionInfo != nullptr)
  713. {
  714. /* 更新时间信息 */
  715. pFuncActionInfo->StartTime = func.StartTime;
  716. pFuncActionInfo->EndTime = func.EndTime;
  717. continue;
  718. }
  719. FuncActionInfo* fa = new FuncActionInfo;
  720. fa->ChannelID = func.ChannelID;
  721. fa->appFunction = AppFunction::APP_NOMASK;
  722. fa->strFunctionName = "未戴口罩识别";
  723. fa->StartTime = func.StartTime;
  724. fa->EndTime = func.EndTime;
  725. listFuncActionInfo.push_back(fa);
  726. }
  727. else if (func.AppType & 0x0100)
  728. {
  729. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_ALLDOWN);
  730. if(pFuncActionInfo != nullptr)
  731. {
  732. /* 更新时间信息 */
  733. pFuncActionInfo->StartTime = func.StartTime;
  734. pFuncActionInfo->EndTime = func.EndTime;
  735. continue;
  736. }
  737. FuncActionInfo* fa = new FuncActionInfo;
  738. fa->ChannelID = func.ChannelID;
  739. fa->appFunction = AppFunction::APP_ALLDOWN;
  740. fa->strFunctionName = "摔倒识别";
  741. fa->StartTime = func.StartTime;
  742. fa->EndTime = func.EndTime;
  743. listFuncActionInfo.push_back(fa);
  744. }
  745. }
  746. return true;
  747. }
  748. // /**
  749. // * @brief 添加功能信息,一个应用功能在一个频道内只有一个实例
  750. // *
  751. // * @param func 应用功能
  752. // * @return true 添加成功,或者已有这个应用功能
  753. // * @return false
  754. // */
  755. // bool ListFuncActInfo::addFuncActionInfo(AppFunction& func)
  756. // {
  757. // if(func == AppFunction::APP_NONE)
  758. // {
  759. // return false;
  760. // }
  761. // /* 先查找有没有这个应用信息 */
  762. // if(findAppFunction(func))
  763. // {
  764. // return true;
  765. // }
  766. // FuncActionInfo* pFuncActionInfo = new FuncActionInfo;
  767. // pFuncActionInfo->appFunction = func;
  768. // if(func == AppFunction::APP_ONWORK)
  769. // {
  770. // pFuncActionInfo->strFunctionName = "人员在岗识别";
  771. // }
  772. // else if(func == AppFunction::APP_ILLEGAL)
  773. // {
  774. // pFuncActionInfo->strFunctionName = "非法入侵检测";
  775. // }
  776. // else if(func == AppFunction::APP_REGIONAL)
  777. // {
  778. // pFuncActionInfo->strFunctionName = "人员计数";
  779. // }
  780. // else if(func == AppFunction::APP_CONTRABAND)
  781. // {
  782. // pFuncActionInfo->strFunctionName = "违禁物品";
  783. // }
  784. // else if(func == AppFunction::APP_PLAYPHONE)
  785. // {
  786. // pFuncActionInfo->strFunctionName = "玩手机";
  787. // }
  788. // else if(func == AppFunction::APP_FATIGUE)
  789. // {
  790. // pFuncActionInfo->strFunctionName = "疲劳检测";
  791. // }
  792. // else if(func == AppFunction::APP_MOUSE)
  793. // {
  794. // pFuncActionInfo->strFunctionName = "动物识别";
  795. // }
  796. // else if(func == AppFunction::APP_NOMASK)
  797. // {
  798. // pFuncActionInfo->strFunctionName = "口罩识别";
  799. // }
  800. // listFuncActionInfo.push_back(pFuncActionInfo);
  801. // return true;
  802. // }
  803. /**
  804. * @brief 添加算法信息,根据传进来的算法ID,将其加入到对应的功能中
  805. *
  806. * @param info
  807. * @return true
  808. * @return false
  809. */
  810. bool ListFuncActInfo::addActionInfo(const ActionInfo& info)
  811. {
  812. if(info.ActionID.empty())
  813. {
  814. return false;
  815. }
  816. /* 人脸识别算法(人员在岗识别、非法入侵检测) */
  817. if(info.ActionID == g_actionList.ActFace)
  818. {
  819. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_ONWORK);
  820. if(pFuncActionInfo != nullptr)
  821. {
  822. pFuncActionInfo->addActionInfo(info);
  823. }
  824. pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_ILLEGAL);
  825. }
  826. /* 人员计数 */
  827. else if (info.ActionID == g_actionList.ActPersonNumber)
  828. {
  829. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_REGIONAL);
  830. if(pFuncActionInfo != nullptr)
  831. {
  832. pFuncActionInfo->addActionInfo(info);
  833. }
  834. }
  835. /* 违禁物品 */
  836. else if (info.ActionID == g_actionList.ActContraband)
  837. {
  838. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_CONTRABAND);
  839. if(pFuncActionInfo != nullptr)
  840. {
  841. pFuncActionInfo->addActionInfo(info);
  842. }
  843. }
  844. /* 玩手机 */
  845. else if (info.ActionID == g_actionList.ActPlayPhone)
  846. {
  847. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_PLAYPHONE);
  848. if(pFuncActionInfo != nullptr)
  849. {
  850. pFuncActionInfo->addActionInfo(info);
  851. }
  852. }
  853. /* 睡岗识别 */
  854. else if (info.ActionID == g_actionList.ActSleep)
  855. {
  856. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_FATIGUE);
  857. if(pFuncActionInfo != nullptr)
  858. {
  859. pFuncActionInfo->addActionInfo(info);
  860. }
  861. }
  862. /* 疲劳检测 */
  863. else if(info.ActionID == g_actionList.ActFatigueDetection)
  864. {
  865. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_FATIGUE);
  866. if(pFuncActionInfo != nullptr)
  867. {
  868. pFuncActionInfo->addActionInfo(info);
  869. }
  870. }
  871. /* 动物识别 */
  872. else if (info.ActionID == g_actionList.ActAnimalDetect)
  873. {
  874. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_MOUSE);
  875. if(pFuncActionInfo != nullptr)
  876. {
  877. pFuncActionInfo->addActionInfo(info);
  878. }
  879. }
  880. /* 老鼠识别 */
  881. else if (info.ActionID == g_actionList.ActMouseDetect)
  882. {
  883. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_MOUSE);
  884. if(pFuncActionInfo != nullptr)
  885. {
  886. pFuncActionInfo->addActionInfo(info);
  887. }
  888. }
  889. /* 口罩识别 */
  890. else if (info.ActionID == g_actionList.ActMask)
  891. {
  892. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_NOMASK);
  893. if(pFuncActionInfo != nullptr)
  894. {
  895. pFuncActionInfo->addActionInfo(info);
  896. }
  897. }
  898. else {
  899. SPDLOG_WARN("未知的算法ID: {}", info.ActionID);
  900. return false;
  901. }
  902. return true;
  903. }
  904. /**
  905. * @brief 清空无用的功能信息
  906. * 摄像机和算法信息为空的,或者运行状态为STOP,都会被清理掉
  907. *
  908. */
  909. void ListFuncActInfo::clearNoneFuncActionInfo()
  910. {
  911. for(auto it0 = listFuncActionInfo.begin(); it0 != listFuncActionInfo.end();)
  912. {
  913. if((*it0)->listRoomCamActInfo.empty() || ((*it0)->RunState == RunTimeState::RUN_STATE_STOP))
  914. {
  915. delete *it0;
  916. it0 = listFuncActionInfo.erase(it0);
  917. }else {
  918. ++it0;
  919. }
  920. }
  921. }
  922. /* 清空算法列表 */
  923. void ListFuncActInfo::clearActionList()
  924. {
  925. for(auto& it0 : listFuncActionInfo)
  926. {
  927. it0->listRoomCamActInfo.clear();
  928. }
  929. }
  930. /* 查找应用信息 */
  931. bool ListFuncActInfo::findAppFunction(const AppFunction func)
  932. {
  933. for(const auto& it0 : listFuncActionInfo)
  934. {
  935. if(it0->appFunction == func)
  936. {
  937. return true;
  938. }
  939. }
  940. return false;
  941. }
  942. /* 根据频率和功能查找实例 */
  943. FuncActionInfo* ListFuncActInfo::findAppFunction(const int ChannelID, const AppFunction func)
  944. {
  945. for(const auto& it0 : listFuncActionInfo)
  946. {
  947. if( (it0->appFunction == func) && (it0->ChannelID == ChannelID) )
  948. {
  949. return it0;
  950. }
  951. }
  952. return nullptr;
  953. }
  954. /**
  955. * @brief 查找这个应用信息
  956. *
  957. * @param func
  958. * @return FuncActionInfo*
  959. */
  960. FuncActionInfo* ListFuncActInfo::findAppFunction(const FuncActionInfo& func)
  961. {
  962. for(const auto& it0 : listFuncActionInfo)
  963. {
  964. if(it0->ChannelID == func.ChannelID && it0->appFunction == func.appFunction)
  965. {
  966. return it0;
  967. }
  968. }
  969. return nullptr;
  970. }
  971. /* ====================================================================================
  972. * ************************** GlobalConfig成员函数 ******************************
  973. * ====================================================================================*/
  974. /* 创建实例 */
  975. GlobalConfig g_config;
  976. GlobalConfig::GlobalConfig()
  977. {
  978. ThreadSleepMS = 300;
  979. }
  980. /* 读取配置文件 */
  981. bool GlobalConfig::readConfig(const QString& strConfigFile)
  982. {
  983. if(strConfigFile.isEmpty())
  984. {
  985. SPDLOG_ERROR("读取配置文件失败! 配置文件名为空");
  986. return false;
  987. }
  988. SPDLOG_DEBUG("读取配置文件: {}", strConfigFile.toStdString());
  989. QSettings settings(strConfigFile, QSettings::IniFormat);
  990. settings.setIniCodec("UTF-8");
  991. settings.beginGroup("System");
  992. AppPeopleOnWork = settings.value("APPPEPOLEONWORK", 300).toInt(); /* 离岗时间 */
  993. Contraband = settings.value("APPBADTHING", 50).toInt(); /* 违禁物品出现的时间 */
  994. AppBadMan = settings.value("APPBADMAN", 50).toInt(); /* 非法入侵 */
  995. AppTired = settings.value("APPTIRED", 50).toInt(); /* 疲劳检测时间 */
  996. AppPeopleCont = settings.value("APPPEPOLECONT", 50).toInt(); /* 人员聚集时间 */
  997. AppPlayPhone = settings.value("APPPLAYPHONE", 50).toInt(); /* 玩手机识别 */
  998. AppMouse = settings.value("APPMOUSE", 50).toInt(); /* 手势识别 */
  999. AppMask = settings.value("APPMASK", 5).toInt(); /* 戴口罩识别 */
  1000. CheckSet = settings.value("CHECKSET", 300).toInt(); /* 服务端多久检测一次配置 */
  1001. EventTimeValid = settings.value("EventTimeValid", 300).toInt(); /* 事件时间有效期 */
  1002. Key = settings.value("Key").toString().toStdString(); /* Key */
  1003. Secret = settings.value("Secret").toString().toStdString(); /* Secret */
  1004. settings.endGroup();
  1005. if(Key.empty() || Secret.empty())
  1006. {
  1007. SPDLOG_ERROR("读取配置文件失败! Key或Secret为空");
  1008. return false;
  1009. }
  1010. return true;
  1011. }
  1012. /* 打印读取到的值 */
  1013. void GlobalConfig::printValue()
  1014. {
  1015. SPDLOG_INFO("APPPEPOLEONWORK: {}", AppPeopleOnWork);
  1016. SPDLOG_INFO("APPBADTHING: {}", Contraband);
  1017. SPDLOG_INFO("APPBADMAN: {}", AppBadMan);
  1018. SPDLOG_INFO("APPTIRED: {}", AppTired);
  1019. SPDLOG_INFO("APPPEOPLECONT: {}", AppPeopleCont);
  1020. SPDLOG_INFO("APPPLAYPHONE: {}", AppPlayPhone);
  1021. SPDLOG_INFO("APPMOUSE: {}", AppMouse);
  1022. SPDLOG_INFO("APPMASK: {}", AppMask);
  1023. SPDLOG_INFO("CHECKSET: {}", CheckSet);
  1024. SPDLOG_INFO("EventTimeValid: {}", EventTimeValid);
  1025. }