Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
Revision 135:6cf6e7bd21c9, committed 2014-11-21
- Comitter:
- rgrover1
- Date:
- Fri Nov 21 09:23:23 2014 +0000
- Parent:
- 134:49321f76753e
- Child:
- 136:723d378149be
- Commit message:
- Synchronized with git rev 503f8d52
Author: Rohit Grover
introduce GattServer::initializeGattDatabase()
Changed in this revision
--- a/README.md Fri Nov 21 09:23:23 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -# mbed Bluetooth Low Energy Stack -This is the github repo for the BLE_API used by developer.mbed.org . The BLE stack is under development and constantly evolving. For up to date documentation please see [the mbed BLE Documentation page](http://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/docs/tip/). - -# Supported Services -Supported GATT services and constantly being added and can be found in the /services folder. -Currently supported services include: -* Battery -* Device Firmware Update (DFU) -* Device Information -* Health Thermometer -* Heart Rate -* UART - -# Getting Started -The mbed BLE API is meant to be used in projects on developer.mbed.org. Please see examples and sample project files there. -A good starting point are these pages: -* [mbed BLE API](developer.mbed.org/teams/Bluetooth-Low-Energy/) -* [mbed BLE Getting Started Guide](http://developer.mbed.org/forum/team-63-Bluetooth-Low-Energy-community/topic/5262/) \ No newline at end of file
--- a/common/blecommon.h Fri Nov 21 09:23:23 2014 +0000
+++ b/common/blecommon.h Fri Nov 21 09:23:23 2014 +0000
@@ -27,7 +27,6 @@
#endif
#include <stdint.h>
-#include <stddef.h>
/** @defgroup BLE_UUID_VALUES Assigned Values for BLE UUIDs
* @{ */
--- a/public/BLEDevice.h Fri Nov 21 09:23:23 2014 +0000
+++ b/public/BLEDevice.h Fri Nov 21 09:23:23 2014 +0000
@@ -17,6 +17,7 @@
#ifndef __BLE_DEVICE__
#define __BLE_DEVICE__
+#include "mbed.h"
#include "blecommon.h"
#include "Gap.h"
#include "GattServer.h"
@@ -42,13 +43,13 @@
* Set the BTLE MAC address and type.
* @return BLE_ERROR_NONE on success.
*/
- ble_error_t setAddress(Gap::addr_type_t type, const uint8_t address[Gap::ADDR_LEN]);
+ ble_error_t setAddress(Gap::addr_type_t type, const Gap::address_t address);
/**
* Fetch the BTLE MAC address and type.
* @return BLE_ERROR_NONE on success.
*/
- ble_error_t getAddress(Gap::addr_type_t *typeP, uint8_t address[Gap::ADDR_LEN]);
+ ble_error_t getAddress(Gap::addr_type_t *typeP, Gap::address_t address);
/**
* @param[in] advType
@@ -365,13 +366,13 @@
}
inline ble_error_t
-BLEDevice::setAddress(Gap::addr_type_t type, const uint8_t address[Gap::ADDR_LEN])
+BLEDevice::setAddress(Gap::addr_type_t type, const Gap::address_t address)
{
return transport->getGap().setAddress(type, address);
}
inline ble_error_t
-BLEDevice::getAddress(Gap::addr_type_t *typeP, uint8_t address[Gap::ADDR_LEN])
+BLEDevice::getAddress(Gap::addr_type_t *typeP, Gap::address_t address)
{
return transport->getGap().getAddress(typeP, address);
}
--- a/public/CallChainOfFunctionPointersWithContext.h Fri Nov 21 09:23:23 2014 +0000
+++ b/public/CallChainOfFunctionPointersWithContext.h Fri Nov 21 09:23:23 2014 +0000
@@ -19,6 +19,7 @@
#include <string.h>
#include "FunctionPointerWithContext.h"
+namespace mbed {
/** Group one or more functions in an instance of a CallChainOfFunctionPointersWithContext, then call them in
* sequence using CallChainOfFunctionPointersWithContext::call(). Used mostly by the interrupt chaining code,
@@ -26,6 +27,7 @@
*
* Example:
* @code
+ * #include "mbed.h"
*
* CallChainOfFunctionPointersWithContext<void *> chain;
*
@@ -145,4 +147,6 @@
CallChainOfFunctionPointersWithContext & operator = (const CallChainOfFunctionPointersWithContext &);
};
-#endif
\ No newline at end of file
+} // namespace mbed
+
+#endif
--- a/public/FunctionPointerWithContext.h Fri Nov 21 09:23:23 2014 +0000
+++ b/public/FunctionPointerWithContext.h Fri Nov 21 09:23:23 2014 +0000
@@ -19,6 +19,7 @@
#include <string.h>
+namespace mbed {
/** A class for storing and calling a pointer to a static or member void function
* which takes a context.
@@ -125,5 +126,6 @@
* external memory to manage the chain. Also refer to
* 'CallChain' as an alternative. */
};
+} // namespace mbed
#endif // ifndef MBED_FUNCTIONPOINTER_WITH_CONTEXT_H
\ No newline at end of file
--- a/public/Gap.h Fri Nov 21 09:23:23 2014 +0000
+++ b/public/Gap.h Fri Nov 21 09:23:23 2014 +0000
@@ -17,6 +17,7 @@
#ifndef __GAP_H__
#define __GAP_H__
+#include "mbed.h"
#include "blecommon.h"
#include "GapAdvertisingData.h"
#include "GapAdvertisingParams.h"
@@ -40,6 +41,7 @@
} addr_type_t;
static const unsigned ADDR_LEN = 6;
+ typedef uint8_t address_t[ADDR_LEN];
/**
* enumeration for disconnection reasons. The values for these reasons are
@@ -63,48 +65,55 @@
typedef uint16_t Handle_t;
typedef struct {
- uint16_t minConnectionInterval; /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
- uint16_t maxConnectionInterval; /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
- uint16_t slaveLatency; /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/
- uint16_t connectionSupervisionTimeout; /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/
+ uint16_t minConnectionInterval; /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
+ uint16_t maxConnectionInterval; /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
+ uint16_t slaveLatency; /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/
+ uint16_t connectionSupervisionTimeout; /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/
} ConnectionParams_t;
+ static const uint16_t UNIT_1_25_MS = 1250; /**< Number of microseconds in 1.25 milliseconds. */
+ static uint16_t MSEC_TO_GAP_DURATION_UNITS(uint32_t durationInMillis) {
+ return (durationInMillis * 1000) / UNIT_1_25_MS;
+ }
+
public:
/* These functions must be defined in the sub-class */
- virtual ble_error_t setAddress(addr_type_t type, const uint8_t address[ADDR_LEN]) = 0;
- virtual ble_error_t getAddress(addr_type_t *typeP, uint8_t address[ADDR_LEN]) = 0;
+ virtual ble_error_t setAddress(addr_type_t type, const address_t address) = 0;
+ virtual ble_error_t getAddress(addr_type_t *typeP, address_t address) = 0;
virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &) = 0;
- virtual ble_error_t startAdvertising(const GapAdvertisingParams &) = 0;
- virtual ble_error_t stopAdvertising(void) = 0;
- virtual ble_error_t disconnect(DisconnectionReason_t reason) = 0;
- virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params) = 0;
- virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params) = 0;
- virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params) = 0;
+ virtual ble_error_t startAdvertising(const GapAdvertisingParams &) = 0;
+ virtual ble_error_t stopAdvertising(void) = 0;
+ virtual ble_error_t disconnect(DisconnectionReason_t reason) = 0;
+ virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params) = 0;
+ virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params) = 0;
+ virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params) = 0;
- virtual ble_error_t setDeviceName(const uint8_t *deviceName) = 0;
+ virtual ble_error_t setDeviceName(const uint8_t *deviceName) = 0;
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP) = 0;
- virtual ble_error_t setAppearance(uint16_t appearance) = 0;
- virtual ble_error_t getAppearance(uint16_t *appearanceP) = 0;
+ virtual ble_error_t setAppearance(uint16_t appearance) = 0;
+ virtual ble_error_t getAppearance(uint16_t *appearanceP) = 0;
typedef void (*EventCallback_t)(void);
- typedef void (*ConnectionEventCallback_t)(Handle_t, const ConnectionParams_t *);
+ typedef void (*ConnectionEventCallback_t)(Handle_t, addr_type_t peerAddrType, const address_t peerAddr, const ConnectionParams_t *);
typedef void (*DisconnectionEventCallback_t)(Handle_t, DisconnectionReason_t);
/* Event callback handlers */
void setOnTimeout(EventCallback_t callback) {
onTimeout = callback;
}
+
void setOnConnection(ConnectionEventCallback_t callback) {
onConnection = callback;
}
+
void setOnDisconnection(DisconnectionEventCallback_t callback) {
onDisconnection = callback;
}
- void processConnectionEvent(Handle_t handle, const ConnectionParams_t *params) {
+ void processConnectionEvent(Handle_t handle, addr_type_t type, const address_t addr, const ConnectionParams_t *params) {
state.connected = 1;
if (onConnection) {
- onConnection(handle, params);
+ onConnection(handle, type, addr, params);
}
}
@@ -136,7 +145,7 @@
}
protected:
- GapState_t state;
+ GapState_t state;
private:
EventCallback_t onTimeout;
--- a/public/GapAdvertisingParams.h Fri Nov 21 09:23:23 2014 +0000
+++ b/public/GapAdvertisingParams.h Fri Nov 21 09:23:23 2014 +0000
@@ -19,11 +19,6 @@
#include "blecommon.h"
-#define GAP_ADV_PARAMS_INTERVAL_MIN (0x0020)
-#define GAP_ADV_PARAMS_INTERVAL_MIN_NONCON (0x00A0)
-#define GAP_ADV_PARAMS_INTERVAL_MAX (0x1000)
-#define GAP_ADV_PARAMS_TIMEOUT_MAX (0x3FFF)
-
/**************************************************************************/
/*!
\brief
@@ -50,6 +45,11 @@
class GapAdvertisingParams
{
public:
+ static const unsigned GAP_ADV_PARAMS_INTERVAL_MIN = 0x0020;
+ static const unsigned GAP_ADV_PARAMS_INTERVAL_MIN_NONCON = 0x00A0;
+ static const unsigned GAP_ADV_PARAMS_INTERVAL_MAX = 0x4000;
+ static const unsigned GAP_ADV_PARAMS_TIMEOUT_MAX = 0x3FFF;
+
/**************************************************************************/
/*!
\brief
@@ -70,6 +70,7 @@
ADV_NON_CONNECTABLE_UNDIRECTED /**< Vol 3, Part C, Section 9.3.2 and Vol 6, Part B, Section 2.3.1.3 */
};
+public:
GapAdvertisingParams(AdvertisingType advType = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED,
uint16_t interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON,
uint16_t timeout = 0);
--- a/public/GapEvents.h Fri Nov 21 09:23:23 2014 +0000 +++ b/public/GapEvents.h Fri Nov 21 09:23:23 2014 +0000 @@ -18,6 +18,7 @@ #define __GAP_EVENTS_H__ #include "blecommon.h" +#include "mbed.h" /**************************************************************************/ /*!
--- a/public/GattServer.h Fri Nov 21 09:23:23 2014 +0000
+++ b/public/GattServer.h Fri Nov 21 09:23:23 2014 +0000
@@ -17,7 +17,6 @@
#ifndef __GATT_SERVER_H__
#define __GATT_SERVER_H__
-#include "blecommon.h"
#include "GattService.h"
#include "GattServerEvents.h"
#include "GattCharacteristicWriteCBParams.h"
@@ -37,6 +36,7 @@
virtual ble_error_t addService(GattService &) = 0;
virtual ble_error_t readValue(uint16_t handle, uint8_t buffer[], uint16_t *const lengthP) = 0;
virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false) = 0;
+ virtual ble_error_t initializeGATTDatabase(void) = 0;
// ToDo: For updateValue, check the CCCD to see if the value we are
// updating has the notify or indicate bits sent, and if BOTH are set
@@ -67,6 +67,12 @@
onConfirmationReceived = callback;
}
+protected:
+ GattServer() : serviceCount(0), characteristicCount(0), onDataSent(NULL), onDataWritten(), onUpdatesEnabled(NULL), onUpdatesDisabled(NULL), onConfirmationReceived(NULL) {
+ /* empty */
+ }
+
+protected:
void handleDataWrittenEvent(const GattCharacteristicWriteCBParams *params) {
if (onDataWritten.hasCallbacksAttached()) {
onDataWritten.call(params);
@@ -100,14 +106,8 @@
}
protected:
- GattServer() : serviceCount(0), characteristicCount(0), onDataSent(NULL), onDataWritten(), onUpdatesEnabled(NULL), onUpdatesDisabled(NULL), onConfirmationReceived(NULL) {
- /* empty */
- }
-
-protected:
uint8_t serviceCount;
uint8_t characteristicCount;
- uint8_t descriptorCount;
private:
ServerEventCallbackWithCount_t onDataSent;
--- a/public/GattServerEvents.h Fri Nov 21 09:23:23 2014 +0000 +++ b/public/GattServerEvents.h Fri Nov 21 09:23:23 2014 +0000 @@ -18,6 +18,7 @@ #define __GATT_SERVER_EVENTS_H__ #include "blecommon.h" +#include "mbed.h" /**************************************************************************/ /*!
--- a/services/UARTService.h Fri Nov 21 09:23:23 2014 +0000 +++ b/services/UARTService.h Fri Nov 21 09:23:23 2014 +0000 @@ -17,7 +17,6 @@ #ifndef __BLE_UART_SERVICE_H__ #define __BLE_UART_SERVICE_H__ -#include "mbed.h" #include "Stream.h" #include "UUID.h"
