From 3f25ccabd6c46ba06bf32fb15b221c2fcdfc5191 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Wed, 8 Nov 2023 18:27:20 -0500 Subject: [PATCH] Subaru Pre-Global: Reverse driver torque signal for certain platforms (#1648) * Subaru Pre-Global: Reverse driver torque signal for certain platforms * added flag * fix tests * use dbc instead * duplicate --------- Co-authored-by: Shane Smiskol Co-authored-by: Justin Newberry Co-authored-by: Justin Newberry --- board/safety/safety_subaru_preglobal.h | 8 +++++++- python/__init__.py | 2 ++ tests/safety/test_subaru_preglobal.py | 11 +++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/board/safety/safety_subaru_preglobal.h b/board/safety/safety_subaru_preglobal.h index f644d339..145a5cfa 100644 --- a/board/safety/safety_subaru_preglobal.h +++ b/board/safety/safety_subaru_preglobal.h @@ -39,6 +39,11 @@ AddrCheckStruct subaru_preglobal_addr_checks[] = { #define SUBARU_PG_ADDR_CHECK_LEN (sizeof(subaru_preglobal_addr_checks) / sizeof(subaru_preglobal_addr_checks[0])) addr_checks subaru_preglobal_rx_checks = {subaru_preglobal_addr_checks, SUBARU_PG_ADDR_CHECK_LEN}; + +const int SUBARU_PG_PARAM_REVERSED_DRIVER_TORQUE = 1; +bool subaru_pg_reversed_driver_torque = false; + + static int subaru_preglobal_rx_hook(CANPacket_t *to_push) { bool valid = addr_safety_check(to_push, &subaru_preglobal_rx_checks, NULL, NULL, NULL, NULL); @@ -51,6 +56,7 @@ static int subaru_preglobal_rx_hook(CANPacket_t *to_push) { int torque_driver_new; torque_driver_new = (GET_BYTE(to_push, 3) >> 5) + (GET_BYTE(to_push, 4) << 3); torque_driver_new = to_signed(torque_driver_new, 11); + torque_driver_new = subaru_pg_reversed_driver_torque ? -torque_driver_new : torque_driver_new; update_sample(&torque_driver, torque_driver_new); } @@ -120,7 +126,7 @@ static int subaru_preglobal_fwd_hook(int bus_num, int addr) { } static const addr_checks* subaru_preglobal_init(uint16_t param) { - UNUSED(param); + subaru_pg_reversed_driver_torque = GET_FLAG(param, SUBARU_PG_PARAM_REVERSED_DRIVER_TORQUE); return &subaru_preglobal_rx_checks; } diff --git a/python/__init__.py b/python/__init__.py index 6f99f4fa..db992047 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -219,6 +219,8 @@ class Panda: FLAG_SUBARU_GEN2 = 1 FLAG_SUBARU_LONG = 2 + FLAG_SUBARU_PREGLOBAL_REVERSED_DRIVER_TORQUE = 1 + FLAG_NISSAN_ALT_EPS_BUS = 1 FLAG_GM_HW_CAM = 1 diff --git a/tests/safety/test_subaru_preglobal.py b/tests/safety/test_subaru_preglobal.py index a351d6fd..06c4cdef 100755 --- a/tests/safety/test_subaru_preglobal.py +++ b/tests/safety/test_subaru_preglobal.py @@ -7,6 +7,8 @@ from panda.tests.safety.common import CANPackerPanda class TestSubaruPreglobalSafety(common.PandaCarSafetyTest, common.DriverTorqueSteeringSafetyTest): + FLAGS = 0 + DBC = "subaru_outback_2015_generated" TX_MSGS = [[0x161, 0], [0x164, 0]] STANDSTILL_THRESHOLD = 0 # kph RELAY_MALFUNCTION_ADDRS = {0: (0x164,)} @@ -24,9 +26,9 @@ class TestSubaruPreglobalSafety(common.PandaCarSafetyTest, common.DriverTorqueSt DRIVER_TORQUE_FACTOR = 10 def setUp(self): - self.packer = CANPackerPanda("subaru_outback_2015_generated") + self.packer = CANPackerPanda(self.DBC) self.safety = libpanda_py.libpanda - self.safety.set_safety_hooks(Panda.SAFETY_SUBARU_PREGLOBAL, 0) + self.safety.set_safety_hooks(Panda.SAFETY_SUBARU_PREGLOBAL, self.FLAGS) self.safety.init_tests() def _set_prev_torque(self, t): @@ -59,5 +61,10 @@ class TestSubaruPreglobalSafety(common.PandaCarSafetyTest, common.DriverTorqueSt return self.packer.make_can_msg_panda("CruiseControl", 0, values) +class TestSubaruPreglobalReversedDriverTorqueSafety(TestSubaruPreglobalSafety): + FLAGS = Panda.FLAG_SUBARU_PREGLOBAL_REVERSED_DRIVER_TORQUE + DBC = "subaru_outback_2019_generated" + + if __name__ == "__main__": unittest.main()