Skip to content

Commit dabb4ea

Browse files
committed
PowerStress client approximately works
1 parent 119be81 commit dabb4ea

4 files changed

Lines changed: 31 additions & 23 deletions

File tree

meshtastic/__main__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -852,14 +852,14 @@ def setSimpleConfig(modem_preset):
852852
qr = pyqrcode.create(url)
853853
print(qr.terminal())
854854

855-
if args.slog_out:
855+
if args.slog_out or args.power_stress:
856856
# Setup loggers
857857
global meter
858858
LogSet(interface, args.slog_out if args.slog_out != 'default' else None, meter)
859859

860-
if args.power_stress:
861-
stress = PowerStress(interface)
862-
stress.run()
860+
if args.power_stress:
861+
stress = PowerStress(interface)
862+
stress.run()
863863

864864
if args.listen:
865865
closeNow = False

meshtastic/powermon/stress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def sendPowerStress(
4747
self.node_id,
4848
portnums_pb2.POWERSTRESS_APP,
4949
wantAck=True,
50-
wantResponse=False,
50+
wantResponse=True,
5151
onResponse=onResponse,
5252
onResponseAckPermitted=True
5353
)
@@ -64,7 +64,7 @@ def run(self):
6464
# Send the power stress command
6565
gotAck = False
6666

67-
def onResponse(packet, interface):
67+
def onResponse(packet: dict): # pylint: disable=unused-argument
6868
nonlocal gotAck
6969
gotAck = True
7070

meshtastic/slog/slog.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""code logging power consumption of meshtastic devices."""
22

33
import atexit
4+
import io
45
import logging
56
import os
67
import re
78
import threading
8-
import io
99
import time
1010
from dataclasses import dataclass
1111
from datetime import datetime
@@ -100,10 +100,17 @@ def __init__(self, client: MeshInterface, dir_path: str) -> None:
100100
"""
101101
self.client = client
102102
self.writer = FeatherWriter(f"{dir_path}/slog")
103-
self.raw_file: Optional[io.TextIOWrapper] = open( # pylint: disable=consider-using-with
103+
self.raw_file: Optional[
104+
io.TextIOWrapper
105+
] = open( # pylint: disable=consider-using-with
104106
f"{dir_path}/raw.txt", "w", encoding="utf8"
105107
)
106-
self.listener = pub.subscribe(self._onLogMessage, TOPIC_MESHTASTIC_LOG_LINE)
108+
109+
# We need a closure here because the subscription API is very strict about exact arg matching
110+
def listen_glue(line, interface): # pylint: disable=unused-argument
111+
self._onLogMessage(line)
112+
113+
self.listener = pub.subscribe(listen_glue, TOPIC_MESHTASTIC_LOG_LINE)
107114

108115
def close(self) -> None:
109116
"""Stop logging."""
@@ -113,9 +120,7 @@ def close(self) -> None:
113120
self.raw_file = None # mark that we are shutting down
114121
f.close() # Close the raw.txt file
115122

116-
def _onLogMessage(
117-
self, line: str, interface: MeshInterface # pylint: disable=unused-argument
118-
) -> None:
123+
def _onLogMessage(self, line: str) -> None:
119124
"""Handle log messages.
120125
121126
line (str): the line of log output
@@ -126,17 +131,20 @@ def _onLogMessage(
126131
args = m.group(2)
127132
args += " " # append a space so that if the last arg is an empty str it will still be accepted as a match
128133
logging.debug(f"SLog {src}, reason: {args}")
129-
d = log_defs.get(src)
130-
if d:
131-
r = d.format.parse(args) # get the values with the correct types
132-
if r:
133-
di = r.named
134-
di["time"] = datetime.now()
135-
self.writer.add_row(di)
136-
else:
137-
logging.warning(f"Failed to parse slog {line} with {d.format}")
134+
if(src != "PM"):
135+
logging.warning(f"Not yet handling structured log {src} (FIXME)")
138136
else:
139-
logging.warning(f"Unknown Structured Log: {line}")
137+
d = log_defs.get(src)
138+
if d:
139+
r = d.format.parse(args) # get the values with the correct types
140+
if r:
141+
di = r.named
142+
di["time"] = datetime.now()
143+
self.writer.add_row(di)
144+
else:
145+
logging.warning(f"Failed to parse slog {line} with {d.format}")
146+
else:
147+
logging.warning(f"Unknown Structured Log: {line}")
140148
if self.raw_file:
141149
self.raw_file.write(line + "\n") # Write the raw log
142150

protobufs

0 commit comments

Comments
 (0)