Dawn Framework 1.0
Universal data acquisition framework for embedded systems
capabilities.cxx
1// dawn/src/io/capabilities.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/io/capabilities.hxx"
7
8#include <errno.h>
9
10#include <cstring>
11
12#include "dawn/prog/common.hxx"
13#include "dawn/proto/common.hxx"
14
15using namespace dawn;
16
17int CIOCapabilities::configureDesc(const CDescObject &desc)
18{
19 const SObjectCfg::SObjectCfgItem *item = nullptr;
20 size_t offset = 0;
21 size_t i = 0;
22
23 for (i = 0; i < desc.getSize(); i++)
24 {
25 item = desc.objectCfgItemAtOffset(offset);
26
27 switch (item->cfgid.s.cls)
28 {
30 {
31 offset += cfgCmnOffset(item);
32 break;
33 }
34
35 default:
36 {
37 DAWNERR("unsupported capabilities cfg 0x08%" PRIx32 "\n", item->cfgid.v);
38 return -EINVAL;
39 }
40 }
41 }
42
43 return OK;
44}
45
46void CIOCapabilities::setBitmapBit(uint8_t *bitmap, uint16_t bit)
47{
48 uint16_t by;
49 uint16_t bi;
50
51 by = static_cast<uint16_t>(bit / 8u);
52 bi = static_cast<uint16_t>(bit % 8u);
53
54 if (by < CAPS_BITMAP_BYTES)
55 {
56 bitmap[by] |= static_cast<uint8_t>(1u << bi);
57 }
58}
59
60void CIOCapabilities::buildIoBitmap()
61{
62 uint8_t *ioBitmap;
63
64 ioBitmap = payloadBuf + CAPS_IO_BITMAP_OFFSET;
65 std::memset(ioBitmap, 0, CAPS_BITMAP_BYTES);
66
67#ifdef CONFIG_DAWN_IO_CONFIG
68 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_CONFIG);
69#endif
70#ifdef CONFIG_DAWN_IO_TRIGGER
71 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_TRIGGER);
72#endif
73#ifdef CONFIG_DAWN_IO_DESCRIPTOR
74 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_DESCRIPTOR);
75#endif
76#ifdef CONFIG_DAWN_IO_CONTROL
77 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_CONTROL);
78#endif
79#ifdef CONFIG_DAWN_IO_CAPABILITIES
80 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_CAPABILITIES);
81#endif
82#ifdef CONFIG_DAWN_IO_DESC_SELECTOR
83 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_DESC_SELECTOR);
84#endif
85#ifdef CONFIG_DAWN_IO_DUMMY
86 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_DUMMY);
87#endif
88#ifdef CONFIG_DAWN_IO_TIMESTAMPIO
89 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_TIMESTAMP);
90#endif
91#ifdef CONFIG_DAWN_IO_RANDIO
92 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_RAND);
93#endif
94#ifdef CONFIG_DAWN_IO_DUMMY_NOTIFY
95 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_DUMMY_NOTIFY);
96#endif
97#ifdef CONFIG_DAWN_IO_FILE
98 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_FILE);
99#endif
100#ifdef CONFIG_DAWN_IO_SENSOR
101 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_ACCELEROMETER);
102 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_MAGNETICFIELD);
103 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_GYROSCOPE);
104 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_LIGHT);
105 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_BAROMETER);
106 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_PROXIMITY);
107 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_HUMIDITY);
108 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_TEMPERATURE);
109 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_ATEMPERATURE);
110 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_RGB);
111 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_IR);
112 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_UV);
113 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_GAS);
114#endif
115#ifdef CONFIG_DAWN_IO_SENSOR_PRODUCER
118 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_PRODUCER_GYROSCOPE);
119 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_PRODUCER_LIGHT);
120 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_PRODUCER_BAROMETER);
121 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_PRODUCER_PROXIMITY);
122 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_PRODUCER_HUMIDITY);
125 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_PRODUCER_RGB);
126 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_PRODUCER_IR);
127 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_PRODUCER_UV);
128 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SENSOR_PRODUCER_GAS);
129#endif
130#ifdef CONFIG_DAWN_IO_SYSINFO
131 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SYSTEM_UPTIME);
132 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SYSTEM_CPULOAD);
133#endif
134#ifdef CONFIG_DAWN_IO_BOARDCTL
135 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SYSTEM_RESET);
136 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SYSTEM_RESETCAUSE);
137 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SYSTEM_POWEROFF);
138#endif
139#ifdef CONFIG_DAWN_IO_UNAME
140 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SYSTEM_HOSTNAME);
141#endif
142#ifdef CONFIG_DAWN_IO_UUID
143 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SYSTEM_UUID);
144#endif
145#ifdef CONFIG_DAWN_IO_SYSTIME
146 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_SYSTEM_SYSTEMTIME);
147#endif
148#ifdef CONFIG_DAWN_IO_GPI
149 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_GPI_SINGLE);
150#endif
151#ifdef CONFIG_DAWN_IO_GPO
152 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_GPO_SINGLE);
153#endif
154#ifdef CONFIG_DAWN_IO_BUTTONS
155 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_BUTTONS);
156#endif
157#ifdef CONFIG_DAWN_IO_LEDS
158 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_LEDS);
159#endif
160#ifdef CONFIG_DAWN_IO_RGB_LED
161 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_RGBLED);
162#endif
163#ifdef CONFIG_DAWN_IO_PWM
164 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_PWM);
165#endif
166#ifdef CONFIG_DAWN_IO_ADC_FETCH
167 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_ADC_FETCH);
168#endif
169#ifdef CONFIG_DAWN_IO_ADC_SYNC
170 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_ADC_SYNC);
171#endif
172#ifdef CONFIG_DAWN_IO_ADC_STREAM
173 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_ADC_STREAM);
174#endif
175#ifdef CONFIG_DAWN_IO_DAC
176 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_DAC);
177#endif
178#ifdef CONFIG_DAWN_IO_ENCODER
179 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_ENCODER);
180#endif
181#ifdef CONFIG_DAWN_IO_ENCODER_INDEX
182 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_ENCODER_INDEX);
183#endif
184#ifdef CONFIG_DAWN_IO_VIRT
185 setBitmapBit(ioBitmap, CIOCommon::IO_CLASS_VIRT);
186#endif
187}
188
189void CIOCapabilities::buildProgBitmap()
190{
191 uint8_t *progBitmap;
192
193 progBitmap = payloadBuf + CAPS_PROG_BITMAP_OFFSET;
194 std::memset(progBitmap, 0, CAPS_BITMAP_BYTES);
195
196#ifdef CONFIG_DAWN_PROG_STATS_MIN
197 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_STATS_MIN);
198#endif
199#ifdef CONFIG_DAWN_PROG_STATS_MAX
200 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_STATS_MAX);
201#endif
202#ifdef CONFIG_DAWN_PROG_STATS_AVG
203 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_STATS_AVG);
204#endif
205#ifdef CONFIG_DAWN_PROG_STATS_SUM
206 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_STATS_SUM);
207#endif
208#ifdef CONFIG_DAWN_PROG_STATS_COUNT
209 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_STATS_COUNT);
210#endif
211#ifdef CONFIG_DAWN_PROG_STATS_RMS
212 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_STATS_RMS);
213#endif
214#ifdef CONFIG_DAWN_PROG_SAMPLING
215 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_SAMPLING);
216#endif
217#ifdef CONFIG_DAWN_PROG_DUMMY
218 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_DUMMY);
219#endif
220#ifdef CONFIG_DAWN_PROG_ADJUST
221 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_ADJUST);
222#endif
223#ifdef CONFIG_DAWN_PROG_GATEWAY
224 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_GATEWAY);
225#endif
226#ifdef CONFIG_DAWN_PROG_LATEST
227 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_LATEST);
228#endif
229#ifdef CONFIG_DAWN_PROG_REDIRECT
230 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_REDIRECT);
231#endif
232#ifdef CONFIG_DAWN_PROG_MOVING_AVG
233 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_MOVING_AVG);
234#endif
235#ifdef CONFIG_DAWN_PROG_IIR_FILTER
236 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_IIR_FILTER);
237#endif
238#ifdef CONFIG_DAWN_PROG_THRESHOLD
239 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_THRESHOLD);
240#endif
241#ifdef CONFIG_DAWN_PROG_THRESHOLD_VALUE
242 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_THRESHOLD_VALUE);
243#endif
244#ifdef CONFIG_DAWN_PROG_BUFFER
245 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_BUFFER);
246#endif
247#ifdef CONFIG_DAWN_PROG_SEQUENCER
248 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_SEQUENCER);
249#endif
250#ifdef CONFIG_DAWN_PROG_BITSPLIT
251 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_BITSPLIT);
252#endif
253#ifdef CONFIG_DAWN_PROG_TOGGLE
254 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_TOGGLE);
255#endif
256#ifdef CONFIG_DAWN_PROG_COUNTER
257 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_COUNTER);
258#endif
259#ifdef CONFIG_DAWN_PROG_SWITCH
260 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_SWITCH);
261#endif
262#ifdef CONFIG_DAWN_PROG_EXPRESSION
263 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_EXPRESSION);
264#endif
265#ifdef CONFIG_DAWN_PROG_SELECTOR
266 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_SELECTOR);
267#endif
268#ifdef CONFIG_DAWN_PROG_BITPACK
269 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_BITPACK);
270#endif
271#ifdef CONFIG_DAWN_PROG_VECPACK
272 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_VECPACK);
273#endif
274#ifdef CONFIG_DAWN_PROG_VECSPLIT
275 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_VECSPLIT);
276#endif
277#ifdef CONFIG_DAWN_PROG_CONFIGWRITER
278 setBitmapBit(progBitmap, CProgCommon::PROG_CLASS_CONFIGWRITER);
279#endif
280}
281
282void CIOCapabilities::buildProtoBitmap()
283{
284 uint8_t *protoBitmap;
285
286 protoBitmap = payloadBuf + CAPS_PROTO_BITMAP_OFFSET;
287 std::memset(protoBitmap, 0, CAPS_BITMAP_BYTES);
288
289#ifdef CONFIG_DAWN_PROTO_DUMMY
290 setBitmapBit(protoBitmap, CProtoCommon::PROTO_CLASS_DUMMY);
291#endif
292#ifdef CONFIG_DAWN_PROTO_NIMBLE_PERIPHERAL
293 setBitmapBit(protoBitmap, CProtoCommon::PROTO_CLASS_NIMBLE_PRPH);
294#endif
295#ifdef CONFIG_DAWN_PROTO_NXSCOPE_DUMMY
296 setBitmapBit(protoBitmap, CProtoCommon::PROTO_CLASS_NXSCOPE_DUMMY);
297#endif
298#ifdef CONFIG_DAWN_PROTO_NXSCOPE_SERIAL
299 setBitmapBit(protoBitmap, CProtoCommon::PROTO_CLASS_NXSCOPE_SERIAL);
300#endif
301#ifdef CONFIG_DAWN_PROTO_NXSCOPE_UDP
302 setBitmapBit(protoBitmap, CProtoCommon::PROTO_CLASS_NXSCOPE_UDP);
303#endif
304#ifdef CONFIG_DAWN_PROTO_SHELL_PRETTY
305 setBitmapBit(protoBitmap, CProtoCommon::PROTO_CLASS_SHELL_STD);
306#endif
307#ifdef CONFIG_DAWN_PROTO_SERIAL
308 setBitmapBit(protoBitmap, CProtoCommon::PROTO_CLASS_SERIAL);
309#endif
310#ifdef CONFIG_DAWN_PROTO_MODBUS_RTU
311 setBitmapBit(protoBitmap, CProtoCommon::PROTO_CLASS_MODBUS_RTU);
312#endif
313#ifdef CONFIG_DAWN_PROTO_MODBUS_TCP
314 setBitmapBit(protoBitmap, CProtoCommon::PROTO_CLASS_MODBUS_TCP);
315#endif
316#ifdef CONFIG_DAWN_PROTO_CAN
317 setBitmapBit(protoBitmap, CProtoCommon::PROTO_CLASS_CAN);
318#endif
319#ifdef CONFIG_DAWN_PROTO_UDP
320 setBitmapBit(protoBitmap, CProtoCommon::PROTO_CLASS_UDP);
321#endif
322#ifdef CONFIG_DAWN_PROTO_IPC
323 setBitmapBit(protoBitmap, CProtoCommon::PROTO_CLASS_IPC);
324#endif
325}
326
327void CIOCapabilities::setMetaWord(uint16_t index, uint32_t value)
328{
329 size_t off;
330
331 if (index >= CAPS_META_WORDS)
332 {
333 return;
334 }
335
336 off = CAPS_META_OFFSET + static_cast<size_t>(index) * 4u;
337 payloadBuf[off + 0] = static_cast<uint8_t>(value & 0xffu);
338 payloadBuf[off + 1] = static_cast<uint8_t>((value >> 8) & 0xffu);
339 payloadBuf[off + 2] = static_cast<uint8_t>((value >> 16) & 0xffu);
340 payloadBuf[off + 3] = static_cast<uint8_t>((value >> 24) & 0xffu);
341}
342
343void CIOCapabilities::buildMetaPayload()
344{
345 uint32_t dtypeBitmap;
346 uint32_t ioFlagsBitmap;
347 uint32_t buildFlags;
348
349 std::memset(payloadBuf + CAPS_META_OFFSET, 0, CAPS_PAYLOAD_SIZE - CAPS_META_OFFSET);
350
351 dtypeBitmap = 0;
352 ioFlagsBitmap = 0;
353 buildFlags = 0;
354
355 // DTYPE_ANY
356 dtypeBitmap |= (1u << SObjectId::DTYPE_ANY);
357#ifdef CONFIG_DAWN_DTYPE_BOOL
358 dtypeBitmap |= (1u << SObjectId::DTYPE_BOOL);
359#endif
360#ifdef CONFIG_DAWN_DTYPE_INT8
361 dtypeBitmap |= (1u << SObjectId::DTYPE_INT8);
362#endif
363#ifdef CONFIG_DAWN_DTYPE_UINT8
364 dtypeBitmap |= (1u << SObjectId::DTYPE_UINT8);
365#endif
366#ifdef CONFIG_DAWN_DTYPE_INT16
367 dtypeBitmap |= (1u << SObjectId::DTYPE_INT16);
368#endif
369#ifdef CONFIG_DAWN_DTYPE_UINT16
370 dtypeBitmap |= (1u << SObjectId::DTYPE_UINT16);
371#endif
372#ifdef CONFIG_DAWN_DTYPE_INT32
373 dtypeBitmap |= (1u << SObjectId::DTYPE_INT32);
374#endif
375#ifdef CONFIG_DAWN_DTYPE_UINT32
376 dtypeBitmap |= (1u << SObjectId::DTYPE_UINT32);
377#endif
378#ifdef CONFIG_DAWN_DTYPE_INT64
379 dtypeBitmap |= (1u << SObjectId::DTYPE_INT64);
380#endif
381#ifdef CONFIG_DAWN_DTYPE_UINT64
382 dtypeBitmap |= (1u << SObjectId::DTYPE_UINT64);
383#endif
384#ifdef CONFIG_DAWN_DTYPE_FLOAT
385 dtypeBitmap |= (1u << SObjectId::DTYPE_FLOAT);
386#endif
387#ifdef CONFIG_DAWN_DTYPE_DOUBLE
388 dtypeBitmap |= (1u << SObjectId::DTYPE_DOUBLE);
389#endif
390#ifdef CONFIG_DAWN_DTYPE_B16
391 dtypeBitmap |= (1u << SObjectId::DTYPE_B16);
392#endif
393#ifdef CONFIG_DAWN_DTYPE_UB16
394 dtypeBitmap |= (1u << SObjectId::DTYPE_UB16);
395#endif
396#ifdef CONFIG_DAWN_DTYPE_CHAR
397 dtypeBitmap |= (1u << SObjectId::DTYPE_CHAR);
398#endif
399#ifdef CONFIG_DAWN_DTYPE_BLOCK
400 dtypeBitmap |= (1u << SObjectId::DTYPE_BLOCK);
401#endif
402
403#ifdef CONFIG_DAWN_IO_TIMESTAMP
404 ioFlagsBitmap |= (1u << 0);
405#endif
406
407 buildFlags |= CAPS_BUILD_OS_NUTTX;
408#ifdef CONFIG_FS_PROCFS
409 buildFlags |= CAPS_BUILD_FILESYSTEM;
410#endif
411#ifdef CONFIG_DAWN_IO_NOTIFY
412 buildFlags |= CAPS_BUILD_IO_NOTIFY;
413#endif
414#ifdef CONFIG_DAWN_IO_HAS_STATS
415 buildFlags |= CAPS_BUILD_IO_HAS_STATS;
416#endif
417#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
418 buildFlags |= CAPS_BUILD_OBJECT_HASNAME;
419#endif
420#if CONFIG_DAWN_DESC_SLOTS > 1
421 buildFlags |= CAPS_BUILD_DESC_DYNAMIC;
422#endif
423
424 // v2 metadata layout:
425 // [0] dtype bits lo, [1] dtype bits hi,
426 // [2] io flags lo, [3] io flags hi,
427 // [4] build flags lo, [5] build flags hi,
428 // [6] descriptor slots, [7] descriptor slot size,
429 // [8] max io class id, [9] max prog class id, [10] max proto class id,
430 // [11..] reserved.
431 setMetaWord(0, dtypeBitmap);
432 setMetaWord(1, 0);
433 setMetaWord(2, ioFlagsBitmap);
434 setMetaWord(3, 0);
435 setMetaWord(4, buildFlags);
436 setMetaWord(5, 0);
437 setMetaWord(6, CONFIG_DAWN_DESC_SLOTS);
438 setMetaWord(7, CONFIG_DAWN_DESC_SLOT_SIZE);
439 setMetaWord(8, 0x1ffu);
440 setMetaWord(9, 0x1ffu);
441 setMetaWord(10, 0x1ffu);
442 setMetaWord(11, 0);
443}
444
445int CIOCapabilities::configurePayload()
446{
447 std::memset(payloadBuf, 0, sizeof(payloadBuf));
448 buildIoBitmap();
449 buildProgBitmap();
450 buildProtoBitmap();
451 buildMetaPayload();
452 return OK;
453}
454
455size_t CIOCapabilities::copyFromBlob(uint8_t *dst, size_t offset, size_t len) const
456{
457 uint8_t hdr[CAPS_HDR_SIZE];
458 size_t copied;
459 size_t hstart;
460 size_t hcopy;
461 size_t pstart;
462 size_t pcopy;
463
464 hdr[0] = CAPS_VERSION;
465 hdr[1] = 0;
466 hdr[2] = static_cast<uint8_t>(CAPS_PAYLOAD_SIZE & 0xff);
467 hdr[3] = static_cast<uint8_t>((CAPS_PAYLOAD_SIZE >> 8) & 0xff);
468 hdr[4] = 0;
469 hdr[5] = 0;
470 hdr[6] = 0;
471 hdr[7] = 0;
472
473 copied = 0;
474
475 if (offset < CAPS_HDR_SIZE)
476 {
477 hstart = offset;
478 hcopy = CAPS_HDR_SIZE - hstart;
479 if (hcopy > len)
480 {
481 hcopy = len;
482 }
483
484 std::memcpy(dst, &hdr[hstart], hcopy);
485 copied += hcopy;
486 }
487
488 if (copied < len)
489 {
490 if (offset + copied < CAPS_HDR_SIZE)
491 {
492 pstart = 0;
493 }
494 else
495 {
496 pstart = offset + copied - CAPS_HDR_SIZE;
497 }
498
499 pcopy = CAPS_PAYLOAD_SIZE - pstart;
500 if (pcopy > (len - copied))
501 {
502 pcopy = len - copied;
503 }
504
505 if (pcopy > 0)
506 {
507 std::memcpy(dst + copied, payloadBuf + pstart, pcopy);
508 copied += pcopy;
509 }
510 }
511
512 return copied;
513}
514
515CIOCapabilities::~CIOCapabilities()
516{
517 deinit();
518}
519
521{
522 int ret;
523
524 ret = configureDesc(getDesc());
525 if (ret != OK)
526 {
527 return ret;
528 }
529
530 return configurePayload();
531}
532
534{
535 return OK;
536}
537
539{
540 (void)data;
541 (void)len;
542 return -ENOTSUP;
543}
544
546{
547 (void)data;
548 return -ENOTSUP;
549}
550
551int CIOCapabilities::getDataAtImpl(IODataCmn &data, size_t len, size_t offset)
552{
553 size_t total;
554 size_t avail;
555 size_t toCopy;
556
557 if (len != 1)
558 {
559 return -EINVAL;
560 }
561
562 total = getDataSize();
563 if (offset >= total)
564 {
565 return -EINVAL;
566 }
567
568 avail = total - offset;
569 toCopy = data.getDataSize() < avail ? data.getDataSize() : avail;
570 copyFromBlob(static_cast<uint8_t *>(data.getDataPtr()), offset, toCopy);
571
572 return OK;
573}
574
576{
577 return CAPS_TOTAL_SIZE;
578}
579
581{
582 return getDataSize();
583}
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemAtOffset(size_t offset) const
Get configuration item at specified offset.
int getDataAtImpl(IODataCmn &data, size_t len, size_t offset)
Get data at byte offset (override in seekable IOs).
int deinit()
De-initialize object.
size_t getDataDim() const
Get data vector dimension.
int configure()
Configure object from descriptor data.
size_t getDataSize() const
Get data size in bytes.
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
size_t cfgCmnOffset(const SObjectCfg::SObjectCfgItem *cfg)
Get offset of configuration item in descriptor.
Definition common.cxx:144
@ IO_CLASS_SENSOR_PRODUCER_MAGNETICFIELD
Magnetic field publisher.
Definition common.hxx:130
@ IO_CLASS_SENSOR_MAGNETICFIELD
Magnetic field sensor.
Definition common.hxx:114
@ IO_CLASS_SENSOR_PRODUCER_ACCELEROMETER
Accelerometer publisher.
Definition common.hxx:129
@ IO_CLASS_DAC
Digital-to-analog converter.
Definition common.hxx:176
@ IO_CLASS_TRIGGER
Trigger I/O.
Definition common.hxx:91
@ IO_CLASS_PWM
PWM output.
Definition common.hxx:172
@ IO_CLASS_SYSTEM_RESETCAUSE
Reset cause.
Definition common.hxx:153
@ IO_CLASS_ADC_STREAM
ADC stream (batch/high-throughput)
Definition common.hxx:179
@ IO_CLASS_VIRT
Virtual I/O.
Definition common.hxx:188
@ IO_CLASS_SYSTEM_UPTIME
System uptime.
Definition common.hxx:150
@ IO_CLASS_SYSTEM_POWEROFF
Power off control.
Definition common.hxx:154
@ IO_CLASS_GPI_SINGLE
Single GPIO input.
Definition common.hxx:164
@ IO_CLASS_SENSOR_PRODUCER_LIGHT
Light publisher.
Definition common.hxx:132
@ IO_CLASS_SENSOR_PRODUCER_ATEMPERATURE
Ambient temperature publisher.
Definition common.hxx:137
@ IO_CLASS_ANY
Any I/O class.
Definition common.hxx:86
@ IO_CLASS_SYSTEM_SYSTEMTIME
System time.
Definition common.hxx:157
@ IO_CLASS_SENSOR_PRODUCER_HUMIDITY
Humidity publisher.
Definition common.hxx:135
@ IO_CLASS_ENCODER_INDEX
Quadrature encoder (position+index)
Definition common.hxx:184
@ IO_CLASS_SENSOR_PRODUCER_IR
Infrared publisher.
Definition common.hxx:139
@ IO_CLASS_ADC_FETCH
ADC fetch (on-demand)
Definition common.hxx:177
@ IO_CLASS_CAPABILITIES
Capabilities bitmask I/O.
Definition common.hxx:94
@ IO_CLASS_SENSOR_LIGHT
Light sensor.
Definition common.hxx:116
@ IO_CLASS_SENSOR_BAROMETER
Barometer sensor.
Definition common.hxx:117
@ IO_CLASS_SENSOR_PRODUCER_UV
Ultraviolet publisher.
Definition common.hxx:140
@ IO_CLASS_SENSOR_HUMIDITY
Humidity sensor.
Definition common.hxx:119
@ IO_CLASS_SENSOR_PROXIMITY
Proximity sensor.
Definition common.hxx:118
@ IO_CLASS_SENSOR_PRODUCER_GAS
Gas publisher.
Definition common.hxx:141
@ IO_CLASS_SENSOR_TEMPERATURE
Temperature sensor.
Definition common.hxx:120
@ IO_CLASS_FILE
File system I/O.
Definition common.hxx:109
@ IO_CLASS_SENSOR_PRODUCER_GYROSCOPE
Gyroscope publisher.
Definition common.hxx:131
@ IO_CLASS_CONTROL
Control I/O.
Definition common.hxx:93
@ IO_CLASS_BUTTONS
Button input.
Definition common.hxx:166
@ IO_CLASS_SYSTEM_HOSTNAME
System hostname.
Definition common.hxx:155
@ IO_CLASS_SENSOR_PRODUCER_RGB
RGB color publisher.
Definition common.hxx:138
@ IO_CLASS_SENSOR_PRODUCER_TEMPERATURE
Temperature publisher.
Definition common.hxx:136
@ IO_CLASS_SENSOR_UV
Ultraviolet sensor.
Definition common.hxx:124
@ IO_CLASS_CONFIG
Configuration I/O.
Definition common.hxx:90
@ IO_CLASS_DESC_SELECTOR
Descriptor slot selector I/O.
Definition common.hxx:95
@ IO_CLASS_DUMMY
Dummy I/O (for testing)
Definition common.hxx:99
@ IO_CLASS_SENSOR_ACCELEROMETER
Accelerometer sensor.
Definition common.hxx:113
@ IO_CLASS_SENSOR_RGB
RGB color sensor.
Definition common.hxx:122
@ IO_CLASS_TIMESTAMP
Timestamp generator.
Definition common.hxx:103
@ IO_CLASS_SENSOR_GYROSCOPE
Gyroscope sensor.
Definition common.hxx:115
@ IO_CLASS_SYSTEM_UUID
UUID.
Definition common.hxx:156
@ IO_CLASS_ADC_SYNC
ADC sync (HW-triggered control loop)
Definition common.hxx:178
@ IO_CLASS_ENCODER
Quadrature encoder (position)
Definition common.hxx:183
@ IO_CLASS_GPO_SINGLE
Single GPIO output.
Definition common.hxx:165
@ IO_CLASS_SENSOR_IR
Infrared sensor.
Definition common.hxx:123
@ IO_CLASS_SYSTEM_CPULOAD
CPU load.
Definition common.hxx:151
@ IO_CLASS_SENSOR_PRODUCER_PROXIMITY
Proximity publisher.
Definition common.hxx:134
@ IO_CLASS_SENSOR_ATEMPERATURE
Ambient temperature sensor.
Definition common.hxx:121
@ IO_CLASS_DUMMY_NOTIFY
Timer-driven dummy IO.
Definition common.hxx:105
@ IO_CLASS_LEDS
LED output.
Definition common.hxx:167
@ IO_CLASS_RGBLED
RGB LED output.
Definition common.hxx:168
@ IO_CLASS_RAND
Random number generator.
Definition common.hxx:104
@ IO_CLASS_SENSOR_GAS
Gas sensor.
Definition common.hxx:125
@ IO_CLASS_SENSOR_PRODUCER_BAROMETER
Barometer publisher.
Definition common.hxx:133
@ IO_CLASS_DESCRIPTOR
Descriptor I/O.
Definition common.hxx:92
@ IO_CLASS_SYSTEM_RESET
System reset control.
Definition common.hxx:152
CDescObject & getDesc()
Get descriptor object for this object.
Definition object.cxx:190
@ PROG_CLASS_LATEST
Cache latest notified sample for fetch-based readers.
Definition common.hxx:79
@ PROG_CLASS_MOVING_AVG
Moving average filter.
Definition common.hxx:87
@ PROG_CLASS_IIR_FILTER
First-order IIR filter.
Definition common.hxx:91
@ PROG_CLASS_DUMMY
Dummy program (test/helper).
Definition common.hxx:67
@ PROG_CLASS_THRESHOLD_VALUE
Threshold comparator returning gated source value.
Definition common.hxx:99
@ PROG_CLASS_STATS_MAX
Maximum value tracker.
Definition common.hxx:43
@ PROG_CLASS_STATS_MIN
Minimum value tracker.
Definition common.hxx:39
@ PROG_CLASS_GATEWAY
Protocol-to-protocol IO gateway.
Definition common.hxx:75
@ PROG_CLASS_SEQUENCER
Periodic state sequencer.
Definition common.hxx:107
@ PROG_CLASS_STATS_SUM
Sum accumulator.
Definition common.hxx:51
@ PROG_CLASS_BUFFER
Notify-driven history capture buffer.
Definition common.hxx:103
@ PROG_CLASS_SAMPLING
Periodic data sampler.
Definition common.hxx:63
@ PROG_CLASS_THRESHOLD
Threshold and hysteresis comparator.
Definition common.hxx:95
@ PROG_CLASS_REDIRECT
Generic input-to-output routing bridge.
Definition common.hxx:83
@ PROG_CLASS_STATS_RMS
Running RMS (root mean square) calculator.
Definition common.hxx:59
@ PROG_CLASS_ADJUST
Scale/offset adjustment.
Definition common.hxx:71
@ PROG_CLASS_STATS_COUNT
Sample counter.
Definition common.hxx:55
@ PROG_CLASS_STATS_AVG
Running average calculator.
Definition common.hxx:47
@ PROTO_CLASS_NXSCOPE_UDP
NxScope real-time visualization (UDP interface).
Definition common.hxx:51
@ PROTO_CLASS_MODBUS_TCP
Modbus TCP (network implementation).
Definition common.hxx:71
@ PROTO_CLASS_MODBUS_RTU
Modbus RTU (serial implementation).
Definition common.hxx:67
@ PROTO_CLASS_NXSCOPE_SERIAL
NxScope real-time visualization (serial interface).
Definition common.hxx:47
@ PROTO_CLASS_DUMMY
Dummy protocol (test/helper).
Definition common.hxx:43
@ PROTO_CLASS_UDP
UDP-based protocol.
Definition common.hxx:79
@ PROTO_CLASS_SERIAL
Compact binary protocol over serial port.
Definition common.hxx:63
@ PROTO_CLASS_NIMBLE_PRPH
BLE Peripheral using Apache NimBLE stack.
Definition common.hxx:35
@ PROTO_CLASS_IPC
FIFO-based local IPC protocol.
Definition common.hxx:83
@ PROTO_CLASS_NXSCOPE_DUMMY
NxScope real-time visualization (dummy interface).
Definition common.hxx:39
@ PROTO_CLASS_SHELL_STD
Interactive shell on stdin/stdout.
Definition common.hxx:55
@ PROTO_CLASS_CAN
CAN bus protocol.
Definition common.hxx:75
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
virtual void * getDataPtr(size_t batch=0)=0
Get pointer to data only (skips timestamp if present).
virtual size_t getDataSize()=0
Get data size in bytes.
Single configuration item within object.
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
@ DTYPE_FLOAT
IEEE 754 single-precision floating point (32-bit).
Definition objectid.hxx:112
@ DTYPE_INT32
Signed 32-bit integer (-2147483648 to 2147483647).
Definition objectid.hxx:92
@ DTYPE_UINT8
Unsigned 8-bit integer (0 to 255).
Definition objectid.hxx:80
@ DTYPE_INT16
Signed 16-bit integer (-32768 to 32767).
Definition objectid.hxx:84
@ DTYPE_INT8
Signed 8-bit integer (-128 to 127).
Definition objectid.hxx:76
@ DTYPE_ANY
Wildcard data type (matches any actual type).
Definition objectid.hxx:68
@ DTYPE_BLOCK
Opaque block/byte-stream data type.
Definition objectid.hxx:153
@ DTYPE_UINT64
Unsigned 64-bit integer.
Definition objectid.hxx:104
@ DTYPE_UINT16
Unsigned 16-bit integer (0 to 65535).
Definition objectid.hxx:88
@ DTYPE_UB16
Unsigned 16.16 fixed-point (32-bit).
Definition objectid.hxx:132
@ DTYPE_DOUBLE
IEEE 754 double-precision floating point (64-bit).
Definition objectid.hxx:120
@ DTYPE_CHAR
Character/string type (null-terminated, 4-byte aligned).
Definition objectid.hxx:144
@ DTYPE_INT64
Signed 64-bit integer.
Definition objectid.hxx:100
@ 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
@ DTYPE_B16
Signed 16.16 fixed-point (32-bit).
Definition objectid.hxx:128
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
Definition objectcfg.hxx:82
uint32_t cls
Object class (bits 21-29, max 511).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.