BLE_API_Tiny_BLE
Fork of BLE_API by
public/GattAttribute.h@118:620d28e7a1ba, 2014-09-22 (annotated)
- Committer:
- Rohit Grover
- Date:
- Mon Sep 22 10:59:09 2014 +0100
- Revision:
- 118:620d28e7a1ba
- Parent:
- 112:64c88ad45610
- Child:
- 137:4b648181ea6b
Release 0.2.0
=============
Highlights:
Introducing standard services to simplify applications.
Add support for over-the-air firmware updates.
Features
~~~~~~~~
- This release introduces 'templates' for common services such as heart-rate,
battery-level, device-info, UART, device-firmware-update etc. These services
take the shape of class declarations within header files aggregated under a
new folder called 'services/'. These service-classes provide a high-level
API hopefully easing the burden of developing BLE applications. The
underlying APIs to work with characteristics and services are still
available to allow greater control if needed. We expect to grow the
supported services to include all SIG defined BLE profiles.
- WriteCallbackParams now includes the characteristic's value-attribute
handle; this changes the signature of onDataWritten().
- BLEDevice::onDataWritten() now allows chaining of callbacks--this means that
it is possible to chain together multiple onDataWritten callbacks
(potentially from different modules of an application) to receive updates to
characteristics. Many services, such as DFU and UART add their own
onDataWritten callbacks behind the scenes to trap interesting events. It is
also possible to chain callbacks to functions within objects.
- Added the following expectation for GattCharacteristic: If valuePtr ==
NULL, initialLength == 0, and properties == READ for the value attribute of
a characteristic, then that particular characteristic may be considered
optional and dropped while instantiating the service with the underlying BLE
stack.
- Introducing the typedef GattAttribute::Handle_t to capture Attribute handles.
Bugfixes
~~~~~~~~
None.
Compatibility
~~~~~~~~~~~~~
The signature of onDataWritten() has seen a change; so application programs
using this new version of the BLE API will need minor modifications. Please
refer to sample programs under BLE team page.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
carlescufi | 112:64c88ad45610 | 1 | /* mbed Microcontroller Library |
carlescufi | 112:64c88ad45610 | 2 | * Copyright (c) 2006-2013 ARM Limited |
carlescufi | 112:64c88ad45610 | 3 | * |
carlescufi | 112:64c88ad45610 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
carlescufi | 112:64c88ad45610 | 5 | * you may not use this file except in compliance with the License. |
carlescufi | 112:64c88ad45610 | 6 | * You may obtain a copy of the License at |
carlescufi | 112:64c88ad45610 | 7 | * |
carlescufi | 112:64c88ad45610 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
carlescufi | 112:64c88ad45610 | 9 | * |
carlescufi | 112:64c88ad45610 | 10 | * Unless required by applicable law or agreed to in writing, software |
carlescufi | 112:64c88ad45610 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
carlescufi | 112:64c88ad45610 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
carlescufi | 112:64c88ad45610 | 13 | * See the License for the specific language governing permissions and |
carlescufi | 112:64c88ad45610 | 14 | * limitations under the License. |
carlescufi | 112:64c88ad45610 | 15 | */ |
carlescufi | 112:64c88ad45610 | 16 | |
carlescufi | 112:64c88ad45610 | 17 | |
carlescufi | 112:64c88ad45610 | 18 | #ifndef __GATT_ATTRIBUTE_H__ |
carlescufi | 112:64c88ad45610 | 19 | #define __GATT_ATTRIBUTE_H__ |
carlescufi | 112:64c88ad45610 | 20 | |
carlescufi | 112:64c88ad45610 | 21 | #include "blecommon.h" |
carlescufi | 112:64c88ad45610 | 22 | #include "UUID.h" |
carlescufi | 112:64c88ad45610 | 23 | |
carlescufi | 112:64c88ad45610 | 24 | /**************************************************************************/ |
carlescufi | 112:64c88ad45610 | 25 | /*! |
carlescufi | 112:64c88ad45610 | 26 | \brief GATT attribute |
carlescufi | 112:64c88ad45610 | 27 | */ |
carlescufi | 112:64c88ad45610 | 28 | /**************************************************************************/ |
carlescufi | 112:64c88ad45610 | 29 | class GattAttribute |
carlescufi | 112:64c88ad45610 | 30 | { |
carlescufi | 112:64c88ad45610 | 31 | public: |
Rohit Grover |
118:620d28e7a1ba | 32 | typedef uint16_t Handle_t; |
carlescufi | 112:64c88ad45610 | 33 | |
Rohit Grover |
118:620d28e7a1ba | 34 | public: |
carlescufi | 112:64c88ad45610 | 35 | /** |
carlescufi | 112:64c88ad45610 | 36 | * @brief Creates a new GattAttribute using the specified |
carlescufi | 112:64c88ad45610 | 37 | * UUID, value length, and inital value |
carlescufi | 112:64c88ad45610 | 38 | * |
carlescufi | 112:64c88ad45610 | 39 | * @param[in] uuid |
carlescufi | 112:64c88ad45610 | 40 | * The UUID to use for this attribute |
carlescufi | 112:64c88ad45610 | 41 | * @param[in] valuePtr |
carlescufi | 112:64c88ad45610 | 42 | * The memory holding the initial value. |
carlescufi | 112:64c88ad45610 | 43 | * @param[in] initialLen |
carlescufi | 112:64c88ad45610 | 44 | * The min length in bytes of this characteristic's value |
carlescufi | 112:64c88ad45610 | 45 | * @param[in] maxLen |
carlescufi | 112:64c88ad45610 | 46 | * The max length in bytes of this characteristic's value |
carlescufi | 112:64c88ad45610 | 47 | * |
carlescufi | 112:64c88ad45610 | 48 | * @section EXAMPLE |
carlescufi | 112:64c88ad45610 | 49 | * |
carlescufi | 112:64c88ad45610 | 50 | * @code |
carlescufi | 112:64c88ad45610 | 51 | * |
carlescufi | 112:64c88ad45610 | 52 | * // UUID = 0x2A19, Min length 2, Max len = 2, Properties = write |
carlescufi | 112:64c88ad45610 | 53 | * GattCharacteristic c = GattCharacteristic( 0x2A19, 2, 2, BLE_GATT_CHAR_PROPERTIES_WRITE ); |
carlescufi | 112:64c88ad45610 | 54 | * |
carlescufi | 112:64c88ad45610 | 55 | * @endcode |
carlescufi | 112:64c88ad45610 | 56 | */ |
carlescufi | 112:64c88ad45610 | 57 | /**************************************************************************/ |
carlescufi | 112:64c88ad45610 | 58 | GattAttribute(const UUID &uuid, uint8_t *valuePtr = NULL, uint16_t initialLen = 0, uint16_t maxLen = 0) : |
carlescufi | 112:64c88ad45610 | 59 | _uuid(uuid), _valuePtr(valuePtr), _initialLen(initialLen), _lenMax(maxLen), _handle(){ |
carlescufi | 112:64c88ad45610 | 60 | /* empty */ |
carlescufi | 112:64c88ad45610 | 61 | } |
carlescufi | 112:64c88ad45610 | 62 | |
carlescufi | 112:64c88ad45610 | 63 | public: |
Rohit Grover |
118:620d28e7a1ba | 64 | Handle_t getHandle(void) const { |
carlescufi | 112:64c88ad45610 | 65 | return _handle; |
carlescufi | 112:64c88ad45610 | 66 | } |
Rohit Grover |
118:620d28e7a1ba | 67 | |
Rohit Grover |
118:620d28e7a1ba | 68 | void setHandle(Handle_t id) { |
carlescufi | 112:64c88ad45610 | 69 | _handle = id; |
carlescufi | 112:64c88ad45610 | 70 | } |
Rohit Grover |
118:620d28e7a1ba | 71 | |
carlescufi | 112:64c88ad45610 | 72 | const UUID &getUUID(void) const { |
carlescufi | 112:64c88ad45610 | 73 | return _uuid; |
carlescufi | 112:64c88ad45610 | 74 | } |
Rohit Grover |
118:620d28e7a1ba | 75 | |
carlescufi | 112:64c88ad45610 | 76 | uint16_t getInitialLength(void) const { |
carlescufi | 112:64c88ad45610 | 77 | return _initialLen; |
carlescufi | 112:64c88ad45610 | 78 | } |
Rohit Grover |
118:620d28e7a1ba | 79 | |
carlescufi | 112:64c88ad45610 | 80 | uint16_t getMaxLength(void) const { |
carlescufi | 112:64c88ad45610 | 81 | return _lenMax; |
carlescufi | 112:64c88ad45610 | 82 | } |
Rohit Grover |
118:620d28e7a1ba | 83 | |
carlescufi | 112:64c88ad45610 | 84 | uint8_t *getValuePtr(void) { |
carlescufi | 112:64c88ad45610 | 85 | return _valuePtr; |
carlescufi | 112:64c88ad45610 | 86 | } |
carlescufi | 112:64c88ad45610 | 87 | |
carlescufi | 112:64c88ad45610 | 88 | protected: |
carlescufi | 112:64c88ad45610 | 89 | UUID _uuid; /* Characteristic UUID */ |
carlescufi | 112:64c88ad45610 | 90 | uint8_t *_valuePtr; |
carlescufi | 112:64c88ad45610 | 91 | uint16_t _initialLen; /* Initial length of the value */ |
carlescufi | 112:64c88ad45610 | 92 | uint16_t _lenMax; /* Maximum length of the value */ |
Rohit Grover |
118:620d28e7a1ba | 93 | Handle_t _handle; |
carlescufi | 112:64c88ad45610 | 94 | }; |
carlescufi | 112:64c88ad45610 | 95 | |
carlescufi | 112:64c88ad45610 | 96 | #endif // ifndef __GATT_ATTRIBUTE_H__ |