libpowermon 1.00
PowerMon Access Library
Loading...
Searching...
No Matches
powermon_log.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_LOG_H
19#define _POWERMON_LOG_H
20
21
22#include <powermon_config.h>
23
24#include <vector>
25#include <functional>
26#include <math.h>
27
28
33{
34public:
35 enum Version
36 {
37 VER_FAMILY_MASK = 0xF0,
38 VER_POWERMON_WIFI_5W = 0x00,
39 };
40
41 struct Sample
42 {
43 uint32_t time;
44 float voltage1;
45 float voltage2;
46 float current;
47 float power;
48 float temperature;
49 uint8_t soc;
50 uint8_t ps;
51 };
52
53 static uint32_t decode(const std::vector<char> &data, std::vector<Sample> &samples);
54
55private:
56 enum Flags
57 {
58 POWER_VOLTAGE_SOURCE = (1 << 0)
59 };
60
61 enum Mask
62 {
63 V1 = (1 << 0),
64 V2 = (1 << 1),
65 V3 = (1 << 2),
66 V4 = (1 << 3),
67 V5 = (1 << 4),
68 V6 = (1 << 5),
69
70 I1 = (1 << 6),
71 I2 = (1 << 7),
72
73 P1 = (1 << 8),
74 P2 = (1 << 9),
75
76 T1 = (1 << 10),
77 T2 = (1 << 11),
78
79 SOC1 = (1 << 12),
80 SOC2 = (1 << 13),
81
82 PS1 = (1 << 14),
83 PS2 = (1 << 15),
84
85 VOLTAGE_SOURCE = (1 << 31)
86 };
87
88 struct Header
89 {
90 uint8_t magic[4];
91
92 uint8_t version;
93 uint8_t mode;
94 uint16_t reserved0;
95
96 uint32_t time;
97
98 uint32_t mask;
99 uint32_t flags;
100 };
101
102 static uint32_t getSamplePeriodInSeconds(uint8_t mode)
103 {
104 switch(mode)
105 {
106 case PowermonConfig::LOG_MODE_1_SEC: return 1;
107 case PowermonConfig::LOG_MODE_2_SEC: return 2;
108 case PowermonConfig::LOG_MODE_5_SEC: return 5;
109 case PowermonConfig::LOG_MODE_10_SEC: return 10;
110 case PowermonConfig::LOG_MODE_20_SEC: return 20;
111 case PowermonConfig::LOG_MODE_30_SEC: return 30;
112 case PowermonConfig::LOG_MODE_60_SEC: return 60;
113 }
114
115 return 0;
116 }
117};
118
119#endif
PowermonLogFile is a class representing a PowerMon log file. It also contains support to decode the d...
Definition powermon_log.h:33
Definition powermon_log.h:42