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.

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