libpowermon 1.12
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 mac[6];
197 uint8_t channel;
198
199 struct
200 {
201 uint8_t wep : 1;
202 uint8_t wpa : 1;
203 uint8_t wpa2 : 1;
204 uint8_t wpa3 : 1;
205 uint8_t pmf : 1;
206 uint8_t unused : 1;
207 uint8_t psk : 1;
208 uint8_t eap : 1;
209 }security;
210
211 int8_t rssi;
212
213 bool operator==(const WifiScanResult &rhs) const;
214 };
215
216
221 {
222 std::string name;
223
224 uint16_t firmware_version_bcd;
225 uint8_t hardware_revision_bcd;
226
227 uint64_t address;
228 uint64_t serial;
229
230 uint8_t ssid_length;
231 uint8_t ssid[MAX_WIFI_SSID_SIZE];
232 uint8_t flags;
233 int8_t timezone;
234
235 bool isUserPasswordSet(void) const;
236 bool isMasterPasswordSet(void) const;
237 bool isUserLocked(void) const;
238 bool isMasterLocked(void) const;
239
240 bool isWifiConnecting(void) const;
241 bool isWifiConnected(void) const;
242 bool isWifiFailed(void) const;
243 };
244
245
249 struct DeviceIdentifier
250 {
251 std::string name;
252 uint64_t serial;
254 uint64_t address;
255
257
258 DeviceIdentifier();
259
260 bool operator==(const DeviceIdentifier &rhs);
261
267 bool fromURL(const char* url);
268
273 std::string toURL(void);
274 };
275
276
281 {
284
285 uint32_t time;
286 uint32_t flags;
287
288 float voltage1;
289 float voltage2;
290 float current;
291 float power;
293
295 int64_t energy_meter;
296
298
299 uint8_t fg_soc;
300 uint16_t fg_runtime;
301
302 int16_t rssi = INT16_MIN;
303
307 bool isTemperatureExternal(void) const;
308 };
309
310
315 {
317
318 float voltage1_min;
319 float voltage1_max;
320
321 float voltage2_min;
322 float voltage2_max;
323
324 float peak_charge_current;
325 float peak_discharge_current;
326
329 };
330
331
336 {
337 uint32_t time_since_last_full_charge; //in seconds
338 float full_charge_capacity; //current total capacity in Ah
339
340 uint64_t total_discharge; //in mAh
341 uint64_t total_discharge_energy; //in mWh
342
343 uint64_t total_charge; //in mAh
344 uint64_t total_charge_energy; //in mWh
345
346 float min_voltage;
347 float max_voltage;
348 float max_discharge_current;
349 float max_charge_current;
350
351 float deepest_discharge; //in Ah
352 float last_discharge; //in Ah
353
354 float soc; //in percentage
355 uint32_t RESERVED;
356 };
357
358
363 {
364 uint32_t id;
365 uint32_t size;
366 };
367
368
374 virtual ~Powermon();
375
380 static uint16_t getVersion(void);
381
382
387 virtual bool initBle(void) = 0;
388
389
394 virtual void connectWifi(const WifiAccessKey &key) = 0;
395
396
401 virtual void connectWifi(uint32_t ipaddr) = 0;
402
403
408 virtual void connectBle(uint64_t ble_address) = 0;
409
410
414 virtual void disconnect(void) = 0;
415
416
420 virtual bool isLocalConnection(void) const = 0;
421
422
427 virtual void setOnConnectCallback(const std::function<void(void)> &cb) = 0;
428
429
434 virtual void setOnDisconnectCallback(const std::function<void(DisconnectReason)> &cb) = 0;
435
436
442 virtual void setOnMonitorDataCallback(const std::function<void(const MonitorData&)> &cb) = 0;
443
444
452 virtual void setOnWifiScanReportCallback(const std::function<void(const WifiScanResult*)> &cb) = 0;
453
454
459 virtual const DeviceInfo& getLastDeviceInfo(void) const = 0;
460
461
466 virtual void requestGetInfo(const std::function<void(ResponseCode, const DeviceInfo&)> &cb) = 0;
467
468
473 virtual void requestGetMonitorData(const std::function<void(ResponseCode, const MonitorData&)> &cb) = 0;
474
475
480 virtual void requestGetStatistics(const std::function<void(ResponseCode, const MonitorStatistics&)> &cb) = 0;
481
482
487 virtual void requestGetFgStatistics(const std::function<void(ResponseCode, const FuelgaugeStatistics&)> &cb) = 0;
488
489
495 virtual void requestUnlock(const AuthKey &key, std::function<void(ResponseCode)> cb) = 0;
496
497
503 virtual void requestSetUserPasswordLock(const AuthKey &key, std::function<void(ResponseCode)> cb) = 0;
504
505
511 virtual void requestSetMasterPasswordLock(const AuthKey &key, std::function<void(ResponseCode)> cb) = 0;
512
513
518 virtual void requestClearUserPasswordLock(std::function<void(ResponseCode)> cb) = 0;
519
520
525 virtual void requestClearMasterPasswordLock(std::function<void(ResponseCode)> cb) = 0;
526
527
532 virtual void requestGetAuthKey(std::function<void(ResponseCode, const AuthKey&)> cb) = 0;
533
534
539 virtual void requestResetAuthKey(std::function<void(ResponseCode)> cb) = 0;
540
541
546 virtual void requestResetEnergyMeter(const std::function<void(ResponseCode)> &cb) = 0;
547
548
553 virtual void requestResetCoulombMeter(const std::function<void(ResponseCode)> &cb) = 0;
554
555
560 virtual void requestResetStatistics(const std::function<void(ResponseCode)> &cb) = 0;
561
562
568 virtual void requestSetPowerState(bool state, const std::function<void(ResponseCode)> &cb) = 0;
569
570
575 virtual void requestGetConfig(const std::function<void(ResponseCode, const PowermonConfig&)> &cb) = 0;
576
577
583 virtual void requestSetConfig(const PowermonConfig &config, const std::function<void(ResponseCode)> &cb) = 0;
584
585
591 virtual void requestResetConfig(const std::function<void(ResponseCode)> &cb) = 0;
592
593
599 virtual void requestRename(const char* name, const std::function<void(ResponseCode)> &cb) = 0;
600
601
607 virtual void requestSetTime(uint32_t time, const std::function<void(ResponseCode)> &cb) = 0;
608
609
614 virtual void requestFgSynchronize(const std::function<void(ResponseCode)> &cb) = 0;
615
616
621 virtual void requestStartWifiScan(const std::function<void(ResponseCode)> &cb) = 0;
622
623
630 virtual void requestWifiConfigure(const WifiNetwork &network, const std::function<void(ResponseCode)> &cb) = 0;
631
632
637 virtual void requestGetWifiNetworks(const std::function<void(ResponseCode, const std::vector<WifiNetwork>&)> &cb) = 0;
638
645 virtual void requestAddWifiNetwork(const WifiNetwork& network, const std::function<void(ResponseCode)> &cb) = 0;
646
652 virtual void requestRemoveWifiNetwork(uint8_t index, const std::function<void(ResponseCode)> &cb) = 0;
653
654
659 virtual void requestGetAccessKeys(const std::function<void(ResponseCode, const WifiAccessKey&)> &cb) = 0;
660
661
666 virtual void requestResetAccessKeys(const std::function<void(ResponseCode)> &cb) = 0;
667
668
673 virtual void requestZeroCurrentOffset(const std::function<void(ResponseCode)> &cb) = 0;
674
675
681 virtual void requestCalibrateCurrent(float value, const std::function<void(ResponseCode)> &cb) = 0;
682
683
688 virtual void requestGetSchedules(const std::function<void(ResponseCode, const std::vector<PowermonSchedule>&)> &cb) = 0;
689
690
696 virtual void requestAddSchedules(const std::vector<PowermonSchedule> &schedules, const std::function<void(ResponseCode)> &cb) = 0;
697
698
705 virtual void requestUpdateSchedule(uint64_t old_schedule_descriptor, const PowermonSchedule &new_schedule, const std::function<void(ResponseCode)> &cb) = 0;
706
707
713 virtual void requestDeleteSchedule(uint64_t schedule_descriptor, const std::function<void(ResponseCode)> &cb) = 0;
714
715
720 virtual void requestClearSchedules(const std::function<void(ResponseCode)> &cb) = 0;
721
722
727 virtual void requestCommitSchedules(const std::function<void(ResponseCode)> &cb) = 0;
728
729
734 virtual void requestGetLogFileList(const std::function<void(ResponseCode, const std::vector<LogFileDescriptor>&)> &cb) = 0;
735
736
744 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;
745
746
751 virtual void requestClearLog(const std::function<void(ResponseCode)> &cb) = 0;
752
753
762 virtual void requestUpdateFirmware(const uint8_t* firmware_image, uint32_t size, const std::function<bool(uint32_t, uint32_t)> &progress_cb,
763 const std::function<void(ResponseCode)> &done_cb) = 0;
764
765
766
767 virtual void requestReadDebug(uint32_t offset, uint32_t read_size, const std::function<void(ResponseCode, const uint8_t*, size_t)> &cb) = 0;
768 virtual void requestEraseDebug(const std::function<void(ResponseCode)> &cb) = 0;
769
770
771 virtual void requestReboot(const std::function<void(ResponseCode)> &cb) = 0;
772
773
774
778 static std::string getIpAddressString(uint32_t ip);
779
780
784 static std::string getMacAddressString(uint64_t mac);
785
786
790 static uint64_t parseMacAddress(const char* address);
791
792
796 static std::string getHardwareString(uint8_t bcd);
797
798
802 static std::string getPowerStatusString(PowerStatus ps);
803
804
808 static bool hasDataLog(uint8_t bcd);
809
810
814 static bool hasVoltage2(uint8_t bcd);
815
816
820 static bool hasConfigurableShunt(uint8_t bcd);
821
822
826 static bool hasIntegratedShunt(uint8_t bcd);
827
828
832 static bool hasWifi(uint8_t bcd);
833
834
838 static bool hasEthernet(uint8_t bcd);
839
840
844 static bool hasNetwork(uint8_t bcd);
845
846
850 static bool hasBluetooth(uint8_t bcd);
851
852
856 static inline bool checkBCD(uint16_t bcd)
857 {
858 for(uint32_t i = 0; i < 4; i++)
859 {
860 if ((bcd & 0xF) > 0x9)
861 return false;
862 bcd >>= 4;
863 }
864
865 return true;
866 }
867
873 static AuthKey getAuthKeyFromPassword(const char* password);
874
878 static std::string getUpdateFirmwareImageUrl(uint8_t hardware_revision_bcd, uint16_t firmware_revision_bcd);
879
883 static uint16_t checkFirmwareImage(const uint8_t* image, size_t size, uint8_t hardware_revision_bcd);
884};
885
886
887#include <powermon_scanner.h>
888
889
890#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:856
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:252
uint8_t hardware_revision_bcd
Identifies if it's a WiFi or BLE device.
Definition powermon.h:253
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:256
std::string name
Device name.
Definition powermon.h:251
uint64_t address
contains the BLE MAC address for a BLE device of the IP address of a local WiFi device.
Definition powermon.h:254
DeviceInfo is the information structure returned by PowerMon as response to the GetInfo request.
Definition powermon.h:221
FuelgaugeStatistics is a structure containing battery statistics.
Definition powermon.h:336
LogFileDescriptor represents a PowerMon log file.
Definition powermon.h:363
uint32_t id
ID of the file (timestamp in UNIX time of the first sample in the file)
Definition powermon.h:364
uint32_t size
Size in bytes.
Definition powermon.h:365
MonitorData is a structure containing the real-time PowerMon data.
Definition powermon.h:281
float power
Power in Watts. Depending on the configuration, either V1 or V2 are used to compute this value.
Definition powermon.h:291
float temperature
Temperature in Celsius.
Definition powermon.h:292
uint16_t firmware_version_bcd
current firmware version in BCD format xx.yy
Definition powermon.h:282
int64_t energy_meter
Energy meter in mWh.
Definition powermon.h:295
uint16_t fg_runtime
Fuelgauge runtime in minutes. 0xFFFF means the FG is not enabled. The maximum valid value is 0xFFF0.
Definition powermon.h:300
float current
Current in Amperes.
Definition powermon.h:290
float voltage2
Voltage 2 in Volts.
Definition powermon.h:289
int64_t coulomb_meter
Coulomb meter in mAh.
Definition powermon.h:294
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:302
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:299
float voltage1
Voltage 1 in Volts.
Definition powermon.h:288
uint32_t flags
various flags - do not use directly
Definition powermon.h:286
uint8_t hardware_revision_bcd
current hardware revision in BCD format x.y
Definition powermon.h:283
uint32_t time
UNIX time in localtime (not UTC)
Definition powermon.h:285
PowerStatus power_status
Device power status.
Definition powermon.h:297
MonitorStatistics is a structure containing power meter statistics.
Definition powermon.h:315
float temperature_max
in Celsius
Definition powermon.h:328
uint32_t seconds_since_on
number of seconds since PowerMon was powered up
Definition powermon.h:316
float temperature_min
in Celsius
Definition powermon.h:327
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:206
uint8_t wep
Network supports WEP.
Definition powermon.h:201
uint8_t psk
Network supports Personal authentication.
Definition powermon.h:207
uint8_t wpa3
Network supports WPA3. If multiple WPA bits are set the network supports mixed mode.
Definition powermon.h:204
uint8_t wpa2
Network supports WPA2. If both WPA bits are set the network supports mixed mode.
Definition powermon.h:203
uint8_t eap
Network supports Enterprise authentication.
Definition powermon.h:208
uint8_t wpa
Network supports WPA. If both WPA bits are set the network supports mixed mode.
Definition powermon.h:202
uint8_t pmf
Networks requires use of Protected Management Frames.
Definition powermon.h:205
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