Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
AntonLS
Date:
Sat Jul 11 01:57:40 2015 +0000
Revision:
16:3c873f2c8a27
Converted BLE_API lib to folder so the version stays frozen.

Who changed what in which revision?

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