-
Notifications
You must be signed in to change notification settings - Fork 3
/
crc.py
43 lines (36 loc) · 911 Bytes
/
crc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
##### CRC Methods
gCrc = 0
def InitCRC():
global gCrc
gCrc = 0
# def ProcessCRC(const uint8_t *data, int len)
def ProcessCRC(data, len):
global gCrc
# for (j = len; j; j--, data++):
i = 0
j = len
while j:
# gCrc ^= (*data << 8)
# left shift
l = list(data[0:1])[0]
del data[0:1]
gCrc ^= l
# for(i = 8; i; i--) {
i = 8
while i:
if (gCrc & 0x8000):
gCrc ^= (0x1070 << 3)
gCrc <<= 1
i -= 1
j -= 1
# I think we were advancing the pointer here in c
# not necessary in this python implementation
# since we're effectively popping values off of the left side
# the data "pointer" is always moving
# data += 1
# uint8_t GetCRC() {
def GetCRC():
global gCrc
# return (uint8_t)(gCrc >> 8)
return gCrc >> 8
#####