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.

241 lines
6.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Sensor: re-initialise after a gateway reconnect; say why a gateway connection dropped Field: the Ethernet2UART gateway connection dropped and reconnected within a second ("Peer Closes Connection!" -> "Connected to ..."), but the 2D sensor stayed offline until la_mojo was restarted. The sensor was re-initialised (MODE_DETECTOR + handshake) only if its thread saw the transport's short CS_DISCONNECTED. On a fast reconnect it did not, and stayed in idle mode, believing the device to be in detector mode (m_bActualDeviceWM) and only polling getState2. A device that left detector mode while the link was down was never set back. A restart starts from MODE_NONE, which is why it helped. - basicTransport::getConnectEpoch(): +1 on every change to CS_CONNECTED. - device2DSensor remembers the epoch when it binds its port (connectMode). validateCommunicationRessource() (every loop pass above connection mode) runs the connection sequence again when the epoch changed: "Transport reconnected - re-initialising the sensor". - deviceETH2UART: "Peer Closes Connection!" says why: "closed by the gateway" (FIN) or "error: <errno>" (e.g. Connection timed out = sent data not acknowledged within E2UART_TCP_USER_TIMEOUT_MS), plus the TCP_INFO figures. Tested with the real gateway class: a device that goes silent (reconnect after 5 unanswered requests) and a gateway that closes the connection. After each reconnect the epoch changes (1 -> 2), so the sensor would re-initialise, and requests are answered again. The close is logged as "closed by the gateway; TCP: ...". ASan clean. The full 2D sensor can't run here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
8 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __OBJECT_NET_NODE_2D_HEADERS__
  2. #define __OBJECT_NET_NODE_2D_HEADERS__
  3. #include "../../alg/lgs/mask.h"
  4. #include "../../components/base/basicLogCollection.h"
  5. #include "../../components/base/basicMutex.h"
  6. #include "../../components/base/basicObject.h"
  7. #include "../../components/base/basicSettingsProvider.h"
  8. #include "../../components/base/basicThread.h"
  9. #include "../../data/protocol/protocolLGS2D.h"
  10. #include "../../data/rfs/fs_helper.h"
  11. #include "deviceNodeSensor.h"
  12. #include <cfloat> //For DBL_MAX
  13. #include <stdlib.h>
  14. #include <sys/stat.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. #ifndef LRF_PROXY_ONLY
  22. #ifdef DEBUG
  23. #include <opencv2/opencv.hpp>
  24. #endif
  25. #endif
  26. typedef enum E_WORKING_STATE_LRF2D
  27. {
  28. WS_2D_BEFORE_START = 0,
  29. WS_2D_CREATE_PORT = 1,
  30. WS_2D_CONNECT,
  31. WS_2D_WAIT_CONNECT,
  32. WS_2D_SET_BORDER_MODE,
  33. WS_2D_SET_DETECTION_MODE,
  34. WS_2D_SET_GETFILE_MODE,
  35. WS_2D_SET_FILESYSTEM_MODE,
  36. WS_2D_GET_SERIAL_NUM,
  37. WS_2D_GET_VERSION,
  38. WS_2D_GET_DETECTION_PROFILE,
  39. WS_2D_GET_MASTER_PARAM,
  40. WS_2D_GET_SLAVE_PARAM,
  41. WS_2D_GET_MASK_INFO,
  42. WS_2D_SET_MASK_INFO,
  43. WS_2D_GET_FAST_DRAW,
  44. WS_2D_SET_SHADOW_DONE,
  45. WS_2D_GET_SHADOW_POLY_INFO,
  46. WS_2D_GET_SHADOW_POLY_POINT,
  47. WS_2D_SET_SHADOW_POLY_INFO,
  48. WS_2D_SET_SHADOW_POLY_POINT,
  49. WS_2D_SET_SHADOW_RAY_LINE,
  50. WS_2D_SET_SHADOW_RAY,
  51. WS_2D_SEND_GETFILE_MODE,
  52. WS_2D_SET_MASTER_PARAM,
  53. WS_2D_SET_SLAVE_PARAM,
  54. WS_2D_ISSUE_FULL_RESET,
  55. WS_2D_ISSUE_RESET,
  56. WS_2D_FS_READY,
  57. WS_2D_GET_FS_CURDIR,
  58. WS_2D_READ_FILE,
  59. WS_2D_SAVE_FILE,
  60. WS_2D_FS_FETCH_NEXT_PART,
  61. WS_2D_FS_OPERATION_FINISHED,
  62. WS_2D_FS_OPERATION_ABORTED,
  63. WS_2D_PING,
  64. WS_2D_PONG,
  65. WS_2D_SLEEP_AND_RECONNECT,
  66. WS_2D_WAIT_DEVICE_REPLAY,
  67. WS_2D_WAIT_CHECK_REPLAY
  68. } WORKING_STATE_LRF2D;
  69. typedef struct S_SHADOW_IO_HELPER
  70. {
  71. uint16_t m_nCurrentPolygon;
  72. uint16_t m_nCurrentPoint;
  73. uint16_t m_nCurrentRayLine;
  74. uint16_t m_nCurrentRay;
  75. uint8_t m_bSequence;
  76. } SHADOW_IO_HELPER;
  77. typedef struct S_GETFILE_IO_HELPER
  78. {
  79. uint32_t fileSize;
  80. uint8_t index;
  81. char destName[33];
  82. char sourceName[33];
  83. uint8_t state;
  84. uint32_t db_id;
  85. FILE * fd;
  86. uint8_t data[250];
  87. uint8_t data_size;
  88. } GETFILE_IO_HELPER;
  89. typedef std::vector<GETFILE_IO_HELPER *> VECTOR_GF_HELPERS;
  90. typedef enum E_GF_ENDING_MODE
  91. {
  92. GF_EM_DO_NOTHING = 0,
  93. GF_EM_ISSUE_RESET = 1,
  94. GF_EM_ISSUE_SAVE_FW = 2,
  95. } GF_ENDING_MODE;
  96. typedef struct S_GF_HELPER_STRUCT
  97. {
  98. VECTOR_GF_HELPERS helpers;
  99. uint8_t current;
  100. uint8_t transfer_ending_mode;
  101. } GF_HELPER_STRUCT;
  102. typedef struct S_TEST_POINT
  103. {
  104. float x;
  105. float y;
  106. } TEST_POINT;
  107. typedef enum E_COMMAND_SEQUENCE_TYPE
  108. {
  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. {
  120. private:
  121. uint8_t m_bPortType;
  122. basicTransport * m_pPort;
  123. uint32_t m_nPortEpoch; // m_pPort->getConnectEpoch() when the sensor was (re)initialised
  124. uint32_t m_nSleepTime;
  125. uint8_t m_bInitialFlips;
  126. uint16_t m_nCurrentAngle;
  127. uint8_t m_bDrawType;
  128. uint32_t m_nProcessingCmdId;
  129. uint32_t m_vDrawRanges[ANODE_2D_MAX_DRAW_ANGLES];
  130. uint8_t m_bCurShadowMask;
  131. bool m_bDeviceIsSynced;
  132. bool m_bForceSync;
  133. bool m_bSerialStringValid;
  134. bool m_bVersionStringValid;
  135. bool m_bTargetArived;
  136. char m_tSN[65];
  137. char m_tSV[129];
  138. uint8_t m_nActiveDetectionProfile;
  139. // Shadow
  140. SHADOW_IO_HELPER m_sShadowHelper;
  141. SHADOW m_sShadow;
  142. // GetFile
  143. // GETFILE_IO_HELPER m_sGetFileHelper;
  144. GF_HELPER_STRUCT m_sGetFileTransfers;
  145. uint8_t m_bGetFileTransferRetryCount;
  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. #ifdef PERSISTED_TARGET_SIM
  155. uint16_t m_nTargSimAngle;
  156. uint16_t m_nTargSimRange;
  157. #endif
  158. WORKING_STATE_LRF2D m_eWState;
  159. TARGET_DATA * prepareTargetData(uint16_t AZ, uint16_t RANGE, uint32_t WIDTH, uint8_t LRFID = 0);
  160. WIDTH_TABLE * prepareWidthTable();
  161. GETFILE_IO_HELPER * prepareFileTransfer(CSTR lname, CSTR rname);
  162. void fileTransferSpecialWait();
  163. // void saveRawDrawData( uint16_t alngles );
  164. void cleanShadowStructs();
  165. bool PtInPolygons(TEST_POINT & point, uint8_t F);
  166. bool PtInPolygon(SHADOW_POLY & Poly, TEST_POINT & point);
  167. bool rasterizeShadow();
  168. bool saveShadowToDB(void);
  169. bool loadShadowFromDB(void);
  170. bool cleanShadowInDB(void);
  171. // bool downloadFile( CSTR fname );
  172. // COMMAND_SEQUENCE_TYPE m_eCurrentSequence;
  173. // uint8_t m_bSequenceStep;
  174. // bool runSequence( COMMAND_SEQUENCE_TYPE SequenceID );
  175. #ifndef LRF_PROXY_ONLY
  176. #ifdef DEBUG
  177. void makeShadowPic(CSTR picname);
  178. #endif
  179. #endif
  180. #ifdef SEND_MASKS_VIA_FILE
  181. bool generateMaskFiles(CSTR vname, CSTR bname);
  182. #endif
  183. protected:
  184. virtual void connectMode();
  185. virtual void handshakeMode();
  186. virtual void readMode();
  187. virtual void fileTransferMode();
  188. virtual void syncMode();
  189. virtual void drawMode();
  190. virtual void fullDrawMode();
  191. virtual void maskMode();
  192. virtual void alarmMode();
  193. virtual void idleMode();
  194. virtual void getfileMode();
  195. virtual void proceedDBCommands();
  196. virtual void cleanupDeviceStructures();
  197. virtual void save_ini();
  198. virtual void save_detection();
  199. virtual void save_masks();
  200. virtual void save_eprom();
  201. virtual void wait_device();
  202. virtual void wait_channel();
  203. virtual bool validateCommunicationRessource();
  204. virtual bool packetHandler(protocolPackage * Package);
  205. public:
  206. explicit device2DSensor(uint32_t id);
  207. ~device2DSensor();
  208. virtual bool startService();
  209. virtual bool stopService();
  210. virtual bool reset();
  211. virtual bool validate();
  212. virtual void simulateTarget(void);
  213. //virtual uint32_t getChannelId( void );
  214. virtual void setChannelBusy( uint32_t channelID, uint8_t seconds_TO );
  215. virtual void setChannelReady( uint32_t channelID );
  216. };
  217. #endif