Skip to content

Commit

Permalink
powermon WIP (for meshtastic#4136 )
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksville committed Jun 18, 2024
1 parent 03033ec commit b9d2d49
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 1 deletion.
2 changes: 1 addition & 1 deletion protobufs
11 changes: 11 additions & 0 deletions src/PowerMon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "PowerMon.h"

void PowerMon::setState(_meshtastic_PowerMon_State state, const char *reason) {}
void PowerMon::clearState(_meshtastic_PowerMon_State state, const char *reason) {}

PowerMon *powerMon;

void powerMonInit()
{
powerMon = new PowerMon();
}
25 changes: 25 additions & 0 deletions src/PowerMon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include "configuration.h"

#include "meshtastic/powermon.pb.h"

/**
* The singleton class for monitoring power consumption of device
* subsystems/modes.
*
* For more information see the PowerMon docs.
*/
class PowerMon
{
uint64_t states = 0UL;

public:
PowerMon() {}

void setState(_meshtastic_PowerMon_State state, const char *reason);
void clearState(_meshtastic_PowerMon_State state, const char *reason);
};

extern PowerMon *powerMon;

void powerMonInit();
13 changes: 13 additions & 0 deletions src/mesh/generated/meshtastic/powermon.pb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Automatically generated nanopb constant definitions */
/* Generated by nanopb-0.4.8 */

#include "meshtastic/powermon.pb.h"
#if PB_PROTO_HEADER_VERSION != 40
#error Regenerate this file with the current version of nanopb generator.
#endif

PB_BIND(meshtastic_PowerMon_Event, meshtastic_PowerMon_Event, AUTO)




81 changes: 81 additions & 0 deletions src/mesh/generated/meshtastic/powermon.pb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* Automatically generated nanopb header */
/* Generated by nanopb-0.4.8 */

#ifndef PB_MESHTASTIC_POWERMON_MESHTASTIC_POWERMON_PB_H_INCLUDED
#define PB_MESHTASTIC_POWERMON_MESHTASTIC_POWERMON_PB_H_INCLUDED
#include <pb.h>

#if PB_PROTO_HEADER_VERSION != 40
#error Regenerate this file with the current version of nanopb generator.
#endif

/* Enum definitions */
/* Any significant power changing event in meshtastic should be tagged with a powermon state transition.
If you are making new meshtastic features feel free to add new entries at the end of this definition. */
typedef enum _meshtastic_PowerMon_State {
meshtastic_PowerMon_State_None = 0,
meshtastic_PowerMon_State_CPU_DeepSleep = 1,
meshtastic_PowerMon_State_CPU_Sleep = 2,
meshtastic_PowerMon_State_CPU_Awake = 4,
meshtastic_PowerMon_State_Lora_RXOn = 8,
meshtastic_PowerMon_State_Lora_TXOn = 16,
meshtastic_PowerMon_State_Lora_RXActive = 32,
meshtastic_PowerMon_State_BT_On = 64,
meshtastic_PowerMon_State_LED_On = 128,
meshtastic_PowerMon_State_Screen_On = 256,
meshtastic_PowerMon_State_Screen_Drawing = 512,
meshtastic_PowerMon_State_Wifi_On = 1024,
meshtastic_PowerMon_State_GPS_LowPower = 2048,
meshtastic_PowerMon_State_GPS_MediumPower = 4096,
meshtastic_PowerMon_State_GPS_HighPower = 8192
} meshtastic_PowerMon_State;

/* Struct definitions */
/* the log messages will be short and complete (see PowerMon.Event in the protobufs for details).
something like "PwrMon,C,0x00001234,REASON" where the hex number is the bitmask of all current states.
(We use a bitmask for states so that if a log message gets lost it won't be fatal) */
typedef struct _meshtastic_PowerMon_Event {
/* Bitwise-OR of States */
bool has_states;
uint64_t states;
} meshtastic_PowerMon_Event;


#ifdef __cplusplus
extern "C" {
#endif

/* Helper constants for enums */
#define _meshtastic_PowerMon_State_MIN meshtastic_PowerMon_State_None
#define _meshtastic_PowerMon_State_MAX meshtastic_PowerMon_State_GPS_HighPower
#define _meshtastic_PowerMon_State_ARRAYSIZE ((meshtastic_PowerMon_State)(meshtastic_PowerMon_State_GPS_HighPower+1))



/* Initializer values for message structs */
#define meshtastic_PowerMon_Event_init_default {false, 0}
#define meshtastic_PowerMon_Event_init_zero {false, 0}

/* Field tags (for use in manual encoding/decoding) */
#define meshtastic_PowerMon_Event_states_tag 1

/* Struct field encoding specification for nanopb */
#define meshtastic_PowerMon_Event_FIELDLIST(X, a) \
X(a, STATIC, OPTIONAL, UINT64, states, 1)
#define meshtastic_PowerMon_Event_CALLBACK NULL
#define meshtastic_PowerMon_Event_DEFAULT NULL

extern const pb_msgdesc_t meshtastic_PowerMon_Event_msg;

/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
#define meshtastic_PowerMon_Event_fields &meshtastic_PowerMon_Event_msg

/* Maximum encoded size of messages (where known) */
#define MESHTASTIC_POWERMON_MESHTASTIC_POWERMON_PB_H_MAX_SIZE meshtastic_PowerMon_Event_size
#define meshtastic_PowerMon_Event_size 11

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif

0 comments on commit b9d2d49

Please sign in to comment.