Commit 1d684738 authored by Micha Mueller's avatar Micha Mueller
Browse files

Skip first reading in delta plugins as it is not very meaningful

parent f9322eec
......@@ -35,6 +35,7 @@ public:
_cacheIndex(0),
_cache(nullptr),
_delta(false),
_firstReading(true),
_readingQueue(nullptr),
_sinkFile(nullptr) {
......@@ -58,6 +59,7 @@ public:
_cacheIndex(0),
_cache(nullptr),
_delta(other._delta),
_firstReading(true),
_latestValue(other._latestValue),
_lastRawValue(other._lastRawValue),
_lastSentValue(other._lastSentValue),
......@@ -78,6 +80,7 @@ public:
_cacheIndex = 0;
_cache.reset(nullptr);
_delta = other._delta;
_firstReading = true;
_latestValue.timestamp = other._latestValue.timestamp;
_latestValue.value = other._latestValue.value;
_lastRawValue.timestamp = other._lastRawValue.timestamp;
......@@ -133,10 +136,16 @@ public:
void storeReading(reading_t rawReading, double factor=1.0, unsigned long long maxValue=ULLONG_MAX) {
reading_t reading = rawReading;
if( _delta ) {
if (rawReading.value < _lastRawValue.value)
reading.value = (rawReading.value + (maxValue - _lastRawValue.value)) * factor;
else
reading.value = (rawReading.value - _lastRawValue.value) * factor;
if (!_firstReading) {
if (rawReading.value < _lastRawValue.value)
reading.value = (rawReading.value + (maxValue - _lastRawValue.value)) * factor;
else
reading.value = (rawReading.value - _lastRawValue.value) * factor;
} else {
_firstReading = false;
_lastRawValue = rawReading;
return;
}
_lastRawValue = rawReading;
}
else
......@@ -172,6 +181,7 @@ protected:
unsigned int _cacheIndex;
std::unique_ptr<reading_t[]> _cache;
bool _delta;
bool _firstReading;
reading_t _latestValue;
reading_t _lastRawValue;
reading_t _lastSentValue;
......
Supports Markdown
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