Reworked metrics structure and split telemetry into device or environ… (#1331)

* Reworked metrics structure and split telemetry into device or environment

* Comment cleanup
This commit is contained in:
Ben Meadors
2022-03-27 14:55:35 +00:00
committed by GitHub
parent 7b8096f5b2
commit ba2fa84ebd
23 changed files with 584 additions and 379 deletions

View File

@@ -10,23 +10,20 @@
#endif
/* Struct definitions */
/* TODO: REPLACE */
typedef struct _Telemetry {
/* This is usually not sent over the mesh (to save space), but it is sent
from the phone so that the local device can set its RTC If it is sent over
the mesh (because there are devices on the mesh without GPS), it will only
be sent by devices which has a hardware GPS clock (IE Mobile Phone).
seconds since 1970 */
uint32_t time;
/* Key native device metrics such as battery level */
typedef struct _DeviceMetrics {
/* 1-100 (0 means powered) */
uint32_t battery_level;
/* Voltage measured */
float voltage;
/* Utilization for the current channel, including well formed TX, RX and malformed RX (aka noise). */
float channel_utilization;
/* Percent of airtime for transmission used within the last hour. */
float air_util_tx;
/* This is sent by node only if it a router and if hop_limit is set to 0
and is not being sent as a reliable message. */
bool router_heartbeat;
} DeviceMetrics;
/* Weather station or other environmental metrics */
typedef struct _EnvironmentMetrics {
/* Temperature measured */
float temperature;
/* Relative humidity percent measured */
@@ -39,6 +36,22 @@ typedef struct _Telemetry {
float voltage;
/* Current measured */
float current;
} EnvironmentMetrics;
/* Types of Measurements the telemetry module is equipped to handle */
typedef struct _Telemetry {
/* This is usually not sent over the mesh (to save space), but it is sent
from the phone so that the local device can set its RTC If it is sent over
the mesh (because there are devices on the mesh without GPS), it will only
be sent by devices which has a hardware GPS clock (IE Mobile Phone).
seconds since 1970 */
uint32_t time;
/* Key native device metrics such as battery level */
pb_size_t which_variant;
union {
DeviceMetrics device_metrics;
EnvironmentMetrics environment_metrics;
} variant;
} Telemetry;
@@ -47,45 +60,69 @@ extern "C" {
#endif
/* Initializer values for message structs */
#define Telemetry_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
#define Telemetry_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
#define DeviceMetrics_init_default {0, 0, 0, 0}
#define EnvironmentMetrics_init_default {0, 0, 0, 0, 0, 0}
#define Telemetry_init_default {0, 0, {DeviceMetrics_init_default}}
#define DeviceMetrics_init_zero {0, 0, 0, 0}
#define EnvironmentMetrics_init_zero {0, 0, 0, 0, 0, 0}
#define Telemetry_init_zero {0, 0, {DeviceMetrics_init_zero}}
/* Field tags (for use in manual encoding/decoding) */
#define DeviceMetrics_battery_level_tag 1
#define DeviceMetrics_voltage_tag 2
#define DeviceMetrics_channel_utilization_tag 3
#define DeviceMetrics_air_util_tx_tag 4
#define EnvironmentMetrics_temperature_tag 1
#define EnvironmentMetrics_relative_humidity_tag 2
#define EnvironmentMetrics_barometric_pressure_tag 3
#define EnvironmentMetrics_gas_resistance_tag 4
#define EnvironmentMetrics_voltage_tag 5
#define EnvironmentMetrics_current_tag 6
#define Telemetry_time_tag 1
#define Telemetry_battery_level_tag 2
#define Telemetry_channel_utilization_tag 3
#define Telemetry_air_util_tx_tag 4
#define Telemetry_router_heartbeat_tag 5
#define Telemetry_temperature_tag 6
#define Telemetry_relative_humidity_tag 7
#define Telemetry_barometric_pressure_tag 8
#define Telemetry_gas_resistance_tag 9
#define Telemetry_voltage_tag 10
#define Telemetry_current_tag 11
#define Telemetry_device_metrics_tag 2
#define Telemetry_environment_metrics_tag 3
/* Struct field encoding specification for nanopb */
#define DeviceMetrics_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, battery_level, 1) \
X(a, STATIC, SINGULAR, FLOAT, voltage, 2) \
X(a, STATIC, SINGULAR, FLOAT, channel_utilization, 3) \
X(a, STATIC, SINGULAR, FLOAT, air_util_tx, 4)
#define DeviceMetrics_CALLBACK NULL
#define DeviceMetrics_DEFAULT NULL
#define EnvironmentMetrics_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, FLOAT, temperature, 1) \
X(a, STATIC, SINGULAR, FLOAT, relative_humidity, 2) \
X(a, STATIC, SINGULAR, FLOAT, barometric_pressure, 3) \
X(a, STATIC, SINGULAR, FLOAT, gas_resistance, 4) \
X(a, STATIC, SINGULAR, FLOAT, voltage, 5) \
X(a, STATIC, SINGULAR, FLOAT, current, 6)
#define EnvironmentMetrics_CALLBACK NULL
#define EnvironmentMetrics_DEFAULT NULL
#define Telemetry_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, FIXED32, time, 1) \
X(a, STATIC, SINGULAR, UINT32, battery_level, 2) \
X(a, STATIC, SINGULAR, FLOAT, channel_utilization, 3) \
X(a, STATIC, SINGULAR, FLOAT, air_util_tx, 4) \
X(a, STATIC, SINGULAR, BOOL, router_heartbeat, 5) \
X(a, STATIC, SINGULAR, FLOAT, temperature, 6) \
X(a, STATIC, SINGULAR, FLOAT, relative_humidity, 7) \
X(a, STATIC, SINGULAR, FLOAT, barometric_pressure, 8) \
X(a, STATIC, SINGULAR, FLOAT, gas_resistance, 9) \
X(a, STATIC, SINGULAR, FLOAT, voltage, 10) \
X(a, STATIC, SINGULAR, FLOAT, current, 11)
X(a, STATIC, ONEOF, MESSAGE, (variant,device_metrics,variant.device_metrics), 2) \
X(a, STATIC, ONEOF, MESSAGE, (variant,environment_metrics,variant.environment_metrics), 3)
#define Telemetry_CALLBACK NULL
#define Telemetry_DEFAULT NULL
#define Telemetry_variant_device_metrics_MSGTYPE DeviceMetrics
#define Telemetry_variant_environment_metrics_MSGTYPE EnvironmentMetrics
extern const pb_msgdesc_t DeviceMetrics_msg;
extern const pb_msgdesc_t EnvironmentMetrics_msg;
extern const pb_msgdesc_t Telemetry_msg;
/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
#define DeviceMetrics_fields &DeviceMetrics_msg
#define EnvironmentMetrics_fields &EnvironmentMetrics_msg
#define Telemetry_fields &Telemetry_msg
/* Maximum encoded size of messages (where known) */
#define Telemetry_size 53
#define DeviceMetrics_size 21
#define EnvironmentMetrics_size 30
#define Telemetry_size 37
#ifdef __cplusplus
} /* extern "C" */