High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
Revision 134:49321f76753e, committed 2014-11-21
- Comitter:
- rgrover1
- Date:
- Fri Nov 21 09:23:23 2014 +0000
- Parent:
- 133:1f1d7324f5be
- Child:
- 135:6cf6e7bd21c9
- Commit message:
- Synchronized with git rev 814fa470
Author: Yihui Xiong
Update UARTService.h
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Fri Nov 21 09:23:23 2014 +0000 @@ -0,0 +1,18 @@ +# 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,6 +27,7 @@ #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,7 +17,6 @@ #ifndef __BLE_DEVICE__ #define __BLE_DEVICE__ -#include "mbed.h" #include "blecommon.h" #include "Gap.h" #include "GattServer.h" @@ -43,13 +42,13 @@ * Set the BTLE MAC address and type. * @return BLE_ERROR_NONE on success. */ - ble_error_t setAddress(Gap::addr_type_t type, const Gap::address_t address); + ble_error_t setAddress(Gap::addr_type_t type, const uint8_t address[Gap::ADDR_LEN]); /** * Fetch the BTLE MAC address and type. * @return BLE_ERROR_NONE on success. */ - ble_error_t getAddress(Gap::addr_type_t *typeP, Gap::address_t address); + ble_error_t getAddress(Gap::addr_type_t *typeP, uint8_t address[Gap::ADDR_LEN]); /** * @param[in] advType @@ -366,13 +365,13 @@ } inline ble_error_t -BLEDevice::setAddress(Gap::addr_type_t type, const Gap::address_t address) +BLEDevice::setAddress(Gap::addr_type_t type, const uint8_t address[Gap::ADDR_LEN]) { return transport->getGap().setAddress(type, address); } inline ble_error_t -BLEDevice::getAddress(Gap::addr_type_t *typeP, Gap::address_t address) +BLEDevice::getAddress(Gap::addr_type_t *typeP, uint8_t address[Gap::ADDR_LEN]) { 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,7 +19,6 @@ #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, @@ -27,7 +26,6 @@ * * Example: * @code - * #include "mbed.h" * * CallChainOfFunctionPointersWithContext<void *> chain; * @@ -147,6 +145,4 @@ CallChainOfFunctionPointersWithContext & operator = (const CallChainOfFunctionPointersWithContext &); }; -} // namespace mbed - -#endif +#endif \ No newline at end of file
--- 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,7 +19,6 @@ #include <string.h> -namespace mbed { /** A class for storing and calling a pointer to a static or member void function * which takes a context. @@ -126,6 +125,5 @@ * 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,7 +17,6 @@ #ifndef __GAP_H__ #define __GAP_H__ -#include "mbed.h" #include "blecommon.h" #include "GapAdvertisingData.h" #include "GapAdvertisingParams.h" @@ -41,7 +40,6 @@ } 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 @@ -65,55 +63,48 @@ 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 address_t address) = 0; - virtual ble_error_t getAddress(addr_type_t *typeP, address_t address) = 0; + 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 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, addr_type_t peerAddrType, const address_t peerAddr, const ConnectionParams_t *); + typedef void (*ConnectionEventCallback_t)(Handle_t, 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, addr_type_t type, const address_t addr, const ConnectionParams_t *params) { + void processConnectionEvent(Handle_t handle, const ConnectionParams_t *params) { state.connected = 1; if (onConnection) { - onConnection(handle, type, addr, params); + onConnection(handle, params); } } @@ -145,7 +136,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,6 +19,11 @@ #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 @@ -45,11 +50,6 @@ 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,7 +70,6 @@ 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,7 +18,6 @@ #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,6 +17,7 @@ #ifndef __GATT_SERVER_H__ #define __GATT_SERVER_H__ +#include "blecommon.h" #include "GattService.h" #include "GattServerEvents.h" #include "GattCharacteristicWriteCBParams.h" @@ -66,12 +67,6 @@ 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); @@ -105,8 +100,14 @@ } 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,7 +18,6 @@ #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,6 +17,7 @@ #ifndef __BLE_UART_SERVICE_H__ #define __BLE_UART_SERVICE_H__ +#include "mbed.h" #include "Stream.h" #include "UUID.h" @@ -200,4 +201,3 @@ }; #endif /* #ifndef __BLE_UART_SERVICE_H__*/ -