Updated
Fork of BLE_API by
ble/BLEProtocol.h@1210:1f56dc951637, 2017-05-09 (annotated)
- Committer:
- vbahl2
- Date:
- Tue May 09 03:03:23 2017 +0000
- Revision:
- 1210:1f56dc951637
- Parent:
- 1209:b6a364143218
j
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vbahl2 | 1209:b6a364143218 | 1 | /* mbed Microcontroller Library |
vbahl2 | 1209:b6a364143218 | 2 | * Copyright (c) 2006-2013 ARM Limited |
vbahl2 | 1209:b6a364143218 | 3 | * |
vbahl2 | 1209:b6a364143218 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
vbahl2 | 1209:b6a364143218 | 5 | * you may not use this file except in compliance with the License. |
vbahl2 | 1209:b6a364143218 | 6 | * You may obtain a copy of the License at |
vbahl2 | 1209:b6a364143218 | 7 | * |
vbahl2 | 1209:b6a364143218 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
vbahl2 | 1209:b6a364143218 | 9 | * |
vbahl2 | 1209:b6a364143218 | 10 | * Unless required by applicable law or agreed to in writing, software |
vbahl2 | 1209:b6a364143218 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
vbahl2 | 1209:b6a364143218 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
vbahl2 | 1209:b6a364143218 | 13 | * See the License for the specific language governing permissions and |
vbahl2 | 1209:b6a364143218 | 14 | * limitations under the License. |
vbahl2 | 1209:b6a364143218 | 15 | */ |
vbahl2 | 1209:b6a364143218 | 16 | |
vbahl2 | 1209:b6a364143218 | 17 | #ifndef __BLE_PROTOCOL_H__ |
vbahl2 | 1209:b6a364143218 | 18 | #define __BLE_PROTOCOL_H__ |
vbahl2 | 1209:b6a364143218 | 19 | |
vbahl2 | 1209:b6a364143218 | 20 | #include <stddef.h> |
vbahl2 | 1209:b6a364143218 | 21 | #include <stdint.h> |
vbahl2 | 1209:b6a364143218 | 22 | #include <algorithm> |
vbahl2 | 1209:b6a364143218 | 23 | |
vbahl2 | 1209:b6a364143218 | 24 | /** |
vbahl2 | 1209:b6a364143218 | 25 | * A common namespace for types and constants used everywhere in BLE API. |
vbahl2 | 1209:b6a364143218 | 26 | */ |
vbahl2 | 1209:b6a364143218 | 27 | namespace BLEProtocol { |
vbahl2 | 1209:b6a364143218 | 28 | /**< |
vbahl2 | 1209:b6a364143218 | 29 | * A simple container for the enumeration of address-types for Protocol addresses. |
vbahl2 | 1209:b6a364143218 | 30 | * |
vbahl2 | 1209:b6a364143218 | 31 | * Adding a struct to encapsulate the contained enumeration prevents |
vbahl2 | 1209:b6a364143218 | 32 | * polluting the BLEProtocol namespace with the enumerated values. It also |
vbahl2 | 1209:b6a364143218 | 33 | * allows type-aliases for the enumeration while retaining the enumerated |
vbahl2 | 1209:b6a364143218 | 34 | * values. i.e. doing: |
vbahl2 | 1209:b6a364143218 | 35 | * typedef AddressType AliasedType; |
vbahl2 | 1209:b6a364143218 | 36 | * |
vbahl2 | 1209:b6a364143218 | 37 | * would allow the use of AliasedType::PUBLIC in code. |
vbahl2 | 1209:b6a364143218 | 38 | */ |
vbahl2 | 1209:b6a364143218 | 39 | struct AddressType { |
vbahl2 | 1209:b6a364143218 | 40 | /**< Address-types for Protocol addresses. */ |
vbahl2 | 1209:b6a364143218 | 41 | enum Type { |
vbahl2 | 1209:b6a364143218 | 42 | PUBLIC = 0, |
vbahl2 | 1209:b6a364143218 | 43 | RANDOM_STATIC, |
vbahl2 | 1209:b6a364143218 | 44 | RANDOM_PRIVATE_RESOLVABLE, |
vbahl2 | 1209:b6a364143218 | 45 | RANDOM_PRIVATE_NON_RESOLVABLE |
vbahl2 | 1209:b6a364143218 | 46 | }; |
vbahl2 | 1209:b6a364143218 | 47 | }; |
vbahl2 | 1209:b6a364143218 | 48 | typedef AddressType::Type AddressType_t; /**< Alias for AddressType::Type */ |
vbahl2 | 1209:b6a364143218 | 49 | |
vbahl2 | 1209:b6a364143218 | 50 | static const size_t ADDR_LEN = 6; /**< Length (in octets) of the BLE MAC address. */ |
vbahl2 | 1209:b6a364143218 | 51 | typedef uint8_t AddressBytes_t[ADDR_LEN]; /**< 48-bit address, in LSB format. */ |
vbahl2 | 1209:b6a364143218 | 52 | |
vbahl2 | 1209:b6a364143218 | 53 | /** |
vbahl2 | 1209:b6a364143218 | 54 | * BLE address. It contains an address-type (AddressType_t) and bytes (AddressBytes_t). |
vbahl2 | 1209:b6a364143218 | 55 | */ |
vbahl2 | 1209:b6a364143218 | 56 | struct Address_t { |
vbahl2 | 1209:b6a364143218 | 57 | AddressType_t type; /**< The type of the BLE address. */ |
vbahl2 | 1209:b6a364143218 | 58 | AddressBytes_t address; /**< The BLE address. */ |
vbahl2 | 1209:b6a364143218 | 59 | |
vbahl2 | 1209:b6a364143218 | 60 | /** |
vbahl2 | 1209:b6a364143218 | 61 | * Construct an Address_t object with the supplied type and address. |
vbahl2 | 1209:b6a364143218 | 62 | * |
vbahl2 | 1209:b6a364143218 | 63 | * @param[in] typeIn |
vbahl2 | 1209:b6a364143218 | 64 | * The BLE address type. |
vbahl2 | 1209:b6a364143218 | 65 | * @param[in] addressIn |
vbahl2 | 1209:b6a364143218 | 66 | * The BLE address. |
vbahl2 | 1209:b6a364143218 | 67 | */ |
vbahl2 | 1209:b6a364143218 | 68 | Address_t(AddressType_t typeIn, const AddressBytes_t& addressIn) : type(typeIn) { |
vbahl2 | 1209:b6a364143218 | 69 | std::copy(addressIn, addressIn + ADDR_LEN, address); |
vbahl2 | 1209:b6a364143218 | 70 | } |
vbahl2 | 1209:b6a364143218 | 71 | |
vbahl2 | 1209:b6a364143218 | 72 | /** |
vbahl2 | 1209:b6a364143218 | 73 | * Empty constructor. |
vbahl2 | 1209:b6a364143218 | 74 | */ |
vbahl2 | 1209:b6a364143218 | 75 | Address_t() : type(), address() { |
vbahl2 | 1209:b6a364143218 | 76 | } |
vbahl2 | 1209:b6a364143218 | 77 | }; |
vbahl2 | 1209:b6a364143218 | 78 | }; |
vbahl2 | 1209:b6a364143218 | 79 | |
vbahl2 | 1209:b6a364143218 | 80 | #endif /* __BLE_PROTOCOL_H__ */ |