Commit c3a4a8e7 authored by Michael Ott's avatar Michael Ott
Browse files

Fix removal of outdated SensorCache history

parent 67e7d960
......@@ -25,20 +25,21 @@ SensorCache::~SensorCache() {
}
void SensorCache::storeSensor(SensorId sid, uint64_t ts, uint64_t val) {
cacheEntry_t e;
/* Remove the reserved bytes to leverage the standard find function */
sid.setRsvd(0);
sensorCache_t::iterator it = sensorCache.find(sid);
if (it != sensorCache.end()) {
e = it->second;
if (e.front().timestamp+MAX_HISTORY_NS > ts) {
e.pop_front();
}
}
sensorReading_t s = { val, ts };
sensorCache[sid].push_back(s);
sensorReading_t s = { val, ts };
/* Remove the reserved bytes to leverage the standard find function */
sid.setRsvd(0);
sensorCache_t::iterator it = sensorCache.find(sid);
if (it != sensorCache.end()) {
if (it->second.size() && (it->second.front().timestamp+MAX_HISTORY_NS <= ts)) {
std::cout << "SensorCache::storeSensor() Removing " << it->first.toString() << " " << it->second.front().timestamp << std::endl;
it->second.pop_front();
}
it->second.push_back(s);
std::cout << "SensorCache::storeSensor(" << sid.toString() << "," << ts << "," << val << ") size=" << it->second.size() << std::endl;
} else {
sensorCache[sid].push_back(s);
}
}
bool SensorCache::checkValid(cacheEntry_t &entry) {
......
......@@ -13,7 +13,7 @@
#include <utility>
#include <dcdb/sensorid.h>
#define MAX_HISTORY_NS 60000000 // Store max 60s of historic data
#define MAX_HISTORY_NS 60000000000 // Store max 60s of historic data
namespace DCDB {
......
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