From 07a47b8d3d2315f9c8696d17d688dcf0c128609e Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sun, 22 Sep 2024 23:13:11 -0400 Subject: [PATCH] Hyundai: Car Port for Nexo 2021 --- board/safety/safety_hyundai.h | 10 +++++++--- board/safety/safety_hyundai_common.h | 5 +++++ python/__init__.py | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index 3e9d23216c..851a559f24 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -32,9 +32,10 @@ static const CanMsg HYUNDAI_TX_MSGS[] = { {0x485, 0, 4}, // LFAHDA_MFC Bus 0 }; -#define HYUNDAI_COMMON_RX_CHECKS(legacy) \ +#define HYUNDAI_COMMON_RX_CHECKS(legacy) \ {.msg = {{0x260, 0, 8, .check_checksum = true, .max_counter = 3U, .frequency = 100U}, \ - {0x371, 0, 8, .frequency = 100U}, { 0 }}}, \ + {0x371, 0, 8, .frequency = 100U}, \ + {0x91, 0, 8, .frequency = 100U}}}, \ {.msg = {{0x386, 0, 8, .check_checksum = !(legacy), .max_counter = (legacy) ? 0U : 15U, .frequency = 100U}, { 0 }, { 0 }}}, \ {.msg = {{0x394, 0, 8, .check_checksum = !(legacy), .max_counter = (legacy) ? 0U : 7U, .frequency = 100U}, { 0 }, { 0 }}}, \ @@ -145,7 +146,9 @@ static void hyundai_rx_hook(const CANPacket_t *to_push) { gas_pressed = (((GET_BYTE(to_push, 4) & 0x7FU) << 1) | GET_BYTE(to_push, 3) >> 7) != 0U; } else if ((addr == 0x371) && hyundai_hybrid_gas_signal) { gas_pressed = GET_BYTE(to_push, 7) != 0U; - } else if ((addr == 0x260) && !hyundai_ev_gas_signal && !hyundai_hybrid_gas_signal) { + } else if ((addr == 0x91) && hyundai_fcev_gas_signal) { + gas_pressed = GET_BYTE(to_push, 6) != 0U; + } else if ((addr == 0x260) && !hyundai_ev_gas_signal && !hyundai_hybrid_gas_signal && !hyundai_fcev_gas_signal) { gas_pressed = (GET_BYTE(to_push, 7) >> 6) != 0U; } else { } @@ -323,6 +326,7 @@ static safety_config hyundai_legacy_init(uint16_t param) { hyundai_legacy = true; hyundai_longitudinal = false; hyundai_camera_scc = false; + hyundai_fcev_gas_signal = false; return BUILD_SAFETY_CFG(hyundai_legacy_rx_checks, HYUNDAI_TX_MSGS); } diff --git a/board/safety/safety_hyundai_common.h b/board/safety/safety_hyundai_common.h index d83b396401..d12dec88f5 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_fcev_gas_signal; +bool hyundai_fcev_gas_signal = 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_FCEV_GAS = 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_fcev_gas_signal = GET_FLAG(param, HYUNDAI_PARAM_FCEV_GAS); hyundai_last_button_interaction = HYUNDAI_PREV_BUTTON_SAMPLES; diff --git a/python/__init__.py b/python/__init__.py index 0e531dfc75..222b2a9d76 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_FCEV_GAS = 256 FLAG_TESLA_POWERTRAIN = 1 FLAG_TESLA_LONG_CONTROL = 2