Skip to content

Commit

Permalink
Hyundai safety: re-enable button spam safety check
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiasini committed Nov 14, 2019
1 parent 4d1edc0 commit d063a18
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
11 changes: 5 additions & 6 deletions board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 12 additions & 12 deletions tests/safety/test_hyundai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit d063a18

Please sign in to comment.