BLE_API_Tiny_BLE
Fork of BLE_API by
public/UUID.h@302:8f4348c2b6b5, 2015-03-02 (annotated)
- Committer:
- rgrover1
- Date:
- Mon Mar 02 11:50:48 2015 +0000
- Revision:
- 302:8f4348c2b6b5
- Parent:
- 294:ab928e365ea1
- Child:
- 303:a0d78cb2e9ef
Synchronized with git rev 1e6a9cbb
Author: Rohit Grover
Merge branch 'uuid' of https://github.com/jeremybrodt/BLE_API into jeremybrodt-uuid
Who changed what in which revision?
User | Revision | Line number | New 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 | #ifndef __UUID_H__ |
rgrover1 | 302:8f4348c2b6b5 | 18 | #define __UUID_H__ |
rgrover1 | 302:8f4348c2b6b5 | 19 | |
rgrover1 | 302:8f4348c2b6b5 | 20 | #include "blecommon.h" |
rgrover1 | 302:8f4348c2b6b5 | 21 | |
rgrover1 | 302:8f4348c2b6b5 | 22 | const unsigned LENGTH_OF_LONG_UUID = 16; |
rgrover1 | 302:8f4348c2b6b5 | 23 | typedef uint16_t ShortUUIDBytes_t; |
rgrover1 | 302:8f4348c2b6b5 | 24 | typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID]; |
rgrover1 | 302:8f4348c2b6b5 | 25 | |
rgrover1 | 302:8f4348c2b6b5 | 26 | class UUID { |
rgrover1 | 302:8f4348c2b6b5 | 27 | public: |
rgrover1 | 302:8f4348c2b6b5 | 28 | enum { |
rgrover1 | 302:8f4348c2b6b5 | 29 | UUID_TYPE_SHORT = 0, // Short BLE UUID |
rgrover1 | 302:8f4348c2b6b5 | 30 | UUID_TYPE_LONG = 1 // Full 128-bit UUID |
rgrover1 | 302:8f4348c2b6b5 | 31 | }; |
rgrover1 | 302:8f4348c2b6b5 | 32 | |
rgrover1 | 302:8f4348c2b6b5 | 33 | public: |
rgrover1 | 302:8f4348c2b6b5 | 34 | UUID(const LongUUIDBytes_t); |
rgrover1 | 302:8f4348c2b6b5 | 35 | UUID(ShortUUIDBytes_t); |
rgrover1 | 302:8f4348c2b6b5 | 36 | |
rgrover1 | 302:8f4348c2b6b5 | 37 | public: |
rgrover1 | 302:8f4348c2b6b5 | 38 | uint8_t shortOrLong(void) const {return type; } |
rgrover1 | 302:8f4348c2b6b5 | 39 | const uint8_t *getBaseUUID(void) const { |
rgrover1 | 302:8f4348c2b6b5 | 40 | if (type == UUID_TYPE_SHORT) { return (const uint8_t*)&shortUUID; } |
rgrover1 | 302:8f4348c2b6b5 | 41 | else { return baseUUID; } |
rgrover1 | 302:8f4348c2b6b5 | 42 | } |
rgrover1 | 302:8f4348c2b6b5 | 43 | ShortUUIDBytes_t getShortUUID(void) const {return shortUUID;} |
rgrover1 | 302:8f4348c2b6b5 | 44 | uint8_t getLen(void) const { |
rgrover1 | 302:8f4348c2b6b5 | 45 | return ((type == UUID_TYPE_SHORT) ? sizeof(ShortUUIDBytes_t) : LENGTH_OF_LONG_UUID); |
rgrover1 | 302:8f4348c2b6b5 | 46 | } |
rgrover1 | 302:8f4348c2b6b5 | 47 | |
rgrover1 | 302:8f4348c2b6b5 | 48 | bool operator== (const UUID&) const; |
rgrover1 | 302:8f4348c2b6b5 | 49 | |
rgrover1 | 302:8f4348c2b6b5 | 50 | private: |
rgrover1 | 302:8f4348c2b6b5 | 51 | uint8_t type; // UUID_TYPE_SHORT or UUID_TYPE_LONG |
rgrover1 | 302:8f4348c2b6b5 | 52 | LongUUIDBytes_t baseUUID; /* the base of the long UUID (if |
rgrover1 | 302:8f4348c2b6b5 | 53 | * used). Note: bytes 12 and 13 (counting from LSB) |
rgrover1 | 302:8f4348c2b6b5 | 54 | * are zeroed out to allow comparison with other long |
rgrover1 | 302:8f4348c2b6b5 | 55 | * UUIDs which differ only in the 16-bit relative |
rgrover1 | 302:8f4348c2b6b5 | 56 | * part.*/ |
rgrover1 | 302:8f4348c2b6b5 | 57 | ShortUUIDBytes_t shortUUID; // 16 bit uuid (byte 2-3 using with base) |
rgrover1 | 302:8f4348c2b6b5 | 58 | }; |
rgrover1 | 302:8f4348c2b6b5 | 59 | |
rgrover1 | 302:8f4348c2b6b5 | 60 | #endif // ifndef __UUID_H__ |