Skip to content

Commit 42e0694

Browse files
committed
transition through power stress states and capture data
meshtastic-py3.12kevinh@kdesktop:~/development/meshtastic/meshtastic-python$ cd /home/kevinh/development/meshtastic/meshtastic-python ; /usr/bin/env /home/kevinh/.cache/pypoetry/virtualenvs/meshtastic-l6tP90xw-py3.12/bin/python /home/kevinh/.vscode/extensions/ms-python.debugpy-2024.6.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher 52521 -- -m meshtastic --slog --power-ppk2-meter --power-stress --power-voltage 3.3 INFO file:ppk2.py __init__ line:52 Connected to Power Profiler Kit II (PPK2) INFO file:__main__.py create_power_meter line:1022 Setting power supply to 3.3 volts Connected to radio INFO file:slog.py __init__ line:183 Writing slogs to /home/kevinh/.local/share/meshtastic/slogs/20240706-123803 INFO file:stress.py syncPowerStress line:68 Sending power stress command PRINT_INFO INFO file:stress.py run line:105 Running power stress test 48 for 5.0 seconds INFO file:stress.py syncPowerStress line:68 Sending power stress command LED_ON INFO file:stress.py run line:105 Running power stress test 80 for 5.0 seconds INFO file:stress.py syncPowerStress line:68 Sending power stress command BT_OFF INFO file:stress.py run line:105 Running power stress test 81 for 5.0 seconds INFO file:stress.py syncPowerStress line:68 Sending power stress command BT_ON INFO file:stress.py run line:105 Running power stress test 34 for 5.0 seconds INFO file:stress.py syncPowerStress line:68 Sending power stress command CPU_FULLON INFO file:stress.py run line:105 Running power stress test 32 for 5.0 seconds INFO file:stress.py syncPowerStress line:68 Sending power stress command CPU_IDLE INFO file:stress.py run line:105 Running power stress test 33 for 5.0 seconds INFO file:stress.py syncPowerStress line:68 Sending power stress command CPU_DEEPSLEEP INFO file:stress.py run line:108 Power stress test complete. INFO file:slog.py close line:201 Closing slogs in /home/kevinh/.local/share/meshtastic/slogs/20240706-123803 WARNING file:arrow.py close line:67 Discarding empty file: /home/kevinh/.local/share/meshtastic/slogs/20240706-123803/slog.arrow INFO file:arrow.py close line:70 Compressing log data into /home/kevinh/.local/share/meshtastic/slogs/20240706-123803/power.feather meshtastic-py3.12kevinh@kdesktop:~/development/meshtastic/meshtastic-python$
1 parent 6332798 commit 42e0694

4 files changed

Lines changed: 51 additions & 18 deletions

File tree

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
"request": "launch",
205205
"module": "meshtastic",
206206
"justMyCode": false,
207-
"args": ["--slog-out", "default", "--power-ppk2-meter", "--power-stress", "--power-voltage", "3.3", "--seriallog"]
207+
"args": ["--slog", "--power-ppk2-meter", "--power-stress", "--power-voltage", "3.3"]
208208
},
209209
{
210210
"name": "meshtastic test",

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"cSpell.words": [
33
"bitmask",
44
"boardid",
5+
"DEEPSLEEP",
56
"Meshtastic",
67
"milliwatt",
78
"portnums",

meshtastic/__main__.py

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

855+
log_set: Optional[LogSet] = None # we need to keep a reference to the logset so it doesn't get GCed early
855856
if args.slog or args.power_stress:
856857
# Setup loggers
857858
global meter # pylint: disable=global-variable-not-assigned
858-
LogSet(interface, args.slog if args.slog != 'default' else None, meter)
859+
log_set = LogSet(interface, args.slog if args.slog != 'default' else None, meter)
859860

860861
if args.power_stress:
861862
stress = PowerStress(interface)
862863
stress.run()
864+
closeNow = True # exit immediately after stress test
863865

864866
if args.listen:
865867
closeNow = False
@@ -895,6 +897,8 @@ def setSimpleConfig(modem_preset):
895897
# if the user didn't ask for serial debugging output, we might want to exit after we've done our operation
896898
if (not args.seriallog) and closeNow:
897899
interface.close() # after running command then exit
900+
if log_set:
901+
log_set.close()
898902

899903
except Exception as ex:
900904
print(f"Aborting due to: {ex}")

meshtastic/powermon/stress.py

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import time
55

6-
from ..protobuf import ( portnums_pb2, powermon_pb2 )
6+
from ..protobuf import portnums_pb2, powermon_pb2
77

88

99
def onPowerStressResponse(packet, interface):
@@ -53,6 +53,32 @@ def sendPowerStress(
5353
onResponseAckPermitted=True,
5454
)
5555

56+
def syncPowerStress(
57+
self,
58+
cmd: powermon_pb2.PowerStressMessage.Opcode.ValueType,
59+
num_seconds: float = 0.0,
60+
):
61+
"""Send a power stress command and wait for the ack."""
62+
gotAck = False
63+
64+
def onResponse(packet: dict): # pylint: disable=unused-argument
65+
nonlocal gotAck
66+
gotAck = True
67+
68+
logging.info(f"Sending power stress command {powermon_pb2.PowerStressMessage.Opcode.Name(cmd)}")
69+
self.sendPowerStress(cmd, onResponse=onResponse, num_seconds=num_seconds)
70+
71+
if num_seconds == 0.0:
72+
# Wait for the response and then continue
73+
while not gotAck:
74+
time.sleep(0.1)
75+
else:
76+
# we wait a little bit longer than the time the UUT would be waiting (to make sure all of its messages are handled first)
77+
time.sleep(num_seconds + 0.2) # completely block our thread for the duration of the test
78+
if not gotAck:
79+
logging.error("Did not receive ack for power stress command!")
80+
81+
5682

5783
class PowerStress:
5884
"""Walk the UUT through a set of power states so we can capture repeatable power consumption measurements."""
@@ -63,19 +89,21 @@ def __init__(self, iface):
6389
def run(self):
6490
"""Run the power stress test."""
6591
# Send the power stress command
66-
gotAck = False
67-
68-
def onResponse(packet: dict): # pylint: disable=unused-argument
69-
nonlocal gotAck
70-
gotAck = True
71-
72-
logging.info("Starting power stress test, attempting to contact UUT...")
73-
self.client.sendPowerStress(
74-
powermon_pb2.PowerStressMessage.PRINT_INFO, onResponse=onResponse
75-
)
76-
77-
# Wait for the response
78-
while not gotAck:
79-
time.sleep(0.1)
8092

81-
logging.info("Power stress test complete.")
93+
self.client.syncPowerStress(powermon_pb2.PowerStressMessage.PRINT_INFO)
94+
95+
num_seconds = 5.0
96+
states = [
97+
powermon_pb2.PowerStressMessage.LED_ON,
98+
powermon_pb2.PowerStressMessage.BT_OFF,
99+
powermon_pb2.PowerStressMessage.BT_ON,
100+
powermon_pb2.PowerStressMessage.CPU_FULLON,
101+
powermon_pb2.PowerStressMessage.CPU_IDLE,
102+
powermon_pb2.PowerStressMessage.CPU_DEEPSLEEP,
103+
]
104+
for s in states:
105+
s_name = powermon_pb2.PowerStressMessage.Opcode.Name(s)
106+
logging.info(f"Running power stress test {s_name} for {num_seconds} seconds")
107+
self.client.syncPowerStress(s, num_seconds)
108+
109+
logging.info("Power stress test complete.")

0 commit comments

Comments
 (0)