Dawn Framework 1.0
Universal data acquisition framework for embedded systems
sensor_producer.hxx
1// dawn/include/dawn/io/sensor_producer.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include "dawn/io/common.hxx"
9#include "dawn/porting/config.hxx"
10#include "dawn/porting/sensors.hxx"
11
12namespace dawn
13{
22 : public CIOCommon
23 , public CIOSensorPorting
24{
25public:
26 enum
27 {
28 IO_SENSOR_PRODUCER_CFG_FIRST = 0,
29 IO_SENSOR_PRODUCER_CFG_QUEUE_SIZE = 1,
30 IO_SENSOR_PRODUCER_CFG_PERSIST = 2,
31 IO_SENSOR_PRODUCER_CFG_LAST = 31
32 };
33
34 static_assert(IO_SENSOR_PRODUCER_CFG_LAST - 1 <= SObjectCfg::ID_MAX);
35
36 explicit CIOSensorProducer(CDescObject &desc)
37 : CIOCommon(desc)
38 , info(getSensorInfo(producerToSensorClass(getCls())))
39 , queueSize(1)
40 , persist(false)
41 , registered(false)
42 , ts(0)
43 , fd(-1)
44 {
45 }
46
47 ~CIOSensorProducer() override;
48
49#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
50 const char *getClassNameStr() const override
51 {
52 switch (getCls())
53 {
55 return "sprod_accel";
57 return "sprod_mag";
59 return "sprod_gyro";
61 return "sprod_light";
63 return "sprod_baro";
65 return "sprod_prox";
67 return "sprod_hum";
69 return "sprod_temp";
71 return "sprod_atemp";
73 return "sprod_rgb";
75 return "sprod_ir";
77 return "sprod_uv";
79 return "sprod_gas";
81 return "sprod_co2";
83 return "sprod_tvoc";
84 default:
85 return "sprod";
86 }
87 }
88#endif
89
90 int configure() override;
91 int deinit() override;
92 int setDataImpl(IODataCmn &data) override;
93
94 size_t getDataSize() const override;
95 size_t getDataDim() const override;
96
97 bool isRead() const override
98 {
99 return false;
100 };
101
102 bool isWrite() const override
103 {
104 return true;
105 };
106
107 bool isNotify() const override
108 {
109 return false;
110 };
111
112 bool isBatch() const override
113 {
114 return false;
115 };
116
117 constexpr static SObjectId::ObjectId objectId(uint16_t cls, uint8_t dtype, bool ts, uint16_t inst)
118 {
119 uint8_t flags = 0;
120
121#ifdef CONFIG_DAWN_IO_TIMESTAMP
122 if (ts)
123 {
124 flags |= CIOCommon::IO_FLAGS_TS;
125 }
126#else
127 DAWNASSERT(ts == false, "ts not supported");
128#endif
129
130 return SObjectId::objectId(SObjectId::OBJTYPE_IO, cls, dtype, flags, inst);
131 }
132
133 constexpr static SObjectId::ObjectId objectIdAccel(uint8_t dtype, bool ts, uint16_t inst)
134 {
135 return CIOSensorProducer::objectId(
137 }
138
139 constexpr static SObjectId::ObjectId objectIdMag(uint8_t dtype, bool ts, uint16_t inst)
140 {
141 return CIOSensorProducer::objectId(
143 }
144
145 constexpr static SObjectId::ObjectId objectIdGyro(uint8_t dtype, bool ts, uint16_t inst)
146 {
147 return CIOSensorProducer::objectId(
149 }
150
151 constexpr static SObjectId::ObjectId objectIdLight(uint8_t dtype, bool ts, uint16_t inst)
152 {
153 return CIOSensorProducer::objectId(CIOCommon::IO_CLASS_SENSOR_PRODUCER_LIGHT, dtype, ts, inst);
154 }
155
156 constexpr static SObjectId::ObjectId objectIdBaro(uint8_t dtype, bool ts, uint16_t inst)
157 {
158 return CIOSensorProducer::objectId(
160 }
161
162 constexpr static SObjectId::ObjectId objectIdProx(uint8_t dtype, bool ts, uint16_t inst)
163 {
164 return CIOSensorProducer::objectId(
166 }
167
168 constexpr static SObjectId::ObjectId objectIdHum(uint8_t dtype, bool ts, uint16_t inst)
169 {
170 return CIOSensorProducer::objectId(
172 }
173
174 constexpr static SObjectId::ObjectId objectIdTemp(uint8_t dtype, bool ts, uint16_t inst)
175 {
176 return CIOSensorProducer::objectId(
178 }
179
180 constexpr static SObjectId::ObjectId objectIdAtemp(uint8_t dtype, bool ts, uint16_t inst)
181 {
182 return CIOSensorProducer::objectId(
184 }
185
186 constexpr static SObjectId::ObjectId objectIdRgb(uint8_t dtype, bool ts, uint16_t inst)
187 {
188 return CIOSensorProducer::objectId(CIOCommon::IO_CLASS_SENSOR_PRODUCER_RGB, dtype, ts, inst);
189 }
190
191 constexpr static SObjectId::ObjectId objectIdIr(uint8_t dtype, bool ts, uint16_t inst)
192 {
193 return CIOSensorProducer::objectId(CIOCommon::IO_CLASS_SENSOR_PRODUCER_IR, dtype, ts, inst);
194 }
195
196 constexpr static SObjectId::ObjectId objectIdUv(uint8_t dtype, bool ts, uint16_t inst)
197 {
198 return CIOSensorProducer::objectId(CIOCommon::IO_CLASS_SENSOR_PRODUCER_UV, dtype, ts, inst);
199 }
200
201 constexpr static SObjectId::ObjectId objectIdGas(uint8_t dtype, bool ts, uint16_t inst)
202 {
203 return CIOSensorProducer::objectId(CIOCommon::IO_CLASS_SENSOR_PRODUCER_GAS, dtype, ts, inst);
204 }
205
206 constexpr static SObjectId::ObjectId objectIdCo2(uint8_t dtype, bool ts, uint16_t inst)
207 {
208 return CIOSensorProducer::objectId(CIOCommon::IO_CLASS_SENSOR_PRODUCER_CO2, dtype, ts, inst);
209 }
210
211 constexpr static SObjectId::ObjectId objectIdTvoc(uint8_t dtype, bool ts, uint16_t inst)
212 {
213 return CIOSensorProducer::objectId(CIOCommon::IO_CLASS_SENSOR_PRODUCER_TVOC, dtype, ts, inst);
214 }
215
216 constexpr static SObjectCfg::ObjectCfgId cfgIdQueueSize(uint16_t cls)
217 {
219 cls,
221 true,
222 1,
223 IO_SENSOR_PRODUCER_CFG_QUEUE_SIZE);
224 }
225
226 constexpr static SObjectCfg::ObjectCfgId cfgIdPersist(uint16_t cls)
227 {
229 SObjectId::OBJTYPE_IO, cls, SObjectId::DTYPE_BOOL, true, 1, IO_SENSOR_PRODUCER_CFG_PERSIST);
230 }
231
232private:
233 constexpr static const size_t DATA_BUFFER_SIZE = 32;
234
235 const SIOSensorMapInfo *info;
236 uint32_t queueSize;
237 bool persist;
238 bool registered;
239 uint64_t ts;
240 char path[PATH_MAX] = {};
241 int fd;
242
243 int configureDesc(const CDescObject &desc);
244};
245} // namespace dawn
Descriptor wrapper for individual object configuration.
Base class for all I/O objects.
Definition common.hxx:27
@ IO_FLAGS_TS
Timestamp support flag.
Definition common.hxx:76
@ IO_CLASS_SENSOR_PRODUCER_MAGNETICFIELD
Magnetic field publisher.
Definition common.hxx:132
@ IO_CLASS_SENSOR_PRODUCER_ACCELEROMETER
Accelerometer publisher.
Definition common.hxx:131
@ IO_CLASS_SENSOR_PRODUCER_LIGHT
Light publisher.
Definition common.hxx:134
@ IO_CLASS_SENSOR_PRODUCER_ATEMPERATURE
Ambient temperature publisher.
Definition common.hxx:139
@ IO_CLASS_SENSOR_PRODUCER_HUMIDITY
Humidity publisher.
Definition common.hxx:137
@ IO_CLASS_SENSOR_PRODUCER_IR
Infrared publisher.
Definition common.hxx:141
@ IO_CLASS_SENSOR_PRODUCER_UV
Ultraviolet publisher.
Definition common.hxx:142
@ IO_CLASS_SENSOR_PRODUCER_GAS
Gas publisher.
Definition common.hxx:143
@ IO_CLASS_SENSOR_PRODUCER_GYROSCOPE
Gyroscope publisher.
Definition common.hxx:133
@ IO_CLASS_SENSOR_PRODUCER_CO2
CO2 concentration publisher.
Definition common.hxx:144
@ IO_CLASS_SENSOR_PRODUCER_RGB
RGB color publisher.
Definition common.hxx:140
@ IO_CLASS_SENSOR_PRODUCER_TEMPERATURE
Temperature publisher.
Definition common.hxx:138
@ IO_CLASS_SENSOR_PRODUCER_TVOC
TVOC concentration publisher.
Definition common.hxx:145
@ IO_CLASS_SENSOR_PRODUCER_PROXIMITY
Proximity publisher.
Definition common.hxx:136
@ IO_CLASS_SENSOR_PRODUCER_BAROMETER
Barometer publisher.
Definition common.hxx:135
Sensor/uORB publisher backed by Dawn protocol writes.
bool isNotify() const
Check if IO supports notifications.
size_t getDataDim() const
Get data vector dimension.
int configure()
Configure object from descriptor data.
bool isRead() const
Check if IO supports read operations.
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
bool isBatch() const
Check if IO supports batch operations.
bool isWrite() const
Check if IO supports write operations.
size_t getDataSize() const
Get data size in bytes.
int deinit()
De-initialize object.
uint16_t getCls() const
Get object class field.
Definition object.cxx:170
static ObjectCfgId objectCfg(uint8_t type, uint16_t cls, uint8_t dtype, bool rw, uint16_t size, uint8_t id)
Construct 32-bit ConfigID from component fields.
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
Definition objectcfg.hxx:60
static size_t ID_MAX
Configuration ID field constants and bit shift positions.
Definition objectcfg.hxx:45
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
@ OBJTYPE_IO
Input/Output object type.
Definition objectid.hxx:184
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
Definition objectid.hxx:96
@ DTYPE_BOOL
Boolean data type (stored in 32-bit container).
Definition objectid.hxx:72
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44
static ObjectId objectId(uint8_t type, uint16_t cls, uint8_t dtype, uint8_t flags, uint16_t priv)
Construct 32-bit ObjectID from component fields.
Definition objectid.hxx:290