Skip to content

Commit

Permalink
Toyota: using a more generalized CRUISE_ACTIVE bit that works on all …
Browse files Browse the repository at this point in the history
…cars
  • Loading branch information
rbiasini committed Nov 4, 2018
1 parent 6f157aa commit 8291971
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {

// enter controls on rising edge of ACC, exit controls on ACC off
if ((to_push->RIR>>21) == 0x1D2) {
// 4 bits: 55-52
int cruise_engaged = to_push->RDHR & 0xF00000;
// 5th bit is CRUISE_ACTIVE
int cruise_engaged = to_push->RDLR & 0x20;
if (cruise_engaged && !toyota_cruise_engaged_last) {
controls_allowed = 1;
} else if (!cruise_engaged) {
Expand Down
8 changes: 4 additions & 4 deletions tests/safety/test_toyota.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ def test_manually_enable_controls_allowed(self):
def test_enable_control_allowed_from_cruise(self):
to_push = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
to_push[0].RIR = 0x1D2 << 21
to_push[0].RDHR = 0xF00000
to_push[0].RDLR = 0x20

self.safety.toyota_rx_hook(to_push)
self.assertTrue(self.safety.get_controls_allowed())

def test_disable_control_allowed_from_cruise(self):
to_push = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
to_push[0].RIR = 0x1D2 << 21
to_push[0].RDHR = 0
to_push[0].RDLR = 0

self.safety.set_controls_allowed(1)
self.safety.toyota_rx_hook(to_push)
Expand Down Expand Up @@ -373,15 +373,15 @@ def test_angle_cmd_rate_when_enabled(self):
self.assertTrue(self.safety.get_controls_allowed())

# now inject too high rates
self.assertEqual(False, self.safety.toyota_ipas_tx_hook(self._ipas_control_msg(a + sign(a) *
self.assertEqual(False, self.safety.toyota_ipas_tx_hook(self._ipas_control_msg(a + sign(a) *
(max_delta_up + 1), 1)))
self.assertFalse(self.safety.get_controls_allowed())
self.safety.set_controls_allowed(1)
self.assertEqual(True, self.safety.toyota_ipas_tx_hook(self._ipas_control_msg(a + sign(a) * max_delta_up, 1)))
self.assertTrue(self.safety.get_controls_allowed())
self.assertEqual(True, self.safety.toyota_ipas_tx_hook(self._ipas_control_msg(a, 1)))
self.assertTrue(self.safety.get_controls_allowed())
self.assertEqual(False, self.safety.toyota_ipas_tx_hook(self._ipas_control_msg(a - sign(a) *
self.assertEqual(False, self.safety.toyota_ipas_tx_hook(self._ipas_control_msg(a - sign(a) *
(max_delta_down + 1), 1)))
self.assertFalse(self.safety.get_controls_allowed())

Expand Down

0 comments on commit 8291971

Please sign in to comment.