Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chrysler safety: fix mutations failures #2054

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions board/safety/safety_chrysler.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ static void chrysler_rx_hook(const CANPacket_t *to_push) {
// TODO: use the same message for both
// update vehicle moving
if ((chrysler_platform != CHRYSLER_PACIFICA) && (bus == 0) && (addr == chrysler_addrs->ESP_8)) {
vehicle_moving = ((GET_BYTE(to_push, 4) << 8) + GET_BYTE(to_push, 5)) != 0U;
vehicle_moving = (GET_BYTE(to_push, 4) != 0U) || (GET_BYTE(to_push, 5) != 0U);
}
if ((chrysler_platform == CHRYSLER_PACIFICA) && (bus == 0) && (addr == 514)) {
int speed_l = (GET_BYTE(to_push, 0) << 4) + (GET_BYTE(to_push, 1) >> 4);
int speed_r = (GET_BYTE(to_push, 2) << 4) + (GET_BYTE(to_push, 3) >> 4);
vehicle_moving = (speed_l != 0) || (speed_r != 0);
bool speed_l = ((GET_BYTE(to_push, 0) << 4) != 0U) || ((GET_BYTE(to_push, 1) >> 4) != 0U);
maxime-desroches marked this conversation as resolved.
Show resolved Hide resolved
bool speed_r = ((GET_BYTE(to_push, 2) << 4) != 0U) || ((GET_BYTE(to_push, 3) >> 4) != 0U);
vehicle_moving = speed_l || speed_r;
}

// exit controls on rising edge of gas press
Expand Down
99 changes: 81 additions & 18 deletions tests/safety/test_chrysler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,18 @@
from panda.tests.safety.common import CANPackerPanda


class TestChryslerSafety(common.PandaCarSafetyTest, common.MotorTorqueSteeringSafetyTest):
TX_MSGS = [[0x23B, 0], [0x292, 0], [0x2A6, 0]]
class TestChryslerSafetyBase(common.PandaCarSafetyTest, common.MotorTorqueSteeringSafetyTest):
STANDSTILL_THRESHOLD = 0
RELAY_MALFUNCTION_ADDRS = {0: (0x292,)}
FWD_BLACKLISTED_ADDRS = {2: [0x292, 0x2A6]}
FWD_BUS_LOOKUP = {0: 2, 2: 0}

MAX_RATE_UP = 3
MAX_RATE_DOWN = 3
MAX_TORQUE = 261
MAX_RT_DELTA = 112
RT_INTERVAL = 250000
MAX_TORQUE_ERROR = 80

LKAS_ACTIVE_VALUE = 1

DAS_BUS = 0

def setUp(self):
self.packer = CANPackerPanda("chrysler_pacifica_2017_hybrid_generated")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_CHRYSLER, 0)
self.safety.init_tests()
@classmethod
def setUpClass(cls):
if cls.__name__ == "TestChryslerSafetyBase":
raise unittest.SkipTest

def _button_msg(self, cancel=False, resume=False):
values = {"ACC_Cancel": cancel, "ACC_Resume": resume}
Expand Down Expand Up @@ -72,8 +61,82 @@ def test_buttons(self):
self.assertFalse(self._tx(self._button_msg(cancel=True, resume=True)))
self.assertFalse(self._tx(self._button_msg(cancel=False, resume=False)))

class TestChryslerPacificaSafety(TestChryslerSafetyBase):
TX_MSGS = [[0x23B, 0], [0x292, 0], [0x2A6, 0]]
RELAY_MALFUNCTION_ADDRS = {0: (0x292,)}
FWD_BLACKLISTED_ADDRS = {2: [0x292, 0x2A6]}

MAX_RATE_UP = 3
MAX_RATE_DOWN = 3
MAX_TORQUE = 261

LKAS_ACTIVE_VALUE = 1

DAS_BUS = 0

def setUp(self):
self.packer = CANPackerPanda("chrysler_pacifica_2017_hybrid_generated")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_CHRYSLER, 0)
self.safety.init_tests()

def _speed_msg(self, speed):
values = {"SPEED_LEFT": speed, "SPEED_RIGHT": speed}
return self.packer.make_can_msg_panda("SPEED_1", 0, values)

class TestChryslerRamDTSafety(TestChryslerSafety):
def test_rx_hook_vehicle_moving(self):
self.assertFalse(self.safety.get_vehicle_moving())

# speed_l byte 0
msg = self._speed_msg(0)
msg[0].data[0] = 15
self.assertTrue(self._rx(msg))
self.assertTrue(self.safety.get_vehicle_moving())

# speed_l byte 1
msg = self._speed_msg(0)
msg[0].data[1] = 8
self.assertTrue(self._rx(msg))
self.assertFalse(self.safety.get_vehicle_moving())

# speed_r byte 2
msg = self._speed_msg(0)
msg[0].data[2] = 15
self.assertTrue(self._rx(msg))
self.assertTrue(self.safety.get_vehicle_moving())

# speed_r byte 3
msg = self._speed_msg(0)
msg[0].data[3] = 8
self.assertTrue(self._rx(msg))
self.assertFalse(self.safety.get_vehicle_moving())

class TestChryslerRamSafetyBase(TestChryslerSafetyBase):
@classmethod
def setUpClass(cls):
if cls.__name__ == "TestChryslerRamSafetyBase":
raise unittest.SkipTest

def test_rx_hook_vehicle_moving(self):
self.assertFalse(self.safety.get_vehicle_moving())

# test 4th bytes = 0, 5th bytes = 0
self.assertTrue(self._rx(self._speed_msg(0)))
self.assertFalse(self.safety.get_vehicle_moving())

# test 4th bytes = 0, 5th bytes = 128
self.assertTrue(self._rx(self._speed_msg(1)))
self.assertTrue(self.safety.get_vehicle_moving())

# test 4th bytes = 1, 5th bytes = 0
self.assertTrue(self._rx(self._speed_msg(2)))
self.assertTrue(self.safety.get_vehicle_moving())

# test 4th bytes = 1, 5th bytes = 128
self.assertTrue(self._rx(self._speed_msg(3)))
self.assertTrue(self.safety.get_vehicle_moving())

class TestChryslerRamDTSafety(TestChryslerRamSafetyBase):
TX_MSGS = [[0xB1, 2], [0xA6, 0], [0xFA, 0]]
RELAY_MALFUNCTION_ADDRS = {0: (0xA6,)}
FWD_BLACKLISTED_ADDRS = {2: [0xA6, 0xFA]}
Expand All @@ -96,7 +159,7 @@ def _speed_msg(self, speed):
values = {"Vehicle_Speed": speed}
return self.packer.make_can_msg_panda("ESP_8", 0, values)

class TestChryslerRamHDSafety(TestChryslerSafety):
class TestChryslerRamHDSafety(TestChryslerRamSafetyBase):
TX_MSGS = [[0x275, 0], [0x276, 0], [0x23A, 2]]
RELAY_MALFUNCTION_ADDRS = {0: (0x276,)}
FWD_BLACKLISTED_ADDRS = {2: [0x275, 0x276]}
Expand Down
Loading