Skip to content
Snippets Groups Projects
Commit 9395fe80 authored by al.schwinn's avatar al.schwinn
Browse files

[SIL-258] Ping does not work properly

parent 93f798fc
No related branches found
No related tags found
No related merge requests found
...@@ -100,24 +100,20 @@ namespace Silecs ...@@ -100,24 +100,20 @@ namespace Silecs
bool CNVConnection::open(PLC* thePLC) bool CNVConnection::open(PLC* thePLC)
{ {
bool isOK = false; //Controller is reachable at this stage (ping done from doOpen)
bool isOK = true; //all subscription is fine a priori
if (IeRfcPing((char *) thePLC->getName().c_str(), 0) == 0) LOG(DEBUG) << "CNVConnection::open(): Subscribe to all input variables";
{
LOG(DEBUG) << "CNVConnection::open(): Controller is reachable (ping), then subscribe input variables";
isOK = true; //all subscription is fine a priori
// Create all the subscriptions // Create all the subscriptions
blockMapType::iterator pBlockIter; blockMapType::iterator pBlockIter;
for(pBlockIter = thePLC->getBlockMap().begin(); pBlockIter != thePLC->getBlockMap().end(); ++pBlockIter) for(pBlockIter = thePLC->getBlockMap().begin(); pBlockIter != thePLC->getBlockMap().end(); ++pBlockIter)
{ {
//Attention: only CNVInputBlock has doSubscribe/unSubscribe feature (key-map can be used to select appropriate object) //Attention: only CNVInputBlock has doSubscribe/unSubscribe feature (key-map can be used to select appropriate object)
if (pBlockIter->first.find(Block::whichAccessType(Input)) != std::string::npos) if (pBlockIter->first.find(Block::whichAccessType(Input)) != std::string::npos)
{ if (static_cast<CNVInputBlock*>(pBlockIter->second)->doSubscribe() == false) { if (static_cast<CNVInputBlock*>(pBlockIter->second)->doSubscribe() == false)
{ isOK = false; { isOK = false;
break; break;
}
} }
} }
} }
...@@ -127,7 +123,7 @@ namespace Silecs ...@@ -127,7 +123,7 @@ namespace Silecs
bool CNVConnection::close(PLC* thePLC) bool CNVConnection::close(PLC* thePLC)
{ {
LOG(DEBUG) << "CNVConnection::close(): unSubscribe input variables"; LOG(DEBUG) << "CNVConnection::close(): unSubscribe all input variables";
// Delete all the subscription // Delete all the subscription
blockMapType::iterator pBlockIter; blockMapType::iterator pBlockIter;
......
...@@ -90,7 +90,9 @@ namespace Silecs ...@@ -90,7 +90,9 @@ namespace Silecs
bool Connection::doOpen(PLC* thePLC) bool Connection::doOpen(PLC* thePLC)
{ {
//LOG((COMM|DIAG)) << "Start attempt to open connection ..."; .. commented, seem like this creates to many log-entries for KIBANA //LOG((COMM|DIAG)) << "Start attempt to open connection ..."; .. commented, seem like this creates to many log-entries for KIBANA
bool justConnected = false; bool isReachable = false;
bool isOpen = false;
bool justConnected = false;
{ {
Lock lock(connMux_); Lock lock(connMux_);
...@@ -111,49 +113,54 @@ namespace Silecs ...@@ -111,49 +113,54 @@ namespace Silecs
if (isTimeToReconnect()) if (isTimeToReconnect())
{ {
LOG((COMM|DIAG)) << "It's time to reconnect"; if (isReachable = (IeRfcPing((char *) thePLC->getName().c_str(), NULL) == 0))
{
// It's time to open the connection according to the (re)connection timing LOG((COMM|DIAG)) << "It's time to reconnect";
// Let's try several times with limited delay (some ms).
// It allows wake-up frozen PLC (SIEMENS in particular) after long stop period. // It's time to open the connection according to the (re)connection timing
bool isOpen = false; // Let's try several times with limited delay (some ms).
unsigned int nbConn = 2; //for fast low-level iteration // It allows wake-up frozen PLC (SIEMENS in particular) after long stop period.
for(unsigned int i = 0; i<nbConn; i++) bool isOpen = false;
{ unsigned int nbConn = 2; //for fast low-level iteration
LOG((COMM|DIAG)) << "Attempt to open PLC connection ...."; for(unsigned int i = 0; i<nbConn; i++)
isOpen = open(thePLC); {
if(isOpen) LOG((COMM|DIAG)) << "Attempt to open PLC connection ....";
{ isOpen = open(thePLC);
LOG((COMM|DIAG)) << "Connection opened successfully"; if(isOpen)
break; {
} LOG((COMM|DIAG)) << "Connection opened successfully";
usleep(100000); // wait 100ms break;
} }
if(!isOpen) usleep(100000); // wait 100ms
{ }
logError(thePLC); }//pingable?
return isConnected_;
} if(!isOpen)
{
logError(thePLC,isReachable);
return isConnected_;
}
if (thePLC->isSharedConnection())
{
LOG((COMM|DIAG)) << "Shared connection with " << thePLC->getName() << " is established.";
}
else
{
LOG((COMM|DIAG)) << "Connection with " << thePLC->getName() <<
":" << thePLC->theCluster_->getClassName() <<
"/v" << thePLC->theCluster_->getClassVersion() <<
" is established.";
}
isAlive_ = true;
isConnected_ = true;
justConnected = true; //retentive registers synchronization is required!
//Connection status has changed: update the diagnostic variables
LOG((COMM|DIAG)) << "Updating PLC status";
updateStatus(thePLC);
if (thePLC->isSharedConnection())
{
LOG((COMM|DIAG)) << "Shared connection with " << thePLC->getName() << " is established.";
}
else
{
LOG((COMM|DIAG)) << "Connection with " << thePLC->getName() <<
":" << thePLC->theCluster_->getClassName() <<
"/v" << thePLC->theCluster_->getClassVersion() <<
" is established.";
}
isAlive_ = true;
isConnected_ = true;
justConnected = true; //retentive registers synchronization is required!
//Connection status has changed: update the diagnostic variables
LOG((COMM|DIAG)) << "Updating PLC status";
updateStatus(thePLC);
} }
}//release lock }//release lock
...@@ -323,12 +330,11 @@ namespace Silecs ...@@ -323,12 +330,11 @@ namespace Silecs
//------------------------------------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------------------------------------
void Connection::logError(PLC* thePLC) void Connection::logError(PLC* thePLC, bool isReachable)
{ {
std::string errorMsg = "Connection with " + thePLC->getName() + std::string errorMsg = isReachable ? "Connection with " + thePLC->getName() + ":" + thePLC->theCluster_->getClassName() +
":" + thePLC->theCluster_->getClassName() + "/v" + thePLC->theCluster_->getClassVersion() + " has failed.\n"
"/v" + thePLC->theCluster_->getClassVersion() + : "Controller " + thePLC->getName() + " does not respond to ping, might be OFF!\n";
" has failed. ";
if (delayConn_ == LongTermConnection) if (delayConn_ == LongTermConnection)
{ if (remainConn_ > 0) { if (remainConn_ > 0)
......
...@@ -133,7 +133,7 @@ namespace Silecs ...@@ -133,7 +133,7 @@ namespace Silecs
*/ */
void updateStatus(PLC* thePLC); void updateStatus(PLC* thePLC);
void logError(PLC* thePLC); void logError(PLC* thePLC, bool isReachable);
/*! /*!
* \fn isTimeToReconnect * \fn isTimeToReconnect
......
...@@ -143,6 +143,24 @@ namespace Silecs ...@@ -143,6 +143,24 @@ namespace Silecs
throw SilecsException(__FILE__, __LINE__, CONFIG_CLIENT_PLC_NOT_CONSISTENT, message.str()); throw SilecsException(__FILE__, __LINE__, CONFIG_CLIENT_PLC_NOT_CONSISTENT, message.str());
} }
} }
//Warn ACET service that a new connection is established (except for SilecsHeader)
if (theHeader_ != NULL) {
TRACE("cluster") << "ClassName=" << theCluster_->getClassName() << "|" <<
"ClassVersion=" << theCluster_->getClassVersion() << "|" <<
"Owner=" << localOwner_ << "|" <<
"GenerationRelease=" << localRelease_ << "|" <<
"GenerationDate=" << localDate_ << "|" <<
"PlcChecksum=" << localChecksum_ << "|" <<
"PlcDomain=" << domain_ << "|" <<
"PlcHostname=" << name_ << "|" <<
"PlcBrand=" << brand_ << "|" <<
"PlcSystem=" << system_ << "|" <<
"PlcModel=" << model_ << "|" <<
"ProtocolAddress=" << baseAddr_ << "|" <<
"ProtocolMode=" << protocolMode_ << "|" <<
"InstanceNumber=" << deviceCol_.size();
}
}; };
......
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