From 1d874be2b7937bfdc2877021cb42de8e4c6eecbc Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Fri, 18 Aug 2023 16:22:04 -0400 Subject: [PATCH] Safety: unify `controls_allowed` with boolean (#1589) --- board/main.c | 2 +- board/safety.h | 10 +++++----- board/safety/safety_ford.h | 2 +- board/safety/safety_gm.h | 4 ++-- board/safety/safety_honda.h | 10 +++++----- board/safety/safety_hyundai_common.h | 8 ++++---- board/safety/safety_volkswagen_pq.h | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/board/main.c b/board/main.c index 56abbed52..5fccaa7ac 100644 --- a/board/main.c +++ b/board/main.c @@ -237,7 +237,7 @@ void tick_handler(void) { if (controls_allowed && !heartbeat_engaged) { heartbeat_engaged_mismatches += 1U; if (heartbeat_engaged_mismatches >= 3U) { - controls_allowed = 0U; + controls_allowed = false; } } else { heartbeat_engaged_mismatches = 0U; diff --git a/board/safety.h b/board/safety.h index 645d41d83..2c6daddbd 100644 --- a/board/safety.h +++ b/board/safety.h @@ -174,7 +174,7 @@ void safety_tick(const addr_checks *rx_checks) { bool lagging = elapsed_time > MAX(rx_checks->check[i].msg[rx_checks->check[i].index].expected_timestep * MAX_MISSED_MSGS, 1e6); rx_checks->check[i].lagging = lagging; if (lagging) { - controls_allowed = 0; + controls_allowed = false; } if (lagging || !is_msg_valid(rx_checks->check, i)) { @@ -200,7 +200,7 @@ bool is_msg_valid(AddrCheckStruct addr_list[], int index) { if (index != -1) { if (!addr_list[index].valid_checksum || !addr_list[index].valid_quality_flag || (addr_list[index].wrong_counters >= MAX_WRONG_COUNTERS)) { valid = false; - controls_allowed = 0; + controls_allowed = false; } } return valid; @@ -254,19 +254,19 @@ bool addr_safety_check(CANPacket_t *to_push, void generic_rx_checks(bool stock_ecu_detected) { // exit controls on rising edge of gas press if (gas_pressed && !gas_pressed_prev && !(alternative_experience & ALT_EXP_DISABLE_DISENGAGE_ON_GAS)) { - controls_allowed = 0; + controls_allowed = false; } gas_pressed_prev = gas_pressed; // exit controls on rising edge of brake press if (brake_pressed && (!brake_pressed_prev || vehicle_moving)) { - controls_allowed = 0; + controls_allowed = false; } brake_pressed_prev = brake_pressed; // exit controls on rising edge of regen paddle if (regen_braking && (!regen_braking_prev || vehicle_moving)) { - controls_allowed = 0; + controls_allowed = false; } regen_braking_prev = regen_braking; diff --git a/board/safety/safety_ford.h b/board/safety/safety_ford.h index 4f71650c9..8f48868a2 100644 --- a/board/safety/safety_ford.h +++ b/board/safety/safety_ford.h @@ -237,7 +237,7 @@ static int ford_rx_hook(CANPacket_t *to_push) { // Signal: Veh_V_ActlEng float filtered_pcm_speed = ((GET_BYTE(to_push, 6) << 8) | GET_BYTE(to_push, 7)) * 0.01 / 3.6; if (ABS(filtered_pcm_speed - ((float)vehicle_speed.values[0] / VEHICLE_SPEED_FACTOR)) > FORD_MAX_SPEED_DELTA) { - controls_allowed = 0; + controls_allowed = false; } } diff --git a/board/safety/safety_gm.h b/board/safety/safety_gm.h index 76e55f0bc..c4727c0a1 100644 --- a/board/safety/safety_gm.h +++ b/board/safety/safety_gm.h @@ -95,12 +95,12 @@ static int gm_rx_hook(CANPacket_t *to_push) { bool set = (button != GM_BTN_SET) && (cruise_button_prev == GM_BTN_SET); bool res = (button == GM_BTN_RESUME) && (cruise_button_prev != GM_BTN_RESUME); if (set || res) { - controls_allowed = 1; + controls_allowed = true; } // exit controls on cancel press if (button == GM_BTN_CANCEL) { - controls_allowed = 0; + controls_allowed = false; } cruise_button_prev = button; diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index 83e671a5d..40c650e10 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -142,7 +142,7 @@ static int honda_rx_hook(CANPacket_t *to_push) { if ((addr == 0x326) || (addr == 0x1A6)) { acc_main_on = GET_BIT(to_push, ((addr == 0x326) ? 28U : 47U)); if (!acc_main_on) { - controls_allowed = 0; + controls_allowed = false; } } @@ -151,13 +151,13 @@ static int honda_rx_hook(CANPacket_t *to_push) { const bool cruise_engaged = GET_BIT(to_push, 38U) != 0U; // engage on rising edge if (cruise_engaged && !cruise_engaged_prev) { - controls_allowed = 1; + controls_allowed = true; } // Since some Nidec cars can brake down to 0 after the PCM disengages, // we don't disengage when the PCM does. if (!cruise_engaged && (honda_hw != HONDA_NIDEC)) { - controls_allowed = 0; + controls_allowed = false; } cruise_engaged_prev = cruise_engaged; } @@ -169,14 +169,14 @@ static int honda_rx_hook(CANPacket_t *to_push) { // exit controls once main or cancel are pressed if ((button == HONDA_BTN_MAIN) || (button == HONDA_BTN_CANCEL)) { - controls_allowed = 0; + controls_allowed = false; } // enter controls on the falling edge of set or resume bool set = (button == HONDA_BTN_NONE) && (cruise_button_prev == HONDA_BTN_SET); bool res = (button == HONDA_BTN_NONE) && (cruise_button_prev == HONDA_BTN_RESUME); if (acc_main_on && !pcm_cruise && (set || res)) { - controls_allowed = 1; + controls_allowed = true; } cruise_button_prev = button; } diff --git a/board/safety/safety_hyundai_common.h b/board/safety/safety_hyundai_common.h index 3c1d67510..7d16b83be 100644 --- a/board/safety/safety_hyundai_common.h +++ b/board/safety/safety_hyundai_common.h @@ -47,11 +47,11 @@ void hyundai_common_cruise_state_check(const int cruise_engaged) { // enter controls on rising edge of ACC and recent user button press, exit controls when ACC off if (!hyundai_longitudinal) { if (cruise_engaged && !cruise_engaged_prev && (hyundai_last_button_interaction < HYUNDAI_PREV_BUTTON_SAMPLES)) { - controls_allowed = 1; + controls_allowed = true; } if (!cruise_engaged) { - controls_allowed = 0; + controls_allowed = false; } cruise_engaged_prev = cruise_engaged; } @@ -70,12 +70,12 @@ void hyundai_common_cruise_buttons_check(const int cruise_button, const int main bool set = (cruise_button != HYUNDAI_BTN_SET) && (cruise_button_prev == HYUNDAI_BTN_SET); bool res = (cruise_button != HYUNDAI_BTN_RESUME) && (cruise_button_prev == HYUNDAI_BTN_RESUME); if (set || res) { - controls_allowed = 1; + controls_allowed = true; } // exit controls on cancel press if (cruise_button == HYUNDAI_BTN_CANCEL) { - controls_allowed = 0; + controls_allowed = false; } cruise_button_prev = cruise_button; diff --git a/board/safety/safety_volkswagen_pq.h b/board/safety/safety_volkswagen_pq.h index 7a909d4d5..b310ef2c5 100644 --- a/board/safety/safety_volkswagen_pq.h +++ b/board/safety/safety_volkswagen_pq.h @@ -130,7 +130,7 @@ static int volkswagen_pq_rx_hook(CANPacket_t *to_push) { // Signal: Motor_5.GRA_Hauptschalter acc_main_on = GET_BIT(to_push, 50U); if (!acc_main_on) { - controls_allowed = 0; + controls_allowed = false; } } @@ -148,7 +148,7 @@ static int volkswagen_pq_rx_hook(CANPacket_t *to_push) { // Exit controls on rising edge of Cancel, override Set/Resume if present simultaneously // Signal: GRA_ACC_01.GRA_Abbrechen if (GET_BIT(to_push, 9U) == 1U) { - controls_allowed = 0; + controls_allowed = false; } } } else {