From a2505dc4be4a368911533d42d6344ad03b220468 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 16 Feb 2022 17:34:41 -0800 Subject: [PATCH] ao_telemetry: Use int16_t types for telemetry packet intervals This avoids concerns about overflow from int8_t types when computing long intervals between packets as the base interface type was an int16_t. This should help deal with higher sample rate sensors when that occurs. Signed-off-by: Keith Packard --- src/kernel/ao_telemetry.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/kernel/ao_telemetry.c b/src/kernel/ao_telemetry.c index 24dd9679..61156c0d 100644 --- a/src/kernel/ao_telemetry.c +++ b/src/kernel/ao_telemetry.c @@ -235,8 +235,8 @@ ao_send_mega_sensor(void) ao_telemetry_send(); } -static int8_t ao_telemetry_mega_data_max; -static int8_t ao_telemetry_mega_data_cur; +static int16_t ao_telemetry_mega_data_max; +static int16_t ao_telemetry_mega_data_cur; /* Send mega data packet */ static void @@ -300,8 +300,8 @@ ao_send_metrum_sensor(void) ao_telemetry_send(); } -static int8_t ao_telemetry_metrum_data_max; -static int8_t ao_telemetry_metrum_data_cur; +static int16_t ao_telemetry_metrum_data_max; +static int16_t ao_telemetry_metrum_data_cur; /* Send telemetrum data packet */ static void @@ -360,8 +360,8 @@ ao_send_mini(void) #endif /* AO_SEND_MINI */ -static int8_t ao_telemetry_config_max; -static int8_t ao_telemetry_config_cur; +static int16_t ao_telemetry_config_max; +static int16_t ao_telemetry_config_cur; static uint16_t ao_telemetry_flight_number; #ifndef ao_telemetry_battery_convert @@ -400,9 +400,9 @@ ao_send_configuration(void) #if HAS_GPS -static int8_t ao_telemetry_gps_max; -static int8_t ao_telemetry_loc_cur; -static int8_t ao_telemetry_sat_cur; +static int16_t ao_telemetry_gps_max; +static int16_t ao_telemetry_loc_cur; +static int16_t ao_telemetry_sat_cur; static inline void * telemetry_bits(struct ao_telemetry_location *l) @@ -453,8 +453,8 @@ ao_send_satellite(void) #if HAS_COMPANION -static int8_t ao_telemetry_companion_max; -static int8_t ao_telemetry_companion_cur; +static int16_t ao_telemetry_companion_max; +static int16_t ao_telemetry_companion_cur; static void ao_send_companion(void) @@ -620,7 +620,7 @@ ao_telemetry_reset_interval(void) void ao_telemetry_set_interval(uint16_t interval) { - int8_t cur = 0; + int16_t cur = 0; #if HAS_RADIO_RATE /* Limit max telemetry rate based on available radio bandwidth. @@ -646,7 +646,7 @@ ao_telemetry_set_interval(uint16_t interval) ao_telemetry_mega_data_cur = cur; #endif #if AO_SEND_METRUM - ao_telemetry_metrum_data_max = AO_SEC_TO_TICKS(1) / interval; + ao_telemetry_metrum_data_max = (int16_t) (AO_SEC_TO_TICKS(1) / interval); if (ao_telemetry_metrum_data_max > cur) cur++; ao_telemetry_metrum_data_cur = cur; @@ -655,14 +655,14 @@ ao_telemetry_set_interval(uint16_t interval) #if HAS_COMPANION if (!ao_companion_setup.update_period) ao_companion_setup.update_period = AO_SEC_TO_TICKS(1); - ao_telemetry_companion_max = ao_companion_setup.update_period / interval; + ao_telemetry_companion_max = (int16_t) (ao_companion_setup.update_period / interval); if (ao_telemetry_companion_max > cur) cur++; ao_telemetry_companion_cur = cur; #endif #if HAS_GPS - ao_telemetry_gps_max = AO_SEC_TO_TICKS(1) / interval; + ao_telemetry_gps_max = (int16_t) (AO_SEC_TO_TICKS(1) / interval); if (ao_telemetry_gps_max > cur) cur++; ao_telemetry_loc_cur = cur; @@ -671,7 +671,7 @@ ao_telemetry_set_interval(uint16_t interval) ao_telemetry_sat_cur = cur; #endif - ao_telemetry_config_max = AO_SEC_TO_TICKS(5) / interval; + ao_telemetry_config_max = (int16_t) (AO_SEC_TO_TICKS(5) / interval); if (ao_telemetry_config_max > cur) cur++; ao_telemetry_config_cur = cur; -- 2.30.2