Dawn Framework 1.0
Universal data acquisition framework for embedded systems
prph.hxx
1// dawn/include/dawn/proto/nimble/prph.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include "dawn/porting/config.hxx"
9#include "dawn/proto/nimble/adv.hxx"
10#include "dawn/proto/nimble/hci.hxx"
11#include "dawn/proto/nimble/host.hxx"
12#include "dawn/proto/nimble/iprph.hxx"
13#include "host/ble_gap.h"
14#include "host/ble_gatt.h"
15
16namespace dawn
17{
25 : public CProtoCommon
26 , public IProtoNimblePrphCb
27{
28public:
42
43 explicit CProtoNimblePrph(CDescObject &desc)
44 : CProtoCommon(desc)
45 , devno(0)
46 , gapname(nullptr)
47 , svcDefs(nullptr)
48 , noAllocServices(0)
49 {
50 }
51
52 ~CProtoNimblePrph() override;
53
54#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
55 const char *getClassNameStr() const override
56 {
57 return "ble";
58 }
59#endif
60
61 int configure() override;
62 int deinit() override;
63 int doStart() override;
64 int doStop() override;
65 bool hasThread() const override;
66
67 int serviceRegister(struct ble_gatt_svc_def *svc) override;
68 int startService(int id) override;
69 int stopService(int id) override;
70
72 {
73 this->setObjectMapItem(id, nullptr);
74 };
75
77 {
78 return this->getIO(id);
79 };
80
81 size_t getObjectsLen() override
82 {
83 return this->getIOMap().size();
84 };
85
86 static SObjectId::ObjectId objectId(uint16_t id)
87 {
90 }
91
92 static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t dtype, uint8_t size, uint8_t id)
93 {
96 }
97
98 static SObjectCfg::ObjectCfgId cfgIdGapname(uint16_t size)
99 {
100 return CProtoNimblePrph::cfgId(false, SObjectId::DTYPE_CHAR, size, PROTO_NIMBLE_CFG_GAPNAME);
101 }
102
103 static SObjectCfg::ObjectCfgId cfgIdIOBindDis()
104 {
105 return CProtoNimblePrph::cfgId(false, SObjectId::DTYPE_ANY, 0, PROTO_NIMBLE_CFG_IOBIND_DIS);
106 }
107
108 static SObjectCfg::ObjectCfgId cfgIdIOBindBas()
109 {
110 return CProtoNimblePrph::cfgId(false, SObjectId::DTYPE_ANY, 1, PROTO_NIMBLE_CFG_IOBIND_BAS);
111 }
112
113 static SObjectCfg::ObjectCfgId cfgIdIOBindAios(uint16_t size)
114 {
115 return CProtoNimblePrph::cfgId(false, SObjectId::DTYPE_ANY, size, PROTO_NIMBLE_CFG_IOBIND_AIOS);
116 }
117
118 static SObjectCfg::ObjectCfgId cfgIdIOBindEss(uint16_t size)
119 {
120 return CProtoNimblePrph::cfgId(false, SObjectId::DTYPE_ANY, size, PROTO_NIMBLE_CFG_IOBIND_ESS);
121 }
122
123 static SObjectCfg::ObjectCfgId cfgIdIOBindImds(uint16_t size)
124 {
125 return CProtoNimblePrph::cfgId(false, SObjectId::DTYPE_ANY, size, PROTO_NIMBLE_CFG_IOBIND_IMDS);
126 }
127
128 static SObjectCfg::ObjectCfgId cfgIdIOBindOts(uint16_t size)
129 {
130 return CProtoNimblePrph::cfgId(false, SObjectId::DTYPE_ANY, size, PROTO_NIMBLE_CFG_IOBIND_OTS);
131 }
132
133 static SObjectCfg::ObjectCfgId cfgIdIOBindCustom(uint16_t size)
134 {
135 return CProtoNimblePrph::cfgId(
137 }
138
139private:
140 int devno;
141 char *gapname;
142 std::vector<IProtoNimblePrphService *> vservices;
143 std::vector<struct ble_gatt_svc_def *> vSvcDefs;
144 std::vector<bool> vstart;
145 struct ble_gatt_svc_def *svcDefs;
146 uint8_t noAllocServices;
147 CProtoNimbleAdv adv;
148 CProtoNimbleHci hci;
149 CProtoNimbleHost host;
150
151 int configureDesc(const CDescObject &desc);
152 void servicesDefault();
153 int servicesCreate();
154 int servicesCount();
155 int servicesInit();
156
157 static void bleSyncCb();
158};
159} // Namespace dawn
CIOCommon * getIO(SObjectId::ObjectId id)
Get an I/O object by ID.
Definition bindable.cxx:41
void setObjectMapItem(SObjectId::ObjectId id, CObject *obj)
Set an item in the object map.
Definition bindable.cxx:23
const std::map< SObjectId::ObjectId, CIOCommon * > & getIOMap() const
Get the I/O map for this object.
Definition bindable.cxx:18
Descriptor wrapper for individual object configuration.
Base class for all I/O objects.
Definition common.hxx:27
Base class for all protocol implementations.
Definition common.hxx:23
@ PROTO_CLASS_NIMBLE_PRPH
BLE Peripheral using Apache NimBLE stack.
Definition common.hxx:35
BLE Peripheral (Slave) Protocol Implementation using NimBLE.
Definition prph.hxx:27
int stopService(int id)
Stop a specific service.
Definition prph.cxx:464
int doStart()
Start implementation hook.
Definition prph.cxx:363
@ PROTO_NIMBLE_CFG_IOBIND_CUSTOM
Generic custom service binding.
Definition prph.hxx:39
@ PROTO_NIMBLE_CFG_IOBIND_OTS
Object Transfer Service binding.
Definition prph.hxx:38
@ PROTO_NIMBLE_CFG_IOBIND_ESS
Environmental Sensing Service binding.
Definition prph.hxx:36
@ PROTO_NIMBLE_CFG_IOBIND_AIOS
Automation I/O Service binding.
Definition prph.hxx:35
@ PROTO_NIMBLE_CFG_IOBIND_BAS
Battery Service binding.
Definition prph.hxx:34
@ PROTO_NIMBLE_CFG_IOBIND_DIS
Device Information Service binding.
Definition prph.hxx:33
@ PROTO_NIMBLE_CFG_GAPNAME
GAP device name configuration.
Definition prph.hxx:32
@ PROTO_NIMBLE_CFG_IOBIND_IMDS
Industrial Measurement Device Service binding.
Definition prph.hxx:37
size_t getObjectsLen()
Get count of registered I/O objects.
Definition prph.hxx:81
int startService(int id)
Start a specific service.
Definition prph.cxx:421
CIOCommon * getObject(SObjectId::ObjectId id)
Get protocol object by ID.
Definition prph.hxx:76
int configure()
Configure object from descriptor data.
Definition prph.cxx:304
void regObject(SObjectId::ObjectId id)
Register an I/O object for this service.
Definition prph.hxx:71
int serviceRegister(struct ble_gatt_svc_def *svc)
Register a GATT service with the peripheral.
Definition prph.cxx:401
int deinit()
De-initialize object.
Definition prph.cxx:340
bool hasThread() const
Check if a background thread is active.
Definition prph.cxx:396
int doStop()
Stop implementation hook.
Definition prph.cxx:380
Interface for BLE peripheral services with GATT characteristics.
Definition iprph.hxx:24
static ObjectCfgId objectCfg(uint8_t type, uint16_t cls, uint8_t dtype, bool rw, uint16_t size, uint8_t id)
Construct 32-bit ConfigID from component fields.
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
Definition objectcfg.hxx:60
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
@ OBJTYPE_PROTO
Protocol object type.
Definition objectid.hxx:193
@ DTYPE_ANY
Wildcard data type (matches any actual type).
Definition objectid.hxx:68
@ DTYPE_CHAR
Character/string type (null-terminated, 4-byte aligned).
Definition objectid.hxx:144
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44
static ObjectId objectId(uint8_t type, uint16_t cls, uint8_t dtype, uint8_t flags, uint16_t priv)
Construct 32-bit ObjectID from component fields.
Definition objectid.hxx:290