Bsongis/telemetry clean session (#6597)

Telemetry cleaning session
This commit is contained in:
Bertrand Songis
2019-08-02 21:31:03 +02:00
committed by GitHub
parent 5b516b8287
commit 39f29860c9
13 changed files with 151 additions and 172 deletions
+36 -14
View File
@@ -29,31 +29,37 @@
class TelemetryValue {
public:
uint8_t value;
uint8_t value()
{
return _value;
}
void set(uint8_t value)
{
this->value = value;
_value = value;
}
void reset()
{
set(0);
};
}
protected:
uint8_t _value;
};
template <class T>
class TelemetryFilterDecorator: public T {
public:
uint8_t values[TELEMETRY_AVERAGE_COUNT];
void set(uint8_t value)
{
if (this->value == 0 || value == 0) {
if (value == 0 || this->_value == 0) {
memset(values, value, TELEMETRY_AVERAGE_COUNT);
this->value = value;
this->_value = value;
}
else {
//calculate the average from values[] and value
//also shift readings in values [] array
// calculate the average from values[] and value
// also shift readings in values [] array
unsigned int sum = values[0];
for (int i=0; i<TELEMETRY_AVERAGE_COUNT-1; i++) {
uint8_t tmp = values[i+1];
@@ -62,49 +68,65 @@ class TelemetryFilterDecorator: public T {
}
values[TELEMETRY_AVERAGE_COUNT-1] = value;
sum += value;
this->value = sum / (TELEMETRY_AVERAGE_COUNT+1);
this->_value = sum / (TELEMETRY_AVERAGE_COUNT+1);
}
}
void reset()
{
memclear(this, sizeof(*this));
};
}
protected:
uint8_t values[TELEMETRY_AVERAGE_COUNT];
};
template <class T>
class TelemetryExpiringDecorator: public T {
public:
tmr10ms_t expirationTime;
void set(uint8_t value)
{
T::set(value);
expirationTime = get_tmr10ms() + 1000/*10s*/;
}
void reset()
{
memclear(this, sizeof(*this));
}
bool isFresh()
{
return get_tmr10ms() < expirationTime;
}
protected:
tmr10ms_t expirationTime;
};
template <class T>
class TelemetryMinDecorator: public T {
public:
uint8_t min;
void set(uint8_t value)
{
T::set(value);
if (!min || value < min) {
min = value;
if (!_min || value < _min) {
_min = value;
}
}
uint8_t min()
{
return _min;
}
void reset()
{
memclear(this, sizeof(*this));
}
protected:
uint8_t _min;
};
#endif // _TELEMETRY_HOLDERS_H_