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