Skip to content
Snippets Groups Projects
Commit 44690b2c authored by m.marn's avatar m.marn Committed by al.schwinn
Browse files

Log actual error that prevented a successful connection.

See merge request silecs/opensilecs!33
parent 16b39ad9
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ Contributors:
#include <fcntl.h>
#include <signal.h>
#include <cstring>
#include <silecs-communication/interface/equipment/SilecsCluster.h>
#include <silecs-communication/interface/utility/SilecsLog.h>
......@@ -107,15 +108,14 @@ bool Connection::doOpen(PLC* thePLC)
if (!isTimeToReconnect())
{ // Do nothing, just wait a bit to dont pullute the log
return isConnected_;
return isConnected_;
}
if (ping(thePLC->getName().c_str(), NULL))
{
logError(thePLC, false);
return isConnected_;
logError(thePLC, false);
return isConnected_;
}
// It's time to open the connection according to the (re)connection timing
// Let's try several times with limited delay (some ms).
// It allows wake-up frozen PLC (SIEMENS in particular) after long stop period.
......@@ -298,7 +298,7 @@ void Connection::updateStatus(PLC* thePLC)
void Connection::logError(PLC* thePLC, bool isReachable)
{
std::string errorMsg = isReachable ? "Connection with " + thePLC->getName() + ":" + thePLC->theCluster_->getClassName() + "/v" + thePLC->theCluster_->getClassVersion() + " has failed.\n" : "Controller " + thePLC->getName() + " does not respond to ping, might be OFF!\n";
errorMsg += "Error: " + std::string(std::strerror(errno)) + ". ";
if (reconnectDelay_ == longDelay)
{
if (reconnectAttempts_ < MAX_CONNECTION_ATTEMPTS_PER_DELAY)
......@@ -455,6 +455,7 @@ int rfcPing(char *ip, long ts)
/*if hostname is OFF, connect() fails on TIMEOUT*/
if ( (errno == ETIMEDOUT) || (errno == EHOSTDOWN) || (errno == EHOSTUNREACH))
{
LOG(ERROR) << "Error: " << strerror(errno);
return -1;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment