Chrysler: use can packer in safety tests (#522)

* Chrysler: use can packer in safety tests

* bump opendbc
This commit is contained in:
Adeeb 2020-04-30 14:26:28 -07:00 committed by GitHub
parent 9874e73350
commit c9102c00ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 66 deletions

View File

@ -34,7 +34,7 @@ RUN pip install -r /tmp/requirements.txt
WORKDIR /openpilot
RUN git clone https://github.com/commaai/opendbc.git || true
WORKDIR /openpilot/opendbc
RUN git pull && git checkout a57e7ddbd72c92241d5d6442da9d47c55e95a8cf
RUN git pull && git checkout 7f3b1774dd248d4ebad91cc9de0fb1c561fab54b
WORKDIR /openpilot
RUN git clone https://github.com/commaai/cereal.git
WORKDIR /openpilot/cereal

View File

@ -3,34 +3,9 @@ import unittest
from panda import Panda
from panda.tests.safety import libpandasafety_py
import panda.tests.safety.common as common
from panda.tests.safety.common import make_msg
from panda.tests.safety.common import CANPackerPanda
def chrysler_checksum(msg, len_msg):
checksum = 0xFF
for idx in range(0, len_msg-1):
curr = (msg.RDLR >> (8*idx)) if idx < 4 else (msg.RDHR >> (8*(idx - 4)))
curr &= 0xFF
shift = 0x80
for i in range(0, 8):
bit_sum = curr & shift
temp_chk = checksum & 0x80
if (bit_sum != 0):
bit_sum = 0x1C
if (temp_chk != 0):
bit_sum = 1
checksum = checksum << 1
temp_chk = checksum | 1
bit_sum ^= temp_chk
else:
if (temp_chk != 0):
bit_sum = 0x1D
checksum = checksum << 1
bit_sum ^= checksum
checksum = bit_sum
shift = shift >> 1
return ~checksum & 0xFF
class TestChryslerSafety(common.PandaSafetyTest, common.TorqueSteeringSafetyTest):
TX_MSGS = [[571, 0], [658, 0], [678, 0]]
STANDSTILL_THRESHOLD = 0
@ -52,75 +27,58 @@ class TestChryslerSafety(common.PandaSafetyTest, common.TorqueSteeringSafetyTest
cnt_brake = 0
def setUp(self):
self.packer = CANPackerPanda("chrysler_pacifica_2017_hybrid")
self.safety = libpandasafety_py.libpandasafety
self.safety.set_safety_hooks(Panda.SAFETY_CHRYSLER, 0)
self.safety.init_tests_chrysler()
def _button_msg(self, buttons):
to_send = make_msg(0, 571)
to_send[0].RDLR = buttons
return to_send
def _button_msg(self, cancel):
values = {"ACC_CANCEL": cancel}
return self.packer.make_can_msg_panda("WHEEL_BUTTONS", 0, values)
def _pcm_status_msg(self, active):
to_send = make_msg(0, 500)
to_send[0].RDLR = 0x380000 if active else 0
to_send[0].RDHR |= (self.cnt_cruise % 16) << 20
to_send[0].RDHR |= chrysler_checksum(to_send[0], 8) << 24
values = {"ACC_STATUS_2": 0x7 if active else 0, \
"COUNTER": self.cnt_cruise % 16}
self.__class__.cnt_cruise += 1
return to_send
return self.packer.make_can_msg_panda("ACC_2", 0, values)
def _speed_msg(self, speed):
speed = int(speed / 0.071028)
to_send = make_msg(0, 514, 4)
to_send[0].RDLR = ((speed & 0xFF0) >> 4) + ((speed & 0xF) << 12) + \
((speed & 0xFF0) << 12) + ((speed & 0xF) << 28)
return to_send
values = {"SPEED_LEFT": speed, "SPEED_RIGHT": speed}
return self.packer.make_can_msg_panda("SPEED_1", 0, values)
def _gas_msg(self, gas):
to_send = make_msg(0, 308)
to_send[0].RDHR = (gas & 0x7F) << 8
to_send[0].RDHR |= (self.cnt_gas % 16) << 20
values = {"ACCEL_134": gas, "COUNTER": self.cnt_gas % 16}
self.__class__.cnt_gas += 1
return to_send
return self.packer.make_can_msg_panda("ACCEL_GAS_134", 0, values)
def _brake_msg(self, brake):
to_send = make_msg(0, 320)
to_send[0].RDLR = 5 if brake else 0
to_send[0].RDHR |= (self.cnt_brake % 16) << 20
to_send[0].RDHR |= chrysler_checksum(to_send[0], 8) << 24
values = {"BRAKE_PRESSED_2": 5 if brake else 0, \
"COUNTER": self.cnt_brake % 16}
self.__class__.cnt_brake += 1
return to_send
return self.packer.make_can_msg_panda("BRAKE_2", 0, values)
def _torque_meas_msg(self, torque):
to_send = make_msg(0, 544)
to_send[0].RDHR = ((torque + 1024) >> 8) + (((torque + 1024) & 0xff) << 8)
to_send[0].RDHR |= (self.cnt_torque_meas % 16) << 20
to_send[0].RDHR |= chrysler_checksum(to_send[0], 8) << 24
values = {"TORQUE_MOTOR": torque, "COUNTER": self.cnt_torque_meas % 16}
self.__class__.cnt_torque_meas += 1
return to_send
return self.packer.make_can_msg_panda("EPS_STATUS", 0, values)
def _torque_msg(self, torque):
to_send = make_msg(0, 0x292)
to_send[0].RDLR = ((torque + 1024) >> 8) + (((torque + 1024) & 0xff) << 8)
return to_send
values = {"LKAS_STEERING_TORQUE": torque}
return self.packer.make_can_msg_panda("LKAS_COMMAND", 0, values)
def test_disengage_on_gas(self):
self.safety.set_controls_allowed(1)
self._rx(self._speed_msg(2.2))
self._rx(self._speed_msg(2.1))
self._rx(self._gas_msg(1))
self.assertTrue(self.safety.get_controls_allowed())
self._rx(self._gas_msg(0))
self._rx(self._speed_msg(2.3))
self._rx(self._speed_msg(2.2))
self._rx(self._gas_msg(1))
self.assertFalse(self.safety.get_controls_allowed())
def test_cancel_button(self):
CANCEL = 1
for b in range(0, 0x1ff):
if b == CANCEL:
self.assertTrue(self._tx(self._button_msg(b)))
else:
self.assertFalse(self._tx(self._button_msg(b)))
for cancel in [True, False]:
self.assertEqual(cancel, self._tx(self._button_msg(cancel)))
if __name__ == "__main__":