High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Mon Mar 02 11:50:49 2015 +0000
Revision:
307:ecbc3405c66e
Parent:
306:ae0df1c9222a
Synchronized with git rev 22243be7
Author: Rohit Grover
Release 0.2.14
==============

Enhancements
~~~~~~~~~~~~
* Remove the entire thing about zeroing out bytes 2 and 3 of long UUID. Fixes #35.

Bugfixes
~~~~~~~~

none.

Compatibility
~~~~~~~~~~~~~

This release is API compatible with 0.2.4.

Who changed what in which revision?

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