From 51a254f78ef3b6fdc0235e3524d64f57b959d789 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 6 Sep 2023 23:08:34 -0700 Subject: [PATCH] common addrs behind macros --- board/safety/safety_hyundai.h | 36 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index 66cf5c2ec4..dec473b53d 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -51,40 +51,38 @@ const CanMsg HYUNDAI_CAMERA_SCC_TX_MSGS[] = { {0x485, 0, 4}, // LFAHDA_MFC Bus 0 }; +#define HYUNDAI_COMMON_ADDR_CHECKS(legacy) \ + {.msg = {{0x260, 0, 8, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U}, \ + {0x371, 0, 8, .expected_timestep = 10000U}, { 0 }}}, \ + {.msg = {{0x386, 0, 8, .check_checksum = !legacy, .max_counter = legacy ? 0U : 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, \ + {.msg = {{0x394, 0, 8, .check_checksum = !legacy, .max_counter = legacy ? 0U : 7U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, \ + +#define HYUNDAI_SCC12_ADDR_CHECK(scc_bus) \ + {.msg = {{0x421, scc_bus, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, \ + AddrCheckStruct hyundai_addr_checks[] = { - {.msg = {{0x260, 0, 8, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U}, - {0x371, 0, 8, .expected_timestep = 10000U}, { 0 }}}, - {.msg = {{0x386, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, - {.msg = {{0x394, 0, 8, .check_checksum = true, .max_counter = 7U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, - {.msg = {{0x421, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, + HYUNDAI_COMMON_ADDR_CHECKS(false) + HYUNDAI_SCC12_ADDR_CHECK(0) }; #define HYUNDAI_ADDR_CHECK_LEN (sizeof(hyundai_addr_checks) / sizeof(hyundai_addr_checks[0])) AddrCheckStruct hyundai_cam_scc_addr_checks[] = { - {.msg = {{0x260, 0, 8, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U}, - {0x371, 0, 8, .expected_timestep = 10000U}, { 0 }}}, - {.msg = {{0x386, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, - {.msg = {{0x394, 0, 8, .check_checksum = true, .max_counter = 7U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, - {.msg = {{0x421, 2, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, + HYUNDAI_COMMON_ADDR_CHECKS(false) + HYUNDAI_SCC12_ADDR_CHECK(2) }; #define HYUNDAI_CAM_SCC_ADDR_CHECK_LEN (sizeof(hyundai_cam_scc_addr_checks) / sizeof(hyundai_cam_scc_addr_checks[0])) AddrCheckStruct hyundai_long_addr_checks[] = { - {.msg = {{0x260, 0, 8, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U}, - {0x371, 0, 8, .expected_timestep = 10000U}, { 0 }}}, - {.msg = {{0x386, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, - {.msg = {{0x394, 0, 8, .check_checksum = true, .max_counter = 7U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, + HYUNDAI_COMMON_ADDR_CHECKS(false) + // Use CLU11 (buttons) to manage controls allowed instead of SCC cruise state {.msg = {{0x4F1, 0, 4, .check_checksum = false, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, }; #define HYUNDAI_LONG_ADDR_CHECK_LEN (sizeof(hyundai_long_addr_checks) / sizeof(hyundai_long_addr_checks[0])) // older hyundai models have less checks due to missing counters and checksums AddrCheckStruct hyundai_legacy_addr_checks[] = { - {.msg = {{0x260, 0, 8, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U}, - {0x371, 0, 8, .expected_timestep = 10000U}, { 0 }}}, - {.msg = {{0x386, 0, 8, .expected_timestep = 10000U}, { 0 }, { 0 }}}, - {.msg = {{0x394, 0, 8, .expected_timestep = 10000U}, { 0 }, { 0 }}}, - {.msg = {{0x421, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, + HYUNDAI_COMMON_ADDR_CHECKS(true) + HYUNDAI_SCC12_ADDR_CHECK(0) }; #define HYUNDAI_LEGACY_ADDR_CHECK_LEN (sizeof(hyundai_legacy_addr_checks) / sizeof(hyundai_legacy_addr_checks[0]))