Chrsyler: calculate checksum in CAN packer (#1438)
parent
c4592e8547
commit
6ff08f8dee
2
opendbc
2
opendbc
|
@ -1 +1 @@
|
|||
Subproject commit 0c0215516f6a0be50fcbe7fc1e8e2fe0f47f9d86
|
||||
Subproject commit 7456061a7150911a8c186231453a337e6c73c743
|
|
@ -50,7 +50,7 @@ class CarController():
|
|||
|
||||
if pcm_cancel_cmd:
|
||||
# TODO: would be better to start from frame_2b3
|
||||
new_msg = create_wheel_buttons(self.ccframe)
|
||||
new_msg = create_wheel_buttons(self.packer, self.ccframe, cancel=True)
|
||||
can_sends.append(new_msg)
|
||||
|
||||
# LKAS_HEARTBIT is forwarded by Panda so no need to send it here.
|
||||
|
|
|
@ -5,34 +5,6 @@ from selfdrive.car import make_can_msg
|
|||
GearShifter = car.CarState.GearShifter
|
||||
VisualAlert = car.CarControl.HUDControl.VisualAlert
|
||||
|
||||
def calc_checksum(data):
|
||||
"""This function does not want the checksum byte in the input data.
|
||||
|
||||
jeep chrysler canbus checksum from http://illmatics.com/Remote%20Car%20Hacking.pdf
|
||||
"""
|
||||
checksum = 0xFF
|
||||
for curr in data[:-1]:
|
||||
shift = 0x80
|
||||
for _ 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
|
||||
|
||||
|
||||
def create_lkas_hud(packer, gear, lkas_active, hud_alert, hud_count, lkas_car_model):
|
||||
# LKAS_HUD 0x2a6 (678) Controls what lane-keeping icon is displayed.
|
||||
|
||||
|
@ -73,18 +45,13 @@ def create_lkas_command(packer, apply_steer, moving_fast, frame):
|
|||
"LKAS_HIGH_TORQUE": int(moving_fast),
|
||||
"COUNTER": frame % 0x10,
|
||||
}
|
||||
|
||||
dat = packer.make_can_msg("LKAS_COMMAND", 0, values)[2]
|
||||
checksum = calc_checksum(dat)
|
||||
|
||||
values["CHECKSUM"] = checksum
|
||||
return packer.make_can_msg("LKAS_COMMAND", 0, values)
|
||||
|
||||
|
||||
def create_wheel_buttons(frame):
|
||||
def create_wheel_buttons(packer, frame, cancel=False):
|
||||
# WHEEL_BUTTONS (571) Message sent to cancel ACC.
|
||||
start = b"\x01" # acc cancel set
|
||||
counter = (frame % 10) << 4
|
||||
dat = start + counter.to_bytes(1, 'little') + b"\x00"
|
||||
dat = dat[:-1] + calc_checksum(dat).to_bytes(1, 'little')
|
||||
return make_can_msg(0x23b, dat, 0)
|
||||
values = {
|
||||
"ACC_CANCEL": cancel,
|
||||
"COUNTER": frame % 10
|
||||
}
|
||||
return packer.make_can_msg("WHEEL_BUTTONS", 0, values)
|
||||
|
|
|
@ -11,10 +11,6 @@ GearShifter = car.CarState.GearShifter
|
|||
|
||||
class TestChryslerCan(unittest.TestCase):
|
||||
|
||||
def test_checksum(self):
|
||||
self.assertEqual(0x75, chryslercan.calc_checksum(b"\x01\x20\x00"))
|
||||
self.assertEqual(0xcc, chryslercan.calc_checksum(b"\x14\x00\x00\x00\x20\x00"))
|
||||
|
||||
def test_hud(self):
|
||||
packer = CANPacker('chrysler_pacifica_2017_hybrid')
|
||||
self.assertEqual(
|
||||
|
|
Loading…
Reference in New Issue