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.

111 lines
2.4 KiB

​
​
​
​
​
​
​
4 months ago
​
4 months ago
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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 __BASIC_TNSPORT_HEADERS__
  2. #define __BASIC_TNSPORT_HEADERS__
  3. #include "basicLogCollection.h"
  4. #include "basicMutex.h"
  5. #include <algorithm>
  6. #include <vector>
  7. #include <queue>
  8. #ifdef DEBUG
  9. // #ifndef DUBUG_COMMUNICATION
  10. // #define DUBUG_COMMUNICATION
  11. // #endif
  12. #endif
  13. #define SERIAL_PING_PONG
  14. #ifdef SERIAL_PING_PONG
  15. class protocolParser;
  16. #endif
  17. #ifndef MAXIMAL_SERIAL_IO_BUFFER_LENGTH
  18. #define MAXIMAL_SERIAL_IO_BUFFER_LENGTH 102400
  19. #endif
  20. typedef struct S_SIO_TZ {
  21. bool wReplay;
  22. bool finished;
  23. bool success;
  24. int inp_size;
  25. int out_size;
  26. #ifdef SERIAL_PING_PONG
  27. protocolParser * boundParser;
  28. #endif
  29. uint8_t out_buffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH];
  30. uint8_t inp_buffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH];
  31. } SIO_TZ;
  32. typedef std::queue<SIO_TZ *> Q_SIO_TZ;
  33. class protocolParser;
  34. typedef std::vector<protocolParser *> parseQueue;
  35. class basicTransport
  36. {
  37. private:
  38. basicLogCollection * m_pLog;
  39. protected:
  40. parseQueue m_vParsers;
  41. basicMutex m_mQueueProtectorMutex;
  42. basicMutex m_mBufferProtectorMutex;
  43. CONNECTION_STATUS m_eConnectionStatus;
  44. volatile uint32_t m_nConnectEpoch; // +1 on every change to CS_CONNECTED (a reconnect)
  45. public:
  46. basicTransport();
  47. ~basicTransport();
  48. #ifdef SERIAL_PING_PONG
  49. virtual bool sendData(unsigned char * Data, int DataSize, protocolParser *src = NULL )
  50. #else
  51. virtual bool sendData(unsigned char * Data, int DataSize )
  52. #endif
  53. {
  54. if ( !Data ) return false;
  55. if ( !DataSize ) return false;
  56. return true;
  57. }
  58. virtual bool reconnect(void)
  59. {
  60. return false;
  61. }
  62. // The device is reached over a network (e.g. an Ethernet to serial gateway on the Internet):
  63. // replies take longer than on a local serial line
  64. virtual bool isNetworkLink(void)
  65. {
  66. return false;
  67. }
  68. bool addRecipient(protocolParser * ProtoParser);
  69. bool removeRecipient(protocolParser * ProtoParser);
  70. bool getStatus(void)
  71. {
  72. return m_eConnectionStatus == CS_CONNECTED;
  73. }
  74. void setConnectionStatus(CONNECTION_STATUS ES);
  75. // Changes on every (re)connect: a user bound to this transport sees a reconnect it did not notice
  76. // as a short CS_DISCONNECTED (a device behind it may have lost its state meanwhile)
  77. uint32_t getConnectEpoch(void)
  78. {
  79. return m_nConnectEpoch;
  80. }
  81. CONNECTION_STATUS getConnectionStatus(void);
  82. virtual int getRawHandle(void)
  83. {
  84. return -1;
  85. }
  86. };
  87. #endif