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