From 715b1a1695b91d01576f5104352f2a9f327502c3 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Wed, 15 Apr 2020 19:33:41 -0700 Subject: [PATCH] Hyundai-Kia-Genesis (HKG) (#503) * update hkg steer torque message * misra * Get bus * Allow sending LFA HDA message * Add blacklisted addr * Update safety replay * Cleanup bus checks * Update to new torque message --- board/safety/safety_hyundai.h | 13 +++++++------ tests/safety/test_hyundai.py | 10 +++++----- tests/safety_replay/test_safety_replay.py | 3 +-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index fdff6cc..1817b6b 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -6,7 +6,7 @@ const int HYUNDAI_MAX_RATE_DOWN = 7; const int HYUNDAI_DRIVER_TORQUE_ALLOWANCE = 50; const int HYUNDAI_DRIVER_TORQUE_FACTOR = 2; const int HYUNDAI_STANDSTILL_THRSLD = 30; // ~1kph -const AddrBus HYUNDAI_TX_MSGS[] = {{832, 0}, {1265, 0}}; +const AddrBus HYUNDAI_TX_MSGS[] = {{832, 0}, {1265, 0}, {1157, 0}}; // TODO: do checksum and counter checks AddrCheckStruct hyundai_rx_checks[] = { @@ -32,11 +32,12 @@ static int hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { bool unsafe_allow_gas = unsafe_mode & UNSAFE_DISABLE_DISENGAGE_ON_GAS; - if (valid && GET_BUS(to_push) == 0) { - int addr = GET_ADDR(to_push); + int addr = GET_ADDR(to_push); + int bus = GET_BUS(to_push); - if (addr == 897) { - int torque_driver_new = ((GET_BYTES_04(to_push) >> 11) & 0xfff) - 2048; + if (valid && (bus == 0)) { + if (addr == 593) { + int torque_driver_new = ((GET_BYTES_04(to_push) & 0x7ff) * 0.79) - 808; // scale down new driver torque signal to match previous one // update array of samples update_sample(&hyundai_torque_driver, torque_driver_new); } @@ -170,7 +171,7 @@ static int hyundai_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { if (bus_num == 0) { bus_fwd = 2; } - if ((bus_num == 2) && (addr != 832)) { + if ((bus_num == 2) && (addr != 832) && (addr != 1157)) { bus_fwd = 0; } } diff --git a/tests/safety/test_hyundai.py b/tests/safety/test_hyundai.py index d1e3fd0..673770b 100644 --- a/tests/safety/test_hyundai.py +++ b/tests/safety/test_hyundai.py @@ -18,12 +18,11 @@ DRIVER_TORQUE_FACTOR = 2 class TestHyundaiSafety(common.PandaSafetyTest): - - TX_MSGS = [[832, 0], [1265, 0]] + TX_MSGS = [[832, 0], [1265, 0], [1157, 0]] STANDSTILL_THRESHOLD = 30 # ~1kph RELAY_MALFUNCTION_ADDR = 832 RELAY_MALFUNCTION_BUS = 0 - FWD_BLACKLISTED_ADDRS = {2: [832]} + FWD_BLACKLISTED_ADDRS = {2: [832, 1157]} FWD_BUS_LOOKUP = {0: 2, 2: 0} def setUp(self): @@ -57,9 +56,10 @@ class TestHyundaiSafety(common.PandaSafetyTest): self.safety.set_hyundai_desired_torque_last(t) self.safety.set_hyundai_rt_torque_last(t) + # TODO: this is unused def _torque_driver_msg(self, torque): - values = {"CR_Mdps_DrvTq": torque} - return self.packer.make_can_msg_panda("MDPS11", 0, values) + values = {"CR_Mdps_StrColTq": torque} + return self.packer.make_can_msg_panda("MDPS12", 0, values) def _torque_msg(self, torque): values = {"CR_Lkas_StrToqReq": torque} diff --git a/tests/safety_replay/test_safety_replay.py b/tests/safety_replay/test_safety_replay.py index dde81ac..1ba800a 100755 --- a/tests/safety_replay/test_safety_replay.py +++ b/tests/safety_replay/test_safety_replay.py @@ -15,12 +15,12 @@ logs = [ ("38bfd238edecbcd7|2019-06-07--10-15-25.bz2", Panda.SAFETY_TOYOTA, 66), # TOYOTA.PRIUS ("f89c604cf653e2bf|2018-09-29--13-46-50.bz2", Panda.SAFETY_GM, 0), # GM.VOLT ("0375fdf7b1ce594d|2019-05-21--20-10-33.bz2", Panda.SAFETY_HONDA_BOSCH_GIRAFFE, 1), # HONDA.ACCORD - ("02ec6bea180a4d36|2019-04-17--11-21-35.bz2", Panda.SAFETY_HYUNDAI, 0), # HYUNDAI.SANTA_FE ("6fb4948a7ebe670e|2019-11-12--00-35-53.bz2", Panda.SAFETY_CHRYSLER, 0), # CHRYSLER.PACIFICA_2018_HYBRID ("791340bc01ed993d|2019-04-08--10-26-00.bz2", Panda.SAFETY_SUBARU, 0), # SUBARU.IMPREZA ("76b83eb0245de90e|2020-03-05--19-16-05.bz2", Panda.SAFETY_VOLKSWAGEN_MQB, 0), # VOLKSWAGEN.GOLF (MK7) ("d12cd943127f267b|2020-03-27--15-57-18.bz2", Panda.SAFETY_VOLKSWAGEN_PQ, 0), # 2009 VW Passat R36 (B6), supporting OP port not yet upstreamed ("fbbfa6af821552b9|2020-03-03--08-09-43.bz2", Panda.SAFETY_NISSAN, 0), # NISSAN.XTRAIL + ("5b7c365c50084530_2020-04-15--16-13-24--3--rlog.bz2", Panda.SAFETY_HYUNDAI, 0), # HYUNDAI.SONATA ] if __name__ == "__main__": @@ -40,4 +40,3 @@ if __name__ == "__main__": for f in failed: print("\n**** failed on %s ****" % f) assert len(failed) == 0, "\nfailed on %d logs" % len(failed) -