simplify chrysler checksum (#1158)

* simplify obscure chrysler crc function

* update submodules

old-commit-hash: 7f390b38754e97e0a36e6fc461441e8452ac0bc0
This commit is contained in:
rbiasini
2020-02-24 17:04:13 -08:00
committed by GitHub
parent d659cedf20
commit fa287f6a8c
4 changed files with 8 additions and 18 deletions
+1 -1
Submodule opendbc updated: fbbba94aae...a1aa3b78f7
+1 -1
Submodule panda updated: 1b49d3e830...d7f1195d1e
+4 -14
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)
+2 -2
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')