6#include "dawn/io/sensor_producer.hxx"
11#include <nuttx/sensors/sensor.h>
15int CIOSensorProducer::configureDesc(
const CDescObject &desc)
20 for (
size_t i = 0; i < desc.
getSize(); i++)
30 case CIOSensorProducer::IO_SENSOR_PRODUCER_CFG_QUEUE_SIZE:
32 const uint32_t *tmp =
reinterpret_cast<const uint32_t *
>(&item->
data);
38 case CIOSensorProducer::IO_SENSOR_PRODUCER_CFG_PERSIST:
40 const uint32_t *tmp =
reinterpret_cast<const uint32_t *
>(&item->
data);
41 persist = (*tmp != 0);
48 DAWNERR(
"Unsupported sensor producer config 0x%08" PRIx32
"\n",
64 DAWNERR(
"Unsupported sensor producer config 0x%08" PRIx32
"\n", item->
cfgid.
v);
73CIOSensorProducer::~CIOSensorProducer()
85 DAWNERR(
"Unsupported sensor producer class %d\n",
getCls());
89#ifdef CONFIG_SENSORS_USE_B16
92 DAWNERR(
"Sensor producer requires DTYPE_B16 when CONFIG_SENSORS_USE_B16 is enabled\n");
98 DAWNERR(
"Sensor producer requires DTYPE_FLOAT when CONFIG_SENSORS_USE_FLOAT is enabled\n");
104 if (dtypeSize !=
sizeof(sensor_data_t))
106 DAWNERR(
"Sensor producer dtype size %d does not match NuttX sensor data size %zu\n",
108 sizeof(sensor_data_t));
112 if (info->path ==
nullptr || info->rsize == 0 || info->dsize == 0 ||
115 DAWNERR(
"Unsupported sensor producer class %d\n",
getCls());
119 if (DATA_BUFFER_SIZE < info->rsize)
122 "Sensor producer event size %zu exceeds buffer size %zu\n", info->rsize, DATA_BUFFER_SIZE);
126 ret = configureDesc(
getDesc());
129 DAWNERR(
"Sensor producer configure failed (error %d)\n", ret);
135 DAWNERR(
"SENSOR producer device number not configured\n");
139 snprintf(path,
sizeof(path), SENSOR_PATH_FMT, info->path,
"",
getCmnDevno());
141 ret = sensor_user_register(path, info->rsize, queueSize, persist);
146 else if (ret != -EEXIST)
148 DAWNERR(
"failed to register sensor producer %s %d\n", path, ret);
152 fd = sensor_open_write(path);
157 sensor_user_unregister(path);
176 sensor_user_unregister(path);
185 uint8_t buf[DATA_BUFFER_SIZE];
199 std::memset(buf, 0, info->rsize);
200 eventTs =
reinterpret_cast<io_ts_t *
>(buf);
201 *eventTs = sensor_get_timestamp();
204 ret = sensor_write(fd, buf, info->rsize);
207 DAWNERR(
"sensor producer write failed %d\n", ret);
211 if (
static_cast<size_t>(ret) != info->rsize)
216#ifdef CONFIG_DAWN_IO_TIMESTAMP
219 eventTs =
reinterpret_cast<io_ts_t *
>(buf);
229 return info !=
nullptr ? info->dsize *
sizeof(sensor_data_t) : 0;
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.
bool isTimestamp() const
Check if I/O supports timestamp.
int getCmnDevno() const
Get device number for this I/O.
size_t cfgCmnOffset(const SObjectCfg::SObjectCfgItem *cfg)
Get offset of configuration item in descriptor.
@ IO_CLASS_SENSOR_PRODUCER_CONFIG
Sensor producer configuration IDs.
@ IO_CLASS_ANY
Any I/O class.
size_t getDataDim() const
Get data vector dimension.
int configure()
Configure object from descriptor data.
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
size_t getDataSize() const
Get data size in bytes.
int deinit()
De-initialize object.
uint16_t getCls() const
Get object class field.
CDescObject & getDesc()
Get descriptor object for this object.
uint8_t getDtype() const
Get data type field.
Out-of-tree user-extension hooks for Dawn.
uint64_t io_ts_t
Timestamp data type (uint64_t, typically microseconds since boot).
Base interface for I/O data buffers (static and dynamic).
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.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
EObjectDataType
Data types supported by Dawn framework.
@ DTYPE_FLOAT
IEEE 754 single-precision floating point (32-bit).
@ DTYPE_B16
Signed 16.16 fixed-point (32-bit).
static int getDtypeSize_(const EObjectDataType dtype)
Get byte size for a specific data type.
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
uint32_t cls
Object class (bits 21-29, max 511).
uint32_t id
Configuration identifier (bits 0-4, max 31).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.