You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
5.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Dr.Frucht Systems Ltd.
  3. // Copyright � 2000-2022. All Rights Reserved.
  4. // Version 1.0 11/19/2022
  5. // Last modification: 11/19/2022
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: mojoKernel.h
  9. // AUTHOR: gagua
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Header file of mojoKernel.cpp
  13. //----------------------------------------------------------------------------
  14. //
  15. #ifndef __MOJO_KERNEL_H_INCL__
  16. #define __MOJO_KERNEL_H_INCL__
  17. #define LA_METRO 1
  18. #define MER_INC 2
  19. #define NOTARGET_SESSION_CLOSE 120 // sec
  20. // At each local hour change an open session is closed in the old hour's report. If a video segment
  21. // with events is still being recorded, wait for it (so it is stored with its events) at most this long.
  22. #define REPORT_SWITCH_MAX_VIDEO_WAIT 90 // sec
  23. #define EMBED_AUTORESET 300 //sec
  24. #define PEREODIC_SENSORS_RESET
  25. #include "../../alg/generic/md5.h"
  26. #include "../../alg/lgs/detector.h"
  27. #include "../../alg/lgs/detectorStructures.h"
  28. #include "../../alg/lgs/mask.h"
  29. #include "../../components/base/basicEvent.h"
  30. #include "../../components/base/basicEventHeap.h"
  31. #include "../../components/base/basicSettingsProvider.h"
  32. #include "../../components/base/basicThread.h"
  33. #include "../../components/object/objectSystemAnchor.h"
  34. #include "../common/kernelPrototype.h"
  35. #include "mojoRemoteClient.h"
  36. #include "../common/kernelHelperMediaMTX.h"
  37. #define MAX_CYCLE_COUNTER_VALUE 0xFFFFFFFF;
  38. #define SLEEP_KERNEL_INTERVAL 10 // 10 millisecond
  39. #define TIME_SYNC_INTERVAL 900000 // 15 minute(s) in 1 millisecond units
  40. #define STATUS_OK_INTERVAL 2000 // 2 Sec in 1 millisecond units
  41. #define KNL_SETTINGS_DETECTOR_WIDTH "DETECTOR_WIDTH"
  42. #define KNL_SETTINGS_FILTER_KERNELS "ENABLED_LRF"
  43. #define KNL_SETTINGS_DETECTOR_SST "DETECTOR_SST"
  44. // #define KNL_SETTINGS_V_MOTOR_SETPOINT "VERTICAL_ENC_FREQ"
  45. #define MOJO_KERNEL_TAG_SITE_ID "SITE_ID"
  46. #define MOJO_KERNEL_TAG_SERVER_IDENTITY "IDENTITY"
  47. #define CRON_JOB_CREATE_BACKUP 20
  48. /**
  49. * LRF_Kernel class - manages communication between client
  50. * handlers and PRU cores bseide of Event management.
  51. *
  52. *
  53. * @author gagua
  54. */
  55. class mojoKernel : public kernelPrototype
  56. {
  57. private:
  58. basicEventHeap * m_pEventHeap;
  59. ShadowMask * m_pShadow;
  60. time_t m_tTimeTSeconds;
  61. bool m_bApplicationFirstRun;
  62. DBC_SYS_LOAD_INFO m_sSysInfo;
  63. DBC_SITE_DATA m_sSiteData;
  64. char m_sIdentity[128];
  65. uint32_t m_nInstanceID;
  66. uint32_t m_nServerID;
  67. uint32_t m_nServerNodeID;
  68. systemAnchor * m_pSystemAnchor;
  69. mojoRemoteClient * m_pRPC;
  70. #ifndef LRF_PROXY_ONLY
  71. kernelHelperMediaMTX * m_pMediaHelper;
  72. #endif
  73. basicMutex m_mSysInfoProtector;
  74. unsigned long long m_mDateOfToday;
  75. bool m_bForceCloseSessionOnEndOfTheDay;
  76. int m_nReportPeriod; // local day*100+hour of the open report
  77. bool m_bReportSwitchPending; // local hour changed, report not switched yet
  78. time_t m_tReportSwitchDetected; // when the hour change was detected
  79. int m_nSessionPeriod; // local day*100+hour the current session was started in
  80. bool m_bDebugMode;
  81. bool m_bKeepLocalReport;
  82. bool m_bWorkWithRemoteServer;
  83. bool m_bSessionStarted;
  84. bool m_bSessionMustPreserve;
  85. bool m_bFirstSession;
  86. uint8_t m_bMediaMode;
  87. uint32_t m_nNoAlarmCounter;
  88. #ifdef EMBED_AUTORESET
  89. bool m_bEnableAutoReset;
  90. uint32_t m_nAutoResetTime;
  91. uint32_t m_nSessionCounter;
  92. #endif
  93. #ifdef PEREODIC_SENSORS_RESET
  94. bool m_bEnablePereodicReset;
  95. uint32_t m_nPereodicResetTime;
  96. uint32_t m_nPereodicResetCounter;
  97. #endif
  98. #ifdef LA_METRO
  99. #endif
  100. void loadFilters();
  101. void unloadFilters();
  102. void validateFilters();
  103. void validateSession();
  104. basicMutex m_mSessionProtector;
  105. void stopSession(bool forced = true);
  106. void preserveSession()
  107. {
  108. m_bSessionMustPreserve = true;
  109. }
  110. static mojoKernel * _instance;
  111. void handleVideo(VIDEO_SEGMENT_INFO * ptr);
  112. bool validateReports(void);
  113. void handleReportPeriodChange(void);
  114. bool createCronJob(uint8_t job, CSTR param_str = NULL, int param_int = 0);
  115. void cleanUpReportDir(uint32_t days);
  116. void backupReports(uint32_t days);
  117. void getSystemUtilization(DBC_SYS_LOAD_INFO * ptr);
  118. protected:
  119. virtual void m_fThreadProc(void);
  120. // Constructor
  121. explicit mojoKernel(config_setting_t * ptr);
  122. public:
  123. static mojoKernel * getInstance(config_setting_t * ptr = NULL);
  124. // Destructor
  125. virtual ~mojoKernel();
  126. virtual bool create();
  127. virtual bool dispatchEvent(EVENT_CONTAINER * Evt);
  128. virtual void startSession();
  129. inline bool getDebugMode()
  130. {
  131. return m_bDebugMode;
  132. }
  133. bool getTrainPresence();
  134. inline uint8_t getMediaMode()
  135. {
  136. return m_bMediaMode;
  137. }
  138. #ifdef __MOJO_REMOTE_CLIENT_HEADER__
  139. bool fillMojoInfo(ARGUS_DATA_MOJO_INFO * ptr);
  140. #endif
  141. virtual void requestExplicitChannel( uint32_t node_id, uint32_t channel_id, uint8_t seconds_to );
  142. virtual void releaseExplicitChannel( uint32_t node_id, uint32_t channel_id );
  143. friend class mojoRemoteClient;
  144. };
  145. #endif // __MOJJO_KERNEL_H_INCL__