Dawn Framework 1.0
Universal data acquisition framework for embedded systems
battery.hxx
1// dawn/include/dawn/io/battery.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <limits.h>
9
10#include "dawn/io/common.hxx"
11
12namespace dawn
13{
17{
18public:
19 explicit CIOBatteryBase(CDescObject &desc)
20 : CIOCommon(desc)
21 , fd(-1)
22 {
23 }
24
25 ~CIOBatteryBase() override;
26
27 int configure() override;
28 int deinit() override;
29
30#ifdef CONFIG_DAWN_IO_NOTIFY
31 int getFd() const override
32 {
33 return fd;
34 }
35#endif
36
37 size_t getDataSize() const override
38 {
39 return getDtypeSize();
40 }
41
42 size_t getDataDim() const override
43 {
44 return 1;
45 }
46
47 bool isRead() const override
48 {
49 return true;
50 }
51
52 bool isWrite() const override
53 {
54 return false;
55 }
56
57 bool isNotify() const override
58 {
59 return false;
60 }
61
62 bool isBatch() const override
63 {
64 return false;
65 }
66
67protected:
68 int getFdInternal() const
69 {
70 return fd;
71 }
72
75 int batRead(int cmd, void *arg) const;
76
77private:
78 char path[PATH_MAX] = {};
79 int fd;
80};
81
85{
86public:
87 explicit CIOBattVolt(CDescObject &desc)
88 : CIOBatteryBase(desc)
89 {
90 }
91
92#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
93 const char *getClassNameStr() const override
94 {
95 return "battery_volt";
96 }
97#endif
98
99 int getDataImpl(IODataCmn &data, size_t len) override;
100
101 constexpr static SObjectId::ObjectId objectId(bool ts, uint16_t inst)
102 {
104 ts, inst);
105 }
106};
107
111{
112public:
113 explicit CIOBattSoc(CDescObject &desc)
114 : CIOBatteryBase(desc)
115 {
116 }
117
118#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
119 const char *getClassNameStr() const override
120 {
121 return "battery_soc";
122 }
123#endif
124
125 int getDataImpl(IODataCmn &data, size_t len) override;
126
127 constexpr static SObjectId::ObjectId objectId(bool ts, uint16_t inst)
128 {
130 inst);
131 }
132};
133
137{
138public:
139 explicit CIOBattState(CDescObject &desc)
140 : CIOBatteryBase(desc)
141 {
142 }
143
144#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
145 const char *getClassNameStr() const override
146 {
147 return "battery_state";
148 }
149#endif
150
151 int getDataImpl(IODataCmn &data, size_t len) override;
152
153 constexpr static SObjectId::ObjectId objectId(bool ts, uint16_t inst)
154 {
156 ts, inst);
157 }
158};
159
160} // namespace dawn
Descriptor wrapper for individual object configuration.
Battery state of charge in percent (DTYPE_UINT32).
Definition battery.hxx:111
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition battery.cxx:93
Battery charge state as a numeric code (BATTERY_*; DTYPE_UINT32).
Definition battery.hxx:137
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition battery.cxx:114
Battery voltage in mV (DTYPE_UINT32).
Definition battery.hxx:85
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition battery.cxx:72
Shared base for the battery (fuel-gauge) IO family.
Definition battery.hxx:17
int configure()
Configure object from descriptor data.
Definition battery.cxx:24
bool isNotify() const
Check if IO supports notifications.
Definition battery.hxx:57
bool isWrite() const
Check if IO supports write operations.
Definition battery.hxx:52
size_t getDataDim() const
Get data vector dimension.
Definition battery.hxx:42
int batRead(int cmd, void *arg) const
ioctl read of a single battery value into *arg.
Definition battery.cxx:61
bool isRead() const
Check if IO supports read operations.
Definition battery.hxx:47
int deinit()
De-initialize object.
Definition battery.cxx:50
bool isBatch() const
Check if IO supports batch operations.
Definition battery.hxx:62
size_t getDataSize() const
Get data size in bytes.
Definition battery.hxx:37
static SObjectId::ObjectId create(bool ts, uint16_t inst)
Create ObjectID with default data type.
Definition common.hxx:265
Base class for all I/O objects.
Definition common.hxx:27
virtual int getFd() const
Get file descriptor for notifications.
Definition common.hxx:444
size_t getDtypeSize() const
Get size of this object's data type.
Definition object.cxx:195
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Base interface for I/O data buffers (static and dynamic).
Definition idata.hxx:21
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44