Skip to content

Commit

Permalink
Hyundai: fix brake pressed bitmask (#1724)
Browse files Browse the repository at this point in the history
* fix

* test this
  • Loading branch information
sshane authored Nov 18, 2023
1 parent 7c84475 commit 3b165ed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static int hyundai_rx_hook(CANPacket_t *to_push) {
}

if (addr == 0x394) {
brake_pressed = ((GET_BYTE(to_push, 5) >> 5U) & 0x2U) == 0x2U;
brake_pressed = ((GET_BYTE(to_push, 5) >> 5U) & 0x3U) == 0x2U;
}

bool stock_ecu_detected = (addr == 0x340);
Expand Down
4 changes: 3 additions & 1 deletion tests/safety/test_hyundai.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import random
import unittest
from panda import Panda
from panda.tests.libpanda import libpanda_py
Expand Down Expand Up @@ -85,7 +86,8 @@ def _user_gas_msg(self, gas):
return self.packer.make_can_msg_panda("EMS16", 0, values, fix_checksum=checksum)

def _user_brake_msg(self, brake):
values = {"DriverOverride": 2 if brake else 0, "AliveCounterTCS": self.cnt_brake % 8}
values = {"DriverOverride": 2 if brake else random.choice((0, 1, 3)),
"AliveCounterTCS": self.cnt_brake % 8}
self.__class__.cnt_brake += 1
return self.packer.make_can_msg_panda("TCS13", 0, values, fix_checksum=checksum)

Expand Down

0 comments on commit 3b165ed

Please sign in to comment.