Added pycrc based checksum calculation to the CanMessage class.

This commit is contained in:
Christian Sltrop 2012-07-30 15:09:41 +02:00
parent 3233dc96b1
commit 8363ddd5a8
2 changed files with 17 additions and 0 deletions

View file

@ -9,6 +9,8 @@ Created on 06.07.2012
import array
import sys
from pycrc import Crc
class CanMessage(object):
'''
@ -114,3 +116,18 @@ class CanMessage(object):
if tgtBitNo >= 8:
tgtBitNo = 0
tgtByteNo += 1
'''
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.
If this is true for all checksums is not certain! Has been tested for mMotor_5 and mMotor_6 only!
'''
def calculateCRC(self):
crc = Crc(width=8, poly=0x01, reflect_in = False, reflect_out = False, xor_in = 0xff, xor_out = 0xff)
self.composeData()
data = self.Data.tostring()
my_crc = crc.bit_by_bit_fast(data)
#print ("%x" % my_crc)
return my_crc

Binary file not shown.