From fb6bc3ba7e58f627db6cb9e6623b1d61b165bc3f Mon Sep 17 00:00:00 2001 From: Riccardo Date: Wed, 27 Nov 2019 00:19:41 -0800 Subject: [PATCH] Fix Misra --- board/safety/safety_chrysler.h | 2 +- board/safety/safety_ford.h | 2 +- board/safety/safety_gm.h | 2 +- board/safety/safety_honda.h | 2 +- board/safety/safety_hyundai.h | 2 +- board/safety/safety_mazda.h | 2 +- board/safety/safety_subaru.h | 2 +- board/safety/safety_toyota.h | 2 +- board/safety/safety_volkswagen.h | 2 +- board/safety_declarations.h | 2 ++ 10 files changed, 11 insertions(+), 9 deletions(-) diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index 129b7137a79938..ce9f65f2afc536 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -37,7 +37,7 @@ static void chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // check if stock camera ECU is on bus 0 - if ((safety_mode_cnt > 1) && (bus == 0) && (addr == 0x292)) { + if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == 0) && (addr == 0x292)) { relay_malfunction = true; } } diff --git a/board/safety/safety_ford.h b/board/safety/safety_ford.h index 689f9d25d38f87..47c7342a448a51 100644 --- a/board/safety/safety_ford.h +++ b/board/safety/safety_ford.h @@ -55,7 +55,7 @@ static void ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { ford_gas_prev = gas; } - if ((safety_mode_cnt > 1) && (bus == 0) && (addr == 0x3CA)) { + if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == 0) && (addr == 0x3CA)) { relay_malfunction = true; } } diff --git a/board/safety/safety_gm.h b/board/safety/safety_gm.h index b1cc2a1ea0b02f..92c32ad8086a7d 100644 --- a/board/safety/safety_gm.h +++ b/board/safety/safety_gm.h @@ -100,7 +100,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // on powertrain bus. // 384 = ASCMLKASteeringCmd // 715 = ASCMGasRegenCmd - if ((safety_mode_cnt > 1) && (bus == 0) && ((addr == 384) || (addr == 715))) { + if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == 0) && ((addr == 384) || (addr == 715))) { relay_malfunction = true; } } diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index 8f5e14cbe4b4b5..4cef17f79d0ed5 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -104,7 +104,7 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // if steering controls messages are received on the destination bus, it's an indication // that the relay might be malfunctioning int bus_rdr_car = (board_has_relay()) ? 0 : 2; // radar bus, car side - if ((safety_mode_cnt > 1) && ((addr == 0xE4) || (addr == 0x194))) { + if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && ((addr == 0xE4) || (addr == 0x194))) { if ((honda_bosch_hardware && (bus == bus_rdr_car)) || (!honda_bosch_hardware && (bus == 0))) { relay_malfunction = true; diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index 19e2b29ffd822d..b2d215f6876217 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -25,7 +25,7 @@ static void hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // check if stock camera ECU is on bus 0 - if ((safety_mode_cnt > 1) && (bus == 0) && (addr == 832)) { + if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == 0) && (addr == 832)) { relay_malfunction = true; } diff --git a/board/safety/safety_mazda.h b/board/safety/safety_mazda.h index 5c1b6c51deeccc..f1215f23da2acb 100644 --- a/board/safety/safety_mazda.h +++ b/board/safety/safety_mazda.h @@ -55,7 +55,7 @@ void mazda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // if we see wheel speed msgs on MAZDA_CAM bus then relay is closed - if ((safety_mode_cnt > 1) && (bus == MAZDA_CAM) && (addr == MAZDA_WHEEL_SPEED)) { + if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == MAZDA_CAM) && (addr == MAZDA_WHEEL_SPEED)) { relay_malfunction = true; } } diff --git a/board/safety/safety_subaru.h b/board/safety/safety_subaru.h index 402cbbcd5255e7..66e5947f856dfb 100644 --- a/board/safety/safety_subaru.h +++ b/board/safety/safety_subaru.h @@ -41,7 +41,7 @@ static void subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { subaru_cruise_engaged_last = cruise_engaged; } - if ((safety_mode_cnt > 1) && (bus == 0) && ((addr == 0x122) || (addr == 0x164))) { + if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == 0) && ((addr == 0x122) || (addr == 0x164))) { relay_malfunction = true; } } diff --git a/board/safety/safety_toyota.h b/board/safety/safety_toyota.h index 1bd0382fd7c3f3..5555382eaf0a74 100644 --- a/board/safety/safety_toyota.h +++ b/board/safety/safety_toyota.h @@ -92,7 +92,7 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // 0x2E4 is lkas cmd. If it is on bus 0, then relay is unexpectedly closed - if ((safety_mode_cnt > 1) && (addr == 0x2E4) && (bus == 0)) { + if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (addr == 0x2E4) && (bus == 0)) { relay_malfunction = true; } } diff --git a/board/safety/safety_volkswagen.h b/board/safety/safety_volkswagen.h index 26ea03d7a4fc51..0f79b8607752ad 100644 --- a/board/safety/safety_volkswagen.h +++ b/board/safety/safety_volkswagen.h @@ -56,7 +56,7 @@ static void volkswagen_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { volkswagen_gas_prev = gas; } - if ((safety_mode_cnt > 1) && (bus == 0) && (addr == MSG_HCA_01)) { + if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == 0) && (addr == MSG_HCA_01)) { relay_malfunction = true; } } diff --git a/board/safety_declarations.h b/board/safety_declarations.h index 81a242a1db440a..e192d74fb7c345 100644 --- a/board/safety_declarations.h +++ b/board/safety_declarations.h @@ -57,6 +57,8 @@ bool long_controls_allowed = true; // time since safety mode has been changed uint32_t safety_mode_cnt = 0U; +// allow 1s of transition timeout after relay changes state before assessing malfunctioning +const uint32_t RELAY_TRNS_TIMEOUT = 1U; // avg between 2 tracks #define GET_INTERCEPTOR(msg) (((GET_BYTE((msg), 0) << 8) + GET_BYTE((msg), 1) + ((GET_BYTE((msg), 2) << 8) + GET_BYTE((msg), 3)) / 2 ) / 2)