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