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.

229 lines
8.3 KiB

4 years ago
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
4 years ago
4 years ago
​
​
​
​
4 years ago
4 years ago
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
4 years ago
4 years ago
​
​
4 years ago
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
​
​
​
4 years ago
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
3 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
3 years ago
4 years ago
4 years ago
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
4 years ago
​
4 years ago
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
  1. #ifndef __OBJECT_NET_NODE_2D_HEADERS__
  2. #define __OBJECT_NET_NODE_2D_HEADERS__
  3. #include "deviceNodeSensor.h"
  4. #include <cfloat> //For DBL_MAX
  5. #include <stdlib.h>
  6. #include <sys/stat.h>
  7. #include "../../components/base/basicObject.h"
  8. #include "../../components/base/basicMutex.h"
  9. #include "../../components/base/basicThread.h"
  10. #include "../../components/base/basicLogCollection.h"
  11. #include "../../components/base/basicSettingsProvider.h"
  12. #include "../../alg/lgs/mask.h"
  13. #include "../../data/protocol/protocolLGS2D.h"
  14. #include "../../data/rfs/fs_helper.h"
  15. //To Save rasterized masks
  16. #ifdef DEBUG
  17. #include <opencv2/opencv.hpp>
  18. #endif
  19. #define LGS_DEFAULT_SLEEP_TIME 100
  20. #define LGS_ALERT_SLEEP_TIME 10
  21. #define LGS_DEFAULT_TO_COUNTER 10 //100ms
  22. #define LGS_DEFAULT_WS_TIME 10 //100ms
  23. #define LGS_INITIAL_FLIPS 8
  24. #define LGS_CMD_RETRY_COUNT 5
  25. typedef enum E_WORKING_STATE_LRF2D{
  26. WS_2D_BEFORE_START = 0,
  27. WS_2D_CREATE_PORT = 1,
  28. WS_2D_CONNECT,
  29. WS_2D_WAIT_CONNECT,
  30. WS_2D_SET_BORDER_MODE,
  31. WS_2D_SET_DETECTION_MODE,
  32. WS_2D_SET_GETFILE_MODE,
  33. WS_2D_SET_FILESYSTEM_MODE,
  34. WS_2D_GET_SERIAL_NUM,
  35. WS_2D_GET_VERSION,
  36. WS_2D_GET_DETECTION_PROFILE,
  37. WS_2D_GET_MASTER_PARAM,
  38. WS_2D_GET_SLAVE_PARAM,
  39. WS_2D_GET_MASK_INFO,
  40. WS_2D_SET_MASK_INFO,
  41. WS_2D_GET_FAST_DRAW,
  42. WS_2D_SET_SHADOW_DONE,
  43. WS_2D_GET_SHADOW_POLY_INFO,
  44. WS_2D_GET_SHADOW_POLY_POINT,
  45. WS_2D_SET_SHADOW_POLY_INFO,
  46. WS_2D_SET_SHADOW_POLY_POINT,
  47. WS_2D_SET_SHADOW_RAY_LINE,
  48. WS_2D_SET_SHADOW_RAY,
  49. WS_2D_SEND_GETFILE_MODE,
  50. WS_2D_SET_MASTER_PARAM,
  51. WS_2D_SET_SLAVE_PARAM,
  52. WS_2D_ISSUE_FULL_RESET,
  53. WS_2D_ISSUE_RESET,
  54. WS_2D_FS_READY,
  55. WS_2D_GET_FS_CURDIR,
  56. WS_2D_READ_FILE,
  57. WS_2D_SAVE_FILE,
  58. WS_2D_FS_FETCH_NEXT_PART,
  59. WS_2D_FS_OPERATION_FINISHED,
  60. WS_2D_FS_OPERATION_ABORTED,
  61. WS_2D_PING,
  62. WS_2D_PONG,
  63. WS_2D_SLEEP_AND_RECONNECT,
  64. WS_2D_WAIT_DEVICE_REPLAY,
  65. WS_2D_WAIT_CHECK_REPLAY
  66. } WORKING_STATE_LRF2D;
  67. #define ANODE_2D_MAX_DRAW_ANGLES 6000
  68. #define ARGUS_DS_DISCONNECTED 0
  69. #define ARGUS_DS_CONNECTING 1
  70. #define ARGUS_DS_GET_INFO 2
  71. #define ARGUS_DS_STUDY 3
  72. #define ARGUS_DS_READY 4
  73. #define ARGUS_DS_ALARMED 5
  74. #define ARGUS_DS_BUSY 6
  75. typedef struct S_SHADOW_IO_HELPER{
  76. uint16_t m_nCurrentPolygon;
  77. uint16_t m_nCurrentPoint;
  78. uint16_t m_nCurrentRayLine;
  79. uint16_t m_nCurrentRay;
  80. uint8_t m_bSequence;
  81. }SHADOW_IO_HELPER;
  82. typedef struct S_GETFILE_IO_HELPER{
  83. uint32_t fileSize;
  84. uint8_t index;
  85. char destName[33];
  86. char sourceName[33];
  87. uint8_t state;
  88. uint32_t db_id;
  89. FILE * fd;
  90. uint8_t data[250];
  91. uint8_t data_size;
  92. }GETFILE_IO_HELPER;
  93. typedef std::vector<GETFILE_IO_HELPER *> VECTOR_GF_HELPERS;
  94. typedef enum E_GF_ENDING_MODE{
  95. GF_EM_DO_NOTHING = 0,
  96. GF_EM_ISSUE_RESET = 1,
  97. GF_EM_ISSUE_SAVE_FW = 2,
  98. }GF_ENDING_MODE;
  99. typedef struct S_GF_HELPER_STRUCT{
  100. VECTOR_GF_HELPERS helpers;
  101. uint8_t current;
  102. uint8_t transfer_ending_mode;
  103. }GF_HELPER_STRUCT;
  104. typedef struct S_TEST_POINT{
  105. float x;
  106. float y;
  107. }TEST_POINT;
  108. typedef enum E_COMMAND_SEQUENCE_TYPE{
  109. NO_SEQUENCE = 0,
  110. SET_DEVICE_ID = 1,
  111. SET_DEVCOM_SPEED,
  112. SET_DETECTION_PARAMETERS,
  113. SET_SHADOWS,
  114. SET_HW_PARAMS,
  115. FREEZE_TH,
  116. SAVE_ALL_TO_FLESH
  117. } COMMAND_SEQUENCE_TYPE;
  118. class device2DSensor: public deviceNodeSensor, public protocolLGS_2D{
  119. private:
  120. uint8_t m_bPortType;
  121. basicTransport * m_pPort;
  122. E_MODES m_bActualDeviceWM;
  123. E_MODES m_bRequestedDeviceWM;
  124. uint32_t m_nSleepTime;
  125. uint16_t m_bTimeOutCounter;
  126. uint8_t m_bInitialFlips;
  127. uint16_t m_nCurrentAngle;
  128. uint8_t m_bDrawType;
  129. uint8_t m_bOpRetryCnt;
  130. uint32_t m_nProcessingCmdId;
  131. uint32_t m_vDrawRanges[ANODE_2D_MAX_DRAW_ANGLES];
  132. uint8_t m_bCurShadowMask;
  133. bool m_bDeviceIsSynced;
  134. bool m_bForceSync;
  135. bool m_bSerialStringValid;
  136. bool m_bVersionStringValid;
  137. char m_tSN[65];
  138. char m_tSV[129];
  139. uint8_t m_nActiveDetectionProfile;
  140. //Shadow
  141. SHADOW_IO_HELPER m_sShadowHelper;
  142. SHADOW m_sShadow;
  143. //GetFile
  144. //GETFILE_IO_HELPER m_sGetFileHelper;
  145. GF_HELPER_STRUCT m_sGetFileTransfers;
  146. /*
  147. FS_IO_HELPER * m_pFSHelper;
  148. bool m_bSupportedFS;
  149. uint8_t m_pFsPackageBuffer[MAX_PATH];
  150. uint8_t m_bCurrentOperationFS;
  151. FS_DATA_EX m_sInFSData;
  152. FS_DATA_EX m_sOutFSData;
  153. */
  154. WORKING_STATE_LRF2D m_eWState;
  155. TARGET_DATA * prepareTargetData( uint16_t AZ, uint16_t RANGE, uint32_t WIDTH, uint8_t LRFID = 0 );
  156. WIDTH_TABLE * prepareWidthTable();
  157. //void saveRawDrawData( uint16_t alngles );
  158. void cleanupDeviceStructures();
  159. void cleanShadowStructs();
  160. bool PtInPolygons( TEST_POINT& point, uint8_t F );
  161. bool PtInPolygon( SHADOW_POLY& Poly, TEST_POINT& point );
  162. bool rasterizeShadow();
  163. bool saveShadowToDB( void );
  164. bool loadShadowFromDB( void );
  165. bool cleanShadowInDB( void );
  166. void updateDataStatus( uint8_t ds, uint8_t ns = NODE_STATUS_WORK );
  167. //bool downloadFile( CSTR fname );
  168. //COMMAND_SEQUENCE_TYPE m_eCurrentSequence;
  169. //uint8_t m_bSequenceStep;
  170. //bool runSequence( COMMAND_SEQUENCE_TYPE SequenceID );
  171. bool initWModeFunction( uint8_t wm );
  172. void waitStateFunction( LRF_WORK_STAGE boboStage = LRF_WS_INIT );
  173. void poolStateFunction();
  174. #ifdef DEBUG
  175. void makeShadowPic( CSTR picname );
  176. #endif
  177. protected:
  178. virtual void connectMode();
  179. virtual void handshakeMode();
  180. virtual void readMode();
  181. virtual void syncMode();
  182. virtual void drawMode();
  183. virtual void maskMode();
  184. virtual void alarmMode();
  185. virtual void idleMode();
  186. virtual void getfileMode();
  187. virtual void proceedDBCommands();
  188. virtual void save_ini();
  189. virtual void save_detection();
  190. virtual void save_masks();
  191. virtual void save_eprom();
  192. virtual void wait_device();
  193. virtual bool validateCommunicationRessource();
  194. //virtual bool setCommunicationRessurce();
  195. virtual bool packetHandler( protocolPackage *Package );
  196. //virtual void m_fThreadProc( void );
  197. public:
  198. explicit device2DSensor( uint32_t id );
  199. ~device2DSensor();
  200. virtual bool startService();
  201. virtual bool stopService();
  202. virtual bool validate();
  203. virtual void simulateTarget( void );
  204. };
  205. #endif