diff --git a/meshtastic/powermon/stress.py b/meshtastic/powermon/stress.py index 4e82508..b416d8a 100644 --- a/meshtastic/powermon/stress.py +++ b/meshtastic/powermon/stress.py @@ -65,7 +65,9 @@ class PowerStressClient: nonlocal gotAck gotAck = True - logging.info(f"Sending power stress command {powermon_pb2.PowerStressMessage.Opcode.Name(cmd)}") + logging.info( + f"Sending power stress command {powermon_pb2.PowerStressMessage.Opcode.Name(cmd)}" + ) self.sendPowerStress(cmd, onResponse=onResponse, num_seconds=num_seconds) if num_seconds == 0.0: @@ -74,12 +76,13 @@ class PowerStressClient: time.sleep(0.1) else: # we wait a little bit longer than the time the UUT would be waiting (to make sure all of its messages are handled first) - time.sleep(num_seconds + 0.2) # completely block our thread for the duration of the test + time.sleep( + num_seconds + 0.2 + ) # completely block our thread for the duration of the test if not gotAck: logging.error("Did not receive ack for power stress command!") - class PowerStress: """Walk the UUT through a set of power states so we can capture repeatable power consumption measurements.""" @@ -88,24 +91,27 @@ class PowerStress: def run(self): """Run the power stress test.""" - # Send the power stress command + try: + self.client.syncPowerStress(powermon_pb2.PowerStressMessage.PRINT_INFO) - self.client.syncPowerStress(powermon_pb2.PowerStressMessage.PRINT_INFO) + num_seconds = 5.0 + states = [ + powermon_pb2.PowerStressMessage.LED_ON, + powermon_pb2.PowerStressMessage.LED_OFF, + powermon_pb2.PowerStressMessage.BT_OFF, + powermon_pb2.PowerStressMessage.BT_ON, + powermon_pb2.PowerStressMessage.CPU_FULLON, + powermon_pb2.PowerStressMessage.CPU_IDLE, + # FIXME - can't test deepsleep yet because the ttyACM device disappears. Fix the python code to retry connections + # powermon_pb2.PowerStressMessage.CPU_DEEPSLEEP, + ] + for s in states: + s_name = powermon_pb2.PowerStressMessage.Opcode.Name(s) + logging.info( + f"Running power stress test {s_name} for {num_seconds} seconds" + ) + self.client.syncPowerStress(s, num_seconds) - num_seconds = 5.0 - states = [ - powermon_pb2.PowerStressMessage.LED_ON, - powermon_pb2.PowerStressMessage.LED_OFF, - powermon_pb2.PowerStressMessage.BT_OFF, - powermon_pb2.PowerStressMessage.BT_ON, - powermon_pb2.PowerStressMessage.CPU_FULLON, - powermon_pb2.PowerStressMessage.CPU_IDLE, - # FIXME - can't test deepsleep yet because the ttyACM device disappears. Fix the python code to retry connections - # powermon_pb2.PowerStressMessage.CPU_DEEPSLEEP, - ] - for s in states: - s_name = powermon_pb2.PowerStressMessage.Opcode.Name(s) - logging.info(f"Running power stress test {s_name} for {num_seconds} seconds") - self.client.syncPowerStress(s, num_seconds) - - logging.info("Power stress test complete.") \ No newline at end of file + logging.info("Power stress test complete.") + except KeyboardInterrupt as e: + logging.warning(f"Power stress interrupted: {e}")