Skip to content

Commit c8eccb0

Browse files
author
Rohit Grover
committed
Release 0.1.0
============= Mostly API changes. Features ~~~~~~~~ - onConnection() callback now receives connection-parameters applicable to the new connection. - onDataSent() callback now receives a count parameter containing the number of times notifications were sent out since the last callback. - A 'reason' parameter has been added to Gap::disconnect() to indicate the reason for disconnection; and also to the onDisconnection callback to receive a reason from the remote host. Bugfixes ~~~~~~~~ - onDataWritten() callback now receives an additional parameter (GattServer::WriteEventCallback_t) encapsulating the update. This avoids having to re-fetch the updated characteristic's value attribute. It also fixes a bug where multiple updates to the characteristic's value-attribute could get clobbered if they occurred in quick succession before the callbacks could be processed.
1 parent 0cb7eb3 commit c8eccb0

File tree

9 files changed

+120
-171
lines changed

9 files changed

+120
-171
lines changed

common/UUID.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
@endcode
6565
*/
6666
/**************************************************************************/
67-
UUID::UUID(const LongUUID_t longUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(0)
67+
UUID::UUID(const LongUUIDBytes_t longUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(0)
6868
{
6969
memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID);
7070
shortUUID = (uint16_t)((longUUID[2] << 8) | (longUUID[3]));
@@ -98,7 +98,7 @@ UUID::UUID(const LongUUID_t longUUID) : type(UUID_TYPE_SHORT), baseUUID(), short
9898
The 16-bit BLE UUID value.
9999
*/
100100
/**************************************************************************/
101-
UUID::UUID(ShortUUID_t shortUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(shortUUID)
101+
UUID::UUID(ShortUUIDBytes_t shortUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(shortUUID)
102102
{
103103
/* empty */
104104
}

public/BLEDevice.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,27 +194,27 @@ class BLEDevice
194194
*/
195195
ble_error_t stopAdvertising(void);
196196

197-
ble_error_t disconnect(void);
197+
ble_error_t disconnect(Gap::DisconnectionReason_t reason);
198198

199199
/* APIs to set GAP callbacks. */
200200
void onTimeout(Gap::EventCallback_t timeoutCallback);
201201

202-
void onConnection(Gap::HandleSpecificEventCallback_t connectionCallback);
202+
void onConnection(Gap::ConnectionEventCallback_t connectionCallback);
203203
/**
204204
* Used to setup a callback for GAP disconnection.
205205
*/
206-
void onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback);
206+
void onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback);
207207

208208
/**
209209
* Setup a callback for the GATT event DATA_SENT.
210210
*/
211-
void onDataSent(GattServer::ServerEventCallback_t callback);
211+
void onDataSent(GattServer::ServerEventCallbackWithCount_t callback);
212212

213213
/**
214214
* Setup a callback for when a characteristic has its value updated by a
215215
* client.
216216
*/
217-
void onDataWritten(GattServer::EventCallback_t callback);
217+
void onDataWritten(GattServer::WriteEventCallback_t callback);
218218
void onUpdatesEnabled(GattServer::EventCallback_t callback);
219219
void onUpdatesDisabled(GattServer::EventCallback_t callback);
220220
void onConfirmationReceived(GattServer::EventCallback_t callback);
@@ -443,9 +443,9 @@ BLEDevice::stopAdvertising(void)
443443
}
444444

445445
inline ble_error_t
446-
BLEDevice::disconnect(void)
446+
BLEDevice::disconnect(Gap::DisconnectionReason_t reason)
447447
{
448-
return transport->getGap().disconnect();
448+
return transport->getGap().disconnect(reason);
449449
}
450450

451451
inline void
@@ -455,25 +455,25 @@ BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback)
455455
}
456456

457457
inline void
458-
BLEDevice::onConnection(Gap::HandleSpecificEventCallback_t connectionCallback)
458+
BLEDevice::onConnection(Gap::ConnectionEventCallback_t connectionCallback)
459459
{
460460
transport->getGap().setOnConnection(connectionCallback);
461461
}
462462

463463
inline void
464-
BLEDevice::onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback)
464+
BLEDevice::onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback)
465465
{
466466
transport->getGap().setOnDisconnection(disconnectionCallback);
467467
}
468468

469469
inline void
470-
BLEDevice::onDataSent(GattServer::ServerEventCallback_t callback)
470+
BLEDevice::onDataSent(GattServer::ServerEventCallbackWithCount_t callback)
471471
{
472472
transport->getGattServer().setOnDataSent(callback);
473473
}
474474

475475
inline void
476-
BLEDevice::onDataWritten(GattServer::EventCallback_t callback)
476+
BLEDevice::onDataWritten(GattServer::WriteEventCallback_t callback)
477477
{
478478
transport->getGattServer().setOnDataWritten(callback);
479479
}
@@ -551,25 +551,25 @@ BLEDevice::getVersion(void)
551551
inline ble_error_t
552552
BLEDevice::setDeviceName(const uint8_t *deviceName)
553553
{
554-
return transport->getGattServer().setDeviceName(deviceName);
554+
return transport->getGap().setDeviceName(deviceName);
555555
}
556556

557557
inline ble_error_t
558558
BLEDevice::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
559559
{
560-
return transport->getGattServer().getDeviceName(deviceName, lengthP);
560+
return transport->getGap().getDeviceName(deviceName, lengthP);
561561
}
562562

563563
inline ble_error_t
564564
BLEDevice::setAppearance(uint16_t appearance)
565565
{
566-
return transport->getGattServer().setAppearance(appearance);
566+
return transport->getGap().setAppearance(appearance);
567567
}
568568

569569
inline ble_error_t
570570
BLEDevice::getAppearance(uint16_t *appearanceP)
571571
{
572-
return transport->getGattServer().getAppearance(appearanceP);
572+
return transport->getGap().getAppearance(appearanceP);
573573
}
574574

575575
inline ble_error_t

public/Gap.h

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ class Gap
4040
ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE
4141
} addr_type_t;
4242

43+
enum DisconnectionReason_t {
44+
REMOTE_USER_TERMINATED_CONNECTION,
45+
CONN_INTERVAL_UNACCEPTABLE,
46+
LOCAL_HOST_TERMINATED_CONNECTION,
47+
};
48+
4349
/* Describes the current state of the device (more than one bit can be set) */
4450
typedef struct GapState_s {
4551
unsigned advertising : 1; /**< peripheral is currently advertising */
@@ -61,39 +67,42 @@ class Gap
6167
virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &) = 0;
6268
virtual ble_error_t startAdvertising(const GapAdvertisingParams &) = 0;
6369
virtual ble_error_t stopAdvertising(void) = 0;
64-
virtual ble_error_t disconnect(void) = 0;
70+
virtual ble_error_t disconnect(DisconnectionReason_t reason) = 0;
6571
virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params) = 0;
6672
virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params) = 0;
6773
virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params) = 0;
6874

75+
virtual ble_error_t setDeviceName(const uint8_t *deviceName) = 0;
76+
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP) = 0;
77+
virtual ble_error_t setAppearance(uint16_t appearance) = 0;
78+
virtual ble_error_t getAppearance(uint16_t *appearanceP) = 0;
79+
6980
typedef void (*EventCallback_t)(void);
70-
typedef void (*HandleSpecificEventCallback_t)(Handle_t);
81+
typedef void (*ConnectionEventCallback_t)(Handle_t, const ConnectionParams_t *);
82+
typedef void (*DisconnectionEventCallback_t)(Handle_t, DisconnectionReason_t);
7183

7284
/* Event callback handlers */
7385
void setOnTimeout(EventCallback_t callback) {
7486
onTimeout = callback;
7587
}
76-
void setOnConnection(HandleSpecificEventCallback_t callback) {
88+
void setOnConnection(ConnectionEventCallback_t callback) {
7789
onConnection = callback;
7890
}
79-
void setOnDisconnection(HandleSpecificEventCallback_t callback) {
91+
void setOnDisconnection(DisconnectionEventCallback_t callback) {
8092
onDisconnection = callback;
8193
}
8294

83-
void processHandleSpecificEvent(GapEvents::gapEvent_e type, Handle_t handle) {
84-
switch (type) {
85-
case GapEvents::GAP_EVENT_CONNECTED:
86-
state.connected = 1;
87-
if (onConnection) {
88-
onConnection(handle);
89-
}
90-
break;
91-
case GapEvents::GAP_EVENT_DISCONNECTED:
92-
state.connected = 0;
93-
if (onDisconnection) {
94-
onDisconnection(handle);
95-
}
96-
break;
95+
void processConnectionEvent(Handle_t handle, const ConnectionParams_t *params) {
96+
state.connected = 1;
97+
if (onConnection) {
98+
onConnection(handle, params);
99+
}
100+
}
101+
102+
void processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason) {
103+
state.connected = 0;
104+
if (onDisconnection) {
105+
onDisconnection(handle, reason);
97106
}
98107
}
99108

@@ -121,9 +130,9 @@ class Gap
121130
GapState_t state;
122131

123132
private:
124-
EventCallback_t onTimeout;
125-
HandleSpecificEventCallback_t onConnection;
126-
HandleSpecificEventCallback_t onDisconnection;
133+
EventCallback_t onTimeout;
134+
ConnectionEventCallback_t onConnection;
135+
DisconnectionEventCallback_t onDisconnection;
127136
};
128137

129138
#endif // ifndef __GAP_H__

public/GapAdvertisingParams.h

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,15 @@ class GapAdvertisingParams
6363
\li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 9.3
6464
*/
6565
/**************************************************************************/
66-
enum AdvertisingType
67-
{
68-
ADV_CONNECTABLE_UNDIRECTED, /**< Vol 3, Part C, Section 9.3.4 and
69-
*Vol 6, Part B, Section 2.3.1.1 */
70-
ADV_CONNECTABLE_DIRECTED, /**< Vol 3, Part C, Section 9.3.3 and
71-
*Vol 6, Part B, Section 2.3.1.2 */
72-
ADV_SCANNABLE_UNDIRECTED, /**< Include support for Scan Response
73-
*payloads, see Vol 6, Part B, Section
74-
*2.3.1.4 */
75-
ADV_NON_CONNECTABLE_UNDIRECTED /**< Vol 3, Part C, Section 9.3.2 and
76-
*Vol 6, Part B, Section 2.3.1.3 */
66+
enum AdvertisingType {
67+
ADV_CONNECTABLE_UNDIRECTED, /**< Vol 3, Part C, Section 9.3.4 and Vol 6, Part B, Section 2.3.1.1 */
68+
ADV_CONNECTABLE_DIRECTED, /**< Vol 3, Part C, Section 9.3.3 and Vol 6, Part B, Section 2.3.1.2 */
69+
ADV_SCANNABLE_UNDIRECTED, /**< Include support for Scan Response payloads, see Vol 6, Part B, Section 2.3.1.4 */
70+
ADV_NON_CONNECTABLE_UNDIRECTED /**< Vol 3, Part C, Section 9.3.2 and Vol 6, Part B, Section 2.3.1.3 */
7771
};
7872

79-
GapAdvertisingParams(AdvertisingType advType =
80-
GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED,
81-
uint16_t interval =
82-
GAP_ADV_PARAMS_INTERVAL_MIN_NONCON,
73+
GapAdvertisingParams(AdvertisingType advType = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED,
74+
uint16_t interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON,
8375
uint16_t timeout = 0);
8476
virtual ~GapAdvertisingParams(void);
8577

@@ -146,5 +138,4 @@ GapAdvertisingParams::getTimeout(void) const
146138
return _timeout;
147139
}
148140

149-
150141
#endif // ifndef __GAP_ADVERTISING_PARAMS_H__

public/GapEvents.h

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,10 @@ class GapEvents
3838
*/
3939
/******************************************************************/
4040
typedef enum gapEvent_e {
41-
GAP_EVENT_TIMEOUT = 1, /**< Advertising timed out
42-
*before a connection was
43-
*established */
44-
GAP_EVENT_CONNECTED = 2, /**< A connection was
45-
*established with a
46-
*central device */
47-
GAP_EVENT_DISCONNECTED = 3 /**< A connection was
48-
*closed or lost with a
49-
*central device */
41+
GAP_EVENT_TIMEOUT = 1, /**< Advertising timed out before a connection was established */
42+
GAP_EVENT_CONNECTED = 2, /**< A connection was established with a central device */
43+
GAP_EVENT_DISCONNECTED = 3 /**< A connection was closed or lost with a central device */
5044
} gapEvent_t;
51-
52-
/******************************************************************/
53-
/*!
54-
\brief
55-
Advertising timed out before a connection was established
56-
*/
57-
/******************************************************************/
58-
virtual void onTimeout(void) {
59-
}
60-
61-
/******************************************************************/
62-
/*!
63-
\brief
64-
A connection was established with a central device
65-
*/
66-
/******************************************************************/
67-
virtual void onConnected(void) {
68-
}
69-
70-
/******************************************************************/
71-
/*!
72-
\brief
73-
A connection was closed or lost with a central device
74-
*/
75-
/******************************************************************/
76-
virtual void onDisconnected(void) {
77-
}
7845
};
7946

8047
#endif // ifndef __GAP_EVENTS_H__
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2013 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef __GATT_CHARACTERISTIC_WRITE_CB_PARAMS_H__
18+
#define __GATT_CHARACTERISTIC_WRITE_CB_PARAMS_H__
19+
20+
struct GattCharacteristicWriteCBParams {
21+
enum Type {
22+
GATTS_CHAR_OP_INVALID = 0x00, /**< Invalid Operation. */
23+
GATTS_CHAR_OP_WRITE_REQ = 0x01, /**< Write Request. */
24+
GATTS_CHAR_OP_WRITE_CMD = 0x02, /**< Write Command. */
25+
GATTS_CHAR_OP_SIGN_WRITE_CMD = 0x03, /**< Signed Write Command. */
26+
GATTS_CHAR_OP_PREP_WRITE_REQ = 0x04, /**< Prepare Write Request. */
27+
GATTS_CHAR_OP_EXEC_WRITE_REQ_CANCEL = 0x05, /**< Execute Write Request: Cancel all prepared writes. */
28+
GATTS_CHAR_OP_EXEC_WRITE_REQ_NOW = 0x06, /**< Execute Write Request: Immediately execute all prepared writes. */
29+
} op; /**< Type of write operation, */
30+
uint16_t offset; /**< Offset for the write operation. */
31+
uint16_t len; /**< Length of the incoming data. */
32+
const uint8_t *data; /**< Incoming data, variable length. */
33+
};
34+
35+
#endif /*__GATT_CHARACTERISTIC_WRITE_CB_PARAMS_H__*/

0 commit comments

Comments
 (0)