diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index 66cf5c2ec4d..e9e004b7931 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -176,13 +176,13 @@ static int hyundai_rx_hook(CANPacket_t *to_push) { int addr = GET_ADDR(to_push); // SCC12 is on bus 2 for camera-based SCC cars, bus 0 on all others - if (valid && (addr == 0x421) && (((bus == 0) && !hyundai_camera_scc) || ((bus == 2) && hyundai_camera_scc))) { + if (valid && (addr == 0x421) && (bus == hyundai_scc_bus)) { // 2 bits: 13-14 int cruise_engaged = (GET_BYTES(to_push, 0, 4) >> 13) & 0x3U; hyundai_common_cruise_state_check(cruise_engaged); } - if (valid && (bus == 0)) { + if (valid && (bus == hyundai_pt_bus)) { if (addr == 0x251) { int torque_driver_new = ((GET_BYTES(to_push, 0, 4) & 0x7ffU) * 0.79) - 808; // scale down new driver torque signal to match previous one // update array of samples @@ -324,6 +324,8 @@ static const addr_checks* hyundai_init(uint16_t param) { hyundai_common_init(param); hyundai_legacy = false; + hyundai_common_get_bus(false); + if (hyundai_camera_scc) { hyundai_longitudinal = false; } diff --git a/board/safety/safety_hyundai_canfd.h b/board/safety/safety_hyundai_canfd.h index 3ea7a486a54..1df18a0e51f 100644 --- a/board/safety/safety_hyundai_canfd.h +++ b/board/safety/safety_hyundai_canfd.h @@ -184,10 +184,7 @@ static int hyundai_canfd_rx_hook(CANPacket_t *to_push) { int bus = GET_BUS(to_push); int addr = GET_ADDR(to_push); - const int pt_bus = hyundai_canfd_hda2 ? 1 : 0; - const int scc_bus = hyundai_camera_scc ? 2 : pt_bus; - - if (valid && (bus == pt_bus)) { + if (valid && (bus == hyundai_pt_bus)) { // driver torque if (addr == 0xea) { int torque_driver_new = ((GET_BYTE(to_push, 11) & 0x1fU) << 8U) | GET_BYTE(to_push, 10); @@ -233,7 +230,7 @@ static int hyundai_canfd_rx_hook(CANPacket_t *to_push) { } } - if (valid && (bus == scc_bus)) { + if (valid && (bus == hyundai_scc_bus)) { // cruise state if ((addr == 0x1a0) && !hyundai_longitudinal) { // 1=enabled, 2=driver override @@ -244,12 +241,11 @@ static int hyundai_canfd_rx_hook(CANPacket_t *to_push) { } const int steer_addr = hyundai_canfd_hda2 ? hyundai_canfd_hda2_get_lkas_addr() : 0x12a; - bool stock_ecu_detected = (addr == steer_addr) && (bus == 0); + bool stock_ecu_detected = (addr == steer_addr) && (bus == HYUNDAI_PT_CAN); if (hyundai_longitudinal) { // on HDA2, ensure ADRV ECU is still knocked out // on others, ensure accel msg is blocked from camera - const int stock_scc_bus = hyundai_canfd_hda2 ? 1 : 0; - stock_ecu_detected = stock_ecu_detected || ((addr == 0x1a0) && (bus == stock_scc_bus)); + stock_ecu_detected = stock_ecu_detected || ((addr == 0x1a0) && (bus == hyundai_pt_bus)); } generic_rx_checks(stock_ecu_detected); @@ -363,6 +359,8 @@ static const addr_checks* hyundai_canfd_init(uint16_t param) { hyundai_canfd_alt_buttons = GET_FLAG(param, HYUNDAI_PARAM_CANFD_ALT_BUTTONS); hyundai_canfd_hda2_alt_steering = GET_FLAG(param, HYUNDAI_PARAM_CANFD_HDA2_ALT_STEERING); + hyundai_common_get_bus(hyundai_canfd_hda2); + // no long for ICE yet if (!hyundai_ev_gas_signal && !hyundai_hybrid_gas_signal) { hyundai_longitudinal = false; diff --git a/board/safety/safety_hyundai_common.h b/board/safety/safety_hyundai_common.h index 7d16b83beea..7ed60d9d900 100644 --- a/board/safety/safety_hyundai_common.h +++ b/board/safety/safety_hyundai_common.h @@ -1,6 +1,10 @@ #ifndef SAFETY_HYUNDAI_COMMON_H #define SAFETY_HYUNDAI_COMMON_H +#define HYUNDAI_PT_CAN 0 +#define HYUNDAI_CANFD_A_CAN 1 +#define HYUNDAI_CAM_CAN 2 + const int HYUNDAI_PARAM_EV_GAS = 1; const int HYUNDAI_PARAM_HYBRID_GAS = 2; const int HYUNDAI_PARAM_LONGITUDINAL = 4; @@ -24,6 +28,8 @@ bool hyundai_longitudinal = false; bool hyundai_camera_scc = false; bool hyundai_alt_limits = false; uint8_t hyundai_last_button_interaction; // button messages since the user pressed an enable button +int hyundai_pt_bus; +int hyundai_scc_bus; void hyundai_common_init(uint16_t param) { hyundai_ev_gas_signal = GET_FLAG(param, HYUNDAI_PARAM_EV_GAS); @@ -82,4 +88,9 @@ void hyundai_common_cruise_buttons_check(const int cruise_button, const int main } } +void hyundai_common_get_bus(const bool canfd_hda2) { + hyundai_pt_bus = canfd_hda2 ? HYUNDAI_CANFD_A_CAN : HYUNDAI_PT_CAN; + hyundai_scc_bus = hyundai_camera_scc ? HYUNDAI_CAM_CAN : hyundai_pt_bus; +} + #endif