Skip to content

Commit

Permalink
YARP_dev: move the logic of the timeout check from `RemoteControlBoar…
Browse files Browse the repository at this point in the history
…d` to the `stateExtendedReader`.

In this way every read has a timeout check that before was only in few functions
like `getEncoders`. It fixes robotology#1833
  • Loading branch information
Nicogene authored and drdanz committed Apr 11, 2019
1 parent b173764 commit 9a57eb3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ namespace yarp{
#ifndef DOXYGEN_SHOULD_SKIP_THIS

const double DIAGNOSTIC_THREAD_PERIOD=1.000;
const double TIMEOUT=0.5;

inline bool getTimeStamp(Bottle &bot, Stamp &st)
{
Expand Down Expand Up @@ -1478,10 +1477,6 @@ class yarp::dev::RemoteControlBoard :
extendedPortMutex.lock();
bool ret = extendedIntputStatePort.getLastSingle(j, VOCAB_ENCODER, v, lastStamp, localArrivalTime);
extendedPortMutex.unlock();

if (ret && ( (Time::now()-localArrivalTime) > TIMEOUT) )
ret = false;

return ret;
}

Expand All @@ -1499,10 +1494,6 @@ class yarp::dev::RemoteControlBoard :
bool ret = extendedIntputStatePort.getLastSingle(j, VOCAB_ENCODER, v, lastStamp, localArrivalTime);
*t=lastStamp.getTime();
extendedPortMutex.unlock();

if (ret && ( (Time::now()-localArrivalTime) > TIMEOUT) )
ret = false;

return ret;
}

Expand Down Expand Up @@ -1538,10 +1529,6 @@ class yarp::dev::RemoteControlBoard :
bool ret = extendedIntputStatePort.getLastVector(VOCAB_ENCODERS, encs, lastStamp, localArrivalTime);
std::fill_n(ts, nj, lastStamp.getTime());
extendedPortMutex.unlock();

if ( (Time::now()-localArrivalTime) > TIMEOUT)
ret=false;

return ret;
}
/**
Expand Down Expand Up @@ -1750,10 +1737,6 @@ class yarp::dev::RemoteControlBoard :
extendedPortMutex.lock();
bool ret = extendedIntputStatePort.getLastSingle(j, VOCAB_MOTOR_ENCODER, v, lastStamp, localArrivalTime);
extendedPortMutex.unlock();

if(ret && ((Time::now()-localArrivalTime) > TIMEOUT) )
ret=false;

return ret;
}

Expand All @@ -1771,10 +1754,6 @@ class yarp::dev::RemoteControlBoard :
bool ret = extendedIntputStatePort.getLastSingle(j, VOCAB_MOTOR_ENCODER, v, lastStamp, localArrivalTime);
*t=lastStamp.getTime();
extendedPortMutex.unlock();

if(ret && ((Time::now()-localArrivalTime) > TIMEOUT) )
ret=false;

return ret;
}

Expand Down Expand Up @@ -1812,10 +1791,6 @@ class yarp::dev::RemoteControlBoard :
bool ret = extendedIntputStatePort.getLastVector(VOCAB_MOTOR_ENCODERS, encs, lastStamp, localArrivalTime);
std::fill_n(ts, nj, lastStamp.getTime());
extendedPortMutex.unlock();

if(ret && ((Time::now()-localArrivalTime) > TIMEOUT) )
ret=false;

return ret;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ bool StateExtendedInputPort::getLastSingle(int j, int field, double *data, Stamp

localArrivalTime=now;
stamp = lastStamp;
if (ret && ( (Time::now()-localArrivalTime) > TIMEOUT_EXT) )
ret = false;
}
mutex.unlock();

Expand Down Expand Up @@ -181,6 +183,9 @@ bool StateExtendedInputPort::getLastSingle(int j, int field, int *data, Stamp &s
}
localArrivalTime=now;
stamp = lastStamp;
if (ret && ( (Time::now()-localArrivalTime) > TIMEOUT_EXT) )
ret = false;

}
mutex.unlock();
return ret;
Expand Down Expand Up @@ -246,6 +251,8 @@ bool StateExtendedInputPort::getLastVector(int field, double* data, Stamp& stamp

localArrivalTime=now;
stamp = lastStamp;
if (ret && ( (Time::now()-localArrivalTime) > TIMEOUT_EXT) )
ret = false;
}
mutex.unlock();

Expand Down Expand Up @@ -276,6 +283,8 @@ bool StateExtendedInputPort::getLastVector(int field, int* data, Stamp& stamp, d
}
localArrivalTime=now;
stamp = lastStamp;
if (ret && ( (Time::now()-localArrivalTime) > TIMEOUT_EXT) )
ret = false;
}
mutex.unlock();
return ret;
Expand Down

0 comments on commit 9a57eb3

Please sign in to comment.