ao_flight: ao_interval_end type was too small, could cause premature landing state
authorKeith Packard <keithp@keithp.com>
Fri, 28 Jan 2022 22:50:58 +0000 (14:50 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 17 Feb 2022 01:26:49 +0000 (17:26 -0800)
ao_interval_end is used to provide a window of time during which the
max/min values for sensors are measured. After that time expires,
those bounds are compared to see if the airframe has been stable and
should be moved to landing state. With a type that is too small, that
could happen immediately after transitioning to main (for baro-enabled
devices) or coast (for accel-only devices). For baro devices, this
would disable any redundant main firing events. For accel-only
devices, this could disable all events occuring after coast, including
firing separation charges or motor igniters.

There are also a couple of additional changes to reduce -Wconversion
messages.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/kernel/ao_flight.c

index 8553ccc5854f8f4d27569e1ae8928aaf7fef63da..cee8b2b8b38d008c16460b5c293b8c4b326c005d 100644 (file)
@@ -63,7 +63,7 @@ uint8_t                       ao_sensor_errors;
  * track min/max data over a long interval to detect
  * resting
  */
  * track min/max data over a long interval to detect
  * resting
  */
-static uint16_t                ao_interval_end;
+static AO_TICK_TYPE    ao_interval_end;
 #ifdef HAS_BARO
 static ao_v_t          ao_interval_min_height;
 static ao_v_t          ao_interval_max_height;
 #ifdef HAS_BARO
 static ao_v_t          ao_interval_min_height;
 static ao_v_t          ao_interval_max_height;
@@ -272,7 +272,7 @@ ao_flight(void)
                         * (15 seconds) has past.
                         */
                        if ((ao_accel < AO_MSS_TO_ACCEL(-2.5)) ||
                         * (15 seconds) has past.
                         */
                        if ((ao_accel < AO_MSS_TO_ACCEL(-2.5)) ||
-                           (AO_TICK_SIGNED) (ao_sample_tick - ao_boost_tick) > BOOST_TICKS_MAX)
+                           (AO_TICK_SIGNED) (ao_sample_tick - ao_boost_tick) > (AO_TICK_SIGNED) BOOST_TICKS_MAX)
                        {
 #if HAS_ACCEL
 #if HAS_BARO
                        {
 #if HAS_ACCEL
 #if HAS_BARO
@@ -320,7 +320,7 @@ ao_flight(void)
                         */
                        if (ao_config.apogee_lockout) {
                                if ((AO_TICK_SIGNED) (ao_sample_tick - ao_launch_tick) <
                         */
                        if (ao_config.apogee_lockout) {
                                if ((AO_TICK_SIGNED) (ao_sample_tick - ao_launch_tick) <
-                                   AO_SEC_TO_TICKS(ao_config.apogee_lockout))
+                                   (AO_TICK_SIGNED) AO_SEC_TO_TICKS(ao_config.apogee_lockout))
                                        break;
                        }
 
                                        break;
                        }