Commit 4e6cdf9a authored by Michael Ott's avatar Michael Ott
Browse files

Fix detection of outdated sensorcache entries

parent 7a60595f
......@@ -51,13 +51,17 @@ uint64_t SensorCache::getSensor(SensorId sid) {
}
if (it->second.deltaT.size()) {
uint64_t ts = Messaging::calculateTimestamp() / 1000000;
uint64_t ts = Messaging::calculateTimestamp();
uint64_t avg = 0;
for (std::list<uint32_t>::iterator dt = it->second.deltaT.begin(); dt != it->second.deltaT.end(); dt++) {
avg+= *dt;
}
avg/= it->second.deltaT.size();
if ((ts - it->second.timestamp) > 5 * avg) {
/*
* A SID is outdated if it's older than 5x the average sampling period.
* The 1000000 accounts for the conversion ns->ms in deltaT.
*/
if ((ts - it->second.timestamp) > 5 * 1000000 * avg) {
throw std::out_of_range("Sid outdated");
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment