decding eror

This commit is contained in:
Matthew Frost 2023-11-01 17:45:12 +01:00
parent afcb5e5828
commit 51c70d2f88

View file

@ -125,25 +125,28 @@ def serial_router():
data = ser.readline() data = ser.readline()
try: try:
data = data.decode('utf-8') data = data.decode('utf-8')
if '=' in data: try:
prefix, value = data.split('=') if '=' in data:
prefix = prefix.strip() prefix, value = data.split('=')
value = value.strip() prefix = prefix.strip()
value = value.strip()
actions = { actions = {
"LOG_MSG": handle_log_msg, "LOG_MSG": handle_log_msg,
"FULL_CARD_ID": check_valid_card, "FULL_CARD_ID": check_valid_card,
"DOOR_DISABLED_STATUS": handle_log_msg, "DOOR_DISABLED_STATUS": handle_log_msg,
"DOOR_LOCK_STATUS": handle_log_msg "DOOR_LOCK_STATUS": handle_log_msg
} }
if prefix in actions: if prefix in actions:
actions[prefix](prefix, value) actions[prefix](prefix, value)
else: else:
print(f"Unknown prefix: {prefix}") print(f"Unknown prefix: {prefix}")
except UnicodeDecodeError: except UnicodeDecodeError:
hex_data = binascii.hexlify(data).decode('utf-8') hex_data = binascii.hexlify(data).decode('utf-8')
print(f"Received non-UTF-8 data: {hex_data}") print(f"Received non-UTF-8 data: {hex_data}")
except:
print("Error decoding serial data")
def start_thread(thread_function): def start_thread(thread_function):
thread = threading.Thread(target=thread_function) thread = threading.Thread(target=thread_function)