diff --git a/board/safety/safety_hyundai_canfd.h b/board/safety/safety_hyundai_canfd.h index 226cab9f..5086a39b 100644 --- a/board/safety/safety_hyundai_canfd.h +++ b/board/safety/safety_hyundai_canfd.h @@ -216,8 +216,10 @@ static int hyundai_canfd_rx_hook(CANPacket_t *to_push) { const int steer_addr = hyundai_canfd_hda2 ? 0x50 : 0x12a; bool stock_ecu_detected = (addr == steer_addr) && (bus == 0); if (hyundai_longitudinal) { - // ensure ADRV ECU is still knocked out - stock_ecu_detected = stock_ecu_detected || ((addr == 0x1a0) && (bus == 1)); + // 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)); } generic_rx_checks(stock_ecu_detected); @@ -262,7 +264,7 @@ static int hyundai_canfd_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed } // UDS: only tester present ("\x02\x3E\x80\x00\x00\x00\x00\x00") allowed on diagnostics address - if (addr == 0x730) { + if ((addr == 0x730) && hyundai_canfd_hda2) { if ((GET_BYTES_04(to_send) != 0x00803E02U) || (GET_BYTES_48(to_send) != 0x0U)) { tx = 0; } @@ -313,7 +315,10 @@ static int hyundai_canfd_fwd_hook(int bus_num, CANPacket_t *to_fwd) { // HUD icons int is_lfahda_msg = ((addr == 0x1e0) && !hyundai_canfd_hda2); - int block_msg = is_lkas_msg || is_lfa_msg || is_lfahda_msg; + // CRUISE_INFO for non-HDA2, we send our own longitudinal commands + int is_scc_msg = ((addr == 0x1a0) && hyundai_longitudinal && !hyundai_canfd_hda2); + + int block_msg = is_lkas_msg || is_lfa_msg || is_lfahda_msg || is_scc_msg; if (!block_msg) { bus_fwd = 0; } @@ -329,7 +334,8 @@ static const addr_checks* hyundai_canfd_init(uint16_t param) { hyundai_canfd_hda2 = GET_FLAG(param, HYUNDAI_PARAM_CANFD_HDA2); hyundai_canfd_alt_buttons = GET_FLAG(param, HYUNDAI_PARAM_CANFD_ALT_BUTTONS); - if (!hyundai_canfd_hda2) { + // no long for ICE yet + if (!hyundai_ev_gas_signal && !hyundai_hybrid_gas_signal) { hyundai_longitudinal = false; } diff --git a/tests/safety/test_hyundai_canfd.py b/tests/safety/test_hyundai_canfd.py index e44e8832..98c5d0f7 100755 --- a/tests/safety/test_hyundai_canfd.py +++ b/tests/safety/test_hyundai_canfd.py @@ -7,6 +7,8 @@ import panda.tests.safety.common as common from panda.tests.safety.common import CANPackerPanda from panda.tests.safety.hyundai_common import HyundaiButtonBase, HyundaiLongitudinalBase + + class TestHyundaiCanfdBase(HyundaiButtonBase, common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTest): TX_MSGS = [[0x50, 0], [0x1CF, 1], [0x2A4, 0]] @@ -188,6 +190,7 @@ class TestHyundaiCanfdHDA2LongEV(HyundaiLongitudinalBase, TestHyundaiCanfdHDA2EV GAS_MSG = ("ACCELERATOR", "ACCELERATOR_PEDAL") STEER_BUS = 1 + def setUp(self): self.packer = CANPackerPanda("hyundai_canfd") self.safety = libpandasafety_py.libpandasafety @@ -202,5 +205,35 @@ class TestHyundaiCanfdHDA2LongEV(HyundaiLongitudinalBase, TestHyundaiCanfdHDA2EV return self.packer.make_can_msg_panda("SCC_CONTROL", 1, values) +class TestHyundaiCanfdHDALongHybrid(HyundaiLongitudinalBase, TestHyundaiCanfdHDA1Base): + + FWD_BLACKLISTED_ADDRS = {2: [0x12a, 0x1e0, 0x1a0]} + + DISABLED_ECU_UDS_MSG = (0x730, 1) + DISABLED_ECU_ACTUATION_MSG = (0x1a0, 0) + + STEER_MSG = "LFA" + GAS_MSG = ("ACCELERATOR_ALT", "ACCELERATOR_PEDAL") + STEER_BUS = 0 + SCC_BUS = 2 + + def setUp(self): + self.packer = CANPackerPanda("hyundai_canfd") + self.safety = libpandasafety_py.libpandasafety + self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CAMERA_SCC | Panda.FLAG_HYUNDAI_LONG | Panda.FLAG_HYUNDAI_HYBRID_GAS) + self.safety.init_tests() + + def _accel_msg(self, accel, aeb_req=False, aeb_decel=0): + values = { + "aReqRaw": accel, + "aReqValue": accel, + } + return self.packer.make_can_msg_panda("SCC_CONTROL", 0, values) + + # no knockout + def test_tester_present_allowed(self): + pass + + if __name__ == "__main__": unittest.main()