From 9903299294c8ca6397c249383144493c70be3d84 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sun, 22 Sep 2024 23:50:54 -0400 Subject: [PATCH] Hyundai: Second alt steering limits --- board/safety/safety_hyundai.h | 11 ++++++++++- board/safety/safety_hyundai_common.h | 5 +++++ python/__init__.py | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index 3e9d23216c3..804439ce7e0 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -175,6 +175,7 @@ static void hyundai_rx_hook(const CANPacket_t *to_push) { static bool hyundai_tx_hook(const CANPacket_t *to_send) { const SteeringLimits HYUNDAI_STEERING_LIMITS = HYUNDAI_LIMITS(384, 3, 7); const SteeringLimits HYUNDAI_STEERING_LIMITS_ALT = HYUNDAI_LIMITS(270, 2, 3); + const SteeringLimits HYUNDAI_STEERING_LIMITS_ALT_2 = HYUNDAI_LIMITS(170, 2, 3); bool tx = true; int addr = GET_ADDR(to_send); @@ -215,7 +216,15 @@ static bool hyundai_tx_hook(const CANPacket_t *to_send) { int desired_torque = ((GET_BYTES(to_send, 0, 4) >> 16) & 0x7ffU) - 1024U; bool steer_req = GET_BIT(to_send, 27U); - const SteeringLimits limits = hyundai_alt_limits ? HYUNDAI_STEERING_LIMITS_ALT : HYUNDAI_STEERING_LIMITS; + SteeringLimits limits; + if (hyundai_alt_limits) { + limits = HYUNDAI_STEERING_LIMITS_ALT; + } else if (hyundai_alt_limits_2) { + limits = HYUNDAI_STEERING_LIMITS_ALT_2; + } else { + limits = HYUNDAI_STEERING_LIMITS; + } + if (steer_torque_cmd_checks(desired_torque, steer_req, limits)) { tx = false; } diff --git a/board/safety/safety_hyundai_common.h b/board/safety/safety_hyundai_common.h index d83b3964010..f62b199a436 100644 --- a/board/safety/safety_hyundai_common.h +++ b/board/safety/safety_hyundai_common.h @@ -36,6 +36,9 @@ bool hyundai_canfd_hda2 = false; extern bool hyundai_alt_limits; bool hyundai_alt_limits = false; +extern bool hyundai_alt_limits_2; +bool hyundai_alt_limits_2 = false; + static uint8_t hyundai_last_button_interaction; // button messages since the user pressed an enable button void hyundai_common_init(uint16_t param) { @@ -44,12 +47,14 @@ void hyundai_common_init(uint16_t param) { const int HYUNDAI_PARAM_CAMERA_SCC = 8; const int HYUNDAI_PARAM_CANFD_HDA2 = 16; const int HYUNDAI_PARAM_ALT_LIMITS = 64; // TODO: shift this down with the rest of the common flags + const int HYUNDAI_PARAM_ALT_LIMITS_2 = 256; hyundai_ev_gas_signal = GET_FLAG(param, HYUNDAI_PARAM_EV_GAS); hyundai_hybrid_gas_signal = !hyundai_ev_gas_signal && GET_FLAG(param, HYUNDAI_PARAM_HYBRID_GAS); hyundai_camera_scc = GET_FLAG(param, HYUNDAI_PARAM_CAMERA_SCC); hyundai_canfd_hda2 = GET_FLAG(param, HYUNDAI_PARAM_CANFD_HDA2); hyundai_alt_limits = GET_FLAG(param, HYUNDAI_PARAM_ALT_LIMITS); + hyundai_alt_limits_2 = GET_FLAG(param, HYUNDAI_PARAM_ALT_LIMITS_2); hyundai_last_button_interaction = HYUNDAI_PREV_BUTTON_SAMPLES; diff --git a/python/__init__.py b/python/__init__.py index 0e531dfc755..b459328a640 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -201,6 +201,7 @@ class Panda: FLAG_HYUNDAI_CANFD_ALT_BUTTONS = 32 FLAG_HYUNDAI_ALT_LIMITS = 64 FLAG_HYUNDAI_CANFD_HDA2_ALT_STEERING = 128 + FLAG_HYUNDAI_ALT_LIMITS_2 = 256 FLAG_TESLA_POWERTRAIN = 1 FLAG_TESLA_LONG_CONTROL = 2