Skip to content

Commit

Permalink
Hyundai: support non-HDA2 EV gas signals (commaai#1100)
Browse files Browse the repository at this point in the history
* Hyundai: support non-HDA2 EV gas signals

* update tests
  • Loading branch information
adeebshihadeh authored Oct 13, 2022
1 parent 622ce92 commit de38096
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ static int hyundai_rx_hook(CANPacket_t *to_push) {
hyundai_common_cruise_buttons_check(cruise_button, main_button);
}

// read gas pressed signal
// gas press, different for EV, hybrid, and ICE models
if ((addr == 881) && hyundai_ev_gas_signal) {
gas_pressed = (((GET_BYTE(to_push, 4) & 0x7FU) << 1) | GET_BYTE(to_push, 3) >> 7) != 0U;
} else if ((addr == 881) && hyundai_hybrid_gas_signal) {
gas_pressed = GET_BYTE(to_push, 7) != 0U;
} else if (addr == 608) { // ICE
} else if ((addr == 608) && !hyundai_ev_gas_signal && !hyundai_hybrid_gas_signal) {
gas_pressed = (GET_BYTE(to_push, 7) >> 6) != 0U;
} else {
}
Expand Down
9 changes: 5 additions & 4 deletions board/safety/safety_hyundai_canfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const CanMsg HYUNDAI_CANFD_HDA1_TX_MSGS[] = {

AddrCheckStruct hyundai_canfd_addr_checks[] = {
{.msg = {{0x35, 1, 32, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 10000U},
{0x105, 0, 32, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 10000U}, { 0 }}},
{0x35, 0, 32, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 10000U},
{0x105, 0, 32, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 10000U}}},
{.msg = {{0x65, 1, 32, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 10000U},
{0x65, 0, 32, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 10000U}, { 0 }}},
{.msg = {{0xa0, 1, 24, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 10000U},
Expand Down Expand Up @@ -152,10 +153,10 @@ static int hyundai_canfd_rx_hook(CANPacket_t *to_push) {
hyundai_common_cruise_state_check(cruise_engaged);
}

// gas press
if ((addr == 0x35) && hyundai_canfd_hda2) {
// gas press, different for EV, hybrid, and ICE models
if ((addr == 0x35) && hyundai_ev_gas_signal) {
gas_pressed = GET_BYTE(to_push, 5) != 0U;
} else if ((addr == 0x105) && !hyundai_canfd_hda2) {
} else if ((addr == 0x105) && !hyundai_ev_gas_signal && !hyundai_hybrid_gas_signal) {
gas_pressed = (GET_BIT(to_push, 103U) != 0U) || (GET_BYTE(to_push, 13) != 0U) || (GET_BIT(to_push, 112U) != 0U);
} else {
}
Expand Down
4 changes: 2 additions & 2 deletions tests/safety/test_hyundai_canfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class TestHyundaiCanfdHDA2(TestHyundaiCanfdBase):
def setUp(self):
self.packer = CANPackerPanda("hyundai_canfd")
self.safety = libpandasafety_py.libpandasafety
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CANFD_HDA2)
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CANFD_HDA2 | Panda.FLAG_HYUNDAI_EV_GAS)
self.safety.init_tests()


Expand All @@ -145,7 +145,7 @@ class TestHyundaiCanfdHDA2Long(HyundaiLongitudinalBase, TestHyundaiCanfdHDA2):
def setUp(self):
self.packer = CANPackerPanda("hyundai_canfd")
self.safety = libpandasafety_py.libpandasafety
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CANFD_HDA2 | Panda.FLAG_HYUNDAI_LONG)
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CANFD_HDA2 | Panda.FLAG_HYUNDAI_LONG | Panda.FLAG_HYUNDAI_EV_GAS)
self.safety.init_tests()

def _accel_msg(self, accel, aeb_req=False, aeb_decel=0):
Expand Down

0 comments on commit de38096

Please sign in to comment.