テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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