6#include "dawn/proto/nimble/prph_bas.hxx"
12#include "dawn/io/common.hxx"
16#include "services/bas/ble_svc_bas.h"
21int CProtoNimblePrphBas::notifierCb(
void *priv,
io_ddata_t *data)
27 DAWNERR(
"NULL ncb pointer in BAS notifier\n");
33 DAWNERR(
"NULL data pointer in BAS notifier\n");
37 if (ncb->data ==
nullptr)
39 DAWNERR(
"NULL BAS data buffer in notifier\n");
43 std::memcpy(ncb->data->getDataPtr(), data->
getDataPtr(), ncb->data->getDataSize());
45 ble_svc_bas_battery_level_set(*
static_cast<uint8_t *
>(ncb->data->getDataPtr()));
52 DAWNINFO(
"allocate object 0x%" PRIx32
"\n", obj.
v);
67 DAWNERR(
"Invalid BAS config size: %d\n", item->
cfgid.
s.
size);
71 const auto *tmp =
reinterpret_cast<const SProtoNimblePrphIOBindBas *
>(&item->
data);
75 allocObject(tmp->objid);
88CProtoNimblePrphBas::~CProtoNimblePrphBas()
105 id =
cb->serviceRegister(
nullptr);
108 DAWNERR(
"BAS service registration failed\n");
119#ifdef CONFIG_DAWN_IO_NOTIFY
120 if (ncb->io !=
nullptr && ncb->io->isNotify())
122 ncb->io->setNotifier(
nullptr, 0,
nullptr);
134int CProtoNimblePrphBas::bindObject()
146 DAWNERR(
"BAS requires exactly one battery-level IO\n");
150 io =
cb->getObject(
vio[0]);
153 DAWNERR(
"BAS IO not found\n");
159 DAWNERR(
"seekable IO not supported by BAS (objid=0x%08" PRIx32
")\n", io->
getIdV());
165 DAWNERR(
"BAS requires notify-capable IO (objid=0x%08" PRIx32
")\n", io->
getIdV());
171 DAWNERR(
"BAS IO data size too small: %zu\n", io->
getDataSize());
178 DAWNERR(
"BAS notifier allocation failed\n");
185 if (ncb->data ==
nullptr)
187 DAWNERR(
"BAS data allocation failed\n");
193 ret = io->setNotifier(notifierCb, 0, ncb);
196 DAWNERR(
"ERROR: set notifier failed for BAS objId = 0x%" PRIx32
"\n",
vio[0]);
206int CProtoNimblePrphBas::updateBatteryLevel()
211 if (ncb ==
nullptr || ncb->io ==
nullptr || ncb->data ==
nullptr)
216 ret = ncb->io->
getData(*ncb->data, 1);
222 level = *
static_cast<uint8_t *
>(ncb->data->getDataPtr());
223 return ble_svc_bas_battery_level_set(level);
236 ret = updateBatteryLevel();
244 return cb->startService(
id);
251 return cb->stopService(
id);
Base class for all I/O objects.
int getData(IODataCmn &data, size_t len, size_t offset=0)
Get data from I/O (public interface with stats tracking).
virtual bool isNotify() const =0
Check if IO supports notifications.
virtual bool isSeekable() const
Check if IO supports partial (seekable) access.
io_ddata_t * ddata_alloc(size_t batch, size_t chunk_size=0)
Allocate data buffer for this I/O.
virtual size_t getDataSize() const =0
Get data size in bytes.
SObjectId::ObjectId getIdV() const
Get object identifier as raw 32-bit value.
int init()
Initialize service.
int start()
Start service.
int deinit()
Deinitialize service.
Interface for BLE peripheral services with GATT characteristics.
Base interface for GATT services exposed by BLE peripheral.
std::vector< SObjectId::ObjectId > vio
Vector of I/O objects exposed by this service.
const SObjectCfg::SObjectCfgItem * desc
Configuration descriptor for this service.
IProtoNimblePrphCb * cb
Callback interface to peripheral.
Out-of-tree user-extension hooks for Dawn.
Context data for characteristic notification callbacks.
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).
Heap-allocated dynamic I/O data buffer.
void * getDataPtr(size_t batch=0)
Get pointer to data only (skips timestamp if present).
struct dawn::SObjectCfg::UObjectCfgId::@334307326077356333363326153167141302007100111136 s
Bit-field structure for named member access.
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
32-bit encoded object identifier (union with bit field).
ObjectId v
Raw 32-bit ObjectID value (for comparison, hashing, storage).