Fixed crc

This commit is contained in:
Sebastian 2018-10-20 20:07:35 +02:00
parent 1c86aa4fe3
commit ae1b3cb08f
2 changed files with 9 additions and 5 deletions

View File

@ -21,7 +21,7 @@ ARCHIVE_KEEP_INTERVAL = 365 * 24 * 60 * 60 # 1 year
MAX_MISSING = 0.5
# Manual claims poly should be 0x8404, internet says xmodem
CRC_TYPE = 'xmodem'
CRC_TYPE = 'crc-aug-ccitt'
STORED_VALUES = [

View File

@ -12,13 +12,17 @@ calc_crc = crcmod.predefined.mkCrcFun(CRC_TYPE)
def parse_line(line):
if line[-2:] != "\r\n":
print("newline fucked")
return {key : None for key in FORMAT}
line = line[:-2]
crc_str = line[-2:]
payload = line[0:-2]
crc = (ord(crc_str[0]) << 8) | ord(crc_str[1])
crc_str = line[-4:]
print(crc_str)
payload = line[0:-4]
crc = int(crc_str, 16)
calced_crc = calc_crc(payload.encode('ascii'))
if crc != calc_crc(payload.encode('ascii')):
print("CRC fucked")
return {key : None for key in FORMAT}
parts = payload.split(';')
@ -74,7 +78,7 @@ def update_graphs():
# Render current data
graph_params = ['%s.png' % graph_name, '-a',
'PNG', '-s', 'n-%d' % ARCHIVE_INTERVAL]
for name, lable, color in lines:
graph_params += ['DEF:%s=%s:%s:LAST' % (name, DATA_FILE, name)]
graph_params += ['LINE1:%s%s:%s' % (name, color, lable)]