Skip to content

Commit

Permalink
Hyundai: steering fault bit safety (#1095)
Browse files Browse the repository at this point in the history
comment

smaller comment

simpler test

check controls allowed

more classical

more like the buttons

revert

flip
  • Loading branch information
sshane authored Oct 11, 2022
1 parent aaa70b1 commit 2334a41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ static int hyundai_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
if (addr == 832) {
int desired_torque = ((GET_BYTES_04(to_send) >> 16) & 0x7ffU) - 1024U;
bool steer_req = GET_BIT(to_send, 27U) != 0U;
bool toi_flt = GET_BIT(to_send, 28U) != 0U;
if (toi_flt && !controls_allowed) {
tx = 0;
}

if (steer_torque_cmd_checks(desired_torque, steer_req, HYUNDAI_STEERING_LIMITS)) {
tx = 0;
Expand Down
12 changes: 10 additions & 2 deletions tests/safety/test_hyundai.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ def _torque_driver_msg(self, torque):
values = {"CR_Mdps_StrColTq": torque}
return self.packer.make_can_msg_panda("MDPS12", 0, values)

def _torque_cmd_msg(self, torque, steer_req=1):
values = {"CR_Lkas_StrToqReq": torque, "CF_Lkas_ActToi": steer_req}
def _torque_cmd_msg(self, torque, steer_req=1, toi_flt=0):
values = {"CR_Lkas_StrToqReq": torque, "CF_Lkas_ActToi": steer_req, "CF_Lkas_ToiFlt": toi_flt}
return self.packer.make_can_msg_panda("LKAS11", 0, values)

def test_steer_req_bit(self):
Expand All @@ -194,6 +194,14 @@ def test_steer_req_bit(self):
for _ in range(100):
self.assertTrue(self._tx(self._torque_cmd_msg(self.MAX_TORQUE, steer_req=1)))

def test_toi_flt_bit(self):
# No actuation of fault bit while controls are not allowed
for controls_allowed in [True, False]:
for toi_flt in [0, 1]:
self.safety.set_controls_allowed(controls_allowed)
should_tx = toi_flt == 0 or controls_allowed
self.assertEqual(should_tx, self._tx(self._torque_cmd_msg(0, toi_flt=toi_flt)))


class TestHyundaiSafetyCameraSCC(TestHyundaiSafety):
BUTTONS_BUS = 2 # tx on 2, rx on 0
Expand Down

0 comments on commit 2334a41

Please sign in to comment.