libpowermon 1.11
PowerMon Access Library
Loading...
Searching...
No Matches
powermon.h
1/* Copyright (C) 2020 - 2024, Thornwave Labs Inc
2 * Written by Razvan Turiac <razvan.turiac@thornwave.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 * documentation files (the “Software”), to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 *
9 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 * Attribution shall be given to Thornwave Labs Inc. and shall be made visible to the final user.
11 *
12 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
13 * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
14 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
15 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16*/
17
18#ifndef _POWERMON_H
19#define _POWERMON_H
20
21
22#include <stdint.h>
23#include <string.h>
24
25#include <string>
26#include <vector>
27#include <functional>
28
29
30#include <powermon_config.h>
31#include <powermon_schedule.h>
32#include <powermon_log.h>
33
34
35#define MAX_WIFI_SSID_SIZE 32
36#define MAX_WIFI_PASSWORD_SIZE 64
37
38#define CHANNEL_ID_SIZE 16
39#define ENCRYPTION_KEY_SIZE 32
40
41#define MAX_BLE_NAME_LENGTH 8
42#define MAX_NAME_LENGTH 32
43
44#define MAX_TIMER_NAME_LENGTH 16
45#define MAX_TIMER_COUNT 16
46
47#define FG_SOC_DISABLED 0xFF
48#define FG_SOC_UNKNOWN 0xFE
49
50#define FG_RUNTIME_DISABLED 0xFFFF
51#define FG_RUNTIME_UNKNOWN 0xFFFE
52#define FG_RUNTIME_MAX 0xFFF0
53
54
59{
60public:
64 enum HardwareRevision: uint8_t
65 {
66 FAMILY_MASK = 0xF0,
67
68 POWERMON_E = 0x10,
69 POWERMON = 0x20,
70 POWERMON_5S = 0x30,
71 POWERMON_W = 0x40
72 };
73
74
78 enum State: uint8_t
79 {
83 };
84
85
89 enum DisconnectReason: uint8_t
90 {
91 CLOSED = 0,
92 NO_ROUTE,
93 FAILED,
94 UNEXPECTED_ERROR,
95 UNEXPECTED_RESPONSE,
96 WRITE_ERROR,
97 READ_ERROR,
98 };
99
100
104 enum ResponseCode: uint16_t
105 {
106 RSP_SUCCESS = 0x0000,
107 RSP_SUCCESS_MORE = 0x0100,
108
109 RSP_INVALID_REQ = 0x0001,
110 RSP_INVALID_PARAM = 0x0002,
111 RSP_ERROR = 0x0003,
112 RSP_LOCKED_USER = 0x0004,
113 RSP_LOCKED_MASTER = 0x0005,
114 RSP_CANNOT_UNLOCK = 0x0006,
115 RSP_NOT_FOUND = 0x0007,
116
117 RSP_TIMEOUT = 0x0008,
118 RSP_INVALID = 0x0009,
119 RSP_CANCELLED = 0x000A,
120 };
121
122
126 enum PowerStatus: uint8_t
127 {
128 PS_OFF = 0,
129 PS_ON = 1,
130 PS_LVD = 2,
131 PS_OCD = 3,
132 PS_HVD = 4,
133 PS_FGD = 5,
134 PS_NCH = 6,
135 PS_LTD = 7,
136 PS_HTD = 8,
137 };
138
139
143 struct AuthKey
144 {
145 uint8_t data[32];
146 };
147
148
153 {
154 uint8_t channel_id[CHANNEL_ID_SIZE];
155 uint8_t encryption_key[ENCRYPTION_KEY_SIZE];
156 };
157
158
163 {
164 enum SecurityMode: uint16_t
165 {
166 OPEN = 0x0,
167 WEP = 0x1,
169 WPA2_PSK = 0x4,
170 WPA3_SAE = 0x6
171 };
172
173 uint8_t ssid_length;
174 uint8_t ssid[MAX_WIFI_SSID_SIZE];
175
176 uint8_t pass_length;
177 uint8_t pass[MAX_WIFI_PASSWORD_SIZE];
178
179 uint16_t flags;
180
181 bool isPasswordProtected(void) const;
182 bool isMetered(void) const;
183 bool isFailed(void) const;
184
185 void setMetered(bool enabled);
186 };
187
188
193 {
194 uint8_t ssid_length;
195 uint8_t ssid[MAX_WIFI_SSID_SIZE];
196 uint8_t channel;
197
198 struct
199 {
200 uint8_t wep : 1;
201 uint8_t wpa : 1;
202 uint8_t wpa2 : 1;
203 uint8_t wpa3 : 1;
204 uint8_t pmf : 1;
205 uint8_t unused : 1;
206 uint8_t psk : 1;
207 uint8_t eap : 1;
208 }security;
209
210 int8_t rssi;
211
212 bool operator==(const WifiScanResult &rhs) const;
213 };
214
215
220 {
221 std::string name;
222
223 uint16_t firmware_version_bcd;
224 uint8_t hardware_revision_bcd;
225
226 uint64_t address;
227 uint64_t serial;
228
229 uint8_t ssid_length;
230 uint8_t ssid[MAX_WIFI_SSID_SIZE];
231 uint8_t flags;
232 int8_t timezone;
233
234 bool isUserPasswordSet(void) const;
235 bool isMasterPasswordSet(void) const;
236 bool isUserLocked(void) const;
237 bool isMasterLocked(void) const;
238
239 bool isWifiConnecting(void) const;
240 bool isWifiConnected(void) const;
241 bool isWifiFailed(void) const;
242 };
243
244
248 struct DeviceIdentifier
249 {
250 std::string name;
251 uint64_t serial;
253 uint64_t address;
254
256
257 DeviceIdentifier();
258
259 bool operator==(const DeviceIdentifier &rhs);
260
266 bool fromURL(const char* url);
267
272 std::string toURL(void);
273 };
274
275
280 {
283
284 uint32_t time;
285 uint32_t flags;
286
287 float voltage1;
288 float voltage2;
289 float current;
290 float power;
292
294 int64_t energy_meter;
295
297
298 uint8_t fg_soc;
299 uint16_t fg_runtime;
300
301 int16_t rssi = INT16_MIN;
302
306 bool isTemperatureExternal(void) const;
307 };
308
309
314 {
316
317 float voltage1_min;
318 float voltage1_max;
319
320 float voltage2_min;
321 float voltage2_max;
322
323 float peak_charge_current;
324 float peak_discharge_current;
325
328 };
329
330
335 {
336 uint32_t time_since_last_full_charge; //in seconds
337 float full_charge_capacity; //current total capacity in Ah
338
339 uint64_t total_discharge; //in mAh
340 uint64_t total_discharge_energy; //in mWh
341
342 uint64_t total_charge; //in mAh
343 uint64_t total_charge_energy; //in mWh
344
345 float min_voltage;
346 float max_voltage;
347 float max_discharge_current;
348 float max_charge_current;
349
350 float deepest_discharge; //in Ah
351 float last_discharge; //in Ah
352
353 float soc; //in percentage
354 uint32_t RESERVED;
355 };
356
357
362 {
363 uint32_t id;
364 uint32_t size;
365 };
366
367
373 virtual ~Powermon();
374
379 static uint16_t getVersion(void);
380
381
386 virtual bool initBle(void) = 0;
387
388
393 virtual void connectWifi(const WifiAccessKey &key) = 0;
394
395
400 virtual void connectWifi(uint32_t ipaddr) = 0;
401
402
407 virtual void connectBle(uint64_t ble_address) = 0;
408
409
413 virtual void disconnect(void) = 0;
414
415
419 virtual bool isLocalConnection(void) const = 0;
420
421
426 virtual void setOnConnectCallback(const std::function<void(void)> &cb) = 0;
427
428
433 virtual void setOnDisconnectCallback(const std::function<void(DisconnectReason)> &cb) = 0;
434
435
441 virtual void setOnMonitorDataCallback(const std::function<void(const MonitorData&)> &cb) = 0;
442
443
451 virtual void setOnWifiScanReportCallback(const std::function<void(const WifiScanResult*)> &cb) = 0;
452
453
458 virtual const DeviceInfo& getLastDeviceInfo(void) const = 0;
459
460
465 virtual void requestGetInfo(const std::function<void(ResponseCode, const DeviceInfo&)> &cb) = 0;
466
467
472 virtual void requestGetMonitorData(const std::function<void(ResponseCode, const MonitorData&)> &cb) = 0;
473
474
479 virtual void requestGetStatistics(const std::function<void(ResponseCode, const MonitorStatistics&)> &cb) = 0;
480
481
486 virtual void requestGetFgStatistics(const std::function<void(ResponseCode, const FuelgaugeStatistics&)> &cb) = 0;
487
488
494 virtual void requestUnlock(const AuthKey &key, std::function<void(ResponseCode)> cb) = 0;
495
496
502 virtual void requestSetUserPasswordLock(const AuthKey &key, std::function<void(ResponseCode)> cb) = 0;
503
504
510 virtual void requestSetMasterPasswordLock(const AuthKey &key, std::function<void(ResponseCode)> cb) = 0;
511
512
517 virtual void requestClearUserPasswordLock(std::function<void(ResponseCode)> cb) = 0;
518
519
524 virtual void requestClearMasterPasswordLock(std::function<void(ResponseCode)> cb) = 0;
525
526
531 virtual void requestGetAuthKey(std::function<void(ResponseCode, const AuthKey&)> cb) = 0;
532
533
538 virtual void requestResetAuthKey(std::function<void(ResponseCode)> cb) = 0;
539
540
545 virtual void requestResetEnergyMeter(const std::function<void(ResponseCode)> &cb) = 0;
546
547
552 virtual void requestResetCoulombMeter(const std::function<void(ResponseCode)> &cb) = 0;
553
554
559 virtual void requestResetStatistics(const std::function<void(ResponseCode)> &cb) = 0;
560
561
567 virtual void requestSetPowerState(bool state, const std::function<void(ResponseCode)> &cb) = 0;
568
569
574 virtual void requestGetConfig(const std::function<void(ResponseCode, const PowermonConfig&)> &cb) = 0;
575
576
582 virtual void requestSetConfig(const PowermonConfig &config, const std::function<void(ResponseCode)> &cb) = 0;
583
584
590 virtual void requestResetConfig(const std::function<void(ResponseCode)> &cb) = 0;
591
592
598 virtual void requestRename(const char* name, const std::function<void(ResponseCode)> &cb) = 0;
599
600
606 virtual void requestSetTime(uint32_t time, const std::function<void(ResponseCode)> &cb) = 0;
607
608
613 virtual void requestFgSynchronize(const std::function<void(ResponseCode)> &cb) = 0;
614
615
620 virtual void requestStartWifiScan(const std::function<void(ResponseCode)> &cb) = 0;
621
622
629 virtual void requestWifiConfigure(const WifiNetwork &network, const std::function<void(ResponseCode)> &cb) = 0;
630
631
636 virtual void requestGetWifiNetworks(const std::function<void(ResponseCode, const std::vector<WifiNetwork>&)> &cb) = 0;
637
644 virtual void requestAddWifiNetwork(const WifiNetwork& network, const std::function<void(ResponseCode)> &cb) = 0;
645
651 virtual void requestRemoveWifiNetwork(uint8_t index, const std::function<void(ResponseCode)> &cb) = 0;
652
653
658 virtual void requestGetAccessKeys(const std::function<void(ResponseCode, const WifiAccessKey&)> &cb) = 0;
659
660
665 virtual void requestResetAccessKeys(const std::function<void(ResponseCode)> &cb) = 0;
666
667
672 virtual void requestZeroCurrentOffset(const std::function<void(ResponseCode)> &cb) = 0;
673
674
680 virtual void requestCalibrateCurrent(float value, const std::function<void(ResponseCode)> &cb) = 0;
681
682
687 virtual void requestGetSchedules(const std::function<void(ResponseCode, const std::vector<PowermonSchedule>&)> &cb) = 0;
688
689
695 virtual void requestAddSchedules(const std::vector<PowermonSchedule> &schedules, const std::function<void(ResponseCode)> &cb) = 0;
696
697
704 virtual void requestUpdateSchedule(uint64_t old_schedule_descriptor, const PowermonSchedule &new_schedule, const std::function<void(ResponseCode)> &cb) = 0;
705
706
712 virtual void requestDeleteSchedule(uint64_t schedule_descriptor, const std::function<void(ResponseCode)> &cb) = 0;
713
714
719 virtual void requestClearSchedules(const std::function<void(ResponseCode)> &cb) = 0;
720
721
726 virtual void requestCommitSchedules(const std::function<void(ResponseCode)> &cb) = 0;
727
728
733 virtual void requestGetLogFileList(const std::function<void(ResponseCode, const std::vector<LogFileDescriptor>&)> &cb) = 0;
734
735
743 virtual void requestReadLogFile(uint32_t file_id, uint32_t offset, uint32_t read_size, const std::function<void(ResponseCode, const uint8_t*, size_t)> &cb) = 0;
744
745
750 virtual void requestClearLog(const std::function<void(ResponseCode)> &cb) = 0;
751
752
761 virtual void requestUpdateFirmware(const uint8_t* firmware_image, uint32_t size, const std::function<bool(uint32_t, uint32_t)> &progress_cb,
762 const std::function<void(ResponseCode)> &done_cb) = 0;
763
764
765
766 virtual void requestReadDebug(uint32_t offset, uint32_t read_size, const std::function<void(ResponseCode, const uint8_t*, size_t)> &cb) = 0;
767 virtual void requestEraseDebug(const std::function<void(ResponseCode)> &cb) = 0;
768
769
770 virtual void requestReboot(const std::function<void(ResponseCode)> &cb) = 0;
771
772
773
777 static std::string getIpAddressString(uint32_t ip);
778
779
783 static std::string getMacAddressString(uint64_t mac);
784
785
789 static uint64_t parseMacAddress(const char* address);
790
791
795 static std::string getHardwareString(uint8_t bcd);
796
797
801 static std::string getPowerStatusString(PowerStatus ps);
802
803
807 static bool hasDataLog(uint8_t bcd);
808
809
813 static bool hasVoltage2(uint8_t bcd);
814
815
819 static bool hasConfigurableShunt(uint8_t bcd);
820
821
825 static bool hasIntegratedShunt(uint8_t bcd);
826
827
831 static bool hasWifi(uint8_t bcd);
832
833
837 static bool hasEthernet(uint8_t bcd);
838
839
843 static bool hasNetwork(uint8_t bcd);
844
845
849 static bool hasBluetooth(uint8_t bcd);
850
851
855 static inline bool checkBCD(uint16_t bcd)
856 {
857 for(uint32_t i = 0; i < 4; i++)
858 {
859 if ((bcd & 0xF) > 0x9)
860 return false;
861 bcd >>= 4;
862 }
863
864 return true;
865 }
866
872 static AuthKey getAuthKeyFromPassword(const char* password);
873
877 static std::string getUpdateFirmwareImageUrl(uint8_t hardware_revision_bcd, uint16_t firmware_revision_bcd);
878
882 static uint16_t checkFirmwareImage(const uint8_t* image, size_t size, uint8_t hardware_revision_bcd);
883};
884
885
886#include <powermon_scanner.h>
887
888
889#endif
Powermon is a class representing one PowerMon device (BLE or WiFi) and offers a set of functions for ...
Definition powermon.h:59
static uint64_t parseMacAddress(const char *address)
Parses a MAC address string.
virtual void requestResetAuthKey(std::function< void(ResponseCode)> cb)=0
Requests the reset of the device authentication key.
HardwareRevision
HardwareRevision definitions (2 digit BCD format)
Definition powermon.h:65
@ POWERMON_W
PowerMon-W (WiFi)
Definition powermon.h:71
@ FAMILY_MASK
Mask for the family part of the revision number.
Definition powermon.h:66
@ POWERMON
Original PowerMon (BLE)
Definition powermon.h:69
@ POWERMON_E
PowerMon-E (Ethernet)
Definition powermon.h:68
@ POWERMON_5S
PowerMon-5S (BLE)
Definition powermon.h:70
virtual void requestGetConfig(const std::function< void(ResponseCode, const PowermonConfig &)> &cb)=0
Retrieves the device configuration structure.
virtual void requestGetMonitorData(const std::function< void(ResponseCode, const MonitorData &)> &cb)=0
Requests the device monitor data. It only applies to the WiFi devices.
static bool hasEthernet(uint8_t bcd)
Returns true if the PowerMon described by the BCD hardware revision has Ethernet.
virtual void requestSetPowerState(bool state, const std::function< void(ResponseCode)> &cb)=0
Requests changing the power state.
virtual void requestStartWifiScan(const std::function< void(ResponseCode)> &cb)=0
Requests starting the WiFi scan (only applies to the WiFi PowerMons). WiFi scanning will stop automat...
PowerStatus
PowerStatus is an enumeration of all possible power states.
Definition powermon.h:127
@ PS_LTD
Power status is Low Temperature Disconnect.
Definition powermon.h:135
@ PS_ON
Power status is On.
Definition powermon.h:129
@ PS_FGD
Power status is Fuel Gauge Disconnect.
Definition powermon.h:133
@ PS_HTD
Power status is High Temperature Disconnect.
Definition powermon.h:136
@ PS_NCH
Power status is Not CHarging (for LiFePO4 charge manager only)
Definition powermon.h:134
@ PS_OCD
Power status is Over-Current Disconnect.
Definition powermon.h:131
@ PS_LVD
Power status is Low Voltage Disconnect.
Definition powermon.h:130
@ PS_OFF
Power status is Off.
Definition powermon.h:128
@ PS_HVD
Power status is High Voltage Disconnect.
Definition powermon.h:132
virtual void requestResetAccessKeys(const std::function< void(ResponseCode)> &cb)=0
Requests resetting of the WiFi access keys (only applies to the WiFi PowerMons). This effectively sev...
virtual void requestSetConfig(const PowermonConfig &config, const std::function< void(ResponseCode)> &cb)=0
Sends new configuration to the device.
static uint16_t getVersion(void)
Returns the PowerMon access library version.
virtual void requestUpdateSchedule(uint64_t old_schedule_descriptor, const PowermonSchedule &new_schedule, const std::function< void(ResponseCode)> &cb)=0
Requests updating an existing schedule.
virtual void requestClearSchedules(const std::function< void(ResponseCode)> &cb)=0
Requests clearing of all schedule.
virtual void connectWifi(uint32_t ipaddr)=0
Connects to a local WiFi PowerMon.
virtual bool initBle(void)=0
Initialized the BLE sub-system. This should be called once after creating the Powermon object.
virtual void requestGetStatistics(const std::function< void(ResponseCode, const MonitorStatistics &)> &cb)=0
Requests the device power monitor statistics data.
virtual void requestFgSynchronize(const std::function< void(ResponseCode)> &cb)=0
Requests forcing the SoC to 100% (SoC synchronize)
static std::string getPowerStatusString(PowerStatus ps)
Returns the power status string representation.
DisconnectReason
DisconnectReason is an enumeration of all reasons a connection can be terminated.
Definition powermon.h:90
virtual void requestWifiConfigure(const WifiNetwork &network, const std::function< void(ResponseCode)> &cb)=0
Sends new WiFi network credentials to the PowerMon device. The new credentials will be saved by the d...
virtual void requestGetAccessKeys(const std::function< void(ResponseCode, const WifiAccessKey &)> &cb)=0
Requests the WiFi access keys (only applies to the WiFi PowerMons). The access keys are used to remot...
virtual void requestSetUserPasswordLock(const AuthKey &key, std::function< void(ResponseCode)> cb)=0
Requests setting a user password lock.
static std::string getIpAddressString(uint32_t ip)
Returns the IP address as string.
virtual void connectWifi(const WifiAccessKey &key)=0
Connects to a remote WiFi PowerMon.
virtual void requestClearUserPasswordLock(std::function< void(ResponseCode)> cb)=0
Requests clearing of the user password lock.
virtual void requestRemoveWifiNetwork(uint8_t index, const std::function< void(ResponseCode)> &cb)=0
Removes a stored WiFi network.
static bool hasNetwork(uint8_t bcd)
Returns true if the PowerMon described by the BCD hardware revision has Ethernet.
static bool checkBCD(uint16_t bcd)
Returns true if the parameter is a valid BCD number.
Definition powermon.h:855
virtual void requestZeroCurrentOffset(const std::function< void(ResponseCode)> &cb)=0
Requests zeroing of the current reading offset.
virtual void requestAddSchedules(const std::vector< PowermonSchedule > &schedules, const std::function< void(ResponseCode)> &cb)=0
Requests adding new schedules.
static AuthKey getAuthKeyFromPassword(const char *password)
Generates the SHA256 hash of a password.
virtual const DeviceInfo & getLastDeviceInfo(void) const =0
Returns the last DeviceInfo retrieved from the PowerMon.
static bool hasBluetooth(uint8_t bcd)
Returns true if the PowerMon described by the BCD hardware revision has Bluetooth.
static bool hasDataLog(uint8_t bcd)
Returns true if the PowerMon described by the BCD hardware revision has data logging capabilities.
virtual void requestGetFgStatistics(const std::function< void(ResponseCode, const FuelgaugeStatistics &)> &cb)=0
Requests the device battery statistics data.
static bool hasWifi(uint8_t bcd)
Returns true if the PowerMon described by the BCD hardware revision has WiFi.
static std::string getMacAddressString(uint64_t mac)
Returns the Bluetooth MAC address as string.
ResponseCode
ResponseCodes is an enumeration of all possible response codes for requests to a PowerMon device.
Definition powermon.h:105
static bool hasVoltage2(uint8_t bcd)
Returns true if the PowerMon described by the BCD hardware revision has V2.
virtual void requestSetTime(uint32_t time, const std::function< void(ResponseCode)> &cb)=0
Requests setting the internal clock of the PowerMon device.
virtual void requestAddWifiNetwork(const WifiNetwork &network, const std::function< void(ResponseCode)> &cb)=0
Add a new WiFi network The new credentials will be saved by the device whether PowerMon can or cannot...
virtual void requestGetInfo(const std::function< void(ResponseCode, const DeviceInfo &)> &cb)=0
Requests the device information.
static Powermon * createInstance(void)
Creates an instance of the Powermon class.
virtual void requestCalibrateCurrent(float value, const std::function< void(ResponseCode)> &cb)=0
Requests calibration of the current reading.
virtual void requestDeleteSchedule(uint64_t schedule_descriptor, const std::function< void(ResponseCode)> &cb)=0
Requests deleting an existing schedule.
virtual void setOnConnectCallback(const std::function< void(void)> &cb)=0
Sets the callback to be called by the driver when a connection to the PowerMon device is fully establ...
virtual void requestUpdateFirmware(const uint8_t *firmware_image, uint32_t size, const std::function< bool(uint32_t, uint32_t)> &progress_cb, const std::function< void(ResponseCode)> &done_cb)=0
Requests firmware update.
virtual void setOnWifiScanReportCallback(const std::function< void(const WifiScanResult *)> &cb)=0
Sets the callback to be called by the driver when a new WiFi scan result is received from the PowerMo...
virtual void requestUnlock(const AuthKey &key, std::function< void(ResponseCode)> cb)=0
Requests unlocking a password protected device.
static bool hasIntegratedShunt(uint8_t bcd)
Returns true if the PowerMon described by the BCD hardware revision has an initegrated shunt.
static std::string getUpdateFirmwareImageUrl(uint8_t hardware_revision_bcd, uint16_t firmware_revision_bcd)
Returns the update firmware image URL based on the hardware revision and firmware version.
virtual void requestResetEnergyMeter(const std::function< void(ResponseCode)> &cb)=0
Requests the reset of the energy meter.
virtual void requestResetStatistics(const std::function< void(ResponseCode)> &cb)=0
Requests the reset of the power meter statistics.
virtual void requestRename(const char *name, const std::function< void(ResponseCode)> &cb)=0
Requests renaming the PowerMon device.
virtual bool isLocalConnection(void) const =0
Returns true if the current connection is local.
virtual void setOnDisconnectCallback(const std::function< void(DisconnectReason)> &cb)=0
Sets the callback to be called by the driver when a connection to the PowerMon device is disconnected...
static bool hasConfigurableShunt(uint8_t bcd)
Returns true if the PowerMon described by the BCD hardware revision supports configurable shunts.
virtual void requestClearMasterPasswordLock(std::function< void(ResponseCode)> cb)=0
Requests clearing of the master password lock.
virtual void requestClearLog(const std::function< void(ResponseCode)> &cb)=0
Requests committing the schedules to non-volatile memory.
virtual void requestGetSchedules(const std::function< void(ResponseCode, const std::vector< PowermonSchedule > &)> &cb)=0
Requests the list of all schedules stored in the device.
virtual void connectBle(uint64_t ble_address)=0
Connects to a local BLE PowerMon.
static std::string getHardwareString(uint8_t bcd)
Returns the hardware name based on the hardware revision in BCD format.
virtual void requestGetWifiNetworks(const std::function< void(ResponseCode, const std::vector< WifiNetwork > &)> &cb)=0
Returns a list of all WiFi networks known by the device.
virtual void requestGetLogFileList(const std::function< void(ResponseCode, const std::vector< LogFileDescriptor > &)> &cb)=0
Requests the list of log files.
State
State represents the PowerMon connection state.
Definition powermon.h:79
@ Connecting
Device is in the process of connecting.
Definition powermon.h:81
@ Disconnected
Device is not connected.
Definition powermon.h:80
@ Connected
Device is connected.
Definition powermon.h:82
virtual void requestResetConfig(const std::function< void(ResponseCode)> &cb)=0
Resets the PowerMon configuration to factory settings This will also clear the data log,...
virtual void requestSetMasterPasswordLock(const AuthKey &key, std::function< void(ResponseCode)> cb)=0
Requests setting a master password lock on.
virtual void requestGetAuthKey(std::function< void(ResponseCode, const AuthKey &)> cb)=0
Requests the authentication key from the device. This key can be used to unlock a locked device....
virtual void setOnMonitorDataCallback(const std::function< void(const MonitorData &)> &cb)=0
Sets the callback to be called by the driver when new monitor data is received. This applies to the B...
static uint16_t checkFirmwareImage(const uint8_t *image, size_t size, uint8_t hardware_revision_bcd)
Checks the validity of the firmware update image.
virtual void requestReadLogFile(uint32_t file_id, uint32_t offset, uint32_t read_size, const std::function< void(ResponseCode, const uint8_t *, size_t)> &cb)=0
Requests reading of a log file.
virtual void disconnect(void)=0
Disconnects from a connected device.
virtual void requestCommitSchedules(const std::function< void(ResponseCode)> &cb)=0
Requests committing the schedules to non-volatile memory.
virtual void requestResetCoulombMeter(const std::function< void(ResponseCode)> &cb)=0
Requests the reset of the coulomb meter.
AuthKey is a structure representing an authentication key used to unlock a locked PowerMon device.
Definition powermon.h:144
uint64_t serial
Device serial number.
Definition powermon.h:251
uint8_t hardware_revision_bcd
Identifies if it's a WiFi or BLE device.
Definition powermon.h:252
bool fromURL(const char *url)
Initializes the current object from a device link.
std::string toURL(void)
Saves the current PowerMon-W access structure to a link. Only remote access WiFi device identifiers c...
WifiAccessKey access_key
Contains the access keys for a remote WiFi device. In this case address is zero.
Definition powermon.h:255
std::string name
Device name.
Definition powermon.h:250
uint64_t address
contains the BLE MAC address for a BLE device of the IP address of a local WiFi device.
Definition powermon.h:253
DeviceInfo is the information structure returned by PowerMon as response to the GetInfo request.
Definition powermon.h:220
FuelgaugeStatistics is a structure containing battery statistics.
Definition powermon.h:335
LogFileDescriptor represents a PowerMon log file.
Definition powermon.h:362
uint32_t id
ID of the file (timestamp in UNIX time of the first sample in the file)
Definition powermon.h:363
uint32_t size
Size in bytes.
Definition powermon.h:364
MonitorData is a structure containing the real-time PowerMon data.
Definition powermon.h:280
float power
Power in Watts. Depending on the configuration, either V1 or V2 are used to compute this value.
Definition powermon.h:290
float temperature
Temperature in Celsius.
Definition powermon.h:291
uint16_t firmware_version_bcd
current firmware version in BCD format xx.yy
Definition powermon.h:281
int64_t energy_meter
Energy meter in mWh.
Definition powermon.h:294
uint16_t fg_runtime
Fuelgauge runtime in minutes. 0xFFFF means the FG is not enabled. The maximum valid value is 0xFFF0.
Definition powermon.h:299
float current
Current in Amperes.
Definition powermon.h:289
float voltage2
Voltage 2 in Volts.
Definition powermon.h:288
int64_t coulomb_meter
Coulomb meter in mAh.
Definition powermon.h:293
bool isTemperatureExternal(void) const
Returns true if the temperature is read from an external sensor.
int16_t rssi
RSSI as seen by the device in dBm.
Definition powermon.h:301
uint8_t fg_soc
Fuelgauge SoC (State of Charge) in percentage. 0xFF means the FG is not enabled. 0xFE means the SoC i...
Definition powermon.h:298
float voltage1
Voltage 1 in Volts.
Definition powermon.h:287
uint32_t flags
various flags - do not use directly
Definition powermon.h:285
uint8_t hardware_revision_bcd
current hardware revision in BCD format x.y
Definition powermon.h:282
uint32_t time
UNIX time in localtime (not UTC)
Definition powermon.h:284
PowerStatus power_status
Device power status.
Definition powermon.h:296
MonitorStatistics is a structure containing power meter statistics.
Definition powermon.h:314
float temperature_max
in Celsius
Definition powermon.h:327
uint32_t seconds_since_on
number of seconds since PowerMon was powered up
Definition powermon.h:315
float temperature_min
in Celsius
Definition powermon.h:326
WifiAccessKey is a structure representing the access keys used to connect to a WiFi/Ethernet PowerMon...
Definition powermon.h:153
WifiNetwork represents all information required by PowerMon-W to connect to an access point.
Definition powermon.h:163
SecurityMode
Definition powermon.h:165
@ WPA2_WPA1_PSK
Use WPA1 or WPA2.
Definition powermon.h:168
@ WPA2_PSK
Use only WPA2.
Definition powermon.h:169
@ WEP
Use WEP.
Definition powermon.h:167
@ WPA3_SAE
Use WPA3 (STA mode only)
Definition powermon.h:170
@ OPEN
No security.
Definition powermon.h:166
WifiScanResult represents a WiFi network detected by PowerMon-W during WiFi scanning.
Definition powermon.h:193
uint8_t unused
Reserved, set to zero.
Definition powermon.h:205
uint8_t wep
Network supports WEP.
Definition powermon.h:200
uint8_t psk
Network supports Personal authentication.
Definition powermon.h:206
uint8_t wpa3
Network supports WPA3. If multiple WPA bits are set the network supports mixed mode.
Definition powermon.h:203
uint8_t wpa2
Network supports WPA2. If both WPA bits are set the network supports mixed mode.
Definition powermon.h:202
uint8_t eap
Network supports Enterprise authentication.
Definition powermon.h:207
uint8_t wpa
Network supports WPA. If both WPA bits are set the network supports mixed mode.
Definition powermon.h:201
uint8_t pmf
Networks requires use of Protected Management Frames.
Definition powermon.h:204
PowermonConfig is a structure containing the PowerMon configuration.
Definition powermon_config.h:30
PowermonSchedule is a structure containing one PowerMon schedule (timer)
Definition powermon_schedule.h:30