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.

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