Dawn Framework 1.0
Universal data acquisition framework for embedded systems
prph_imds.hxx
1// dawn/include/dawn/proto/nimble/prph_imds.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <map>
9
10#include "dawn/porting/config.hxx"
11#include "dawn/proto/nimble/iprph.hxx"
12#include "host/ble_gatt.h"
13
14namespace dawn
15{
16// Forward reference
17
18class CProtoNimblePrph;
19
28{
29public:
30 constexpr static uint8_t IMDS_CFG0_SIZE_SHIFT = 0;
31 constexpr static uint8_t IMDS_CFG0_SIZE_MASK = 0b1111;
32 constexpr static uint8_t IMDS_OBJCFG_TYPE_SHIFT = 0;
33 constexpr static uint8_t IMDS_OBJCFG_TYPE_MASK = 0b1111;
34 constexpr static uint8_t IMDS_EXTCFG_KIND_SHIFT = 0;
35 constexpr static uint8_t IMDS_EXTCFG_KIND_MASK = 0xff;
36 constexpr static uint8_t IMDS_EXTCFG_SIZE_SHIFT = 8;
37 constexpr static uint8_t IMDS_EXTCFG_SIZE_MASK = 0xff;
38 constexpr static uint8_t IMDS_DESC_USER_DESCRIPTION = 1 << 0;
39 constexpr static uint8_t IMDS_USER_DESCRIPTION_MAX = 16;
40
41 constexpr static uint16_t UUID16_CHR_USER_DESCRIPTION = 0x2901;
42
43 enum
44 {
46 };
47
48 enum
49 {
57 };
58
59 struct
60 {
61 uint32_t cfg;
63 uint32_t extCount;
64 } typedef SProtoNimblePrphIOBindImdsObjid;
65
66 struct
67 {
68 uint32_t cfg0;
69 uint32_t cfg1;
70 uint32_t cfg2;
71
72 uint32_t data[];
73 } typedef SProtoNimblePrphIOBindImds;
74
75 CProtoNimblePrphImds(const SObjectCfg::SObjectCfgItem *item, IProtoNimblePrphCb *cb_);
76
77 ~CProtoNimblePrphImds() override;
78
79 int init() override;
80 int deinit() override;
81 int start() override;
82 int stop() override;
83
84 static uint32_t cfgIdIOBindImdsCfgObj(uint8_t type)
85 {
86 return ((type & IMDS_OBJCFG_TYPE_MASK) << IMDS_OBJCFG_TYPE_SHIFT);
87 }
88
89 static uint8_t cfgIdIOBindImdsCfgObjTypeGet(uint32_t val)
90 {
91 return (val >> IMDS_OBJCFG_TYPE_SHIFT) & IMDS_OBJCFG_TYPE_MASK;
92 }
93
94 static uint32_t cfgIdIOBindImdsExt(uint8_t kind, uint8_t size)
95 {
96 return ((kind & IMDS_EXTCFG_KIND_MASK) << IMDS_EXTCFG_KIND_SHIFT) |
97 ((size & IMDS_EXTCFG_SIZE_MASK) << IMDS_EXTCFG_SIZE_SHIFT);
98 }
99
100 static uint8_t cfgIdIOBindImdsExtKindGet(uint32_t val)
101 {
102 return (val >> IMDS_EXTCFG_KIND_SHIFT) & IMDS_EXTCFG_KIND_MASK;
103 }
104
105 static uint8_t cfgIdIOBindImdsExtSizeGet(uint32_t val)
106 {
107 return (val >> IMDS_EXTCFG_SIZE_SHIFT) & IMDS_EXTCFG_SIZE_MASK;
108 }
109
110 static uint32_t cfgIdIOBindImdsCfg0(uint8_t size)
111 {
112 return ((size & IMDS_CFG0_SIZE_MASK) << IMDS_CFG0_SIZE_SHIFT);
113 }
114
115 static uint8_t cfgIdIOBindImdsCfg0SizeGet(uint32_t val)
116 {
117 return (val >> IMDS_CFG0_SIZE_SHIFT) & IMDS_CFG0_SIZE_MASK;
118 }
119
120 static uint32_t cfgIdIOBindImdsCfg1(uint8_t res)
121 {
122 return 0;
123 }
124
125 static uint32_t cfgIdIOBindImdsCfg2(uint8_t res)
126 {
127 return 0;
128 }
129
130private:
131 int id;
132 size_t noChar;
133 bool created;
134 struct ble_gatt_svc_def svc;
135 std::map<const SObjectId::ObjectId, uint8_t>
136 ioTypeMap;
137
138 struct SImdsMeta
139 {
140 uint32_t desc;
141 char userDescription[IMDS_USER_DESCRIPTION_MAX];
142 };
143
144 struct SImdsDscCb
145 {
146 uint8_t kind;
147 uint8_t len;
148 uint8_t data[IMDS_USER_DESCRIPTION_MAX];
149 };
150
151 std::map<const SObjectId::ObjectId, SImdsMeta> ioMetaMap;
152
153#ifdef CONFIG_DAWN_IO_NOTIFY
154 static int notifierCb(void *priv, io_ddata_t *data);
155#endif
156
157 template<typename T, size_t WriteBytes = sizeof(T)>
158 static int callback(uint16_t conn_handle,
159 uint16_t attr_handle,
160 struct ble_gatt_access_ctxt *ctxt,
161 void *arg);
162
163 static int descriptorCb(uint16_t conn_handle,
164 uint16_t attr_handle,
165 struct ble_gatt_access_ctxt *ctxt,
166 void *arg);
167
168 int allocIMDS();
169 int createIMDS();
170 void deleteIMDS();
171 void configureDesc(const SObjectCfg::SObjectCfgItem *item);
172 void allocObject(const SProtoNimblePrphIOBindImdsObjid &obj, const uint32_t *ext);
173 int configureDescriptors(struct ble_gatt_chr_def *chr, SObjectId::ObjectId objid);
174};
175} // Namespace dawn
Industrial Measurement Device Service (IMDS) for BLE Peripheral.
Definition prph_imds.hxx:28
int deinit()
Deinitialize service.
int init()
Initialize service.
int stop()
Stop service.
int start()
Start service.
@ IMDS_EXT_USER_DESCRIPTION
Characteristic User Description descriptor.
Definition prph_imds.hxx:45
@ PRPH_IMDS_TYPE_LIGHT
Industrial illuminance / light sensor.
Definition prph_imds.hxx:56
@ PRPH_IMDS_TYPE_GAS
Industrial gas resistance sensor (non-standard UUID).
Definition prph_imds.hxx:54
@ PRPH_IMDS_TYPE_TEMP
Industrial temperature sensor.
Definition prph_imds.hxx:50
@ PRPH_IMDS_TYPE_UVIDX
Industrial UV index sensor.
Definition prph_imds.hxx:53
@ PRPH_IMDS_TYPE_HUM
Industrial humidity sensor.
Definition prph_imds.hxx:51
@ PRPH_IMDS_TYPE_PRESS
Industrial pressure sensor.
Definition prph_imds.hxx:52
Base interface for GATT services exposed by BLE peripheral.
Definition iprph.hxx:467
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44
32-bit encoded object identifier (union with bit field).
Definition objectid.hxx:218