Added full code for serial handling

This commit is contained in:
Sebastian 2018-10-20 20:20:27 +02:00
parent 557a158a9c
commit b471d9cab8
1 changed files with 6 additions and 4 deletions

View File

@ -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()