From d063a188853a5d237ff4b037854a191807e45dc7 Mon Sep 17 00:00:00 2001 From: Riccardo Date: Wed, 13 Nov 2019 23:57:07 -0800 Subject: [PATCH] Hyundai safety: re-enable button spam safety check --- board/safety/safety_hyundai.h | 11 +++++------ tests/safety/test_hyundai.py | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index 21796e4caaf128..2e49f34f73d58b 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -115,12 +115,11 @@ static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // FORCE CANCEL: safety check only relevant when spamming the cancel button. // ensuring that only the cancel button press is sent (VAL 4) when controls are off. // This avoids unintended engagements while still allowing resume spam - // TODO: fix bug preventing the button msg to be fwd'd on bus 2 - //if ((addr == 1265) && !controls_allowed && (bus == 0) { - // if ((GET_BYTES_04(to_send) & 0x7) != 4) { - // tx = 0; - // } - //} + if ((addr == 1265) && !controls_allowed) { + if ((GET_BYTES_04(to_send) & 0x7) != 4) { + tx = 0; + } + } // 1 allows the message through return tx; diff --git a/tests/safety/test_hyundai.py b/tests/safety/test_hyundai.py index 3cf8cb7c71bf0a..0821fafa4bf119 100644 --- a/tests/safety/test_hyundai.py +++ b/tests/safety/test_hyundai.py @@ -176,18 +176,18 @@ def test_realtime_limits(self): self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) - #def test_spam_cancel_safety_check(self): - # RESUME_BTN = 1 - # SET_BTN = 2 - # CANCEL_BTN = 4 - # BUTTON_MSG = 1265 - # self.safety.set_controls_allowed(0) - # self.assertTrue(self.safety.safety_tx_hook(self._button_msg(CANCEL_BTN))) - # self.assertFalse(self.safety.safety_tx_hook(self._button_msg(RESUME_BTN))) - # self.assertFalse(self.safety.safety_tx_hook(self._button_msg(SET_BTN))) - # # do not block resume if we are engaged already - # self.safety.set_controls_allowed(1) - # self.assertTrue(self.safety.safety_tx_hook(self._button_msg(RESUME_BTN))) + def test_spam_cancel_safety_check(self): + RESUME_BTN = 1 + SET_BTN = 2 + CANCEL_BTN = 4 + BUTTON_MSG = 1265 + self.safety.set_controls_allowed(0) + self.assertTrue(self.safety.safety_tx_hook(self._button_msg(CANCEL_BTN))) + self.assertFalse(self.safety.safety_tx_hook(self._button_msg(RESUME_BTN))) + self.assertFalse(self.safety.safety_tx_hook(self._button_msg(SET_BTN))) + # do not block resume if we are engaged already + self.safety.set_controls_allowed(1) + self.assertTrue(self.safety.safety_tx_hook(self._button_msg(RESUME_BTN))) def test_fwd_hook(self):