Added full code for serial handling
This commit is contained in:
parent
557a158a9c
commit
b471d9cab8
10
update.py
10
update.py
|
@ -12,17 +12,16 @@ calc_crc = crcmod.predefined.mkCrcFun(CRC_TYPE)
|
||||||
|
|
||||||
def parse_line(line):
|
def parse_line(line):
|
||||||
if line[-2:] != "\r\n":
|
if line[-2:] != "\r\n":
|
||||||
print("newline fucked")
|
print("Failed to parse: newline broken")
|
||||||
return {key : None for key in FORMAT}
|
return {key : None for key in FORMAT}
|
||||||
line = line[:-2]
|
line = line[:-2]
|
||||||
|
|
||||||
crc_str = line[-4:]
|
crc_str = line[-4:]
|
||||||
print(crc_str)
|
|
||||||
payload = line[0:-4]
|
payload = line[0:-4]
|
||||||
crc = int(crc_str, 16)
|
crc = int(crc_str, 16)
|
||||||
calced_crc = calc_crc(payload.encode('ascii'))
|
calced_crc = calc_crc(payload.encode('ascii'))
|
||||||
if 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}
|
return {key : None for key in FORMAT}
|
||||||
|
|
||||||
parts = payload.split(';')
|
parts = payload.split(';')
|
||||||
|
@ -121,10 +120,13 @@ def main():
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
line = ser.readline().decode('ascii')
|
line = ser.readline().decode('ascii')
|
||||||
print(line)
|
|
||||||
if len(line) > 0:
|
if len(line) > 0:
|
||||||
|
print(line)
|
||||||
parsed = parse_line(line)
|
parsed = parse_line(line)
|
||||||
update_database(parsed)
|
update_database(parsed)
|
||||||
|
update_graphs()
|
||||||
|
upload_graphs()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue