Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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