Sensor not restored after the Ethernet2UART gateway node was rebuilt #27

Merged
ClaudeAI merged 1 commits from fix/sensor-gateway-rebuild into master 2 hours ago
  1. 14
      lib/App/common/deviceNode2D.cpp
  2. 13
      lib/App/common/deviceNodeEthernet2Serial.cpp
  3. 7
      lib/components/base/basicTransport.cpp
  4. 29
      lib/data/protocol/protocol.cpp
  5. 4
      lib/data/protocol/protocol.h

14
lib/App/common/deviceNode2D.cpp

@ -3310,6 +3310,20 @@ bool device2DSensor::validateCommunicationRessource()
the link was down; a fast reconnect was not seen here as CS_DISCONNECTED, so the sensor was only the link was down; a fast reconnect was not seen here as CS_DISCONNECTED, so the sensor was only
polled in idle mode (getState2), believed to be in detector mode, and stayed "offline" until a restart. polled in idle mode (getState2), believed to be in detector mode, and stayed "offline" until a restart.
*/ */
if (m_pPort != NULL && m_oDataTransport != m_pPort)
{
/*
The transport object was deleted (e.g. the node factory rebuilt the Ethernet2UART gateway node,
or its settings changed): the pointer is stale. Request the resource again - the new object -
and run the connection sequence on it. Before, the sensor stayed bound to the deleted gateway
and was "unavailable" until la_mojo was restarted.
*/
LOG("Transport object destroyed - binding to the new resource");
m_pPort = NULL;
updateDataStatus(ARGUS_DS_DISCONNECTED);
setWM(LRF_WM_CONNECTION);
return false;
};
if (m_pPort != NULL && m_pPort->getConnectEpoch() != m_nPortEpoch) if (m_pPort != NULL && m_pPort->getConnectEpoch() != m_nPortEpoch)
{ {
LOG("Transport reconnected - re-initialising the sensor"); LOG("Transport reconnected - re-initialising the sensor");

13
lib/App/common/deviceNodeEthernet2Serial.cpp

@ -270,11 +270,14 @@ bool deviceETH2UART::validate(void)
#endif #endif
m_bValid = connectSOL(); m_bValid = connectSOL();
}; };
if (m_bValid)
{
m_bValid = deviceNode::validate();
}
return m_bValid;
/*
The node is valid while its DB record is unchanged - the link state is not part of it: the node
reconnects itself (above, with the back-off) and the users see it through isValid() /
getConnectionStatus() / getConnectEpoch(). Returning false on a lost link made the node factory
delete this object and create a new one: the sensors bound to it kept the deleted object and
were never restored.
*/
return deviceNode::validate();
} }
#include <netinet/ip_icmp.h> #include <netinet/ip_icmp.h>

7
lib/components/base/basicTransport.cpp

@ -16,8 +16,13 @@ basicTransport::basicTransport() :
basicTransport::~basicTransport() basicTransport::~basicTransport()
{ {
// ToDo: Cleanup parsers vector
// Tell the bound parsers: they kept the pointer to this object after it was deleted (a sensor
// behind an Ethernet2UART gateway that was rebuilt kept talking to the old gateway object)
m_mQueueProtectorMutex.lock(); m_mQueueProtectorMutex.lock();
for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++)
{
(*index)->transportDestroyed(this);
};
m_vParsers.clear(); m_vParsers.clear();
m_mQueueProtectorMutex.unlock(); m_mQueueProtectorMutex.unlock();
} }

29
lib/data/protocol/protocol.cpp

@ -15,6 +15,7 @@ protocolParser::protocolParser() :
m_pLog = basicLogCollection::getInstance(); m_pLog = basicLogCollection::getInstance();
m_eConnectionStatus = CS_UNKNOWN; m_eConnectionStatus = CS_UNKNOWN;
m_oDataTransport = NULL; m_oDataTransport = NULL;
m_bTransportRecipient = false;
m_pParserBuffer = (U8 *) malloc(PROTOCOL_PARSER_BUFFER_SIZE); m_pParserBuffer = (U8 *) malloc(PROTOCOL_PARSER_BUFFER_SIZE);
if (m_pParserBuffer) if (m_pParserBuffer)
{ {
@ -40,6 +41,14 @@ protocolParser::~protocolParser()
LOG("Destructor Begin"); LOG("Destructor Begin");
#endif #endif
m_mBufferProtectorMutex.unlock(); m_mBufferProtectorMutex.unlock();
// Leave the transport's recipient list: it would call setConnectionStatus() / deliver data to
// a deleted parser (only when added by setTransport(): other paths set the pointer only)
if (m_bTransportRecipient && m_oDataTransport != NULL)
{
m_oDataTransport->removeRecipient(this);
};
m_oDataTransport = NULL;
m_bTransportRecipient = false;
/* /*
#ifdef PROTOCOL_PARSER_IN_THREAD #ifdef PROTOCOL_PARSER_IN_THREAD
if (m_bParserThreadStatus > TH_ARMED ) { if (m_bParserThreadStatus > TH_ARMED ) {
@ -137,17 +146,19 @@ bool protocolParser::setTransport(basicTransport * Transport, bool CAE)
}; };
} }
else else
{ // Danger -> If transport Object is deleted the pointer is wrong!
if (m_oDataTransport != NULL)
{ // A deleted transport calls transportDestroyed(): the pointer is NULL then
if (m_oDataTransport != NULL && m_bTransportRecipient)
{ {
m_oDataTransport->removeRecipient(this); m_oDataTransport->removeRecipient(this);
}; };
}; };
m_oDataTransport = Transport;
m_oDataTransport = Transport;
m_bTransportRecipient = false;
if (Transport != NULL) if (Transport != NULL)
{ {
setConnectionStatus(CS_CONNECTED); setConnectionStatus(CS_CONNECTED);
return m_oDataTransport->addRecipient(this);
m_bTransportRecipient = m_oDataTransport->addRecipient(this);
return m_bTransportRecipient;
} }
else else
{ {
@ -156,6 +167,16 @@ bool protocolParser::setTransport(basicTransport * Transport, bool CAE)
return true; return true;
} }
void protocolParser::transportDestroyed(basicTransport * Transport)
{
if (Transport != NULL && m_oDataTransport == Transport)
{
m_oDataTransport = NULL;
m_bTransportRecipient = false;
setConnectionStatus(CS_DISCONNECTED);
};
}
basicTransport * protocolParser::getCurrentTransport(void) basicTransport * protocolParser::getCurrentTransport(void)
{ {
LOG("Get Transport Req"); LOG("Get Transport Req");

4
lib/data/protocol/protocol.h

@ -53,6 +53,7 @@ class protocolParser
protected: protected:
basicTransport * m_oDataTransport; basicTransport * m_oDataTransport;
bool m_bTransportRecipient; // added to m_oDataTransport's recipients by setTransport()
CONNECTION_STATUS m_eConnectionStatus; CONNECTION_STATUS m_eConnectionStatus;
U8 m_bStatus; U8 m_bStatus;
packagePoll m_vPackagePool; packagePoll m_vPackagePool;
@ -98,6 +99,9 @@ class protocolParser
CONNECTION_STATUS getConnectionStatus(void); CONNECTION_STATUS getConnectionStatus(void);
bool setTransport(basicTransport * ptrTransport, bool check_if_allready = true); bool setTransport(basicTransport * ptrTransport, bool check_if_allready = true);
basicTransport * getCurrentTransport(void); basicTransport * getCurrentTransport(void);
// Called by the transport's destructor: the pointer is dropped (it would dangle) and the
// connection is reported as lost, so the owner can bind to a new transport object
void transportDestroyed(basicTransport * ptrTransport);
virtual bool validate() virtual bool validate()
{ {

Loading…
Cancel
Save