Merge branch 'pr-poetry' into powermon

This commit is contained in:
Kevin Hester
2024-06-22 10:34:16 -07:00
parent 4203553a44
commit b41cb7d8df
11 changed files with 575 additions and 13 deletions

View File

@@ -39,6 +39,7 @@ class StreamInterface(MeshInterface):
self._wantExit = False
self.is_windows11 = is_windows11()
self.cur_log_line = ""
# FIXME, figure out why daemon=True causes reader thread to exit too early
self._rxThread = threading.Thread(target=self.__reader, args=(), daemon=True)
@@ -124,6 +125,26 @@ class StreamInterface(MeshInterface):
if self._rxThread != threading.current_thread():
self._rxThread.join() # wait for it to exit
def _handleLogByte(self, b):
"""Handle a byte that is part of a log message from the device."""
utf = "?" # assume we might fail
try:
utf = b.decode("utf-8")
except:
pass
if utf == "\r":
pass # ignore
elif utf == "\n":
self._handleLogLine(self.cur_log_line)
self.cur_log_line = ""
else:
self.cur_log_line += utf
if self.debugOut is not None:
self.debugOut.write(utf)
def __reader(self):
"""The reader thread that reads bytes from our stream"""
logging.debug("in __reader()")
@@ -146,11 +167,9 @@ class StreamInterface(MeshInterface):
if ptr == 0: # looking for START1
if c != START1:
self._rxBuf = empty # failed to find start
if self.debugOut is not None:
try:
self.debugOut.write(b.decode("utf-8"))
except:
self.debugOut.write("?")
# This must be a log message from the device
self._handleLogByte(b)
elif ptr == 1: # looking for START2
if c != START2: