Skip to content

Commit

Permalink
Hyundai CAN-FD: fix SCC bus for HDA1
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh committed Oct 20, 2022
1 parent 24ccc34 commit 723e60c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
17 changes: 10 additions & 7 deletions board/safety/safety_hyundai_canfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ AddrCheckStruct hyundai_canfd_addr_checks[] = {
{.msg = {{0xea, 1, 24, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 10000U},
{0xea, 0, 24, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 10000U}, { 0 }}},
{.msg = {{0x1a0, 1, 32, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 20000U},
{0x1a0, 0, 32, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 20000U}, { 0 }}},
{0x1a0, 2, 32, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 20000U}, { 0 }}},
{.msg = {{0x1cf, 1, 8, .check_checksum = false, .max_counter = 0xfU, .expected_timestep = 20000U},
{0x1cf, 0, 8, .check_checksum = false, .max_counter = 0xfU, .expected_timestep = 20000U},
{0x1aa, 0, 16, .check_checksum = false, .max_counter = 0xffU, .expected_timestep = 20000U}}},
Expand Down Expand Up @@ -146,6 +146,7 @@ static int hyundai_canfd_rx_hook(CANPacket_t *to_push) {
int addr = GET_ADDR(to_push);

const int pt_bus = hyundai_canfd_hda2 ? 1 : 0;
const int scc_bus = hyundai_canfd_hda2 ? 1 : 2;

if (valid && (bus == pt_bus)) {
// driver torque
Expand All @@ -170,12 +171,6 @@ static int hyundai_canfd_rx_hook(CANPacket_t *to_push) {
hyundai_common_cruise_buttons_check(cruise_button, main_button);
}

// cruise state
if ((addr == 0x1a0) && !hyundai_longitudinal) {
bool cruise_engaged = ((GET_BYTE(to_push, 8) >> 4) & 0x3U) != 0U;
hyundai_common_cruise_state_check(cruise_engaged);
}

// gas press, different for EV, hybrid, and ICE models
if ((addr == 0x35) && hyundai_ev_gas_signal) {
gas_pressed = GET_BYTE(to_push, 5) != 0U;
Expand All @@ -199,6 +194,14 @@ static int hyundai_canfd_rx_hook(CANPacket_t *to_push) {
}
}

if (valid && (bus == scc_bus)) {
// cruise state
if ((addr == 0x1a0) && !hyundai_longitudinal) {
bool cruise_engaged = ((GET_BYTE(to_push, 8) >> 4) & 0x3U) != 0U;
hyundai_common_cruise_state_check(cruise_engaged);
}
}

const int steer_addr = hyundai_canfd_hda2 ? 0x50 : 0x12a;
bool stock_ecu_detected = (addr == steer_addr) && (bus == 0);
if (hyundai_longitudinal) {
Expand Down
2 changes: 1 addition & 1 deletion tests/safety/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool addr_checks_valid() {
const AddrCheckStruct addr = current_rx_checks->check[i];
bool valid = addr.msg_seen && !addr.lagging && addr.valid_checksum && (addr.wrong_counters < MAX_WRONG_COUNTERS);
if (!valid) {
//printf("seen %d lagging %d valid checksum %d wrong counters %d\n", addr.msg_seen, addr.lagging, addr.valid_checksum, addr.wrong_counters);
printf("i %d seen %d lagging %d valid checksum %d wrong counters %d\n", i, addr.msg_seen, addr.lagging, addr.valid_checksum, addr.wrong_counters);
return false;
}
}
Expand Down
4 changes: 3 additions & 1 deletion tests/safety/test_hyundai_canfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TestHyundaiCanfdBase(HyundaiButtonBase, common.PandaSafetyTest, common.Dri
MIN_VALID_STEERING_RT_INTERVAL = 810000 # a ~10% buffer, can send steer up to 110Hz

PT_BUS = 0
SCC_BUS = 2
STEER_BUS = 0
STEER_MSG = ""
BUTTONS_TX_BUS = 1
Expand Down Expand Up @@ -64,7 +65,7 @@ def _user_gas_msg(self, gas):

def _pcm_status_msg(self, enable):
values = {"CRUISE_STATUS": 3 if enable else 0}
return self.packer.make_can_msg_panda("CRUISE_INFO", self.PT_BUS, values)
return self.packer.make_can_msg_panda("CRUISE_INFO", self.SCC_BUS, values)

def _button_msg(self, buttons, main_button=0, bus=None):
if bus is None:
Expand Down Expand Up @@ -132,6 +133,7 @@ class TestHyundaiCanfdHDA2(TestHyundaiCanfdBase):
FWD_BUS_LOOKUP = {0: 2, 2: 0}

PT_BUS = 1
SCC_BUS = 1
STEER_MSG = "LKAS"

def setUp(self):
Expand Down

0 comments on commit 723e60c

Please sign in to comment.