comparison server/utils.py @ 332:05c1249da994

- Move crc16 to utils and fix it - Fix main.c crc calculation
author Matt Johnston <matt@ucc.asn.au>
date Thu, 07 Jun 2012 20:26:50 +0800
parents 5de3fc71ce48
children 340a14fcbaeb
comparison
equal deleted inserted replaced
331:5de3fc71ce48 332:05c1249da994
79 79
80 buf += c 80 buf += c
81 if c == '\n': 81 if c == '\n':
82 return buf 82 return buf
83 83
84 # from http://blog.stalkr.net/2011/04/pctf-2011-32-thats-no-bluetooth.html
85 def crc16(buff, crc = 0, poly = 0x8408):
86 l = len(buff)
87 i = 0
88 while i < l:
89 ch = ord(buff[i])
90 uc = 0
91 while uc < 8:
92 if (crc & 1) ^ (ch & 1):
93 crc = (crc >> 1) ^ poly
94 else:
95 crc >>= 1
96 ch >>= 1
97 uc += 1
98 i += 1
99 return crc