2019-09-25 08:50:53 +08:00
|
|
|
#!/usr/bin/env python3
|
2018-11-07 04:28:33 +08:00
|
|
|
import unittest
|
2019-10-03 09:20:32 +08:00
|
|
|
from panda import Panda
|
2022-12-01 09:41:24 +08:00
|
|
|
from panda.tests.libpanda import libpanda_py
|
2020-04-18 04:34:23 +08:00
|
|
|
import panda.tests.safety.common as common
|
2020-05-01 05:26:28 +08:00
|
|
|
from panda.tests.safety.common import CANPackerPanda
|
|
|
|
|
2022-05-26 10:24:55 +08:00
|
|
|
|
2023-11-07 08:19:27 +08:00
|
|
|
class TestChryslerSafety(common.PandaCarSafetyTest, common.MotorTorqueSteeringSafetyTest):
|
2023-09-01 11:13:37 +08:00
|
|
|
TX_MSGS = [[0x23B, 0], [0x292, 0], [0x2A6, 0]]
|
2020-04-18 04:34:23 +08:00
|
|
|
STANDSTILL_THRESHOLD = 0
|
2023-11-08 11:03:08 +08:00
|
|
|
RELAY_MALFUNCTION_ADDRS = {0: (0x292,)}
|
2023-09-01 11:13:37 +08:00
|
|
|
FWD_BLACKLISTED_ADDRS = {2: [0x292, 0x2A6]}
|
2020-04-18 04:34:23 +08:00
|
|
|
FWD_BUS_LOOKUP = {0: 2, 2: 0}
|
|
|
|
|
2023-02-14 06:13:40 +08:00
|
|
|
MAX_RATE_UP = 3
|
|
|
|
MAX_RATE_DOWN = 3
|
2020-04-30 11:37:12 +08:00
|
|
|
MAX_TORQUE = 261
|
|
|
|
MAX_RT_DELTA = 112
|
|
|
|
RT_INTERVAL = 250000
|
|
|
|
MAX_TORQUE_ERROR = 80
|
|
|
|
|
2023-09-01 07:01:16 +08:00
|
|
|
LKAS_ACTIVE_VALUE = 1
|
|
|
|
|
2022-07-07 13:50:29 +08:00
|
|
|
DAS_BUS = 0
|
|
|
|
|
2020-04-18 04:34:23 +08:00
|
|
|
def setUp(self):
|
2022-07-06 07:33:12 +08:00
|
|
|
self.packer = CANPackerPanda("chrysler_pacifica_2017_hybrid_generated")
|
2022-12-01 09:41:24 +08:00
|
|
|
self.safety = libpanda_py.libpanda
|
2020-04-18 04:34:23 +08:00
|
|
|
self.safety.set_safety_hooks(Panda.SAFETY_CHRYSLER, 0)
|
2020-05-27 05:23:39 +08:00
|
|
|
self.safety.init_tests()
|
2018-11-07 04:28:33 +08:00
|
|
|
|
2022-07-07 14:43:56 +08:00
|
|
|
def _button_msg(self, cancel=False, resume=False):
|
|
|
|
values = {"ACC_Cancel": cancel, "ACC_Resume": resume}
|
2022-07-07 13:50:29 +08:00
|
|
|
return self.packer.make_can_msg_panda("CRUISE_BUTTONS", self.DAS_BUS, values)
|
2018-11-07 04:28:33 +08:00
|
|
|
|
2020-06-03 07:27:07 +08:00
|
|
|
def _pcm_status_msg(self, enable):
|
2022-07-06 07:33:12 +08:00
|
|
|
values = {"ACC_ACTIVE": enable}
|
2022-07-22 09:50:42 +08:00
|
|
|
return self.packer.make_can_msg_panda("DAS_3", self.DAS_BUS, values)
|
2020-02-25 08:36:46 +08:00
|
|
|
|
2020-02-20 15:46:38 +08:00
|
|
|
def _speed_msg(self, speed):
|
2020-05-01 05:26:28 +08:00
|
|
|
values = {"SPEED_LEFT": speed, "SPEED_RIGHT": speed}
|
|
|
|
return self.packer.make_can_msg_panda("SPEED_1", 0, values)
|
2020-02-20 15:46:38 +08:00
|
|
|
|
2022-03-29 04:13:27 +08:00
|
|
|
def _user_gas_msg(self, gas):
|
2022-07-06 07:33:12 +08:00
|
|
|
values = {"Accelerator_Position": gas}
|
2022-07-22 09:50:42 +08:00
|
|
|
return self.packer.make_can_msg_panda("ECM_5", 0, values)
|
2020-02-20 15:46:38 +08:00
|
|
|
|
2022-03-29 04:13:27 +08:00
|
|
|
def _user_brake_msg(self, brake):
|
2022-07-06 07:33:12 +08:00
|
|
|
values = {"Brake_Pedal_State": 1 if brake else 0}
|
2022-07-22 09:50:42 +08:00
|
|
|
return self.packer.make_can_msg_panda("ESP_1", 0, values)
|
2020-02-27 10:19:18 +08:00
|
|
|
|
2019-01-03 13:53:07 +08:00
|
|
|
def _torque_meas_msg(self, torque):
|
2022-07-06 07:33:12 +08:00
|
|
|
values = {"EPS_TORQUE_MOTOR": torque}
|
2022-07-22 09:50:42 +08:00
|
|
|
return self.packer.make_can_msg_panda("EPS_2", 0, values)
|
2018-11-07 04:28:33 +08:00
|
|
|
|
2022-05-26 10:24:55 +08:00
|
|
|
def _torque_cmd_msg(self, torque, steer_req=1):
|
2023-09-01 07:01:16 +08:00
|
|
|
values = {"STEERING_TORQUE": torque, "LKAS_CONTROL_BIT": self.LKAS_ACTIVE_VALUE if steer_req else 0}
|
2020-05-01 05:26:28 +08:00
|
|
|
return self.packer.make_can_msg_panda("LKAS_COMMAND", 0, values)
|
2018-11-07 04:28:33 +08:00
|
|
|
|
2022-07-07 14:43:56 +08:00
|
|
|
def test_buttons(self):
|
|
|
|
for controls_allowed in (True, False):
|
|
|
|
self.safety.set_controls_allowed(controls_allowed)
|
|
|
|
|
|
|
|
# resume only while controls allowed
|
|
|
|
self.assertEqual(controls_allowed, self._tx(self._button_msg(resume=True)))
|
|
|
|
|
|
|
|
# can always cancel
|
|
|
|
self.assertTrue(self._tx(self._button_msg(cancel=True)))
|
|
|
|
|
|
|
|
# only one button at a time
|
|
|
|
self.assertFalse(self._tx(self._button_msg(cancel=True, resume=True)))
|
|
|
|
self.assertFalse(self._tx(self._button_msg(cancel=False, resume=False)))
|
2019-11-18 14:31:26 +08:00
|
|
|
|
2018-11-07 04:28:33 +08:00
|
|
|
|
2022-08-12 05:41:46 +08:00
|
|
|
class TestChryslerRamDTSafety(TestChryslerSafety):
|
2023-09-01 11:13:37 +08:00
|
|
|
TX_MSGS = [[0xB1, 2], [0xA6, 0], [0xFA, 0]]
|
2023-11-08 11:03:08 +08:00
|
|
|
RELAY_MALFUNCTION_ADDRS = {0: (0xA6,)}
|
2023-09-01 11:13:37 +08:00
|
|
|
FWD_BLACKLISTED_ADDRS = {2: [0xA6, 0xFA]}
|
2022-07-07 13:50:29 +08:00
|
|
|
|
2023-02-14 06:13:40 +08:00
|
|
|
MAX_RATE_UP = 6
|
|
|
|
MAX_RATE_DOWN = 6
|
2023-03-14 08:24:02 +08:00
|
|
|
MAX_TORQUE = 350
|
2023-02-14 06:13:40 +08:00
|
|
|
|
2022-07-07 13:50:29 +08:00
|
|
|
DAS_BUS = 2
|
|
|
|
|
2023-09-01 07:01:16 +08:00
|
|
|
LKAS_ACTIVE_VALUE = 2
|
|
|
|
|
2022-07-07 13:50:29 +08:00
|
|
|
def setUp(self):
|
|
|
|
self.packer = CANPackerPanda("chrysler_ram_dt_generated")
|
2022-12-01 09:41:24 +08:00
|
|
|
self.safety = libpanda_py.libpanda
|
2022-07-07 13:50:29 +08:00
|
|
|
self.safety.set_safety_hooks(Panda.SAFETY_CHRYSLER, Panda.FLAG_CHRYSLER_RAM_DT)
|
|
|
|
self.safety.init_tests()
|
|
|
|
|
|
|
|
def _speed_msg(self, speed):
|
|
|
|
values = {"Vehicle_Speed": speed}
|
2022-07-22 09:50:42 +08:00
|
|
|
return self.packer.make_can_msg_panda("ESP_8", 0, values)
|
2022-07-07 13:50:29 +08:00
|
|
|
|
2022-08-12 05:41:46 +08:00
|
|
|
class TestChryslerRamHDSafety(TestChryslerSafety):
|
2023-09-01 11:13:37 +08:00
|
|
|
TX_MSGS = [[0x275, 0], [0x276, 0], [0x23A, 2]]
|
2023-11-08 11:03:08 +08:00
|
|
|
RELAY_MALFUNCTION_ADDRS = {0: (0x276,)}
|
2023-09-01 11:13:37 +08:00
|
|
|
FWD_BLACKLISTED_ADDRS = {2: [0x275, 0x276]}
|
2022-08-12 05:41:46 +08:00
|
|
|
|
|
|
|
MAX_TORQUE = 361
|
|
|
|
MAX_RATE_UP = 14
|
|
|
|
MAX_RATE_DOWN = 14
|
|
|
|
MAX_RT_DELTA = 182
|
|
|
|
|
|
|
|
DAS_BUS = 2
|
|
|
|
|
2023-09-01 07:01:16 +08:00
|
|
|
LKAS_ACTIVE_VALUE = 2
|
|
|
|
|
2022-08-12 05:41:46 +08:00
|
|
|
def setUp(self):
|
|
|
|
self.packer = CANPackerPanda("chrysler_ram_hd_generated")
|
2022-12-01 09:41:24 +08:00
|
|
|
self.safety = libpanda_py.libpanda
|
2022-08-12 05:41:46 +08:00
|
|
|
self.safety.set_safety_hooks(Panda.SAFETY_CHRYSLER, Panda.FLAG_CHRYSLER_RAM_HD)
|
|
|
|
self.safety.init_tests()
|
|
|
|
|
|
|
|
def _speed_msg(self, speed):
|
|
|
|
values = {"Vehicle_Speed": speed}
|
|
|
|
return self.packer.make_can_msg_panda("ESP_8", 0, values)
|
2022-07-07 13:50:29 +08:00
|
|
|
|
|
|
|
|
2018-11-07 04:28:33 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|