Added TDW logging

fix-v0.2
Tom Wilson 6 years ago
parent bb4c777ec6
commit 4c6bdbba7d

@ -21,8 +21,11 @@ import threading
import serial
import re
import time
import logging
from enum import Enum
log = logging.getLogger(__name__)
DEFAULT = object()
MAX_MSG_LEN = 128
@ -108,7 +111,7 @@ class TXMessage(Message):
# Allow single value or string as arg, convert to list
if isinstance(arguments, str) or (not hasattr(arguments, "__iter__")):
arguments = list(arguments)
arguments = [arguments]
# Stringify args and put in immutable tuples
immutable_args = tuple([str(arg) for arg in arguments])
@ -117,7 +120,7 @@ class TXMessage(Message):
if multipart_args is not None:
# Allow single value or string as arg, convert to list
if isinstance(multipart_args, str) or (not hasattr(multipart_args, "__iter__")):
multipart_args = list(multipart_args)
multipart_args = [multipart_args]
immutable_multipart_args = []
for arglist in multipart_args:
@ -288,7 +291,7 @@ class MessageHandler():
send_str = F"{self._tx_message.msg_type}{self._tx_message.msg_name}{argstr}\n"
self.port.write(send_str.encode('utf-8'))
self._tx_sent_time = time.time()
#print(F"TX: {send_str}")
log.debug(F"Msg TX: {send_str}")
# Only keep the current message around if we need to track a response
if not self._tx_message.needs_response:
self._tx_message = None
@ -339,7 +342,7 @@ class MessageHandler():
Only called from the serial_comm thread
"""
#print(F"RX: {msg_str}")
log.debug(F"Msg RX: {msg_str}")
self._last_rx_time = time.time()
msg_name, _, msg_args_text = msg_str.strip(' \t').partition(':')
@ -458,9 +461,11 @@ class MessageHandler():
# Serial comms is not synchronous, so need to be available to recieve characters
# at any point
try:
log.info(F"Connecting to serial port {self.port.port}, with baud {self.port.baudrate}...")
self.port.open()
while True:
self._handle_serial_port()
except serial.SerialException:
log.error("Could not open serial port")
time.sleep(1)
# If there's a serialexception, try to reopen the port

Loading…
Cancel
Save