Compilation fix
[opentx.git] / radio / src / telemetry / telemetry_sensors.h
blobdef941861c45b667f517dde854609577687d9e4e
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _TELEMETRY_SENSORS_H_
22 #define _TELEMETRY_SENSORS_H_
24 #include "telemetry.h"
26 constexpr int8_t TELEMETRY_SENSOR_TIMEOUT_UNAVAILABLE = -2;
27 constexpr int8_t TELEMETRY_SENSOR_TIMEOUT_OLD = -1;
28 constexpr int8_t TELEMETRY_SENSOR_TIMEOUT_START = 125; // * 160ms = 20s
30 class TelemetryItem
32 public:
33 union {
34 int32_t value; // value, stored as uint32_t but interpreted accordingly to type
35 uint32_t distFromEarthAxis;
38 union {
39 int32_t valueMin; // min store
40 int32_t pilotLongitude;
43 union {
44 int32_t valueMax; // max store
45 int32_t pilotLatitude;
48 int8_t timeout; // for detection of sensor loss
50 union {
51 struct {
52 int32_t offsetAuto;
53 int32_t filterValues[TELEMETRY_AVERAGE_COUNT];
54 } std;
55 struct {
56 uint16_t prescale;
57 } consumption;
58 struct {
59 uint8_t count;
60 CellValue values[6];
61 } cells;
62 struct {
63 uint16_t year; // full year (4 digits)
64 uint8_t month;
65 uint8_t day;
66 uint8_t hour;
67 uint8_t min;
68 uint8_t sec;
69 } datetime;
70 struct {
71 int32_t latitude;
72 int32_t longitude;
73 // pilot longitude is stored in min
74 // pilot latitude is stored in max
75 // distFromEarthAxis is stored in value
76 } gps;
77 char text[16];
80 TelemetryItem()
82 clear();
85 void clear()
87 memset(reinterpret_cast<void*>(this), 0, sizeof(TelemetryItem));
88 timeout = TELEMETRY_SENSOR_TIMEOUT_UNAVAILABLE;
91 void eval(const TelemetrySensor & sensor);
92 void per10ms(const TelemetrySensor & sensor);
94 void setValue(const TelemetrySensor & sensor, int32_t newVal, uint32_t unit, uint32_t prec=0);
96 inline bool isAvailable()
98 return (timeout != TELEMETRY_SENSOR_TIMEOUT_UNAVAILABLE);
101 inline bool isOld()
103 return (timeout == TELEMETRY_SENSOR_TIMEOUT_OLD);
106 inline bool hasReceiveTime()
108 return timeout >= 0;
111 inline int8_t getDelaySinceLastValue()
113 return hasReceiveTime() ? TELEMETRY_SENSOR_TIMEOUT_START - timeout : TELEMETRY_SENSOR_TIMEOUT_OLD;
116 inline bool isFresh()
118 return TELEMETRY_SENSOR_TIMEOUT_START - timeout <= 1; // 2 * 160ms
121 inline void setFresh()
123 timeout = TELEMETRY_SENSOR_TIMEOUT_START;
126 inline void setOld()
128 timeout = TELEMETRY_SENSOR_TIMEOUT_OLD;
132 extern TelemetryItem telemetryItems[MAX_TELEMETRY_SENSORS];
133 extern uint8_t allowNewSensors;
134 bool isFaiForbidden(source_t idx);
136 #endif // _TELEMETRY_SENSORS_H_