simplify chrysler checksum (#1158)

* simplify obscure chrysler crc function

* update submodules
albatross
rbiasini 2020-02-24 17:04:13 -08:00 committed by GitHub
parent c13d83ba16
commit 7f390b3875
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 18 deletions

@ -1 +1 @@
Subproject commit fbbba94aae1e992c42f6f106c18d898905e3e39b
Subproject commit a1aa3b78f7ae9405fcb42fa8f94aa3dae8acb987

2
panda

@ -1 +1 @@
Subproject commit 1b49d3e830f6d894f9daf820f956f315fd951428
Subproject commit d7f1195d1eef4ca3f90c17e61f07d95a566f3107

View File

@ -10,19 +10,10 @@ def calc_checksum(data):
jeep chrysler canbus checksum from http://illmatics.com/Remote%20Car%20Hacking.pdf
"""
end_index = len(data)
index = 0
checksum = 0xFF
temp_chk = 0
bit_sum = 0
if(end_index <= index):
return False
for index in range(0, end_index):
for curr in data[:-1]:
shift = 0x80
curr = data[index]
iterate = 8
while(iterate > 0):
iterate -= 1
for i in range(0, 8):
bit_sum = curr & shift
temp_chk = checksum & 0x80
if (bit_sum != 0):
@ -84,7 +75,6 @@ def create_lkas_command(packer, apply_steer, moving_fast, frame):
}
dat = packer.make_can_msg("LKAS_COMMAND", 0, values)[2]
dat = dat[:-1]
checksum = calc_checksum(dat)
values["CHECKSUM"] = checksum
@ -95,6 +85,6 @@ def create_wheel_buttons(frame):
# 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')
dat = dat + calc_checksum(dat).to_bytes(1, 'little')
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)

View File

@ -12,8 +12,8 @@ GearShifter = car.CarState.GearShifter
class TestChryslerCan(unittest.TestCase):
def test_checksum(self):
self.assertEqual(0x75, chryslercan.calc_checksum(b"\x01\x20"))
self.assertEqual(0xcc, chryslercan.calc_checksum(b"\x14\x00\x00\x00\x20"))
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')