allow logging serial debug to different files

This commit is contained in:
geeksville
2020-04-28 10:11:57 -07:00
parent 380cf4c999
commit 1b8df614bf
4 changed files with 25 additions and 11 deletions

1
*.pyc
View File

@@ -1 +0,0 @@
*.pyc

View File

@@ -1 +1 @@
python3 -m meshtastic --debug
python3 -m meshtastic --debug "$@"

View File

@@ -3,7 +3,7 @@
import argparse
from .interface import StreamInterface
import logging
from time import sleep
import sys
def main():
@@ -15,13 +15,27 @@ def main():
help="The port the Meshtastic device is connected to, i.e. /dev/ttyUSB0. If unspecified, we'll try to find it.",
default=None)
parser.add_argument("--debug", help="Show debug log message",
parser.add_argument(
"--seriallog",
help="Log device serial output to either 'stdout', 'none' or a filename to append to. Defaults to stdout.",
default="stdout")
parser.add_argument("--debug", help="Show API library debug log messages",
action="store_true")
args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
client = StreamInterface(args.device)
if args.seriallog == "stdout":
logfile = sys.stdout
elif args.seriallog == "none":
logging.debug("Not logging serial output")
logfile = None
else:
logging.info(f"Logging serial output to {args.seriallog}")
logfile = open(args.seriallog, 'w+', buffering=1) # line buffering
client = StreamInterface(args.device, debugOut=logfile)
if __name__ == "__main__":

View File

@@ -137,7 +137,7 @@ class StreamInterface(MeshInterface):
devPath, 921600, exclusive=True, timeout=0.5)
self._rxThread = threading.Thread(target=self.__reader, args=())
self._rxThread.start()
MeshInterface.__init__(self)
MeshInterface.__init__(self, debugOut=debugOut)
def _sendToRadio(self, toRadio):
"""Send a ToRadio protobuf to the device"""
@@ -172,10 +172,11 @@ class StreamInterface(MeshInterface):
if ptr == 0: # looking for START1
if c != START1:
self._rxBuf = empty # failed to find start
try:
self.debugOut.write(b.decode("utf-8"))
except:
self.debugOut.write('?')
if self.debugOut != None:
try:
self.debugOut.write(b.decode("utf-8"))
except:
self.debugOut.write('?')
elif ptr == 1: # looking for START2
if c != START2: