Skip to content

Commit 42f99e1

Browse files
author
Rohit Grover
committed
Release 0.4.1
============= This is a minor release. Enhancements ~~~~~~~~~~~~ * Introduce API GattServer::areUpdatesEnabled() to determine notification status for a characteristic. This is a follow up from #41. @jeremybrodt did a lovely job submitting that pull request, but there had been too many changes in the neighbouring code recently to merge his work directly. I didn't take the trouble of preserving his submission in the history; my apologies--credit for this API goes entirely to him. * Replace DiscoveredCharacteristic::setupOnDataRead() with GattClient::onDataRead(). * Move GATT_MTU_SIZE_DEFAULT into blecommon.h as BLE_GATT_MTU_SIZE_DEFAULT. * Replace uses of the deprecated updateCharacteristicValue() with ble.gattServer().write(). * Change access levels to protected for various members of the standard services. * Update LinkLossService with a recent change to the definition of GattWriteCallbackParams. Involved renaming member charHandle to handle. Bugfixes ~~~~~~~~ * None.
2 parents d80fec8 + 4ac9700 commit 42f99e1

13 files changed

+127
-75
lines changed

ble/DiscoveredCharacteristic.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,6 @@ class DiscoveredCharacteristic {
135135
*/
136136
ble_error_t write(uint16_t length, const uint8_t *value) const;
137137

138-
static void setupOnDataRead(GattClient::ReadCallback_t callback) {
139-
onDataReadCallback = callback;
140-
}
141-
142-
static void setupOnDataWrite(GattClient::WriteCallback_t callback) {
143-
onDataWriteCallback = callback;
144-
}
145-
146138
void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
147139
uuid.setupLong(longUUID);
148140
}
@@ -182,10 +174,6 @@ class DiscoveredCharacteristic {
182174
GattAttribute::Handle_t valueHandle;
183175

184176
Gap::Handle_t connHandle;
185-
186-
public:
187-
static GattClient::ReadCallback_t onDataReadCallback;
188-
static GattClient::WriteCallback_t onDataWriteCallback;
189177
};
190178

191179
#endif /*__DISCOVERED_CHARACTERISTIC_H__*/

ble/Gap.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class Gap {
154154
* @return BLE_ERROR_NONE on success.
155155
*/
156156
virtual ble_error_t setAddress(AddressType_t type, const Address_t address) {
157-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
157+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
158158
}
159159

160160
/**
@@ -163,7 +163,7 @@ class Gap {
163163
* @return BLE_ERROR_NONE on success.
164164
*/
165165
virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address) {
166-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
166+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
167167
}
168168

169169
/**
@@ -188,7 +188,7 @@ class Gap {
188188
}
189189

190190
virtual ble_error_t stopAdvertising(void) {
191-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
191+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
192192
}
193193

194194
/**
@@ -197,7 +197,7 @@ class Gap {
197197
* @retval BLE_ERROR_NONE if successfully stopped scanning procedure.
198198
*/
199199
virtual ble_error_t stopScan() {
200-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
200+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
201201
}
202202

203203
/**
@@ -219,7 +219,7 @@ class Gap {
219219
Gap::AddressType_t peerAddrType,
220220
const ConnectionParams_t *connectionParams,
221221
const GapScanningParams *scanParams) {
222-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
222+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
223223
}
224224

225225
/**
@@ -231,7 +231,7 @@ class Gap {
231231
* The reason for disconnection to be sent back to the peer.
232232
*/
233233
virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason) {
234-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
234+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
235235
}
236236

237237
/**
@@ -248,7 +248,7 @@ class Gap {
248248
* altertive which takes a connection handle. It will be dropped in the future.
249249
*/
250250
virtual ble_error_t disconnect(DisconnectionReason_t reason) {
251-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
251+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
252252
}
253253

254254
/**
@@ -264,7 +264,7 @@ class Gap {
264264
* the given structure pointed to by params.
265265
*/
266266
virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params) {
267-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
267+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
268268
}
269269

270270
/**
@@ -276,7 +276,7 @@ class Gap {
276276
* The structure containing the desired parameters.
277277
*/
278278
virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params) {
279-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
279+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
280280
}
281281

282282
/**
@@ -290,7 +290,7 @@ class Gap {
290290
* the parameters in the PPCP characteristic of the GAP service will be used instead.
291291
*/
292292
virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params) {
293-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
293+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
294294
}
295295

296296
/**
@@ -299,7 +299,7 @@ class Gap {
299299
* The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string.
300300
*/
301301
virtual ble_error_t setDeviceName(const uint8_t *deviceName) {
302-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
302+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
303303
}
304304

305305
/**
@@ -321,7 +321,7 @@ class Gap {
321321
* use this information to retry with a suitable buffer size.
322322
*/
323323
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP) {
324-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
324+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
325325
}
326326

327327
/**
@@ -330,7 +330,7 @@ class Gap {
330330
* The new value for the device-appearance.
331331
*/
332332
virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance) {
333-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
333+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
334334
}
335335

336336
/**
@@ -339,15 +339,15 @@ class Gap {
339339
* The new value for the device-appearance.
340340
*/
341341
virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP) {
342-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
342+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
343343
}
344344

345345
/**
346346
* Set the radio's transmit power.
347347
* @param[in] txPower Radio transmit power in dBm.
348348
*/
349349
virtual ble_error_t setTxPower(int8_t txPower) {
350-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
350+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
351351
}
352352

353353
/**
@@ -365,7 +365,7 @@ class Gap {
365365
protected:
366366
/* Override the following in the underlying adaptation layer to provide the functionality of scanning. */
367367
virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) {
368-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
368+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
369369
}
370370

371371
/*

ble/GattClient.h

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class GattClient {
2828
typedef void (*ReadCallback_t)(const GattReadCallbackParams *params);
2929

3030
enum WriteOp_t {
31-
GATT_OP_WRITE_REQ = 0x01, /**< Write Request. */
32-
GATT_OP_WRITE_CMD = 0x02, /**< Write Command. */
31+
GATT_OP_WRITE_REQ = 0x01, /**< Write Request. */
32+
GATT_OP_WRITE_CMD = 0x02, /**< Write Command. */
3333
};
3434

3535
typedef void (*WriteCallback_t)(const GattWriteCallbackParams *params);
@@ -39,12 +39,11 @@ class GattClient {
3939
*/
4040
public:
4141
/**
42-
* Launch service discovery. Once launched, service discovery will remain
43-
* active with callbacks being issued back into the application for matching
44-
* services/characteristics. isServiceDiscoveryActive() can be used to
45-
* determine status; and a termination callback (if setup) will be invoked
46-
* at the end. Service discovery can be terminated prematurely if needed
47-
* using terminateServiceDiscovery().
42+
* Launch service discovery. Once launched, application callbacks will be
43+
* invoked for matching services/characteristics. isServiceDiscoveryActive()
44+
* can be used to determine status; and a termination callback (if setup)
45+
* will be invoked at the end. Service discovery can be terminated prematurely
46+
* if needed using terminateServiceDiscovery().
4847
*
4948
* @param connectionHandle
5049
* Handle for the connection with the peer.
@@ -98,7 +97,7 @@ class GattClient {
9897
ServiceDiscovery::CharacteristicCallback_t cc = NULL,
9998
const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
10099
const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) {
101-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
100+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
102101
}
103102

104103
/**
@@ -130,7 +129,7 @@ class GattClient {
130129
virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle,
131130
ServiceDiscovery::ServiceCallback_t callback,
132131
const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) {
133-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
132+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
134133
}
135134

136135
/**
@@ -161,7 +160,7 @@ class GattClient {
161160
ServiceDiscovery::ServiceCallback_t callback,
162161
GattAttribute::Handle_t startHandle,
163162
GattAttribute::Handle_t endHandle) {
164-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
163+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
165164
}
166165

167166
/**
@@ -181,7 +180,7 @@ class GattClient {
181180

182181
/* Initiate a Gatt Client read procedure by attribute-handle. */
183182
virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const {
184-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
183+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
185184
}
186185

187186
/**
@@ -205,7 +204,24 @@ class GattClient {
205204
GattAttribute::Handle_t attributeHandle,
206205
size_t length,
207206
const uint8_t *value) const {
208-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
207+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
208+
}
209+
210+
/* Event callback handlers. */
211+
public:
212+
/**
213+
* Setup a callback for read response events.
214+
*/
215+
void onDataRead(ReadCallback_t callback) {
216+
onDataReadCallback = callback;
217+
}
218+
219+
/**
220+
* Setup a callback for write response events.
221+
* @Note: write commands (issued using writeWoResponse) don't generate a response.
222+
*/
223+
void onDataWrite(WriteCallback_t callback) {
224+
onDataWriteCallback = callback;
209225
}
210226

211227
/**
@@ -220,6 +236,24 @@ class GattClient {
220236
/* empty */
221237
}
222238

239+
/* Entry points for the underlying stack to report events back to the user. */
240+
public:
241+
void processReadResponse(const GattReadCallbackParams *params) {
242+
if (onDataReadCallback) {
243+
onDataReadCallback(params);
244+
}
245+
}
246+
247+
void processWriteResponse(const GattWriteCallbackParams *params) {
248+
if (onDataWriteCallback) {
249+
onDataWriteCallback(params);
250+
}
251+
}
252+
253+
protected:
254+
ReadCallback_t onDataReadCallback;
255+
WriteCallback_t onDataWriteCallback;
256+
223257
private:
224258
/* disallow copy and assignment */
225259
GattClient(const GattClient &);

ble/GattServer.h

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class GattServer {
5353
* characteristics contained within.
5454
*/
5555
virtual ble_error_t addService(GattService &) {
56-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
56+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
5757
}
5858

5959
/**
@@ -72,7 +72,7 @@ class GattServer {
7272
* @return BLE_ERROR_NONE if a value was read successfully into the buffer.
7373
*/
7474
virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP) {
75-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
75+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
7676
}
7777

7878
/**
@@ -97,7 +97,7 @@ class GattServer {
9797
* attribtues (such as the CCCDs).
9898
*/
9999
virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP) {
100-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
100+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
101101
}
102102

103103
/**
@@ -119,7 +119,7 @@ class GattServer {
119119
* @return BLE_ERROR_NONE if we have successfully set the value of the attribute.
120120
*/
121121
virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t *, uint16_t, bool localOnly = false) {
122-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
122+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
123123
}
124124

125125
/**
@@ -145,7 +145,38 @@ class GattServer {
145145
* @return BLE_ERROR_NONE if we have successfully set the value of the attribute.
146146
*/
147147
virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t *, uint16_t, bool localOnly = false) {
148-
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
148+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
149+
}
150+
151+
/**
152+
* Determine the updates-enabled status (notification/indication) for the current connection from a characteristic's CCCD.
153+
*
154+
* @param characteristic
155+
* The characteristic
156+
* @param[out] enabledP
157+
* Upon return, *enabledP is true if updates are enabled, else false.
158+
*
159+
* @return BLE_ERROR_NONE if the connection and handle are found. false otherwise.
160+
*/
161+
virtual ble_error_t areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP) {
162+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
163+
}
164+
165+
/**
166+
* Determine the connection-specific updates-enabled status (notification/indication) from a characteristic's CCCD.
167+
*
168+
* @param connectionHandle
169+
* The connection handle
170+
* @param[out] enabledP
171+
* Upon return, *enabledP is true if updates are enabled, else false.
172+
*
173+
* @param characteristic
174+
* The characteristic
175+
*
176+
* @return BLE_ERROR_NONE if the connection and handle are found. false otherwise.
177+
*/
178+
virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP) {
179+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
149180
}
150181

151182
/**
@@ -267,21 +298,21 @@ class GattServer {
267298
}
268299
}
269300

270-
void handleEvent(GattServerEvents::gattEvent_e type, GattAttribute::Handle_t charHandle) {
301+
void handleEvent(GattServerEvents::gattEvent_e type, GattAttribute::Handle_t attributeHandle) {
271302
switch (type) {
272303
case GattServerEvents::GATT_EVENT_UPDATES_ENABLED:
273304
if (updatesEnabledCallback) {
274-
updatesEnabledCallback(charHandle);
305+
updatesEnabledCallback(attributeHandle);
275306
}
276307
break;
277308
case GattServerEvents::GATT_EVENT_UPDATES_DISABLED:
278309
if (updatesDisabledCallback) {
279-
updatesDisabledCallback(charHandle);
310+
updatesDisabledCallback(attributeHandle);
280311
}
281312
break;
282313
case GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED:
283314
if (confirmationReceivedCallback) {
284-
confirmationReceivedCallback(charHandle);
315+
confirmationReceivedCallback(attributeHandle);
285316
}
286317
break;
287318
default:

ble/blecommon.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ enum ble_error_t {
126126
BLE_ERROR_UNSPECIFIED = 9, /**< Unknown error. */
127127
};
128128

129+
/** @brief Default MTU size. */
130+
static const unsigned BLE_GATT_MTU_SIZE_DEFAULT = 23;
131+
129132
#ifdef __cplusplus
130133
}
131134
#endif

0 commit comments

Comments
 (0)