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.

237 lines
9.7 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Dr.Frucht Systems Ltd.
  3. // Copyright � 2000-2017. All Rights Reserved.
  4. // Version 2.0 7/20/2017
  5. // Last modification: 7/20/2017
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LRF_Kernel.h
  9. // AUTHOR: gagua
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Header file of LRF_Kernel.cpp
  13. //----------------------------------------------------------------------------
  14. //
  15. #ifndef __KERNEL_H_INCL__
  16. #define __KERNEL_H_INCL__
  17. #define MULTI_TARGETS
  18. #define NO_GPIO_HANDLER
  19. #define DUMP_TH_AFTER_FLIP_ON_DISK
  20. #define MAX_LOCAL_VIDEO_SOURCES 5
  21. #define MAX_LRF_SENSORS 9
  22. #define USE_TIME_LAPSE_RECORDER
  23. #include "../../components/base/basicEngine.h"
  24. #include "../../components/base/basicThread.h"
  25. #include "../../components/base/basicMutex.h"
  26. #include "../../components/base/basicRing.h"
  27. #include "../../components/base/basicMediaDestination.h"
  28. #include "../../components/base/basicSettingsProvider.h"
  29. #include "../../components/base/basicEventHeap.h"
  30. #include "../../data/storage/storageProvider.h"
  31. #include "../../data/mysql/database_class.h"
  32. #include "../../data/net/netServer.h"
  33. #include "../../alg/lgs/detector.h"
  34. #include "../../alg/lgs/mask.h"
  35. #include "../../data/media/videoNode.h"
  36. #include "../../data/media/video/videoAVLIBSource.h"
  37. #include "../../data/media/video/videoV4L2Source.h"
  38. #include "../../data/protocol/protocolMastBaum.h"
  39. #ifdef USE_TIME_LAPSE_RECORDER
  40. #include "../../data/media/lapsedVideoRecorder.h"
  41. #else
  42. #define ASSEMBLE_MP4
  43. #ifdef ASSEMBLE_MP4
  44. #include "../../data/media/video/videoAVLIBDestination.h"
  45. //#define KEEP_JPEG_IMAGES
  46. #endif
  47. #endif
  48. #define MAX_CYCLE_COUNTER_VALUE 0xFFFFFFFF;
  49. #define SLEEP_KERNEL_INTERVAL 10 // 10 millisecond
  50. #define TIME_SYNC_INTERVAL 900000 // 15 minute(s) in 1 millisecond units
  51. #define STATUS_OK_INTERVAL 2000 // 2 Sec in 1 millisecond units
  52. #define KNL_SETTINGS_MAIN_TAG ((CSTR)"KERNEL")
  53. #define KNL_SETTINGS_DETECT_ARMED ((CSTR)"DETECTION_ARMED") //bool
  54. #define KNL_SETTINGS_DETECT_OFFSET ((CSTR)"DETECTION_OFFSET") //int
  55. #define KNL_SETTINGS_DETECT_SST ((CSTR)"DETECTION_SST") //int
  56. #define KNL_SETTINGS_DETECT_LAYER_DIST ((CSTR)"DETECTION_LAYER_DIST") //float
  57. #define KNL_SETTINGS_DETECT_MAX_RANGE ((CSTR)"DETECTION_MAX_RANGE") //float
  58. #define KNL_SETTINGS_DETECT_MIN_SPEED ((CSTR)"DETECTION_MIN_SPEED") //float
  59. #define KNL_SETTINGS_VIDEO_ENGINE ((CSTR)"VIDEO_ENGINE") //bool
  60. #define KNL_SETTINGS_VIDEO_OUTPUT ((CSTR)"MP4_ENABLE") //bool
  61. #define KNL_SETTINGS_DATABASE_ENA ((CSTR)"DB_ENABLE") //bool
  62. #define KNL_SETTINGS_DATABASE_HOST ((CSTR)"DB_HOST") //str
  63. #define KNL_SETTINGS_DATABASE_NAME ((CSTR)"DB_NAME") //str
  64. #define KNL_SETTINGS_DATABASE_USER ((CSTR)"DB_USER") //str
  65. #define KNL_SETTINGS_DATABASE_PASS ((CSTR)"DB_PASS") //str
  66. #define KNL_SETTINGS_STORAGE_BASE ((CSTR)"STORAGE_BASE") //str
  67. #define KNL_SETTINGS_SERIAL_PORT ((CSTR)"COM_PORT") //str
  68. #define KNL_SETTINGS_SERIAL_SPEED ((CSTR)"COM_SPEED") //int
  69. #define KNL_SETTINGS_FRAME_COMPOSE ((CSTR)"FRAME_COMPOSITION") //??
  70. #define KNL_SETTINGS_FRAME_COMPOSE_DIM ((CSTR)"FRAME_DIMENTION") //??
  71. #define KNL_SETTINGS_VIDEO_ROTATION ((CSTR)"VIDEO_ROT") //int
  72. #define KNL_SETTINGS_VIDEO_SECTION ((CSTR)"VIDEO_INPUTS")
  73. #define KNL_SETTINGS_VIDEO_INPUT_ID ((CSTR)"VIDEO_INPUT_ID") //int
  74. #define KNL_SETTINGS_VIDEO_INPUT_WIDTH ((CSTR)"VIDEO_INPUT_WIDTH") //int
  75. #define KNL_SETTINGS_VIDEO_INPUT_HEIGHT ((CSTR)"VIDEO_INPUT_HEIGHT") //int
  76. #define KNL_SETTINGS_VIDEO_SCALE_WIDTH ((CSTR)"VIDEO_SCALE_WIDTH") //int
  77. #define KNL_SETTINGS_VIDEO_SCALE_HEIGHT ((CSTR)"VIDEO_SCALE_HEIGHT") //int
  78. #define KNL_SETTINGS_VIDEO_INPUT_FPS ((CSTR)"VIDEO_INPUT_FPS") //float
  79. #define WEB_CMD_NOP 0
  80. #define WEB_CMD_RESET_DETECTION 1
  81. #define WEB_CMD_SET_PARAMS 2
  82. #define WEB_CMD_CLEAR_LOG 3
  83. #define WEB_CMD_DISABLE_DETECTION 4
  84. #define WEB_CMD_ENABLE_DETECTION 5
  85. #define WEB_CMD_MAKE_TEST_ALARM 6
  86. #define WEB_CMD_RESET_DEVICE 7
  87. #define FSL_SYSTEM_STARTUP 0
  88. #define FSL_CONNECT_DISARMED 1
  89. #define FSL_CONNECT_ARMED 2
  90. #define FSL_OPERATOR_DISARMED 3
  91. #define FSL_OPERATOR_ARMED 4
  92. #define FSL_ALARM 5
  93. #define FSL_OPERATOR_ALARM 6
  94. #define FSL_DETECTION_CHANGED 7
  95. #define FSL_LOG_CLEARED 8
  96. #define FSL_TARGET_OVERFLOW 9
  97. #define FSL_DETECTION_RESTORED 10
  98. #define FSL_SYSTEM_RESTARTED 251
  99. #define FSL_SYSTEM_SHUTDOWN 255
  100. #define ST_NO_TASK 0
  101. #define ST_CHECK_STATUS 1
  102. #define ST_CHECK_SETTINGS 2
  103. #define ST_ISSUE_SOFT_RESET 3
  104. #define ST_TURN_OFF_LED 4
  105. #define ST_SEND_SETTINGS 5
  106. #define ST_SEND_WMODE 6
  107. // https://www.bhphotovideo.com/c/product/1076400-REG/sony_ilce_5100l_b_alpha_a5100_mirrorless_digital.html
  108. // https://www.bhphotovideo.com/c/product/1354807-REG/canon_eos_m20_mirrorless_digital.html
  109. //https://github.com/gphoto
  110. //http://www.gphoto.org/proj/libgphoto2/support.php
  111. /**
  112. * LRF_Kernel class - manages communication between client
  113. * handlers and PRU cores bseide of Event management.
  114. *
  115. *
  116. * @author gagua
  117. */
  118. #define MAX_RECORD_FRAMES 120
  119. #define MAX_TARGET_ACCEPTED_AT_ONCE 100
  120. typedef basicRing< cv::Mat > MatRing;
  121. class Kernel: public basicEngine, public basicThread, public basicMediaDestination {
  122. private:
  123. bool m_bDetectorArmed;
  124. int m_nDetectorOffset;
  125. int m_nDetectorSST;
  126. float m_fDetectorMaxDistance;
  127. // Not Using for Now
  128. float m_fDetectorLayerDistance;
  129. float m_fDetectorMinSpeed;
  130. basicLogCollection * m_pLog;
  131. basicEventHeap * m_pEventHeap;
  132. config_setting_t * m_pSettings;
  133. basicSettingsProvider * m_pSettingsProvider;
  134. networkServer * m_pNetClientsServer;
  135. storageProvider * m_pStorageProvider;
  136. MySQL_Connector * m_pDataBase;
  137. CSTR m_pDBHost, m_pDBUser, m_pDBPass, m_pDBName, m_pStorageBase;
  138. uint8_t m_bExitCause;
  139. uint8_t m_bTargetOverflow;
  140. int m_nVideoInputs;
  141. int m_nAlarmCnt;
  142. bool m_bEngineIsAvlib;
  143. basicMediaSource ** m_pVideoInputs;
  144. #ifdef USE_TIME_LAPSE_RECORDER
  145. lapsedVideoRecorder * m_pVideoOutput;
  146. #endif
  147. CSTR * m_pVideoNames;
  148. int m_nWidth;
  149. int m_nHeight;
  150. int m_nPictureRot;
  151. bool m_bDatabaseEnable;
  152. bool m_bPictureRotated;
  153. bool m_bHorizontal;
  154. bool m_bRecordIsActive;
  155. bool m_bRecordIsSaving;
  156. bool m_bEventRegistered;
  157. bool m_bScaleFrames;
  158. bool m_bAssembleMP4;
  159. char m_sSeriesName[MAX_PATH];
  160. char m_sWEBAPIName[MAX_PATH];
  161. char m_sWEBStatus[MAX_PATH];
  162. char m_sFSReportName[MAX_PATH];
  163. uint16_t m_nLRF_Background[MAX_LRF_SENSORS];
  164. #ifdef AMIR_MODE
  165. uint32_t m_nCurrentRange;
  166. #endif
  167. uint32_t m_nInitialFSID;
  168. uint32_t m_nRecordCounter;
  169. uint32_t m_nFrameCounter;
  170. basicMutex * m_pMatProtector;
  171. cv::Mat * m_pFinalFrame;
  172. cv::Mat ** m_pVideoFrame;
  173. #ifndef USE_TIME_LAPSE_RECORDER
  174. cv::Mat * m_pVidRecFrame[MAX_RECORD_FRAMES];
  175. MatRing m_rPrerecord;
  176. #endif
  177. uint32_t m_nCLoopMask;
  178. uint32_t m_nCLoopCheck;
  179. uint32_t m_nCOnlineMask;
  180. uint32_t m_nCOKMask;
  181. uint32_t m_nScheduledTaskCounter;
  182. uint8_t m_nScheduledTaskID;
  183. long long m_lStartTS;
  184. #ifndef USE_TIME_LAPSE_RECORDER
  185. pthread_t m_pSaveThreadHandler;
  186. static void * t_fSavePictures_Proc(void *ptr);
  187. #endif
  188. void putEvent2FS( uint8_t code, int x1=0, int y1=0, int x2=0, int y2=0, float speed = 0, bool has_image=false, CSTR path = NULL );
  189. void postStatus2FS( bool isActive = true );
  190. bool getDevicePath(CSTR Path, CSTR BusID );
  191. protocolMastBaum * m_pProtocol;
  192. enumeratorInfo m_InputInfo;
  193. protected:
  194. void m_fThreadProc( void );
  195. public:
  196. // Constructor
  197. explicit Kernel( CSTR *HM = NULL );
  198. // Destructor
  199. virtual ~Kernel();
  200. bool create( CSTR *ptr = NULL, networkServer *srvPort = NULL );
  201. bool attachNetServer( networkServer *srvPort );
  202. void WaitFinish( bool Force = false );
  203. virtual void pushFrame( cv::Mat *Frame, void *src = NULL );
  204. bool copyFrame( cv::Mat &Frame );
  205. #ifdef AMIR_MODE
  206. void setRange( uint32_t r ){ m_nCurrentRange = r; };
  207. #endif
  208. /* functional API */
  209. void alarm( bool real = true );
  210. void updateStatus( bool ArmMode, uint8_t nCount, uint16_t *bgArray = NULL );
  211. void updateSettings( uint16_t offset, uint16_t min_time, uint8_t sst, uint32_t ol_status, uint32_t ok_status );
  212. void updateTarget( uint8_t LRF, uint8_t Range );
  213. void handleTargets( uint32_t tMask, uint8_t cnt, uint8_t *Ranges );
  214. bool askReset( void );
  215. bool reset( bool FullRestart = false );
  216. bool shutdown( bool Restart = false );
  217. uint8_t getExitCause( void ){ return m_bExitCause; };
  218. };
  219. #endif // __LRF_KERNEL_H_INCL__