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.

239 lines
9.8 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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 KNL_SETTINGS_CONVERT_TYPE ((CSTR)"CONVERT_TYPE") //int
  80. #define WEB_CMD_NOP 0
  81. #define WEB_CMD_RESET_DETECTION 1
  82. #define WEB_CMD_SET_PARAMS 2
  83. #define WEB_CMD_CLEAR_LOG 3
  84. #define WEB_CMD_DISABLE_DETECTION 4
  85. #define WEB_CMD_ENABLE_DETECTION 5
  86. #define WEB_CMD_MAKE_TEST_ALARM 6
  87. #define WEB_CMD_RESET_DEVICE 7
  88. #define FSL_SYSTEM_STARTUP 0
  89. #define FSL_CONNECT_DISARMED 1
  90. #define FSL_CONNECT_ARMED 2
  91. #define FSL_OPERATOR_DISARMED 3
  92. #define FSL_OPERATOR_ARMED 4
  93. #define FSL_ALARM 5
  94. #define FSL_OPERATOR_ALARM 6
  95. #define FSL_DETECTION_CHANGED 7
  96. #define FSL_LOG_CLEARED 8
  97. #define FSL_TARGET_OVERFLOW 9
  98. #define FSL_DETECTION_RESTORED 10
  99. #define FSL_SYSTEM_RESTARTED 251
  100. #define FSL_SYSTEM_SHUTDOWN 255
  101. #define ST_NO_TASK 0
  102. #define ST_CHECK_STATUS 1
  103. #define ST_CHECK_SETTINGS 2
  104. #define ST_ISSUE_SOFT_RESET 3
  105. #define ST_TURN_OFF_LED 4
  106. #define ST_SEND_SETTINGS 5
  107. #define ST_SEND_WMODE 6
  108. // https://www.bhphotovideo.com/c/product/1076400-REG/sony_ilce_5100l_b_alpha_a5100_mirrorless_digital.html
  109. // https://www.bhphotovideo.com/c/product/1354807-REG/canon_eos_m20_mirrorless_digital.html
  110. //https://github.com/gphoto
  111. //http://www.gphoto.org/proj/libgphoto2/support.php
  112. /**
  113. * LRF_Kernel class - manages communication between client
  114. * handlers and PRU cores bseide of Event management.
  115. *
  116. *
  117. * @author gagua
  118. */
  119. #define MAX_RECORD_FRAMES 120
  120. #define MAX_TARGET_ACCEPTED_AT_ONCE 100
  121. typedef basicRing< cv::Mat > MatRing;
  122. class Kernel: public basicEngine, public basicThread, public basicMediaDestination {
  123. private:
  124. bool m_bDetectorArmed;
  125. int m_nDetectorOffset;
  126. int m_nDetectorSST;
  127. float m_fDetectorMaxDistance;
  128. // Not Using for Now
  129. float m_fDetectorLayerDistance;
  130. float m_fDetectorMinSpeed;
  131. basicLogCollection * m_pLog;
  132. basicEventHeap * m_pEventHeap;
  133. config_setting_t * m_pSettings;
  134. basicSettingsProvider * m_pSettingsProvider;
  135. networkServer * m_pNetClientsServer;
  136. storageProvider * m_pStorageProvider;
  137. MySQL_Connector * m_pDataBase;
  138. CSTR m_pDBHost, m_pDBUser, m_pDBPass, m_pDBName, m_pStorageBase;
  139. uint8_t m_bExitCause;
  140. uint8_t m_bTargetOverflow;
  141. int m_nVideoInputs;
  142. int m_nAlarmCnt;
  143. bool m_bEngineIsAvlib;
  144. int m_nConvertType;
  145. basicMediaSource ** m_pVideoInputs;
  146. #ifdef USE_TIME_LAPSE_RECORDER
  147. lapsedVideoRecorder * m_pVideoOutput;
  148. #endif
  149. CSTR * m_pVideoNames;
  150. int m_nWidth;
  151. int m_nHeight;
  152. int m_nPictureRot;
  153. bool m_bDatabaseEnable;
  154. bool m_bPictureRotated;
  155. bool m_bHorizontal;
  156. bool m_bRecordIsActive;
  157. bool m_bRecordIsSaving;
  158. bool m_bEventRegistered;
  159. bool m_bScaleFrames;
  160. bool m_bAssembleMP4;
  161. char m_sSeriesName[MAX_PATH];
  162. char m_sWEBAPIName[MAX_PATH];
  163. char m_sWEBStatus[MAX_PATH];
  164. char m_sFSReportName[MAX_PATH];
  165. uint16_t m_nLRF_Background[MAX_LRF_SENSORS];
  166. #ifdef AMIR_MODE
  167. uint32_t m_nCurrentRange;
  168. #endif
  169. uint32_t m_nInitialFSID;
  170. uint32_t m_nRecordCounter;
  171. uint32_t m_nFrameCounter;
  172. basicMutex * m_pMatProtector;
  173. cv::Mat * m_pFinalFrame;
  174. cv::Mat ** m_pVideoFrame;
  175. #ifndef USE_TIME_LAPSE_RECORDER
  176. cv::Mat * m_pVidRecFrame[MAX_RECORD_FRAMES];
  177. MatRing m_rPrerecord;
  178. #endif
  179. uint32_t m_nCLoopMask;
  180. uint32_t m_nCLoopCheck;
  181. uint32_t m_nCOnlineMask;
  182. uint32_t m_nCOKMask;
  183. uint32_t m_nScheduledTaskCounter;
  184. uint8_t m_nScheduledTaskID;
  185. long long m_lStartTS;
  186. #ifndef USE_TIME_LAPSE_RECORDER
  187. pthread_t m_pSaveThreadHandler;
  188. static void * t_fSavePictures_Proc(void *ptr);
  189. #endif
  190. 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 );
  191. void postStatus2FS( bool isActive = true );
  192. bool getDevicePath(CSTR Path, CSTR BusID );
  193. protocolMastBaum * m_pProtocol;
  194. enumeratorInfo m_InputInfo;
  195. protected:
  196. void m_fThreadProc( void );
  197. public:
  198. // Constructor
  199. explicit Kernel( CSTR *HM = NULL );
  200. // Destructor
  201. virtual ~Kernel();
  202. bool create( CSTR *ptr = NULL, networkServer *srvPort = NULL );
  203. bool attachNetServer( networkServer *srvPort );
  204. void WaitFinish( bool Force = false );
  205. virtual void pushFrame( cv::Mat *Frame, void *src = NULL );
  206. bool copyFrame( cv::Mat &Frame );
  207. #ifdef AMIR_MODE
  208. void setRange( uint32_t r ){ m_nCurrentRange = r; };
  209. #endif
  210. /* functional API */
  211. void alarm( bool real = true );
  212. void updateStatus( bool ArmMode, uint8_t nCount, uint16_t *bgArray = NULL );
  213. void updateSettings( uint16_t offset, uint16_t min_time, uint8_t sst, uint32_t ol_status, uint32_t ok_status );
  214. void updateTarget( uint8_t LRF, uint8_t Range );
  215. void handleTargets( uint32_t tMask, uint8_t cnt, uint8_t *Ranges );
  216. bool askReset( void );
  217. bool reset( bool FullRestart = false );
  218. bool shutdown( bool Restart = false );
  219. uint8_t getExitCause( void ){ return m_bExitCause; };
  220. };
  221. #endif // __LRF_KERNEL_H_INCL__