mirror of https://github.com/commaai/panda.git
Hyundai: only allow cancel while cruise is enabled (#870)
This commit is contained in:
parent
891653fe31
commit
5a7af82f06
|
@ -324,16 +324,17 @@ static int hyundai_tx_hook(CANPacket_t *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
|
||||
if ((addr == 1265) && !controls_allowed) {
|
||||
if ((GET_BYTES_04(to_send) & 0x7U) != 4U) {
|
||||
// BUTTONS: used for resume spamming and cruise cancellation
|
||||
if ((addr == 1265) && !hyundai_longitudinal) {
|
||||
int button = GET_BYTE(to_send, 0) & 0x7U;
|
||||
|
||||
bool allowed_resume = (button == 1) && controls_allowed;
|
||||
bool allowed_cancel = (button == 4) && cruise_engaged_prev;
|
||||
if (!(allowed_resume || allowed_cancel)) {
|
||||
tx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 1 allows the message through
|
||||
return tx;
|
||||
}
|
||||
|
||||
|
|
|
@ -203,14 +203,23 @@ class TestHyundaiSafety(common.PandaSafetyTest):
|
|||
self.assertTrue(self._tx(self._torque_msg(sign * (MAX_RT_DELTA - 1))))
|
||||
self.assertTrue(self._tx(self._torque_msg(sign * (MAX_RT_DELTA + 1))))
|
||||
|
||||
def test_spam_cancel_safety_check(self):
|
||||
def test_buttons(self):
|
||||
"""
|
||||
Only RES and CANCEL buttons are allowed
|
||||
- RES allowed while controls allowed
|
||||
- CANCEL allowed while cruise is enabled
|
||||
"""
|
||||
self.safety.set_controls_allowed(0)
|
||||
self.assertTrue(self._tx(self._button_msg(Buttons.CANCEL)))
|
||||
self.assertFalse(self._tx(self._button_msg(Buttons.RESUME)))
|
||||
self.assertFalse(self._tx(self._button_msg(Buttons.SET)))
|
||||
# do not block resume if we are engaged already
|
||||
|
||||
self.safety.set_controls_allowed(1)
|
||||
self.assertTrue(self._tx(self._button_msg(Buttons.RESUME)))
|
||||
self.assertFalse(self._tx(self._button_msg(Buttons.SET)))
|
||||
|
||||
for enabled in (True, False):
|
||||
self._rx(self._pcm_status_msg(enabled))
|
||||
self.assertEqual(enabled, self._tx(self._button_msg(Buttons.CANCEL)))
|
||||
|
||||
|
||||
class TestHyundaiLegacySafety(TestHyundaiSafety):
|
||||
|
@ -264,6 +273,9 @@ class TestHyundaiLongitudinalSafety(TestHyundaiSafety):
|
|||
def test_cruise_engaged_prev(self):
|
||||
pass
|
||||
|
||||
def test_buttons(self):
|
||||
pass
|
||||
|
||||
def _pcm_status_msg(self, enable):
|
||||
raise NotImplementedError
|
||||
|
||||
|
|
Loading…
Reference in New Issue