Improve readability with getHandle inline

Fork of BLE_API by Bluetooth Low Energy

Committer:
Rohit Grover
Date:
Tue Sep 02 15:09:46 2014 +0100
Revision:
116:ca826083980e
Parent:
106:a20be740075d
Child:
144:c025c8839682
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.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rohit Grover 106:a20be740075d 1 /* mbed Microcontroller Library
Rohit Grover 106:a20be740075d 2 * Copyright (c) 2006-2013 ARM Limited
Rohit Grover 106:a20be740075d 3 *
Rohit Grover 106:a20be740075d 4 * Licensed under the Apache License, Version 2.0 (the "License");
Rohit Grover 106:a20be740075d 5 * you may not use this file except in compliance with the License.
Rohit Grover 106:a20be740075d 6 * You may obtain a copy of the License at
Rohit Grover 106:a20be740075d 7 *
Rohit Grover 106:a20be740075d 8 * http://www.apache.org/licenses/LICENSE-2.0
Rohit Grover 106:a20be740075d 9 *
Rohit Grover 106:a20be740075d 10 * Unless required by applicable law or agreed to in writing, software
Rohit Grover 106:a20be740075d 11 * distributed under the License is distributed on an "AS IS" BASIS,
Rohit Grover 106:a20be740075d 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Rohit Grover 106:a20be740075d 13 * See the License for the specific language governing permissions and
Rohit Grover 106:a20be740075d 14 * limitations under the License.
Rohit Grover 106:a20be740075d 15 */
Rohit Grover 106:a20be740075d 16
Rohit Grover 106:a20be740075d 17
Rohit Grover 106:a20be740075d 18 #include <stdio.h>
Rohit Grover 106:a20be740075d 19 #include <string.h>
Rohit Grover 106:a20be740075d 20
Rohit Grover 106:a20be740075d 21 #include "UUID.h"
Rohit Grover 106:a20be740075d 22
Rohit Grover 106:a20be740075d 23 /**************************************************************************/
Rohit Grover 106:a20be740075d 24 /*!
Rohit Grover 106:a20be740075d 25 @brief Creates a new 128-bit UUID
Rohit Grover 106:a20be740075d 26
Rohit Grover 106:a20be740075d 27 @note The UUID is a unique 128-bit (16 byte) ID used to identify
Rohit Grover 106:a20be740075d 28 different service or characteristics on the BLE device.
Rohit Grover 106:a20be740075d 29
Rohit Grover 106:a20be740075d 30 @note When creating a UUID, the constructor will check if all bytes
Rohit Grover 106:a20be740075d 31 except bytes 2/3 are equal to 0. If only bytes 2/3 have a
Rohit Grover 106:a20be740075d 32 value, the UUID will be treated as a short/BLE UUID, and the
Rohit Grover 106:a20be740075d 33 .type field will be set to UUID::UUID_TYPE_SHORT. If any
Rohit Grover 106:a20be740075d 34 of the bytes outside byte 2/3 have a non-zero value, the UUID
Rohit Grover 106:a20be740075d 35 will be considered a 128-bit ID, and .type will be assigned
Rohit Grover 106:a20be740075d 36 as UUID::UUID_TYPE_LONG.
Rohit Grover 106:a20be740075d 37
Rohit Grover 106:a20be740075d 38 @param[in] uuid_base
Rohit Grover 106:a20be740075d 39 The 128-bit (16-byte) UUID value. For 128-bit values,
Rohit Grover 106:a20be740075d 40 assign all 16 bytes. For 16-bit values, assign the
Rohit Grover 106:a20be740075d 41 16-bits to byte 2 and 3, and leave the rest of the bytes
Rohit Grover 106:a20be740075d 42 as 0.
Rohit Grover 106:a20be740075d 43
Rohit Grover 106:a20be740075d 44 @section EXAMPLE
Rohit Grover 106:a20be740075d 45
Rohit Grover 106:a20be740075d 46 @code
Rohit Grover 106:a20be740075d 47
Rohit Grover 106:a20be740075d 48 // Create a short UUID (0x180F)
Rohit Grover 106:a20be740075d 49 uint8_t shortID[16] = { 0, 0, 0x0F, 0x18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Rohit Grover 106:a20be740075d 50 UUID ble_uuid = UUID(shortID);
Rohit Grover 106:a20be740075d 51 // ble_uuid.type = UUID_TYPE_SHORT
Rohit Grover 106:a20be740075d 52 // ble_uuid.value = 0x180F
Rohit Grover 106:a20be740075d 53
Rohit Grover 106:a20be740075d 54 // Creeate a long UUID
Rohit Grover 106:a20be740075d 55 uint8_t longID[16] = { 0x00, 0x11, 0x22, 0x33,
Rohit Grover 106:a20be740075d 56 0x44, 0x55, 0x66, 0x77,
Rohit Grover 106:a20be740075d 57 0x88, 0x99, 0xAA, 0xBB,
Rohit Grover 106:a20be740075d 58 0xCC, 0xDD, 0xEE, 0xFF };
Rohit Grover 106:a20be740075d 59 UUID custom_uuid = UUID(longID);
Rohit Grover 106:a20be740075d 60 // custom_uuid.type = UUID_TYPE_LONG
Rohit Grover 106:a20be740075d 61 // custom_uuid.value = 0x3322
Rohit Grover 106:a20be740075d 62 // custom_uuid.base = 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF
Rohit Grover 106:a20be740075d 63
Rohit Grover 106:a20be740075d 64 @endcode
Rohit Grover 106:a20be740075d 65 */
Rohit Grover 106:a20be740075d 66 /**************************************************************************/
Rohit Grover 116:ca826083980e 67 UUID::UUID(const LongUUIDBytes_t longUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(0)
Rohit Grover 106:a20be740075d 68 {
Rohit Grover 106:a20be740075d 69 memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID);
Rohit Grover 106:a20be740075d 70 shortUUID = (uint16_t)((longUUID[2] << 8) | (longUUID[3]));
Rohit Grover 106:a20be740075d 71
Rohit Grover 106:a20be740075d 72 /* Check if this is a short of a long UUID */
Rohit Grover 106:a20be740075d 73 unsigned index;
Rohit Grover 106:a20be740075d 74 for (index = 0; index < LENGTH_OF_LONG_UUID; index++) {
Rohit Grover 106:a20be740075d 75 if ((index == 2) || (index == 3)) {
Rohit Grover 106:a20be740075d 76 continue; /* we should not consider bytes 2 and 3 because that's
Rohit Grover 106:a20be740075d 77 * where the 16-bit relative UUID is placed. */
Rohit Grover 106:a20be740075d 78 }
Rohit Grover 106:a20be740075d 79
Rohit Grover 106:a20be740075d 80 if (baseUUID[index] != 0) {
Rohit Grover 106:a20be740075d 81 type = UUID_TYPE_LONG;
Rohit Grover 106:a20be740075d 82
Rohit Grover 106:a20be740075d 83 /* zero out the 16-bit part in the base; this will help equate long
Rohit Grover 106:a20be740075d 84 * UUIDs when they differ only in this 16-bit relative part.*/
Rohit Grover 106:a20be740075d 85 baseUUID[2] = 0;
Rohit Grover 106:a20be740075d 86 baseUUID[3] = 0;
Rohit Grover 106:a20be740075d 87
Rohit Grover 106:a20be740075d 88 return;
Rohit Grover 106:a20be740075d 89 }
Rohit Grover 106:a20be740075d 90 }
Rohit Grover 106:a20be740075d 91 }
Rohit Grover 106:a20be740075d 92
Rohit Grover 106:a20be740075d 93 /**************************************************************************/
Rohit Grover 106:a20be740075d 94 /*!
Rohit Grover 106:a20be740075d 95 @brief Creates a short (16-bit) UUID
Rohit Grover 106:a20be740075d 96
Rohit Grover 106:a20be740075d 97 @param[in] ble_uuid
Rohit Grover 106:a20be740075d 98 The 16-bit BLE UUID value.
Rohit Grover 106:a20be740075d 99 */
Rohit Grover 106:a20be740075d 100 /**************************************************************************/
Rohit Grover 116:ca826083980e 101 UUID::UUID(ShortUUIDBytes_t shortUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(shortUUID)
Rohit Grover 106:a20be740075d 102 {
Rohit Grover 106:a20be740075d 103 /* empty */
Rohit Grover 106:a20be740075d 104 }
Rohit Grover 106:a20be740075d 105
Rohit Grover 106:a20be740075d 106 /**************************************************************************/
Rohit Grover 106:a20be740075d 107 /*!
Rohit Grover 106:a20be740075d 108 @brief UUID destructor
Rohit Grover 106:a20be740075d 109 */
Rohit Grover 106:a20be740075d 110 /**************************************************************************/
Rohit Grover 106:a20be740075d 111 UUID::~UUID(void)
Rohit Grover 106:a20be740075d 112 {
Rohit Grover 106:a20be740075d 113 }