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.

297 lines
8.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __ARGUS_NODE_SENSOR_HEADER__
  2. #define __ARGUS_NODE_SENSOR_HEADER__
  3. #include "../../components/base/basicEventHeap.h"
  4. #include "../../components/base/basicPosition.h"
  5. #include "../../components/object/objectSystemAnchor.h"
  6. #include "deviceNode.h"
  7. #include "targetPipeLine.h"
  8. #include "../../hardware/soc/general/3DLRF.h"
  9. #define LGS_DEFAULT_SLEEP_TIME 100
  10. #define LGS_ALERT_SLEEP_TIME 10
  11. #define LGS_DEFAULT_TO_COUNTER 10 // 100ms
  12. // Sensor behind a network link (Ethernet to serial gateway over the Internet): 3 s per attempt.
  13. // The 1 s of a local serial line was shorter than the round trip of a mobile link at times.
  14. #ifndef LGS_NETWORK_TO_COUNTER
  15. #define LGS_NETWORK_TO_COUNTER 30
  16. #endif
  17. #define LGS_DEFAULT_WS_TIME 10 // 100ms
  18. #define LGS_INITIAL_FLIPS 8
  19. #define LGS_CMD_RETRY_COUNT 16
  20. #define ARGUS_LRF_PCMD_FULL_RESET 1
  21. #define ARGUS_LRF_PCMD_RESET 2
  22. #define ARGUS_LRF_PCMD_DRAW 3
  23. #define ARGUS_LRF_PCMD_GET_PROFILE 4
  24. #define ARGUS_LRF_PCMD_FULL_DRAW 5
  25. #define ARGUS_LRF_ROI_ACTIVATION 42
  26. #define ARGUS_LRF_PUSH_FALSE_TARGET 45
  27. #define ARGUS_LRF_PCMD_SET_MASK_1 60
  28. #define ARGUS_LRF_PCMD_SET_MASK_2 61
  29. #define ARGUS_LRF_PCMD_SET_MASK_3 62
  30. #define ARGUS_LRF_PCMD_SET_MASK_4 63
  31. #define ARGUS_LRF_PCMD_SET_MASK_5 64
  32. #define ARGUS_LRF_PCMD_MASK_STATUS_SET 65
  33. #define ARGUS_LRF_PCMD_CLEAN_MASK_1 75
  34. #define ARGUS_LRF_PCMD_CLEAN_MASK_2 76
  35. #define ARGUS_LRF_PCMD_CLEAN_MASK_3 77
  36. #define ARGUS_LRF_PCMD_CLEAN_MASK_4 78
  37. #define ARGUS_LRF_PCMD_CLEAN_MASK_5 79
  38. #define ARGUS_LRF_PCMD_SET_DP_0 100
  39. #define ARGUS_LRF_PCMD_SET_DP_1 101
  40. #define ARGUS_LRF_PCMD_SET_DP_2 102
  41. #define ARGUS_LRF_PCMD_SET_DP_3 103
  42. #define ARGUS_LRF_PCMD_UPLOAD_FILE 120
  43. #define ARGUS_LRF_PCMD_READ_ALL 128
  44. #define ARGUS_LRF_PCMD_SAVE_ALL 129
  45. #define ARGUS_LRF_PCMD_SAVE_SETTINGS_0 130 // INI
  46. #define ARGUS_LRF_PCMD_SAVE_SETTINGS_1 131 // DETECTION
  47. #define ARGUS_LRF_PCMD_SAVE_SETTINGS_2 132 // MASKS
  48. #define ARGUS_LRF_PCMD_SAVE_SETTINGS_3 133 // all current to EPROM
  49. #define ARGUS_SYM_CMD_0 200
  50. #define ARGUS_SYM_CMD_1 201
  51. #define ARGUS_SYM_CMD_2 202
  52. #define ARGUS_SYM_CMD_3 203
  53. #define ARGUS_SYM_CMD_4 204
  54. #define ARGUS_SYM_CMD_5 205
  55. #define ARGUS_SYM_CMD_6 206
  56. #define ARGUS_SYM_CMD_7 207
  57. #define ARGUS_SYM_CMD_8 208
  58. #define ARGUS_SYM_CMD_9 209
  59. #define ARGUS_SYM_CMD_10 210
  60. #define ANODE_2D_MAX_DRAW_ANGLES 6000
  61. #define ARGUS_DS_DISCONNECTED 0
  62. #define ARGUS_DS_CONNECTING 1
  63. #define ARGUS_DS_GET_INFO 2
  64. #define ARGUS_DS_STUDY 3
  65. #define ARGUS_DS_READY 4
  66. #define ARGUS_DS_ALARMED 5
  67. #define ARGUS_DS_BUSY 6
  68. #define ARGUS_DS_DETECTION_ERROR 7
  69. #define ARGUS_LRF_PCMD_UPDATE_ALL 255
  70. #define DRAW_MODE_RAW_DATA 0
  71. #define DRAW_MODE_MAP 1
  72. #define DRAW_MODE_3D 2
  73. #define DRAW_MODE_2D_100 3
  74. #define DRAW_MODE_2D_50 4
  75. #define DRAW_MODE_2D_25 5
  76. #define DRAW_MODE_2D_12 6
  77. #define DAFAULT_VALIDATION_SKIP_COUNTER 10
  78. // #define SAVE_DRAW_RAW_ONLY
  79. typedef enum E_LRF_WORK_MODE
  80. {
  81. LRF_WM_NONE = 0x00,
  82. LRF_WM_INIT = 0x01,
  83. LRF_WM_CONNECTION,
  84. LRF_WM_HANDSHAKE,
  85. LRF_WM_SYNC_UP,
  86. LRF_WM_SYNC_DOWN,
  87. LRF_WM_SAVE_HW,
  88. LRF_WM_SAVE_DETECTION,
  89. LRF_WM_SAVE_MASKS,
  90. LRF_WM_SAVE_EPROM,
  91. LRF_WM_BORDER,
  92. LRF_WM_FULL_BORDER,
  93. LRF_WM_STATUS_MASK,
  94. LRF_WM_FILE,
  95. LRF_WM_FILE_TF,
  96. LRF_WM_ALARM,
  97. LRF_WM_IDLE,
  98. LRF_WM_WAIT_ONLINE_SPECIAL,
  99. LRF_WM_WAIT_CHANNEL,
  100. LRF_WM_COUNT
  101. } LRF_WORK_MODE;
  102. // For the Stage's Push - Pool condition
  103. typedef enum E_STAGE_PP_CONDITION
  104. {
  105. STG_INIT = 0,
  106. STG_PUSH = 1,
  107. STG_WAIT = 2,
  108. STG_POOL = 3
  109. } STAGE_PP_CONDITION;
  110. #define TRANSACTION_RESULT_OK true
  111. #define TRANSACTION_RESULT_BAD false
  112. #define TRANSACTION_RESULT_REPEAT false
  113. typedef enum E_LRF_WORK_STAGE
  114. {
  115. LRF_WS_INIT = 0x00,
  116. LRF_WS_STAGE_1 = 0x01,
  117. LRF_WS_STAGE_2,
  118. LRF_WS_STAGE_3,
  119. LRF_WS_STAGE_4,
  120. LRF_WS_STAGE_5,
  121. LRF_WS_STAGE_6,
  122. LRF_WS_STAGE_7,
  123. LRF_WS_STAGE_8,
  124. LRF_WS_STAGE_9,
  125. LRF_WS_STAGE_10,
  126. LRF_WS_STAGE_11,
  127. LRF_WS_STAGE_12,
  128. LRF_WS_STAGE_13,
  129. LRF_WS_STAGE_14,
  130. LRF_WS_STAGE_15,
  131. // LRF_WS_DELAY,
  132. // LRF_WS_WAIT,
  133. LRF_WS_COUNT
  134. } LRF_WORK_STAGE;
  135. LRF_WORK_STAGE operator++(LRF_WORK_STAGE & id, int);
  136. #define COMMUNICATION_ERROR_STATISTIC_HARVEST_INTERVAL_IN_SECONDS 60
  137. class deviceNodeSensor : public deviceNode, public basicThread
  138. {
  139. private:
  140. STAGE_PP_CONDITION m_ePPMODE;
  141. LRF_WORK_STAGE m_eWorkingStage;
  142. LRF_WORK_STAGE m_eOldWorkingStage;
  143. basicMutex m_mStageProtector;
  144. basicMutex m_mPPModeProtector;
  145. uint32_t m_nCommErrorsCounter;
  146. uint32_t m_nCommErrorsStatTO;
  147. protected:
  148. DBC_LRF_DATA m_sLRF_DATA;
  149. basicPosition m_oPosition;
  150. basicEventHeap * m_pEventHeap;
  151. basicEventClassID m_eEventClass;
  152. // kernelEventFilter * m_pTargetFilter;
  153. // vectorKernelEventFilters m_vTargetFilters;
  154. targetPipeLine * m_pTargetPipeLine;
  155. uint8_t m_bOpRetryCnt;
  156. uint16_t m_bTimeOutCounter;
  157. uint16_t m_nTOCounterBase; // wait per attempt (x 100 ms): LGS_DEFAULT_TO_COUNTER or LGS_NETWORK_TO_COUNTER
  158. // Communication timing (logged with DEBUG_COMMUNICATION in deviceNodeSensor.cpp; always present: class layout)
  159. uint64_t m_nTxStartMs; // transactionWaitResult() of the running request
  160. uint64_t m_nTxFirstMs; // first attempt of the running command (retries included)
  161. uint32_t m_nTxCount, m_nTxSlow, m_nTxAttemptTO, m_nTxFailed;
  162. uint64_t m_nTxSumMs, m_nTxMaxMs, m_nTxStatStartMs;
  163. void txTimingDone(bool ok);
  164. void txTimingReport(bool force);
  165. E_MODES m_bActualDeviceWM;
  166. E_MODES m_bRequestedDeviceWM;
  167. uint32_t m_nChannelTO;
  168. uint8_t m_bValidationSkipCounter;
  169. //bool m_bInitialSyncIsDone;
  170. char m_pTGENFILENAMES[3][33];
  171. uint8_t m_bTGENFILECNT;
  172. uint8_t m_bTGENFILE;
  173. LRF_WORK_MODE m_SP_WM;
  174. LRF_WORK_STAGE m_SP_STAGE;
  175. bool handleDeviceDraw(uint8_t kID, void * th_data, size_t th_size, bool byMinimum = true);
  176. #ifdef GEN_DRAW_IMAGE
  177. uint8_t * create2dDraw(uint32_t * out_size, uint32_t * th_data, size_t th_size, uint16_t max_digital, int radial_shift, CSTR tpl, bool byMinimum = true);
  178. #endif
  179. bool reloadDeviceNodeFromDB();
  180. void setStage(LRF_WORK_STAGE st, bool update_old_stage = true);
  181. void registerCommError(bool withEvent = false);
  182. LRF_WORK_STAGE getStage();
  183. LRF_WORK_STAGE getPrevStage();
  184. void goNextStage(bool update_old_stage = true);
  185. void transactionResetResult(void);
  186. void transactionSetResult(bool ACK = TRANSACTION_RESULT_OK);
  187. void transactionWaitResult(void);
  188. STAGE_PP_CONDITION getPPStatus();
  189. void startWaitDeviceOnline(LRF_WORK_MODE wm, LRF_WORK_STAGE);
  190. void waitStateFunction(LRF_WORK_STAGE boboStage = LRF_WS_INIT);
  191. void poolStateFunction();
  192. bool generateIniFile(uint8_t i);
  193. bool generateSnFile(uint8_t i);
  194. bool generateRestartFile(uint8_t i);
  195. bool initWModeFunction(uint8_t wm);
  196. void updateDataStatus(uint8_t ds, uint8_t ns = NODE_STATUS_WORK);
  197. virtual void connectMode() {}
  198. virtual void fileTransferMode() {}
  199. virtual void handshakeMode() {}
  200. virtual void readMode() {}
  201. virtual void syncMode() {}
  202. virtual void drawMode() {}
  203. virtual void fullDrawMode() {}
  204. virtual void getfileMode() {}
  205. virtual void maskMode() {}
  206. virtual void alarmMode() {}
  207. virtual void idleMode() {}
  208. virtual void save_ini() {}
  209. virtual void save_detection() {}
  210. virtual void save_masks() {}
  211. virtual void save_eprom() {}
  212. virtual void wait_device() {}
  213. virtual void wait_channel() {}
  214. virtual void proceedDBCommands() {}
  215. virtual void cleanupDeviceStructures() {}
  216. virtual bool validateCommunicationRessource()
  217. {
  218. return false;
  219. }
  220. // virtual bool setSensorData(){ return true;};
  221. // virtual bool setCommunicationRessurce(){ return true;};
  222. // virtual bool connectSensor(){ return true;};
  223. void broadcastConnected(void);
  224. void broadcastDisconnected(void);
  225. void broadcastFlip(uint16_t flipCount);
  226. bool loadFilters();
  227. // bool filterTargetData( TARGET_DATA *ptr );
  228. protected:
  229. virtual void m_fThreadProc(void);
  230. public:
  231. explicit deviceNodeSensor(uint32_t id);
  232. explicit deviceNodeSensor(DBC_NODE_DATA * Data);
  233. virtual ~deviceNodeSensor();
  234. virtual void simulateTarget(void) {}
  235. virtual bool validate();
  236. virtual uint8_t getSensStatus();
  237. };
  238. #endif