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