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);
39 const uint32_t *tmp =
reinterpret_cast<const uint32_t *
>(&item->
data);
57 DAWNERR(
"Unsupported sensor config 0x%08" PRIx32
"\n", item->
cfgid.
v);
66CIOSensor::~CIOSensor()
71int CIOSensor::validateDtype()
75#ifdef CONFIG_SENSORS_USE_B16
78 DAWNERR(
"Sensor requires DTYPE_B16 when CONFIG_SENSORS_USE_B16 is enabled\n");
84 DAWNERR(
"Sensor requires DTYPE_FLOAT when CONFIG_SENSORS_USE_FLOAT is enabled\n");
90 if (dtypeSize !=
sizeof(sensor_data_t))
92 DAWNERR(
"Sensor dtype size %d does not match NuttX sensor data size %zu\n",
94 sizeof(sensor_data_t));
107 ret = validateDtype();
115 DAWNERR(
"Unsupported sensor class %d\n",
getCls());
119 if (DATA_BUFFER_SIZE < info->rsize)
121 DAWNERR(
"Sensor data size %zu exceeds buffer size %zu\n",
info->rsize, DATA_BUFFER_SIZE);
127 ret = configureDesc(
getDesc());
130 DAWNERR(
"Sensor configure failed (error %d)\n", ret);
138 DAWNERR(
"SENSOR device number not configured\n");
149 DAWNERR(
"failed to open file %d\n", -errno);
162 DAWNERR(
"failed to set sensor interval %d\n", ret);
180 uint8_t buf[DATA_BUFFER_SIZE];
181 size_t rsize =
info->rsize;
193 ret = sensor_read(
fd, buf, rsize);
196 DAWNERR(
"sensor_read failed %d\n", ret);
204#ifdef CONFIG_DAWN_IO_TIMESTAMP
215#ifdef CONFIG_DAWN_IO_NOTIFY
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.
uint32_t measurementPeriod
Sensor measurement period in milliseconds.
int fd
File descriptor for sensor device.
int deinit()
De-initialize object.
@ IO_SENSOR_CFG_MEASPERIOD
Measurement period.
@ IO_SENSOR_CFG_UPDATEINTERVAL
Data update interval in milliseconds.
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
size_t getDataSize() const
Get data size in bytes.
size_t dsize
Sensor data size in bytes.
uint32_t updateInterval
Sensor update interval in milliseconds.
char path[PATH_MAX]
Sensor device file path.
const SIOSensorMapInfo * info
Sensor metadata.
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.