diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index f479009..bc93c27 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -852,14 +852,14 @@ def onConnected(interface): qr = pyqrcode.create(url) print(qr.terminal()) - if args.slog_out: + if args.slog_out or args.power_stress: # Setup loggers global meter LogSet(interface, args.slog_out if args.slog_out != 'default' else None, meter) - if args.power_stress: - stress = PowerStress(interface) - stress.run() + if args.power_stress: + stress = PowerStress(interface) + stress.run() if args.listen: closeNow = False diff --git a/meshtastic/powermon/stress.py b/meshtastic/powermon/stress.py index b847e12..0ab8d7d 100644 --- a/meshtastic/powermon/stress.py +++ b/meshtastic/powermon/stress.py @@ -47,7 +47,7 @@ class PowerStressClient: self.node_id, portnums_pb2.POWERSTRESS_APP, wantAck=True, - wantResponse=False, + wantResponse=True, onResponse=onResponse, onResponseAckPermitted=True ) @@ -64,7 +64,7 @@ class PowerStress: # Send the power stress command gotAck = False - def onResponse(packet, interface): + def onResponse(packet: dict): # pylint: disable=unused-argument nonlocal gotAck gotAck = True diff --git a/meshtastic/slog/slog.py b/meshtastic/slog/slog.py index 7f99d38..e7c8efc 100644 --- a/meshtastic/slog/slog.py +++ b/meshtastic/slog/slog.py @@ -1,11 +1,11 @@ """code logging power consumption of meshtastic devices.""" import atexit +import io import logging import os import re import threading -import io import time from dataclasses import dataclass from datetime import datetime @@ -100,10 +100,17 @@ class StructuredLogger: """ self.client = client self.writer = FeatherWriter(f"{dir_path}/slog") - self.raw_file: Optional[io.TextIOWrapper] = open( # pylint: disable=consider-using-with + self.raw_file: Optional[ + io.TextIOWrapper + ] = open( # pylint: disable=consider-using-with f"{dir_path}/raw.txt", "w", encoding="utf8" ) - self.listener = pub.subscribe(self._onLogMessage, TOPIC_MESHTASTIC_LOG_LINE) + + # We need a closure here because the subscription API is very strict about exact arg matching + def listen_glue(line, interface): # pylint: disable=unused-argument + self._onLogMessage(line) + + self.listener = pub.subscribe(listen_glue, TOPIC_MESHTASTIC_LOG_LINE) def close(self) -> None: """Stop logging.""" @@ -113,9 +120,7 @@ class StructuredLogger: self.raw_file = None # mark that we are shutting down f.close() # Close the raw.txt file - def _onLogMessage( - self, line: str, interface: MeshInterface # pylint: disable=unused-argument - ) -> None: + def _onLogMessage(self, line: str) -> None: """Handle log messages. line (str): the line of log output @@ -126,17 +131,20 @@ class StructuredLogger: args = m.group(2) args += " " # append a space so that if the last arg is an empty str it will still be accepted as a match logging.debug(f"SLog {src}, reason: {args}") - d = log_defs.get(src) - if d: - r = d.format.parse(args) # get the values with the correct types - if r: - di = r.named - di["time"] = datetime.now() - self.writer.add_row(di) - else: - logging.warning(f"Failed to parse slog {line} with {d.format}") + if(src != "PM"): + logging.warning(f"Not yet handling structured log {src} (FIXME)") else: - logging.warning(f"Unknown Structured Log: {line}") + d = log_defs.get(src) + if d: + r = d.format.parse(args) # get the values with the correct types + if r: + di = r.named + di["time"] = datetime.now() + self.writer.add_row(di) + else: + logging.warning(f"Failed to parse slog {line} with {d.format}") + else: + logging.warning(f"Unknown Structured Log: {line}") if self.raw_file: self.raw_file.write(line + "\n") # Write the raw log diff --git a/protobufs b/protobufs index c25e0c4..9d747b6 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit c25e0c4e0ba99a5e2e94a1ca7313f999bf794fbd +Subproject commit 9d747b6cf08e2762fdf9530173a7ff825b9daa90