diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index c4e26cf46f8237..8c897115513567 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -102,12 +102,13 @@ static int chrysler_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 when controls are off. - // This avoids unintended engagements while still allowing resume spam - // TODO! + // FORCE CANCEL: only the cancel button press is allowed + if (addr == 571) { + if (GET_BYTE(to_send, 0) != 1) { + tx = 0; + } + } - // 1 allows the message through return tx; } diff --git a/tests/safety/test_chrysler.py b/tests/safety/test_chrysler.py index de3e5ae08f239c..2ddd3aff8ac06a 100755 --- a/tests/safety/test_chrysler.py +++ b/tests/safety/test_chrysler.py @@ -16,23 +16,6 @@ TX_MSGS = [[571, 0], [658, 0], [678, 0]] -def twos_comp(val, bits): - if val >= 0: - return val - else: - return (2**bits) + val - -def sign(a): - if a > 0: - return 1 - else: - return -1 - -def swap_bytes(data_str): - """Accepts string with hex, returns integer with order swapped for CAN.""" - a = int(data_str, 16) - return ((a & 0xff) << 24) + ((a & 0xff00) << 8) + ((a & 0x00ff0000) >> 8) + ((a & 0xff000000) >> 24) - class TestChryslerSafety(unittest.TestCase): @classmethod def setUp(cls): @@ -42,7 +25,7 @@ def setUp(cls): def _button_msg(self, buttons): to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *') - to_send[0].RIR = 1265 << 21 + to_send[0].RIR = 571 << 21 to_send[0].RDLR = buttons return to_send @@ -178,6 +161,14 @@ def test_torque_measurements(self): self.assertEqual(0, self.safety.get_chrysler_torque_meas_max()) self.assertEqual(0, self.safety.get_chrysler_torque_meas_min()) + def test_cancel_button(self): + CANCEL = 1 + for b in range(0, 0xff): + if b == CANCEL: + self.assertTrue(self.safety.safety_tx_hook(self._button_msg(b))) + else: + self.assertFalse(self.safety.safety_tx_hook(self._button_msg(b))) + def test_fwd_hook(self): buss = list(range(0x0, 0x3)) msgs = list(range(0x1, 0x800))