Skip to content

Commit

Permalink
Toyota: add AEB message TX checks (#820)
Browse files Browse the repository at this point in the history
* Toyota: add AEB message TX checks

* misra
  • Loading branch information
adeebshihadeh authored Jan 6, 2022
1 parent 79f5e6f commit f5857bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ static int toyota_tx_hook(CANPacket_t *to_send) {
}
}

// AEB: block all actuation. only used when DSU is unplugged
if (addr == 0x283) {
// only allow the checksum, which is the last byte
bool block = (GET_BYTES_04(to_send) != 0U) || (GET_BYTE(to_send, 4) != 0U) || (GET_BYTE(to_send, 5) != 0U);
if (block) {
tx = 0;
}
}

// LTA steering check
// only sent to prevent dash errors, no actuation is accepted
if (addr == 0x191) {
Expand Down
13 changes: 12 additions & 1 deletion tests/safety/test_toyota.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,23 @@ def _pcm_status_msg(self, enable):
# Toyota gas gains are the same
def _interceptor_msg(self, gas, addr):
to_send = make_msg(0, addr, 6)
to_send[0].data[0] = (gas & 0xFF00) >> 8
to_send[0].data[0] = (gas & 0xFF00) >> 8
to_send[0].data[1] = gas & 0xFF
to_send[0].data[2] = (gas & 0xFF00) >> 8
to_send[0].data[3] = gas & 0xFF
return to_send

def test_block_aeb(self):
for controls_allowed in (True, False):
for bad in (True, False):
for _ in range(10):
self.safety.set_controls_allowed(controls_allowed)
dat = [random.randint(1, 255) for _ in range(7)]
if not bad:
dat = [0]*6 + dat[-1:]
msg = common.package_can_msg([0x283, 0, bytes(dat), 0])
self.assertEqual(not bad, self._tx(msg))

def test_accel_actuation_limits(self):
limits = ((MIN_ACCEL, MAX_ACCEL, UNSAFE_MODE.DEFAULT),
(MIN_ACCEL, MAX_ACCEL, UNSAFE_MODE.RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX))
Expand Down

0 comments on commit f5857bc

Please sign in to comment.