Simplified the VW checksum calculation that is just a simple bitwise XOR over the CAN message bytes.

This commit is contained in:
Christian Sueltrop 2012-10-16 10:13:33 +02:00
parent 5b9b4f56fb
commit 0bd378ccd6

View file

@ -160,14 +160,22 @@ class CanMessage(object):
''' '''
Calculate the CRC checksum over the whole message. Calculate the CRC checksum over the whole message.
This works for the parameters used by VW, as a 0x00 byte somewhere in the message does not provide to the checksum. The VW implementation is a very simple implementation that cannot really be called a CRC: They simply do a bitwise
XOR on the message data.
If this is true for all checksums is not certain! Has been tested for mMotor_5 and mMotor_6 only! If this is true for all checksums is not certain! Has been tested for mMotor_5 and mMotor_6 only!
''' '''
def calculateCRC(self): def calculateCRC(self):
crc = Crc(width=8, poly=0x01, reflect_in = False, reflect_out = False, xor_in = 0xff, xor_out = 0xff) # configure the crc calculator according to the VW parameters #crc = Crc(width=8, poly=0x01, reflect_in = False, reflect_out = False, xor_in = 0xff, xor_out = 0xff) # configure the crc calculator according to the VW parameters
self.composeData() #self.composeData()
data = self.Data.tostring() #data = self.Data.tostring()
my_crc = crc.bit_by_bit_fast(data) #my_crc = crc.bit_by_bit_fast(data)
#return my_crc
my_crc = 0;
for i in range(len(self.Data)):
my_crc ^= self.Data[i]
return my_crc return my_crc