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