mirror of https://github.com/commaai/panda.git
Safety: unify `controls_allowed` with boolean (#1589)
This commit is contained in:
parent
aed103d537
commit
1d874be2b7
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue