Added full code for serial handling

master
Sebastian 5 years ago
parent 557a158a9c
commit b471d9cab8

@ -12,17 +12,16 @@ calc_crc = crcmod.predefined.mkCrcFun(CRC_TYPE)
def parse_line(line):
if line[-2:] != "\r\n":
print("newline fucked")
print("Failed to parse: newline broken")
return {key : None for key in FORMAT}
line = line[:-2]
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")
print("Failed to parse: CRC broken")
return {key : None for key in FORMAT}
parts = payload.split(';')
@ -121,10 +120,13 @@ def main():
while True:
line = ser.readline().decode('ascii')
print(line)
if len(line) > 0:
print(line)
parsed = parse_line(line)
update_database(parsed)
update_graphs()
upload_graphs()

Loading…
Cancel
Save