6#include "dawn/io/sensor.hxx"
13int CIOSensor::configureDesc(
const CDescObject &desc)
18 for (
size_t i = 0; i < desc.
getSize(); i++)
30 const uint32_t *tmp =
reinterpret_cast<const uint32_t *
>(&item->
data);
32 updateInterval = *tmp;
39 const uint32_t *tmp =
reinterpret_cast<const uint32_t *
>(&item->
data);
41 measurementPeriod = *tmp;
57 DAWNERR(
"Unsupported sensor config 0x%08" PRIx32
"\n", item->
cfgid.
v);
66CIOSensor::~CIOSensor()
76#ifdef CONFIG_SENSORS_USE_B16
79 DAWNERR(
"Sensor requires DTYPE_B16 when CONFIG_SENSORS_USE_B16 is enabled\n");
85 DAWNERR(
"Sensor requires DTYPE_FLOAT when CONFIG_SENSORS_USE_FLOAT is enabled\n");
91 if (dtypeSize !=
sizeof(sensor_data_t))
93 DAWNERR(
"Sensor dtype size %d does not match NuttX sensor data size %zu\n",
95 sizeof(sensor_data_t));
103 DAWNERR(
"Unsupported sensor class %d\n",
getCls());
107 if (DATA_BUFFER_SIZE < info->rsize)
109 DAWNERR(
"Sensor data size %zu exceeds buffer size %zu\n", info->rsize, DATA_BUFFER_SIZE);
115 ret = configureDesc(
getDesc());
118 DAWNERR(
"Sensor configure failed (error %d)\n", ret);
126 DAWNERR(
"SENSOR device number not configured\n");
130 snprintf(path,
sizeof(path), SENSOR_PATH_FMT, info->path,
"",
getCmnDevno());
134 fd = sensor_open(path);
137 DAWNERR(
"failed to open file %d\n", -errno);
154 uint8_t buf[DATA_BUFFER_SIZE];
155 size_t rsize = info->rsize;
167 ret = sensor_read(fd, buf, rsize);
170 DAWNERR(
"sensor_read failed %d\n", ret);
178#ifdef CONFIG_DAWN_IO_TIMESTAMP
189#ifdef CONFIG_DAWN_IO_NOTIFY
198 return info->dsize * dsize;
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.
virtual int getFd() const
Get file descriptor for notifications.
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_ANY
Any I/O class.
int deinit()
De-initialize object.
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
size_t getDataSize() const
Get data size in bytes.
@ IO_SENSOR_CFG_MEASPERIOD
Measurement period.
@ IO_SENSOR_CFG_UPDATEINTERVAL
Data update interval in milliseconds.
int configure()
Configure object from descriptor data.
size_t getDataDim() const
Get data vector dimension.
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 uint64_t & getTs(size_t batch=0)=0
Get timestamp reference for batch.
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.