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)
23 SPrphNotiferCb *ncb =
static_cast<SPrphNotiferCb *
>(priv);
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()
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");
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());
175 ncb =
new (std::nothrow) SPrphNotiferCb();
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();
Base class for all I/O objects.
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.
virtual int startService(int id)=0
Start a specific service.
virtual CIOCommon * getObject(SObjectId::ObjectId id)=0
Get protocol object by ID.
virtual int serviceRegister(struct ble_gatt_svc_def *svc)=0
Register a GATT service with the peripheral.
virtual void regObject(SObjectId::ObjectId id)=0
Register an I/O object for this service.
virtual int stopService(int id)=0
Stop a specific service.
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.
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).
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.
32-bit encoded object identifier (union with bit field).
ObjectId v
Raw 32-bit ObjectID value (for comparison, hashing, storage).