# HG changeset patch # User Matt Johnston # Date 1339072010 -28800 # Node ID d3e5934fe55c5270a8bbb6780f0daef71e914e16 # Parent 2943f62c8e621ba7e4bbc0a72228a2f5b67c8e56 - Move crc16 to utils and fix it - Fix main.c crc calculation diff -r 2943f62c8e62 -r d3e5934fe55c main.c --- a/main.c Wed Jun 06 23:05:35 2012 +0800 +++ b/main.c Thu Jun 07 20:26:50 2012 +0800 @@ -204,7 +204,7 @@ UDR0 = c; if (stream == crc_stdout) { - crc_out = _crc_ccitt_update(crc_out, '\n'); + crc_out = _crc_ccitt_update(crc_out, c); } if (c == '\r') { diff -r 2943f62c8e62 -r d3e5934fe55c server/ts.py --- a/server/ts.py Wed Jun 06 23:05:35 2012 +0800 +++ b/server/ts.py Thu Jun 07 20:26:50 2012 +0800 @@ -15,7 +15,7 @@ import time import traceback -from utils import monotonic_time, retry, readline +from utils import monotonic_time, retry, readline, crc16 lightblue = None try: @@ -36,23 +36,6 @@ return s -# from http://blog.stalkr.net/2011/04/pctf-2011-32-thats-no-bluetooth.html -def crc16(buff, crc = 0, poly = 0x8408): - l = len(buff) - i = 0 - while i < l: - ch = ord(buff[i]) - uc = 0 - while uc < 8: - if (crc & 1) ^ (ch & 1): - crc = (crc >> 1) ^ poly - else: - crc >>= 1 - ch >>= 1 - uc += 1 - i += 1 - return crc - @retry() def fetch(sock): diff -r 2943f62c8e62 -r d3e5934fe55c server/utils.py --- a/server/utils.py Wed Jun 06 23:05:35 2012 +0800 +++ b/server/utils.py Thu Jun 07 20:26:50 2012 +0800 @@ -81,3 +81,19 @@ if c == '\n': return buf +# from http://blog.stalkr.net/2011/04/pctf-2011-32-thats-no-bluetooth.html +def crc16(buff, crc = 0, poly = 0x8408): + l = len(buff) + i = 0 + while i < l: + ch = ord(buff[i]) + uc = 0 + while uc < 8: + if (crc & 1) ^ (ch & 1): + crc = (crc >> 1) ^ poly + else: + crc >>= 1 + ch >>= 1 + uc += 1 + i += 1 + return crc