Added TDW logging

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

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

Loading…
Cancel
Save