Skip to content

Commit

Permalink
Safety Chrysler: Added cancel spam button check
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiasini committed Nov 18, 2019
1 parent d44b562 commit 212d336
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
11 changes: 6 additions & 5 deletions board/safety/safety_chrysler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
27 changes: 9 additions & 18 deletions tests/safety/test_chrysler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 212d336

Please sign in to comment.