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.

70 lines
1.6 KiB

8 years ago
6 years ago
8 years ago
​
​
​
​
​
8 years 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
6 hours ago
8 years ago
​
​
​
​
​
​
8 years ago
​
8 years ago
​
8 years ago
​
8 years 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
6 hours ago
​
​
​
8 years ago
​
​
8 years ago
​
8 years ago
​
8 years ago
8 years ago
​
  1. #include "basicTransport.h"
  2. #include "../../data/protocol/protocol.h"
  3. #define LOG(X) m_pLog->Log("BTRANS", this, X)
  4. #define LOG_ERROR(X) m_pLog->Log("BTRANS", this, _LOG_ERROR, X)
  5. basicTransport::basicTransport() :
  6. m_mQueueProtectorMutex(),
  7. m_mBufferProtectorMutex()
  8. {
  9. m_pLog = basicLogCollection::getInstance();
  10. m_eConnectionStatus = CS_UNKNOWN;
  11. m_nConnectEpoch = 0;
  12. }
  13. basicTransport::~basicTransport()
  14. {
  15. // ToDo: Cleanup parsers vector
  16. m_mQueueProtectorMutex.lock();
  17. m_vParsers.clear();
  18. m_mQueueProtectorMutex.unlock();
  19. }
  20. bool basicTransport::addRecipient(protocolParser * ProtoParser)
  21. {
  22. m_mQueueProtectorMutex.lock();
  23. m_vParsers.push_back(ProtoParser);
  24. ProtoParser->setConnectionStatus(m_eConnectionStatus);
  25. m_mQueueProtectorMutex.unlock();
  26. return true;
  27. }
  28. bool basicTransport::removeRecipient(protocolParser * ProtoParser)
  29. {
  30. m_mQueueProtectorMutex.lock();
  31. parseQueue::iterator it = std::find(m_vParsers.begin(), m_vParsers.end(), ProtoParser);
  32. if (it != m_vParsers.end())
  33. {
  34. m_vParsers.erase(it);
  35. m_mQueueProtectorMutex.unlock();
  36. return true;
  37. };
  38. m_mQueueProtectorMutex.unlock();
  39. return false;
  40. }
  41. void basicTransport::setConnectionStatus(CONNECTION_STATUS CS)
  42. {
  43. m_mQueueProtectorMutex.lock();
  44. if (CS == CS_CONNECTED && m_eConnectionStatus != CS_CONNECTED)
  45. {
  46. m_nConnectEpoch = m_nConnectEpoch + 1;
  47. };
  48. m_eConnectionStatus = CS;
  49. for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++)
  50. {
  51. (*index)->setConnectionStatus(m_eConnectionStatus);
  52. };
  53. m_mQueueProtectorMutex.unlock();
  54. }
  55. CONNECTION_STATUS basicTransport::getConnectionStatus(void)
  56. {
  57. return m_eConnectionStatus;
  58. }
  59. #undef LOG
  60. #undef LOG_ERROR