BLE
Fork of BLE_API by
ble/Gap.h@1076:0d0dafb54bc9, 2016-01-11 (annotated)
- Committer:
- vcoubard
- Date:
- Mon Jan 11 08:51:43 2016 +0000
- Revision:
- 1076:0d0dafb54bc9
- Parent:
- 1075:1fedc77d9add
- Child:
- 1078:98d37e26903c
Synchronized with git rev 17d6e5fe
Author: Rohit Grover
Extract Adress related types from Gap.h into BLEProtocol.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 711:b2e1a2660ec2 | 1 | /* mbed Microcontroller Library |
rgrover1 | 711:b2e1a2660ec2 | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 711:b2e1a2660ec2 | 3 | * |
rgrover1 | 711:b2e1a2660ec2 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 711:b2e1a2660ec2 | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 711:b2e1a2660ec2 | 6 | * You may obtain a copy of the License at |
rgrover1 | 711:b2e1a2660ec2 | 7 | * |
rgrover1 | 711:b2e1a2660ec2 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 711:b2e1a2660ec2 | 9 | * |
rgrover1 | 711:b2e1a2660ec2 | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 711:b2e1a2660ec2 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 711:b2e1a2660ec2 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 711:b2e1a2660ec2 | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 711:b2e1a2660ec2 | 14 | * limitations under the License. |
rgrover1 | 711:b2e1a2660ec2 | 15 | */ |
rgrover1 | 711:b2e1a2660ec2 | 16 | |
rgrover1 | 711:b2e1a2660ec2 | 17 | #ifndef __GAP_H__ |
rgrover1 | 711:b2e1a2660ec2 | 18 | #define __GAP_H__ |
rgrover1 | 711:b2e1a2660ec2 | 19 | |
vcoubard | 1076:0d0dafb54bc9 | 20 | #include "ble/BLEProtocol.h" |
rgrover1 | 711:b2e1a2660ec2 | 21 | #include "GapAdvertisingData.h" |
rgrover1 | 711:b2e1a2660ec2 | 22 | #include "GapAdvertisingParams.h" |
rgrover1 | 711:b2e1a2660ec2 | 23 | #include "GapScanningParams.h" |
rgrover1 | 711:b2e1a2660ec2 | 24 | #include "GapEvents.h" |
rgrover1 | 830:9072de50087b | 25 | #include "CallChainOfFunctionPointersWithContext.h" |
rgrover1 | 711:b2e1a2660ec2 | 26 | #include "FunctionPointerWithContext.h" |
rgrover1 | 711:b2e1a2660ec2 | 27 | |
vcoubard | 1049:efb29faf12fc | 28 | /* Forward declarations for classes that will only be used for pointers or references in the following. */ |
rgrover1 | 711:b2e1a2660ec2 | 29 | class GapAdvertisingParams; |
rgrover1 | 711:b2e1a2660ec2 | 30 | class GapScanningParams; |
rgrover1 | 711:b2e1a2660ec2 | 31 | class GapAdvertisingData; |
rgrover1 | 711:b2e1a2660ec2 | 32 | |
rgrover1 | 711:b2e1a2660ec2 | 33 | class Gap { |
vcoubard | 1076:0d0dafb54bc9 | 34 | /* |
vcoubard | 1076:0d0dafb54bc9 | 35 | * DEPRECATION ALERT: all of the APIs in this `public` block are deprecated. |
vcoubard | 1076:0d0dafb54bc9 | 36 | * They have been relocated to the class BLEProtocol. |
vcoubard | 1076:0d0dafb54bc9 | 37 | */ |
rgrover1 | 711:b2e1a2660ec2 | 38 | public: |
vcoubard | 1076:0d0dafb54bc9 | 39 | /** |
vcoubard | 1076:0d0dafb54bc9 | 40 | * Address-type for BLEProtocol addresses. |
vcoubard | 1076:0d0dafb54bc9 | 41 | * @note: deprecated. Use BLEProtocol::AddressType::Type instead. |
vcoubard | 1076:0d0dafb54bc9 | 42 | */ |
vcoubard | 1076:0d0dafb54bc9 | 43 | typedef BLEProtocol::AddressType::Type AddressType_t; |
rgrover1 | 711:b2e1a2660ec2 | 44 | |
vcoubard | 1076:0d0dafb54bc9 | 45 | /** |
vcoubard | 1076:0d0dafb54bc9 | 46 | * Address-type for BLEProtocol addresses. |
vcoubard | 1076:0d0dafb54bc9 | 47 | * @note: deprecated. Use BLEProtocol::AddressType::Type instead. |
vcoubard | 1076:0d0dafb54bc9 | 48 | */ |
vcoubard | 1076:0d0dafb54bc9 | 49 | typedef BLEProtocol::AddressType::Type addr_type_t; |
rgrover1 | 711:b2e1a2660ec2 | 50 | |
vcoubard | 1076:0d0dafb54bc9 | 51 | static const unsigned ADDR_LEN = BLEProtocol::ADDR_LEN; /**< Length (in octets) of the BLE MAC address. */ |
vcoubard | 1076:0d0dafb54bc9 | 52 | typedef BLEProtocol::Address_t Address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::Address_t instead. */ |
vcoubard | 1076:0d0dafb54bc9 | 53 | typedef BLEProtocol::Address_t address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::Address_t instead. */ |
vcoubard | 1076:0d0dafb54bc9 | 54 | |
vcoubard | 1076:0d0dafb54bc9 | 55 | public: |
rgrover1 | 711:b2e1a2660ec2 | 56 | enum TimeoutSource_t { |
rgrover1 | 711:b2e1a2660ec2 | 57 | TIMEOUT_SRC_ADVERTISING = 0x00, /**< Advertising timeout. */ |
rgrover1 | 711:b2e1a2660ec2 | 58 | TIMEOUT_SRC_SECURITY_REQUEST = 0x01, /**< Security request timeout. */ |
rgrover1 | 711:b2e1a2660ec2 | 59 | TIMEOUT_SRC_SCAN = 0x02, /**< Scanning timeout. */ |
rgrover1 | 711:b2e1a2660ec2 | 60 | TIMEOUT_SRC_CONN = 0x03, /**< Connection timeout. */ |
rgrover1 | 711:b2e1a2660ec2 | 61 | }; |
rgrover1 | 711:b2e1a2660ec2 | 62 | |
rgrover1 | 711:b2e1a2660ec2 | 63 | /** |
rgrover1 | 711:b2e1a2660ec2 | 64 | * Enumeration for disconnection reasons. The values for these reasons are |
vcoubard | 1049:efb29faf12fc | 65 | * derived from Nordic's implementation, but the reasons are meant to be |
vcoubard | 1049:efb29faf12fc | 66 | * independent of the transport. If you are returned a reason that is not |
vcoubard | 1049:efb29faf12fc | 67 | * covered by this enumeration, please refer to the underlying |
rgrover1 | 711:b2e1a2660ec2 | 68 | * transport library. |
rgrover1 | 711:b2e1a2660ec2 | 69 | */ |
rgrover1 | 711:b2e1a2660ec2 | 70 | enum DisconnectionReason_t { |
rgrover1 | 711:b2e1a2660ec2 | 71 | CONNECTION_TIMEOUT = 0x08, |
rgrover1 | 711:b2e1a2660ec2 | 72 | REMOTE_USER_TERMINATED_CONNECTION = 0x13, |
vcoubard | 1049:efb29faf12fc | 73 | REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES = 0x14, /**< Remote device terminated connection due to low resources.*/ |
vcoubard | 1049:efb29faf12fc | 74 | REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF = 0x15, /**< Remote device terminated connection due to power off. */ |
rgrover1 | 711:b2e1a2660ec2 | 75 | LOCAL_HOST_TERMINATED_CONNECTION = 0x16, |
rgrover1 | 711:b2e1a2660ec2 | 76 | CONN_INTERVAL_UNACCEPTABLE = 0x3B, |
rgrover1 | 711:b2e1a2660ec2 | 77 | }; |
rgrover1 | 711:b2e1a2660ec2 | 78 | |
vcoubard | 1049:efb29faf12fc | 79 | /* Describes the current state of the device (more than one bit can be set). */ |
rgrover1 | 711:b2e1a2660ec2 | 80 | struct GapState_t { |
vcoubard | 1049:efb29faf12fc | 81 | unsigned advertising : 1; /**< Peripheral is currently advertising. */ |
vcoubard | 1049:efb29faf12fc | 82 | unsigned connected : 1; /**< Peripheral is connected to a central. */ |
rgrover1 | 711:b2e1a2660ec2 | 83 | }; |
rgrover1 | 711:b2e1a2660ec2 | 84 | |
rgrover1 | 711:b2e1a2660ec2 | 85 | typedef uint16_t Handle_t; /* Type for connection handle. */ |
rgrover1 | 711:b2e1a2660ec2 | 86 | |
rgrover1 | 711:b2e1a2660ec2 | 87 | typedef struct { |
rgrover1 | 711:b2e1a2660ec2 | 88 | uint16_t minConnectionInterval; /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/ |
rgrover1 | 711:b2e1a2660ec2 | 89 | uint16_t maxConnectionInterval; /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/ |
rgrover1 | 711:b2e1a2660ec2 | 90 | uint16_t slaveLatency; /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/ |
rgrover1 | 711:b2e1a2660ec2 | 91 | uint16_t connectionSupervisionTimeout; /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/ |
rgrover1 | 711:b2e1a2660ec2 | 92 | } ConnectionParams_t; |
rgrover1 | 711:b2e1a2660ec2 | 93 | |
rgrover1 | 711:b2e1a2660ec2 | 94 | enum Role_t { |
rgrover1 | 711:b2e1a2660ec2 | 95 | PERIPHERAL = 0x1, /**< Peripheral Role. */ |
rgrover1 | 711:b2e1a2660ec2 | 96 | CENTRAL = 0x2, /**< Central Role. */ |
rgrover1 | 711:b2e1a2660ec2 | 97 | }; |
rgrover1 | 711:b2e1a2660ec2 | 98 | |
rgrover1 | 711:b2e1a2660ec2 | 99 | struct AdvertisementCallbackParams_t { |
rgrover1 | 711:b2e1a2660ec2 | 100 | Address_t peerAddr; |
rgrover1 | 711:b2e1a2660ec2 | 101 | int8_t rssi; |
rgrover1 | 711:b2e1a2660ec2 | 102 | bool isScanResponse; |
rgrover1 | 711:b2e1a2660ec2 | 103 | GapAdvertisingParams::AdvertisingType_t type; |
rgrover1 | 711:b2e1a2660ec2 | 104 | uint8_t advertisingDataLen; |
rgrover1 | 711:b2e1a2660ec2 | 105 | const uint8_t *advertisingData; |
rgrover1 | 711:b2e1a2660ec2 | 106 | }; |
rgrover1 | 711:b2e1a2660ec2 | 107 | typedef FunctionPointerWithContext<const AdvertisementCallbackParams_t *> AdvertisementReportCallback_t; |
rgrover1 | 711:b2e1a2660ec2 | 108 | |
rgrover1 | 711:b2e1a2660ec2 | 109 | struct ConnectionCallbackParams_t { |
vcoubard | 1076:0d0dafb54bc9 | 110 | Handle_t handle; |
vcoubard | 1076:0d0dafb54bc9 | 111 | Role_t role; |
vcoubard | 1076:0d0dafb54bc9 | 112 | BLEProtocol::AddressType::Type peerAddrType; |
vcoubard | 1076:0d0dafb54bc9 | 113 | Address_t peerAddr; |
vcoubard | 1076:0d0dafb54bc9 | 114 | BLEProtocol::AddressType::Type ownAddrType; |
vcoubard | 1076:0d0dafb54bc9 | 115 | Address_t ownAddr; |
vcoubard | 1076:0d0dafb54bc9 | 116 | const ConnectionParams_t *connectionParams; |
rgrover1 | 711:b2e1a2660ec2 | 117 | |
vcoubard | 1076:0d0dafb54bc9 | 118 | ConnectionCallbackParams_t(Handle_t handleIn, |
vcoubard | 1076:0d0dafb54bc9 | 119 | Role_t roleIn, |
vcoubard | 1076:0d0dafb54bc9 | 120 | BLEProtocol::AddressType::Type peerAddrTypeIn, |
vcoubard | 1076:0d0dafb54bc9 | 121 | const uint8_t *peerAddrIn, |
vcoubard | 1076:0d0dafb54bc9 | 122 | BLEProtocol::AddressType::Type ownAddrTypeIn, |
vcoubard | 1076:0d0dafb54bc9 | 123 | const uint8_t *ownAddrIn, |
vcoubard | 1076:0d0dafb54bc9 | 124 | const ConnectionParams_t *connectionParamsIn) : |
rgrover1 | 711:b2e1a2660ec2 | 125 | handle(handleIn), |
rgrover1 | 711:b2e1a2660ec2 | 126 | role(roleIn), |
rgrover1 | 711:b2e1a2660ec2 | 127 | peerAddrType(peerAddrTypeIn), |
rgrover1 | 711:b2e1a2660ec2 | 128 | peerAddr(), |
rgrover1 | 711:b2e1a2660ec2 | 129 | ownAddrType(ownAddrTypeIn), |
rgrover1 | 711:b2e1a2660ec2 | 130 | ownAddr(), |
rgrover1 | 711:b2e1a2660ec2 | 131 | connectionParams(connectionParamsIn) { |
rgrover1 | 711:b2e1a2660ec2 | 132 | memcpy(peerAddr, peerAddrIn, ADDR_LEN); |
rgrover1 | 711:b2e1a2660ec2 | 133 | memcpy(ownAddr, ownAddrIn, ADDR_LEN); |
rgrover1 | 711:b2e1a2660ec2 | 134 | } |
rgrover1 | 711:b2e1a2660ec2 | 135 | }; |
rgrover1 | 711:b2e1a2660ec2 | 136 | |
rgrover1 | 830:9072de50087b | 137 | struct DisconnectionCallbackParams_t { |
rgrover1 | 830:9072de50087b | 138 | Handle_t handle; |
rgrover1 | 830:9072de50087b | 139 | DisconnectionReason_t reason; |
rgrover1 | 830:9072de50087b | 140 | |
rgrover1 | 830:9072de50087b | 141 | DisconnectionCallbackParams_t(Handle_t handleIn, |
rgrover1 | 830:9072de50087b | 142 | DisconnectionReason_t reasonIn) : |
rgrover1 | 830:9072de50087b | 143 | handle(handleIn), |
rgrover1 | 830:9072de50087b | 144 | reason(reasonIn) |
rgrover1 | 830:9072de50087b | 145 | {} |
rgrover1 | 830:9072de50087b | 146 | }; |
rgrover1 | 830:9072de50087b | 147 | |
rgrover1 | 711:b2e1a2660ec2 | 148 | static const uint16_t UNIT_1_25_MS = 1250; /**< Number of microseconds in 1.25 milliseconds. */ |
rgrover1 | 711:b2e1a2660ec2 | 149 | static uint16_t MSEC_TO_GAP_DURATION_UNITS(uint32_t durationInMillis) { |
rgrover1 | 711:b2e1a2660ec2 | 150 | return (durationInMillis * 1000) / UNIT_1_25_MS; |
rgrover1 | 711:b2e1a2660ec2 | 151 | } |
rgrover1 | 767:03f1a26f132f | 152 | |
vcoubard | 1053:b55e1ad3e1b3 | 153 | typedef FunctionPointerWithContext<TimeoutSource_t> TimeoutEventCallback_t; |
vcoubard | 1053:b55e1ad3e1b3 | 154 | typedef CallChainOfFunctionPointersWithContext<TimeoutSource_t> TimeoutEventCallbackChain_t; |
rgrover1 | 711:b2e1a2660ec2 | 155 | |
vcoubard | 1053:b55e1ad3e1b3 | 156 | typedef FunctionPointerWithContext<const ConnectionCallbackParams_t *> ConnectionEventCallback_t; |
vcoubard | 1053:b55e1ad3e1b3 | 157 | typedef CallChainOfFunctionPointersWithContext<const ConnectionCallbackParams_t *> ConnectionEventCallbackChain_t; |
vcoubard | 1053:b55e1ad3e1b3 | 158 | |
vcoubard | 1053:b55e1ad3e1b3 | 159 | typedef FunctionPointerWithContext<const DisconnectionCallbackParams_t*> DisconnectionEventCallback_t; |
vcoubard | 1055:f59e5d9a992a | 160 | typedef CallChainOfFunctionPointersWithContext<const DisconnectionCallbackParams_t*> DisconnectionEventCallbackChain_t; |
vcoubard | 1053:b55e1ad3e1b3 | 161 | |
rgrover1 | 754:0f60274cd3ad | 162 | typedef FunctionPointerWithContext<bool> RadioNotificationEventCallback_t; |
rgrover1 | 711:b2e1a2660ec2 | 163 | |
rgrover1 | 711:b2e1a2660ec2 | 164 | /* |
rgrover1 | 711:b2e1a2660ec2 | 165 | * The following functions are meant to be overridden in the platform-specific sub-class. |
rgrover1 | 711:b2e1a2660ec2 | 166 | */ |
rgrover1 | 711:b2e1a2660ec2 | 167 | public: |
rgrover1 | 711:b2e1a2660ec2 | 168 | /** |
rgrover1 | 711:b2e1a2660ec2 | 169 | * Set the BTLE MAC address and type. Please note that the address format is |
vcoubard | 1049:efb29faf12fc | 170 | * least significant byte first (LSB). Please refer to Address_t. |
rgrover1 | 711:b2e1a2660ec2 | 171 | * |
rgrover1 | 711:b2e1a2660ec2 | 172 | * @return BLE_ERROR_NONE on success. |
rgrover1 | 711:b2e1a2660ec2 | 173 | */ |
vcoubard | 1076:0d0dafb54bc9 | 174 | virtual ble_error_t setAddress(BLEProtocol::AddressType::Type type, const Address_t address) { |
rgrover1 | 735:4872b70437ce | 175 | /* avoid compiler warnings about unused variables */ |
rgrover1 | 735:4872b70437ce | 176 | (void)type; |
rgrover1 | 735:4872b70437ce | 177 | (void)address; |
rgrover1 | 735:4872b70437ce | 178 | |
rgrover1 | 729:997ba5e7b3b6 | 179 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 180 | } |
rgrover1 | 711:b2e1a2660ec2 | 181 | |
rgrover1 | 711:b2e1a2660ec2 | 182 | /** |
rgrover1 | 711:b2e1a2660ec2 | 183 | * Fetch the BTLE MAC address and type. |
rgrover1 | 711:b2e1a2660ec2 | 184 | * |
rgrover1 | 711:b2e1a2660ec2 | 185 | * @return BLE_ERROR_NONE on success. |
rgrover1 | 711:b2e1a2660ec2 | 186 | */ |
vcoubard | 1076:0d0dafb54bc9 | 187 | virtual ble_error_t getAddress(BLEProtocol::AddressType::Type *typeP, Address_t address) { |
vcoubard | 1049:efb29faf12fc | 188 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 735:4872b70437ce | 189 | (void)typeP; |
rgrover1 | 735:4872b70437ce | 190 | (void)address; |
rgrover1 | 735:4872b70437ce | 191 | |
rgrover1 | 729:997ba5e7b3b6 | 192 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 193 | } |
rgrover1 | 711:b2e1a2660ec2 | 194 | |
rgrover1 | 711:b2e1a2660ec2 | 195 | /** |
vcoubard | 1057:ce2fb3d09929 | 196 | * @return Minimum Advertising interval in milliseconds for connectable |
vcoubard | 1057:ce2fb3d09929 | 197 | * undirected and connectable directed event types. |
rgrover1 | 711:b2e1a2660ec2 | 198 | */ |
rgrover1 | 711:b2e1a2660ec2 | 199 | virtual uint16_t getMinAdvertisingInterval(void) const { |
rgrover1 | 743:861ed7eb186d | 200 | return 0; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 201 | } |
rgrover1 | 711:b2e1a2660ec2 | 202 | |
rgrover1 | 711:b2e1a2660ec2 | 203 | /** |
vcoubard | 1057:ce2fb3d09929 | 204 | * @return Minimum Advertising interval in milliseconds for scannable |
vcoubard | 1057:ce2fb3d09929 | 205 | * undirected and non-connectable undirected event types. |
rgrover1 | 711:b2e1a2660ec2 | 206 | */ |
rgrover1 | 711:b2e1a2660ec2 | 207 | virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const { |
rgrover1 | 743:861ed7eb186d | 208 | return 0; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 209 | } |
rgrover1 | 711:b2e1a2660ec2 | 210 | |
rgrover1 | 711:b2e1a2660ec2 | 211 | /** |
rgrover1 | 711:b2e1a2660ec2 | 212 | * @return Maximum Advertising interval in milliseconds. |
rgrover1 | 711:b2e1a2660ec2 | 213 | */ |
rgrover1 | 711:b2e1a2660ec2 | 214 | virtual uint16_t getMaxAdvertisingInterval(void) const { |
rgrover1 | 743:861ed7eb186d | 215 | return 0xFFFF; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 216 | } |
rgrover1 | 711:b2e1a2660ec2 | 217 | |
rgrover1 | 711:b2e1a2660ec2 | 218 | virtual ble_error_t stopAdvertising(void) { |
rgrover1 | 729:997ba5e7b3b6 | 219 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 220 | } |
rgrover1 | 711:b2e1a2660ec2 | 221 | |
rgrover1 | 711:b2e1a2660ec2 | 222 | /** |
rgrover1 | 711:b2e1a2660ec2 | 223 | * Stop scanning. The current scanning parameters remain in effect. |
rgrover1 | 711:b2e1a2660ec2 | 224 | * |
rgrover1 | 711:b2e1a2660ec2 | 225 | * @retval BLE_ERROR_NONE if successfully stopped scanning procedure. |
rgrover1 | 711:b2e1a2660ec2 | 226 | */ |
rgrover1 | 711:b2e1a2660ec2 | 227 | virtual ble_error_t stopScan() { |
rgrover1 | 729:997ba5e7b3b6 | 228 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 229 | } |
rgrover1 | 711:b2e1a2660ec2 | 230 | |
rgrover1 | 711:b2e1a2660ec2 | 231 | /** |
rgrover1 | 711:b2e1a2660ec2 | 232 | * Create a connection (GAP Link Establishment). |
rgrover1 | 711:b2e1a2660ec2 | 233 | * |
rgrover1 | 711:b2e1a2660ec2 | 234 | * @param peerAddr |
rgrover1 | 711:b2e1a2660ec2 | 235 | * 48-bit address, LSB format. |
rgrover1 | 711:b2e1a2660ec2 | 236 | * @param peerAddrType |
rgrover1 | 711:b2e1a2660ec2 | 237 | * Address type of the peer. |
rgrover1 | 711:b2e1a2660ec2 | 238 | * @param connectionParams |
rgrover1 | 711:b2e1a2660ec2 | 239 | * Connection parameters. |
rgrover1 | 711:b2e1a2660ec2 | 240 | * @param scanParams |
rgrover1 | 711:b2e1a2660ec2 | 241 | * Paramters to be used while scanning for the peer. |
rgrover1 | 711:b2e1a2660ec2 | 242 | * @return BLE_ERROR_NONE if connection establishment procedure is started |
rgrover1 | 830:9072de50087b | 243 | * successfully. The connectionCallChain (if set) will be invoked upon |
rgrover1 | 711:b2e1a2660ec2 | 244 | * a connection event. |
rgrover1 | 711:b2e1a2660ec2 | 245 | */ |
vcoubard | 1076:0d0dafb54bc9 | 246 | virtual ble_error_t connect(const Address_t peerAddr, |
vcoubard | 1076:0d0dafb54bc9 | 247 | BLEProtocol::AddressType::Type peerAddrType, |
vcoubard | 1076:0d0dafb54bc9 | 248 | const ConnectionParams_t *connectionParams, |
vcoubard | 1076:0d0dafb54bc9 | 249 | const GapScanningParams *scanParams) { |
vcoubard | 1049:efb29faf12fc | 250 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 735:4872b70437ce | 251 | (void)peerAddr; |
rgrover1 | 735:4872b70437ce | 252 | (void)peerAddrType; |
rgrover1 | 735:4872b70437ce | 253 | (void)connectionParams; |
rgrover1 | 735:4872b70437ce | 254 | (void)scanParams; |
rgrover1 | 735:4872b70437ce | 255 | |
rgrover1 | 729:997ba5e7b3b6 | 256 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 257 | } |
rgrover1 | 711:b2e1a2660ec2 | 258 | |
rgrover1 | 711:b2e1a2660ec2 | 259 | /** |
rgrover1 | 711:b2e1a2660ec2 | 260 | * This call initiates the disconnection procedure, and its completion will |
rgrover1 | 711:b2e1a2660ec2 | 261 | * be communicated to the application with an invocation of the |
rgrover1 | 711:b2e1a2660ec2 | 262 | * disconnectionCallback. |
rgrover1 | 711:b2e1a2660ec2 | 263 | * |
rgrover1 | 711:b2e1a2660ec2 | 264 | * @param reason |
vcoubard | 1049:efb29faf12fc | 265 | * The reason for disconnection; to be sent back to the peer. |
rgrover1 | 711:b2e1a2660ec2 | 266 | */ |
rgrover1 | 711:b2e1a2660ec2 | 267 | virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason) { |
rgrover1 | 735:4872b70437ce | 268 | /* avoid compiler warnings about unused variables */ |
rgrover1 | 735:4872b70437ce | 269 | (void)connectionHandle; |
rgrover1 | 735:4872b70437ce | 270 | (void)reason; |
rgrover1 | 735:4872b70437ce | 271 | |
rgrover1 | 729:997ba5e7b3b6 | 272 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 273 | } |
rgrover1 | 711:b2e1a2660ec2 | 274 | |
rgrover1 | 711:b2e1a2660ec2 | 275 | /** |
rgrover1 | 711:b2e1a2660ec2 | 276 | * This call initiates the disconnection procedure, and its completion will |
rgrover1 | 711:b2e1a2660ec2 | 277 | * be communicated to the application with an invocation of the |
rgrover1 | 711:b2e1a2660ec2 | 278 | * disconnectionCallback. |
rgrover1 | 711:b2e1a2660ec2 | 279 | * |
rgrover1 | 711:b2e1a2660ec2 | 280 | * @param reason |
vcoubard | 1049:efb29faf12fc | 281 | * The reason for disconnection; to be sent back to the peer. |
rgrover1 | 711:b2e1a2660ec2 | 282 | * |
vcoubard | 1049:efb29faf12fc | 283 | * @note: This version of disconnect() doesn't take a connection handle. It |
vcoubard | 1049:efb29faf12fc | 284 | * works reliably only for stacks that are limited to a single |
rgrover1 | 711:b2e1a2660ec2 | 285 | * connection. This API should be considered *deprecated* in favour of the |
vcoubard | 1049:efb29faf12fc | 286 | * alternative, which takes a connection handle. It will be dropped in the future. |
rgrover1 | 711:b2e1a2660ec2 | 287 | */ |
rgrover1 | 711:b2e1a2660ec2 | 288 | virtual ble_error_t disconnect(DisconnectionReason_t reason) { |
vcoubard | 1049:efb29faf12fc | 289 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 735:4872b70437ce | 290 | (void)reason; |
rgrover1 | 735:4872b70437ce | 291 | |
rgrover1 | 729:997ba5e7b3b6 | 292 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 293 | } |
rgrover1 | 711:b2e1a2660ec2 | 294 | |
rgrover1 | 711:b2e1a2660ec2 | 295 | /** |
rgrover1 | 711:b2e1a2660ec2 | 296 | * Get the GAP peripheral preferred connection parameters. These are the |
rgrover1 | 711:b2e1a2660ec2 | 297 | * defaults that the peripheral would like to have in a connection. The |
rgrover1 | 711:b2e1a2660ec2 | 298 | * choice of the connection parameters is eventually up to the central. |
rgrover1 | 711:b2e1a2660ec2 | 299 | * |
rgrover1 | 711:b2e1a2660ec2 | 300 | * @param[out] params |
rgrover1 | 711:b2e1a2660ec2 | 301 | * The structure where the parameters will be stored. Memory |
rgrover1 | 711:b2e1a2660ec2 | 302 | * for this is owned by the caller. |
rgrover1 | 711:b2e1a2660ec2 | 303 | * |
rgrover1 | 711:b2e1a2660ec2 | 304 | * @return BLE_ERROR_NONE if the parameters were successfully filled into |
rgrover1 | 711:b2e1a2660ec2 | 305 | * the given structure pointed to by params. |
rgrover1 | 711:b2e1a2660ec2 | 306 | */ |
rgrover1 | 711:b2e1a2660ec2 | 307 | virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params) { |
vcoubard | 1049:efb29faf12fc | 308 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 735:4872b70437ce | 309 | (void)params; |
rgrover1 | 735:4872b70437ce | 310 | |
rgrover1 | 729:997ba5e7b3b6 | 311 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 312 | } |
rgrover1 | 711:b2e1a2660ec2 | 313 | |
rgrover1 | 711:b2e1a2660ec2 | 314 | /** |
rgrover1 | 711:b2e1a2660ec2 | 315 | * Set the GAP peripheral preferred connection parameters. These are the |
rgrover1 | 711:b2e1a2660ec2 | 316 | * defaults that the peripheral would like to have in a connection. The |
rgrover1 | 711:b2e1a2660ec2 | 317 | * choice of the connection parameters is eventually up to the central. |
rgrover1 | 711:b2e1a2660ec2 | 318 | * |
rgrover1 | 711:b2e1a2660ec2 | 319 | * @param[in] params |
rgrover1 | 711:b2e1a2660ec2 | 320 | * The structure containing the desired parameters. |
rgrover1 | 711:b2e1a2660ec2 | 321 | */ |
rgrover1 | 711:b2e1a2660ec2 | 322 | virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params) { |
vcoubard | 1049:efb29faf12fc | 323 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 735:4872b70437ce | 324 | (void)params; |
rgrover1 | 735:4872b70437ce | 325 | |
rgrover1 | 729:997ba5e7b3b6 | 326 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 327 | } |
rgrover1 | 711:b2e1a2660ec2 | 328 | |
rgrover1 | 711:b2e1a2660ec2 | 329 | /** |
rgrover1 | 817:2b4f0ef8c06e | 330 | * Update connection parameters. |
vcoubard | 1049:efb29faf12fc | 331 | * In the central role this will initiate a Link Layer connection parameter update procedure. |
vcoubard | 1049:efb29faf12fc | 332 | * In the peripheral role, this will send the corresponding L2CAP request and wait for |
rgrover1 | 817:2b4f0ef8c06e | 333 | * the central to perform the procedure. |
rgrover1 | 817:2b4f0ef8c06e | 334 | * |
rgrover1 | 711:b2e1a2660ec2 | 335 | * @param[in] handle |
vcoubard | 1049:efb29faf12fc | 336 | * Connection Handle. |
rgrover1 | 711:b2e1a2660ec2 | 337 | * @param[in] params |
rgrover1 | 711:b2e1a2660ec2 | 338 | * Pointer to desired connection parameters. If NULL is provided on a peripheral role, |
rgrover1 | 711:b2e1a2660ec2 | 339 | * the parameters in the PPCP characteristic of the GAP service will be used instead. |
rgrover1 | 711:b2e1a2660ec2 | 340 | */ |
rgrover1 | 711:b2e1a2660ec2 | 341 | virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params) { |
rgrover1 | 735:4872b70437ce | 342 | /* avoid compiler warnings about unused variables */ |
rgrover1 | 735:4872b70437ce | 343 | (void)handle; |
rgrover1 | 735:4872b70437ce | 344 | (void)params; |
rgrover1 | 735:4872b70437ce | 345 | |
rgrover1 | 729:997ba5e7b3b6 | 346 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 347 | } |
rgrover1 | 711:b2e1a2660ec2 | 348 | |
rgrover1 | 711:b2e1a2660ec2 | 349 | /** |
rgrover1 | 711:b2e1a2660ec2 | 350 | * Set the device name characteristic in the GAP service. |
rgrover1 | 711:b2e1a2660ec2 | 351 | * @param[in] deviceName |
rgrover1 | 711:b2e1a2660ec2 | 352 | * The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string. |
rgrover1 | 711:b2e1a2660ec2 | 353 | */ |
rgrover1 | 711:b2e1a2660ec2 | 354 | virtual ble_error_t setDeviceName(const uint8_t *deviceName) { |
vcoubard | 1049:efb29faf12fc | 355 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 735:4872b70437ce | 356 | (void)deviceName; |
rgrover1 | 735:4872b70437ce | 357 | |
rgrover1 | 729:997ba5e7b3b6 | 358 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 359 | } |
rgrover1 | 711:b2e1a2660ec2 | 360 | |
rgrover1 | 711:b2e1a2660ec2 | 361 | /** |
rgrover1 | 711:b2e1a2660ec2 | 362 | * Get the value of the device name characteristic in the GAP service. |
rgrover1 | 711:b2e1a2660ec2 | 363 | * @param[out] deviceName |
rgrover1 | 711:b2e1a2660ec2 | 364 | * Pointer to an empty buffer where the UTF-8 *non NULL- |
rgrover1 | 711:b2e1a2660ec2 | 365 | * terminated* string will be placed. Set this |
rgrover1 | 711:b2e1a2660ec2 | 366 | * value to NULL in order to obtain the deviceName-length |
rgrover1 | 711:b2e1a2660ec2 | 367 | * from the 'length' parameter. |
rgrover1 | 711:b2e1a2660ec2 | 368 | * |
rgrover1 | 711:b2e1a2660ec2 | 369 | * @param[in/out] lengthP |
rgrover1 | 711:b2e1a2660ec2 | 370 | * (on input) Length of the buffer pointed to by deviceName; |
rgrover1 | 711:b2e1a2660ec2 | 371 | * (on output) the complete device name length (without the |
rgrover1 | 711:b2e1a2660ec2 | 372 | * null terminator). |
rgrover1 | 711:b2e1a2660ec2 | 373 | * |
rgrover1 | 711:b2e1a2660ec2 | 374 | * @note If the device name is longer than the size of the supplied buffer, |
rgrover1 | 711:b2e1a2660ec2 | 375 | * length will return the complete device name length, and not the |
rgrover1 | 711:b2e1a2660ec2 | 376 | * number of bytes actually returned in deviceName. The application may |
rgrover1 | 711:b2e1a2660ec2 | 377 | * use this information to retry with a suitable buffer size. |
rgrover1 | 711:b2e1a2660ec2 | 378 | */ |
rgrover1 | 711:b2e1a2660ec2 | 379 | virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP) { |
rgrover1 | 735:4872b70437ce | 380 | /* avoid compiler warnings about unused variables */ |
rgrover1 | 735:4872b70437ce | 381 | (void)deviceName; |
rgrover1 | 735:4872b70437ce | 382 | (void)lengthP; |
rgrover1 | 735:4872b70437ce | 383 | |
rgrover1 | 729:997ba5e7b3b6 | 384 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 385 | } |
rgrover1 | 711:b2e1a2660ec2 | 386 | |
rgrover1 | 711:b2e1a2660ec2 | 387 | /** |
rgrover1 | 711:b2e1a2660ec2 | 388 | * Set the appearance characteristic in the GAP service. |
rgrover1 | 711:b2e1a2660ec2 | 389 | * @param[in] appearance |
rgrover1 | 711:b2e1a2660ec2 | 390 | * The new value for the device-appearance. |
rgrover1 | 711:b2e1a2660ec2 | 391 | */ |
rgrover1 | 711:b2e1a2660ec2 | 392 | virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance) { |
vcoubard | 1049:efb29faf12fc | 393 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 735:4872b70437ce | 394 | (void)appearance; |
rgrover1 | 735:4872b70437ce | 395 | |
rgrover1 | 729:997ba5e7b3b6 | 396 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 397 | } |
rgrover1 | 711:b2e1a2660ec2 | 398 | |
rgrover1 | 711:b2e1a2660ec2 | 399 | /** |
rgrover1 | 711:b2e1a2660ec2 | 400 | * Get the appearance characteristic in the GAP service. |
rgrover1 | 711:b2e1a2660ec2 | 401 | * @param[out] appearance |
rgrover1 | 711:b2e1a2660ec2 | 402 | * The new value for the device-appearance. |
rgrover1 | 711:b2e1a2660ec2 | 403 | */ |
rgrover1 | 711:b2e1a2660ec2 | 404 | virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP) { |
vcoubard | 1049:efb29faf12fc | 405 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 735:4872b70437ce | 406 | (void)appearanceP; |
rgrover1 | 735:4872b70437ce | 407 | |
rgrover1 | 729:997ba5e7b3b6 | 408 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 409 | } |
rgrover1 | 711:b2e1a2660ec2 | 410 | |
rgrover1 | 711:b2e1a2660ec2 | 411 | /** |
rgrover1 | 711:b2e1a2660ec2 | 412 | * Set the radio's transmit power. |
rgrover1 | 711:b2e1a2660ec2 | 413 | * @param[in] txPower Radio transmit power in dBm. |
rgrover1 | 711:b2e1a2660ec2 | 414 | */ |
rgrover1 | 711:b2e1a2660ec2 | 415 | virtual ble_error_t setTxPower(int8_t txPower) { |
vcoubard | 1049:efb29faf12fc | 416 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 735:4872b70437ce | 417 | (void)txPower; |
rgrover1 | 735:4872b70437ce | 418 | |
rgrover1 | 729:997ba5e7b3b6 | 419 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 420 | } |
rgrover1 | 711:b2e1a2660ec2 | 421 | |
rgrover1 | 711:b2e1a2660ec2 | 422 | /** |
rgrover1 | 711:b2e1a2660ec2 | 423 | * Query the underlying stack for permitted arguments for setTxPower(). |
rgrover1 | 711:b2e1a2660ec2 | 424 | * |
rgrover1 | 711:b2e1a2660ec2 | 425 | * @param[out] valueArrayPP |
rgrover1 | 711:b2e1a2660ec2 | 426 | * Out parameter to receive the immutable array of Tx values. |
rgrover1 | 711:b2e1a2660ec2 | 427 | * @param[out] countP |
rgrover1 | 711:b2e1a2660ec2 | 428 | * Out parameter to receive the array's size. |
rgrover1 | 711:b2e1a2660ec2 | 429 | */ |
rgrover1 | 711:b2e1a2660ec2 | 430 | virtual void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP) { |
vcoubard | 1049:efb29faf12fc | 431 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 735:4872b70437ce | 432 | (void)valueArrayPP; |
rgrover1 | 735:4872b70437ce | 433 | (void)countP; |
rgrover1 | 735:4872b70437ce | 434 | |
rgrover1 | 743:861ed7eb186d | 435 | *countP = 0; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 436 | } |
rgrover1 | 711:b2e1a2660ec2 | 437 | |
rgrover1 | 711:b2e1a2660ec2 | 438 | protected: |
rgrover1 | 711:b2e1a2660ec2 | 439 | /* Override the following in the underlying adaptation layer to provide the functionality of scanning. */ |
rgrover1 | 711:b2e1a2660ec2 | 440 | virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) { |
rgrover1 | 773:b6d27ab66c94 | 441 | (void)scanningParams; |
rgrover1 | 729:997ba5e7b3b6 | 442 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 711:b2e1a2660ec2 | 443 | } |
rgrover1 | 711:b2e1a2660ec2 | 444 | |
rgrover1 | 711:b2e1a2660ec2 | 445 | /* |
rgrover1 | 711:b2e1a2660ec2 | 446 | * APIs with non-virtual implementations. |
rgrover1 | 711:b2e1a2660ec2 | 447 | */ |
rgrover1 | 711:b2e1a2660ec2 | 448 | public: |
rgrover1 | 711:b2e1a2660ec2 | 449 | /** |
vcoubard | 1049:efb29faf12fc | 450 | * Returns the current GAP state of the device using a bitmask that |
vcoubard | 1049:efb29faf12fc | 451 | * describes whether the device is advertising or connected. |
rgrover1 | 711:b2e1a2660ec2 | 452 | */ |
rgrover1 | 711:b2e1a2660ec2 | 453 | GapState_t getState(void) const { |
rgrover1 | 711:b2e1a2660ec2 | 454 | return state; |
rgrover1 | 711:b2e1a2660ec2 | 455 | } |
rgrover1 | 711:b2e1a2660ec2 | 456 | |
rgrover1 | 711:b2e1a2660ec2 | 457 | /** |
rgrover1 | 711:b2e1a2660ec2 | 458 | * Set the GAP advertising mode to use for this device. |
rgrover1 | 711:b2e1a2660ec2 | 459 | */ |
rgrover1 | 711:b2e1a2660ec2 | 460 | void setAdvertisingType(GapAdvertisingParams::AdvertisingType_t advType) { |
rgrover1 | 711:b2e1a2660ec2 | 461 | _advParams.setAdvertisingType(advType); |
rgrover1 | 711:b2e1a2660ec2 | 462 | } |
rgrover1 | 711:b2e1a2660ec2 | 463 | |
rgrover1 | 711:b2e1a2660ec2 | 464 | /** |
rgrover1 | 711:b2e1a2660ec2 | 465 | * @param[in] interval |
rgrover1 | 711:b2e1a2660ec2 | 466 | * Advertising interval in units of milliseconds. Advertising |
rgrover1 | 711:b2e1a2660ec2 | 467 | * is disabled if interval is 0. If interval is smaller than |
rgrover1 | 711:b2e1a2660ec2 | 468 | * the minimum supported value, then the minimum supported |
rgrover1 | 711:b2e1a2660ec2 | 469 | * value is used instead. This minimum value can be discovered |
rgrover1 | 711:b2e1a2660ec2 | 470 | * using getMinAdvertisingInterval(). |
rgrover1 | 711:b2e1a2660ec2 | 471 | * |
rgrover1 | 711:b2e1a2660ec2 | 472 | * This field must be set to 0 if connectionMode is equal |
rgrover1 | 711:b2e1a2660ec2 | 473 | * to ADV_CONNECTABLE_DIRECTED. |
rgrover1 | 711:b2e1a2660ec2 | 474 | * |
rgrover1 | 711:b2e1a2660ec2 | 475 | * @note: Decreasing this value will allow central devices to detect a |
vcoubard | 1049:efb29faf12fc | 476 | * peripheral faster, at the expense of more power being used by the radio |
rgrover1 | 711:b2e1a2660ec2 | 477 | * due to the higher data transmit rate. |
rgrover1 | 711:b2e1a2660ec2 | 478 | * |
rgrover1 | 711:b2e1a2660ec2 | 479 | * @Note: [WARNING] This API previously used 0.625ms as the unit for its |
rgrover1 | 711:b2e1a2660ec2 | 480 | * 'interval' argument. That required an explicit conversion from |
rgrover1 | 711:b2e1a2660ec2 | 481 | * milliseconds using Gap::MSEC_TO_GAP_DURATION_UNITS(). This conversion is |
rgrover1 | 711:b2e1a2660ec2 | 482 | * no longer required as the new units are milliseconds. Any application |
vcoubard | 1049:efb29faf12fc | 483 | * code depending on the old semantics needs to be updated accordingly. |
rgrover1 | 711:b2e1a2660ec2 | 484 | */ |
rgrover1 | 711:b2e1a2660ec2 | 485 | void setAdvertisingInterval(uint16_t interval) { |
rgrover1 | 711:b2e1a2660ec2 | 486 | if (interval == 0) { |
rgrover1 | 711:b2e1a2660ec2 | 487 | stopAdvertising(); |
rgrover1 | 711:b2e1a2660ec2 | 488 | } else if (interval < getMinAdvertisingInterval()) { |
rgrover1 | 711:b2e1a2660ec2 | 489 | interval = getMinAdvertisingInterval(); |
rgrover1 | 711:b2e1a2660ec2 | 490 | } |
rgrover1 | 787:d6d7087d8377 | 491 | _advParams.setInterval(interval); |
rgrover1 | 711:b2e1a2660ec2 | 492 | } |
rgrover1 | 711:b2e1a2660ec2 | 493 | |
rgrover1 | 711:b2e1a2660ec2 | 494 | /** |
rgrover1 | 711:b2e1a2660ec2 | 495 | * @param[in] timeout |
rgrover1 | 711:b2e1a2660ec2 | 496 | * Advertising timeout (in seconds) between 0x1 and 0x3FFF (1 |
rgrover1 | 711:b2e1a2660ec2 | 497 | * and 16383). Use 0 to disable the advertising timeout. |
rgrover1 | 711:b2e1a2660ec2 | 498 | */ |
rgrover1 | 711:b2e1a2660ec2 | 499 | void setAdvertisingTimeout(uint16_t timeout) { |
rgrover1 | 711:b2e1a2660ec2 | 500 | _advParams.setTimeout(timeout); |
rgrover1 | 711:b2e1a2660ec2 | 501 | } |
rgrover1 | 711:b2e1a2660ec2 | 502 | |
rgrover1 | 711:b2e1a2660ec2 | 503 | /** |
rgrover1 | 711:b2e1a2660ec2 | 504 | * Start advertising. |
rgrover1 | 711:b2e1a2660ec2 | 505 | */ |
rgrover1 | 711:b2e1a2660ec2 | 506 | ble_error_t startAdvertising(void) { |
vcoubard | 1049:efb29faf12fc | 507 | setAdvertisingData(); /* Update the underlying stack. */ |
rgrover1 | 711:b2e1a2660ec2 | 508 | return startAdvertising(_advParams); |
rgrover1 | 711:b2e1a2660ec2 | 509 | } |
rgrover1 | 711:b2e1a2660ec2 | 510 | |
rgrover1 | 711:b2e1a2660ec2 | 511 | /** |
rgrover1 | 711:b2e1a2660ec2 | 512 | * Reset any advertising payload prepared from prior calls to |
rgrover1 | 711:b2e1a2660ec2 | 513 | * accumulateAdvertisingPayload(). This automatically propagates the re- |
vcoubard | 1049:efb29faf12fc | 514 | * initialized advertising payload to the underlying stack. |
rgrover1 | 711:b2e1a2660ec2 | 515 | */ |
rgrover1 | 711:b2e1a2660ec2 | 516 | void clearAdvertisingPayload(void) { |
rgrover1 | 711:b2e1a2660ec2 | 517 | _advPayload.clear(); |
rgrover1 | 711:b2e1a2660ec2 | 518 | setAdvertisingData(); |
rgrover1 | 711:b2e1a2660ec2 | 519 | } |
rgrover1 | 711:b2e1a2660ec2 | 520 | |
rgrover1 | 711:b2e1a2660ec2 | 521 | /** |
rgrover1 | 711:b2e1a2660ec2 | 522 | * Accumulate an AD structure in the advertising payload. Please note that |
rgrover1 | 711:b2e1a2660ec2 | 523 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
vcoubard | 1049:efb29faf12fc | 524 | * as an additional 31 bytes if the advertising payload is too |
rgrover1 | 711:b2e1a2660ec2 | 525 | * small. |
rgrover1 | 711:b2e1a2660ec2 | 526 | * |
rgrover1 | 711:b2e1a2660ec2 | 527 | * @param[in] flags |
rgrover1 | 711:b2e1a2660ec2 | 528 | * The flags to be added. Please refer to |
rgrover1 | 711:b2e1a2660ec2 | 529 | * GapAdvertisingData::Flags for valid flags. Multiple |
rgrover1 | 711:b2e1a2660ec2 | 530 | * flags may be specified in combination. |
rgrover1 | 711:b2e1a2660ec2 | 531 | */ |
rgrover1 | 711:b2e1a2660ec2 | 532 | ble_error_t accumulateAdvertisingPayload(uint8_t flags) { |
rgrover1 | 711:b2e1a2660ec2 | 533 | ble_error_t rc; |
rgrover1 | 711:b2e1a2660ec2 | 534 | if ((rc = _advPayload.addFlags(flags)) != BLE_ERROR_NONE) { |
rgrover1 | 711:b2e1a2660ec2 | 535 | return rc; |
rgrover1 | 711:b2e1a2660ec2 | 536 | } |
rgrover1 | 711:b2e1a2660ec2 | 537 | |
rgrover1 | 711:b2e1a2660ec2 | 538 | return setAdvertisingData(); |
rgrover1 | 711:b2e1a2660ec2 | 539 | } |
rgrover1 | 711:b2e1a2660ec2 | 540 | |
rgrover1 | 711:b2e1a2660ec2 | 541 | /** |
rgrover1 | 711:b2e1a2660ec2 | 542 | * Accumulate an AD structure in the advertising payload. Please note that |
rgrover1 | 711:b2e1a2660ec2 | 543 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
vcoubard | 1049:efb29faf12fc | 544 | * as an additional 31 bytes if the advertising payload is too |
rgrover1 | 711:b2e1a2660ec2 | 545 | * small. |
rgrover1 | 711:b2e1a2660ec2 | 546 | * |
rgrover1 | 711:b2e1a2660ec2 | 547 | * @param app |
rgrover1 | 711:b2e1a2660ec2 | 548 | * The appearance of the peripheral. |
rgrover1 | 711:b2e1a2660ec2 | 549 | */ |
rgrover1 | 711:b2e1a2660ec2 | 550 | ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app) { |
rgrover1 | 711:b2e1a2660ec2 | 551 | setAppearance(app); |
rgrover1 | 711:b2e1a2660ec2 | 552 | |
rgrover1 | 711:b2e1a2660ec2 | 553 | ble_error_t rc; |
rgrover1 | 711:b2e1a2660ec2 | 554 | if ((rc = _advPayload.addAppearance(app)) != BLE_ERROR_NONE) { |
rgrover1 | 711:b2e1a2660ec2 | 555 | return rc; |
rgrover1 | 711:b2e1a2660ec2 | 556 | } |
rgrover1 | 711:b2e1a2660ec2 | 557 | |
rgrover1 | 711:b2e1a2660ec2 | 558 | return setAdvertisingData(); |
rgrover1 | 711:b2e1a2660ec2 | 559 | } |
rgrover1 | 711:b2e1a2660ec2 | 560 | |
rgrover1 | 711:b2e1a2660ec2 | 561 | /** |
rgrover1 | 711:b2e1a2660ec2 | 562 | * Accumulate an AD structure in the advertising payload. Please note that |
rgrover1 | 711:b2e1a2660ec2 | 563 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
vcoubard | 1049:efb29faf12fc | 564 | * as an additional 31 bytes if the advertising payload is too |
rgrover1 | 711:b2e1a2660ec2 | 565 | * small. |
rgrover1 | 711:b2e1a2660ec2 | 566 | * |
vcoubard | 1049:efb29faf12fc | 567 | * @param power |
rgrover1 | 765:1e560f0d45e1 | 568 | * The max transmit power to be used by the controller (in dBm). |
rgrover1 | 711:b2e1a2660ec2 | 569 | */ |
rgrover1 | 711:b2e1a2660ec2 | 570 | ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power) { |
rgrover1 | 711:b2e1a2660ec2 | 571 | ble_error_t rc; |
rgrover1 | 711:b2e1a2660ec2 | 572 | if ((rc = _advPayload.addTxPower(power)) != BLE_ERROR_NONE) { |
rgrover1 | 711:b2e1a2660ec2 | 573 | return rc; |
rgrover1 | 711:b2e1a2660ec2 | 574 | } |
rgrover1 | 711:b2e1a2660ec2 | 575 | |
rgrover1 | 711:b2e1a2660ec2 | 576 | return setAdvertisingData(); |
rgrover1 | 711:b2e1a2660ec2 | 577 | } |
rgrover1 | 711:b2e1a2660ec2 | 578 | |
rgrover1 | 711:b2e1a2660ec2 | 579 | /** |
rgrover1 | 711:b2e1a2660ec2 | 580 | * Accumulate a variable length byte-stream as an AD structure in the |
rgrover1 | 711:b2e1a2660ec2 | 581 | * advertising payload. Please note that the payload is limited to 31 bytes. |
rgrover1 | 711:b2e1a2660ec2 | 582 | * The SCAN_RESPONSE message may be used as an additional 31 bytes if the |
vcoubard | 1049:efb29faf12fc | 583 | * advertising payload is too small. |
rgrover1 | 711:b2e1a2660ec2 | 584 | * |
vcoubard | 1049:efb29faf12fc | 585 | * @param type The type describing the variable length data. |
vcoubard | 1049:efb29faf12fc | 586 | * @param data Data bytes. |
vcoubard | 1049:efb29faf12fc | 587 | * @param len Length of data. |
rgrover1 | 711:b2e1a2660ec2 | 588 | */ |
rgrover1 | 711:b2e1a2660ec2 | 589 | ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) { |
rgrover1 | 711:b2e1a2660ec2 | 590 | if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) { |
rgrover1 | 711:b2e1a2660ec2 | 591 | setDeviceName(data); |
rgrover1 | 711:b2e1a2660ec2 | 592 | } |
rgrover1 | 711:b2e1a2660ec2 | 593 | |
rgrover1 | 711:b2e1a2660ec2 | 594 | ble_error_t rc; |
rgrover1 | 711:b2e1a2660ec2 | 595 | if ((rc = _advPayload.addData(type, data, len)) != BLE_ERROR_NONE) { |
rgrover1 | 711:b2e1a2660ec2 | 596 | return rc; |
rgrover1 | 711:b2e1a2660ec2 | 597 | } |
rgrover1 | 711:b2e1a2660ec2 | 598 | |
rgrover1 | 711:b2e1a2660ec2 | 599 | return setAdvertisingData(); |
rgrover1 | 711:b2e1a2660ec2 | 600 | } |
rgrover1 | 711:b2e1a2660ec2 | 601 | |
rgrover1 | 711:b2e1a2660ec2 | 602 | /** |
rgrover1 | 766:4cd91998cd48 | 603 | * Update a particular ADV field in the advertising payload (based on |
rgrover1 | 766:4cd91998cd48 | 604 | * matching type and length). Note: the length of the new data must be the |
rgrover1 | 766:4cd91998cd48 | 605 | * same as the old one. |
rgrover1 | 764:36c3e2b1f1ae | 606 | * |
vcoubard | 1049:efb29faf12fc | 607 | * @param[in] type The ADV type field describing the variable length data. |
vcoubard | 1049:efb29faf12fc | 608 | * @param[in] data Data bytes. |
vcoubard | 1049:efb29faf12fc | 609 | * @param[in] len Length of data. |
rgrover1 | 766:4cd91998cd48 | 610 | * |
rgrover1 | 766:4cd91998cd48 | 611 | * @note: If advertisements are enabled, then the update will take effect immediately. |
rgrover1 | 766:4cd91998cd48 | 612 | * |
rgrover1 | 766:4cd91998cd48 | 613 | * @return BLE_ERROR_NONE if the advertisement payload was updated based on |
vcoubard | 1049:efb29faf12fc | 614 | * a <type, len> match; otherwise, an appropriate error. |
rgrover1 | 764:36c3e2b1f1ae | 615 | */ |
rgrover1 | 764:36c3e2b1f1ae | 616 | ble_error_t updateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) { |
rgrover1 | 764:36c3e2b1f1ae | 617 | if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) { |
rgrover1 | 764:36c3e2b1f1ae | 618 | setDeviceName(data); |
rgrover1 | 764:36c3e2b1f1ae | 619 | } |
rgrover1 | 764:36c3e2b1f1ae | 620 | |
rgrover1 | 764:36c3e2b1f1ae | 621 | ble_error_t rc; |
rgrover1 | 764:36c3e2b1f1ae | 622 | if ((rc = _advPayload.updateData(type, data, len)) != BLE_ERROR_NONE) { |
rgrover1 | 764:36c3e2b1f1ae | 623 | return rc; |
rgrover1 | 764:36c3e2b1f1ae | 624 | } |
rgrover1 | 764:36c3e2b1f1ae | 625 | |
rgrover1 | 764:36c3e2b1f1ae | 626 | return setAdvertisingData(); |
rgrover1 | 764:36c3e2b1f1ae | 627 | } |
rgrover1 | 764:36c3e2b1f1ae | 628 | |
rgrover1 | 764:36c3e2b1f1ae | 629 | /** |
vcoubard | 1049:efb29faf12fc | 630 | * Set up a particular, user-constructed advertisement payload for the |
rgrover1 | 711:b2e1a2660ec2 | 631 | * underlying stack. It would be uncommon for this API to be used directly; |
rgrover1 | 711:b2e1a2660ec2 | 632 | * there are other APIs to build an advertisement payload (see above). |
rgrover1 | 711:b2e1a2660ec2 | 633 | */ |
rgrover1 | 711:b2e1a2660ec2 | 634 | ble_error_t setAdvertisingPayload(const GapAdvertisingData &payload) { |
rgrover1 | 711:b2e1a2660ec2 | 635 | _advPayload = payload; |
rgrover1 | 711:b2e1a2660ec2 | 636 | return setAdvertisingData(); |
rgrover1 | 711:b2e1a2660ec2 | 637 | } |
rgrover1 | 711:b2e1a2660ec2 | 638 | |
rgrover1 | 711:b2e1a2660ec2 | 639 | /** |
rgrover1 | 711:b2e1a2660ec2 | 640 | * @return Read back advertising data. Useful for storing and |
rgrover1 | 711:b2e1a2660ec2 | 641 | * restoring payload. |
rgrover1 | 711:b2e1a2660ec2 | 642 | */ |
rgrover1 | 711:b2e1a2660ec2 | 643 | const GapAdvertisingData &getAdvertisingPayload(void) const { |
rgrover1 | 711:b2e1a2660ec2 | 644 | return _advPayload; |
rgrover1 | 711:b2e1a2660ec2 | 645 | } |
rgrover1 | 711:b2e1a2660ec2 | 646 | |
rgrover1 | 711:b2e1a2660ec2 | 647 | /** |
rgrover1 | 711:b2e1a2660ec2 | 648 | * Accumulate a variable length byte-stream as an AD structure in the |
rgrover1 | 711:b2e1a2660ec2 | 649 | * scanResponse payload. |
rgrover1 | 711:b2e1a2660ec2 | 650 | * |
vcoubard | 1049:efb29faf12fc | 651 | * @param[in] type The type describing the variable length data. |
vcoubard | 1049:efb29faf12fc | 652 | * @param[in] data Data bytes. |
vcoubard | 1049:efb29faf12fc | 653 | * @param[in] len Length of data. |
rgrover1 | 711:b2e1a2660ec2 | 654 | */ |
rgrover1 | 711:b2e1a2660ec2 | 655 | ble_error_t accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) { |
rgrover1 | 711:b2e1a2660ec2 | 656 | ble_error_t rc; |
rgrover1 | 711:b2e1a2660ec2 | 657 | if ((rc = _scanResponse.addData(type, data, len)) != BLE_ERROR_NONE) { |
rgrover1 | 711:b2e1a2660ec2 | 658 | return rc; |
rgrover1 | 711:b2e1a2660ec2 | 659 | } |
rgrover1 | 711:b2e1a2660ec2 | 660 | |
rgrover1 | 711:b2e1a2660ec2 | 661 | return setAdvertisingData(); |
rgrover1 | 711:b2e1a2660ec2 | 662 | } |
rgrover1 | 711:b2e1a2660ec2 | 663 | |
rgrover1 | 711:b2e1a2660ec2 | 664 | /** |
rgrover1 | 711:b2e1a2660ec2 | 665 | * Reset any scan response prepared from prior calls to |
rgrover1 | 711:b2e1a2660ec2 | 666 | * accumulateScanResponse(). |
rgrover1 | 711:b2e1a2660ec2 | 667 | * |
rgrover1 | 711:b2e1a2660ec2 | 668 | * Note: This should be followed by a call to setAdvertisingPayload() or |
rgrover1 | 711:b2e1a2660ec2 | 669 | * startAdvertising() before the update takes effect. |
rgrover1 | 711:b2e1a2660ec2 | 670 | */ |
rgrover1 | 711:b2e1a2660ec2 | 671 | void clearScanResponse(void) { |
rgrover1 | 711:b2e1a2660ec2 | 672 | _scanResponse.clear(); |
rgrover1 | 711:b2e1a2660ec2 | 673 | setAdvertisingData(); |
rgrover1 | 711:b2e1a2660ec2 | 674 | } |
rgrover1 | 711:b2e1a2660ec2 | 675 | |
rgrover1 | 711:b2e1a2660ec2 | 676 | /** |
vcoubard | 1049:efb29faf12fc | 677 | * Set up parameters for GAP scanning (observer mode). |
rgrover1 | 711:b2e1a2660ec2 | 678 | * @param[in] interval |
rgrover1 | 711:b2e1a2660ec2 | 679 | * Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s]. |
rgrover1 | 711:b2e1a2660ec2 | 680 | * @param[in] window |
rgrover1 | 711:b2e1a2660ec2 | 681 | * Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s]. |
rgrover1 | 711:b2e1a2660ec2 | 682 | * @param[in] timeout |
vcoubard | 1049:efb29faf12fc | 683 | * Scan timeout (in seconds) between 0x0001 and 0xFFFF; 0x0000 disables the timeout. |
rgrover1 | 711:b2e1a2660ec2 | 684 | * @param[in] activeScanning |
rgrover1 | 711:b2e1a2660ec2 | 685 | * Set to True if active-scanning is required. This is used to fetch the |
rgrover1 | 711:b2e1a2660ec2 | 686 | * scan response from a peer if possible. |
rgrover1 | 711:b2e1a2660ec2 | 687 | * |
rgrover1 | 711:b2e1a2660ec2 | 688 | * The scanning window divided by the interval determines the duty cycle for |
rgrover1 | 711:b2e1a2660ec2 | 689 | * scanning. For example, if the interval is 100ms and the window is 10ms, |
rgrover1 | 711:b2e1a2660ec2 | 690 | * then the controller will scan for 10 percent of the time. It is possible |
rgrover1 | 711:b2e1a2660ec2 | 691 | * to have the interval and window set to the same value. In this case, |
rgrover1 | 711:b2e1a2660ec2 | 692 | * scanning is continuous, with a change of scanning frequency once every |
rgrover1 | 711:b2e1a2660ec2 | 693 | * interval. |
rgrover1 | 711:b2e1a2660ec2 | 694 | * |
rgrover1 | 711:b2e1a2660ec2 | 695 | * Once the scanning parameters have been configured, scanning can be |
rgrover1 | 711:b2e1a2660ec2 | 696 | * enabled by using startScan(). |
rgrover1 | 711:b2e1a2660ec2 | 697 | * |
rgrover1 | 711:b2e1a2660ec2 | 698 | * @Note: The scan interval and window are recommendations to the BLE stack. |
rgrover1 | 711:b2e1a2660ec2 | 699 | */ |
rgrover1 | 711:b2e1a2660ec2 | 700 | ble_error_t setScanParams(uint16_t interval = GapScanningParams::SCAN_INTERVAL_MAX, |
rgrover1 | 711:b2e1a2660ec2 | 701 | uint16_t window = GapScanningParams::SCAN_WINDOW_MAX, |
rgrover1 | 711:b2e1a2660ec2 | 702 | uint16_t timeout = 0, |
rgrover1 | 711:b2e1a2660ec2 | 703 | bool activeScanning = false) { |
rgrover1 | 711:b2e1a2660ec2 | 704 | ble_error_t rc; |
rgrover1 | 711:b2e1a2660ec2 | 705 | if (((rc = _scanningParams.setInterval(interval)) == BLE_ERROR_NONE) && |
rgrover1 | 711:b2e1a2660ec2 | 706 | ((rc = _scanningParams.setWindow(window)) == BLE_ERROR_NONE) && |
rgrover1 | 711:b2e1a2660ec2 | 707 | ((rc = _scanningParams.setTimeout(timeout)) == BLE_ERROR_NONE)) { |
rgrover1 | 711:b2e1a2660ec2 | 708 | _scanningParams.setActiveScanning(activeScanning); |
rgrover1 | 711:b2e1a2660ec2 | 709 | return BLE_ERROR_NONE; |
rgrover1 | 711:b2e1a2660ec2 | 710 | } |
rgrover1 | 711:b2e1a2660ec2 | 711 | |
rgrover1 | 711:b2e1a2660ec2 | 712 | return rc; |
rgrover1 | 711:b2e1a2660ec2 | 713 | } |
rgrover1 | 711:b2e1a2660ec2 | 714 | |
rgrover1 | 711:b2e1a2660ec2 | 715 | /** |
vcoubard | 1049:efb29faf12fc | 716 | * Set up the scanInterval parameter for GAP scanning (observer mode). |
rgrover1 | 711:b2e1a2660ec2 | 717 | * @param[in] interval |
rgrover1 | 711:b2e1a2660ec2 | 718 | * Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s]. |
rgrover1 | 711:b2e1a2660ec2 | 719 | * |
rgrover1 | 711:b2e1a2660ec2 | 720 | * The scanning window divided by the interval determines the duty cycle for |
rgrover1 | 711:b2e1a2660ec2 | 721 | * scanning. For example, if the interval is 100ms and the window is 10ms, |
rgrover1 | 711:b2e1a2660ec2 | 722 | * then the controller will scan for 10 percent of the time. It is possible |
rgrover1 | 711:b2e1a2660ec2 | 723 | * to have the interval and window set to the same value. In this case, |
rgrover1 | 711:b2e1a2660ec2 | 724 | * scanning is continuous, with a change of scanning frequency once every |
rgrover1 | 711:b2e1a2660ec2 | 725 | * interval. |
rgrover1 | 711:b2e1a2660ec2 | 726 | * |
rgrover1 | 711:b2e1a2660ec2 | 727 | * Once the scanning parameters have been configured, scanning can be |
rgrover1 | 711:b2e1a2660ec2 | 728 | * enabled by using startScan(). |
rgrover1 | 711:b2e1a2660ec2 | 729 | */ |
rgrover1 | 711:b2e1a2660ec2 | 730 | ble_error_t setScanInterval(uint16_t interval) { |
rgrover1 | 711:b2e1a2660ec2 | 731 | return _scanningParams.setInterval(interval); |
rgrover1 | 711:b2e1a2660ec2 | 732 | } |
rgrover1 | 711:b2e1a2660ec2 | 733 | |
rgrover1 | 711:b2e1a2660ec2 | 734 | /** |
vcoubard | 1049:efb29faf12fc | 735 | * Set up the scanWindow parameter for GAP scanning (observer mode). |
rgrover1 | 711:b2e1a2660ec2 | 736 | * @param[in] window |
rgrover1 | 711:b2e1a2660ec2 | 737 | * Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s]. |
rgrover1 | 711:b2e1a2660ec2 | 738 | * |
rgrover1 | 711:b2e1a2660ec2 | 739 | * The scanning window divided by the interval determines the duty cycle for |
rgrover1 | 711:b2e1a2660ec2 | 740 | * scanning. For example, if the interval is 100ms and the window is 10ms, |
rgrover1 | 711:b2e1a2660ec2 | 741 | * then the controller will scan for 10 percent of the time. It is possible |
rgrover1 | 711:b2e1a2660ec2 | 742 | * to have the interval and window set to the same value. In this case, |
rgrover1 | 711:b2e1a2660ec2 | 743 | * scanning is continuous, with a change of scanning frequency once every |
rgrover1 | 711:b2e1a2660ec2 | 744 | * interval. |
rgrover1 | 711:b2e1a2660ec2 | 745 | * |
rgrover1 | 711:b2e1a2660ec2 | 746 | * Once the scanning parameters have been configured, scanning can be |
rgrover1 | 711:b2e1a2660ec2 | 747 | * enabled by using startScan(). |
rgrover1 | 771:079b714e9c1a | 748 | * |
rgrover1 | 771:079b714e9c1a | 749 | * If scanning is already active, the updated value of scanWindow will be |
rgrover1 | 771:079b714e9c1a | 750 | * propagated to the underlying BLE stack. |
rgrover1 | 711:b2e1a2660ec2 | 751 | */ |
rgrover1 | 711:b2e1a2660ec2 | 752 | ble_error_t setScanWindow(uint16_t window) { |
rgrover1 | 771:079b714e9c1a | 753 | ble_error_t rc; |
rgrover1 | 771:079b714e9c1a | 754 | if ((rc = _scanningParams.setWindow(window)) != BLE_ERROR_NONE) { |
rgrover1 | 771:079b714e9c1a | 755 | return rc; |
rgrover1 | 771:079b714e9c1a | 756 | } |
rgrover1 | 771:079b714e9c1a | 757 | |
rgrover1 | 771:079b714e9c1a | 758 | /* If scanning is already active, propagate the new setting to the stack. */ |
rgrover1 | 771:079b714e9c1a | 759 | if (scanningActive) { |
rgrover1 | 771:079b714e9c1a | 760 | return startRadioScan(_scanningParams); |
rgrover1 | 771:079b714e9c1a | 761 | } |
rgrover1 | 771:079b714e9c1a | 762 | |
rgrover1 | 771:079b714e9c1a | 763 | return BLE_ERROR_NONE; |
rgrover1 | 711:b2e1a2660ec2 | 764 | } |
rgrover1 | 711:b2e1a2660ec2 | 765 | |
rgrover1 | 711:b2e1a2660ec2 | 766 | /** |
vcoubard | 1049:efb29faf12fc | 767 | * Set up parameters for GAP scanning (observer mode). |
rgrover1 | 711:b2e1a2660ec2 | 768 | * @param[in] timeout |
vcoubard | 1049:efb29faf12fc | 769 | * Scan timeout (in seconds) between 0x0001 and 0xFFFF; 0x0000 disables the timeout. |
rgrover1 | 711:b2e1a2660ec2 | 770 | * |
rgrover1 | 711:b2e1a2660ec2 | 771 | * Once the scanning parameters have been configured, scanning can be |
rgrover1 | 711:b2e1a2660ec2 | 772 | * enabled by using startScan(). |
rgrover1 | 771:079b714e9c1a | 773 | * |
rgrover1 | 771:079b714e9c1a | 774 | * If scanning is already active, the updated value of scanTimeout will be |
rgrover1 | 771:079b714e9c1a | 775 | * propagated to the underlying BLE stack. |
rgrover1 | 711:b2e1a2660ec2 | 776 | */ |
rgrover1 | 711:b2e1a2660ec2 | 777 | ble_error_t setScanTimeout(uint16_t timeout) { |
rgrover1 | 771:079b714e9c1a | 778 | ble_error_t rc; |
rgrover1 | 771:079b714e9c1a | 779 | if ((rc = _scanningParams.setTimeout(timeout)) != BLE_ERROR_NONE) { |
rgrover1 | 771:079b714e9c1a | 780 | return rc; |
rgrover1 | 771:079b714e9c1a | 781 | } |
rgrover1 | 771:079b714e9c1a | 782 | |
rgrover1 | 771:079b714e9c1a | 783 | /* If scanning is already active, propagate the new settings to the stack. */ |
rgrover1 | 771:079b714e9c1a | 784 | if (scanningActive) { |
rgrover1 | 771:079b714e9c1a | 785 | return startRadioScan(_scanningParams); |
rgrover1 | 771:079b714e9c1a | 786 | } |
rgrover1 | 771:079b714e9c1a | 787 | |
rgrover1 | 771:079b714e9c1a | 788 | return BLE_ERROR_NONE; |
rgrover1 | 711:b2e1a2660ec2 | 789 | } |
rgrover1 | 711:b2e1a2660ec2 | 790 | |
rgrover1 | 711:b2e1a2660ec2 | 791 | /** |
vcoubard | 1049:efb29faf12fc | 792 | * Set up parameters for GAP scanning (observer mode). |
rgrover1 | 711:b2e1a2660ec2 | 793 | * @param[in] activeScanning |
rgrover1 | 711:b2e1a2660ec2 | 794 | * Set to True if active-scanning is required. This is used to fetch the |
rgrover1 | 711:b2e1a2660ec2 | 795 | * scan response from a peer if possible. |
rgrover1 | 711:b2e1a2660ec2 | 796 | * |
rgrover1 | 711:b2e1a2660ec2 | 797 | * Once the scanning parameters have been configured, scanning can be |
rgrover1 | 711:b2e1a2660ec2 | 798 | * enabled by using startScan(). |
rgrover1 | 771:079b714e9c1a | 799 | * |
rgrover1 | 771:079b714e9c1a | 800 | * If scanning is already in progress, then active-scanning will be enabled |
rgrover1 | 771:079b714e9c1a | 801 | * for the underlying BLE stack. |
rgrover1 | 711:b2e1a2660ec2 | 802 | */ |
rgrover1 | 771:079b714e9c1a | 803 | ble_error_t setActiveScanning(bool activeScanning) { |
rgrover1 | 711:b2e1a2660ec2 | 804 | _scanningParams.setActiveScanning(activeScanning); |
rgrover1 | 771:079b714e9c1a | 805 | |
rgrover1 | 771:079b714e9c1a | 806 | /* If scanning is already active, propagate the new settings to the stack. */ |
rgrover1 | 771:079b714e9c1a | 807 | if (scanningActive) { |
rgrover1 | 771:079b714e9c1a | 808 | return startRadioScan(_scanningParams); |
rgrover1 | 771:079b714e9c1a | 809 | } |
rgrover1 | 771:079b714e9c1a | 810 | |
rgrover1 | 771:079b714e9c1a | 811 | return BLE_ERROR_NONE; |
rgrover1 | 711:b2e1a2660ec2 | 812 | } |
rgrover1 | 711:b2e1a2660ec2 | 813 | |
rgrover1 | 711:b2e1a2660ec2 | 814 | /** |
rgrover1 | 711:b2e1a2660ec2 | 815 | * Start scanning (Observer Procedure) based on the parameters currently in |
rgrover1 | 711:b2e1a2660ec2 | 816 | * effect. |
rgrover1 | 711:b2e1a2660ec2 | 817 | * |
rgrover1 | 711:b2e1a2660ec2 | 818 | * @param[in] callback |
vcoubard | 1049:efb29faf12fc | 819 | * The application-specific callback to be invoked upon |
rgrover1 | 711:b2e1a2660ec2 | 820 | * receiving every advertisement report. This can be passed in |
rgrover1 | 711:b2e1a2660ec2 | 821 | * as NULL, in which case scanning may not be enabled at all. |
rgrover1 | 711:b2e1a2660ec2 | 822 | */ |
rgrover1 | 711:b2e1a2660ec2 | 823 | ble_error_t startScan(void (*callback)(const AdvertisementCallbackParams_t *params)) { |
rgrover1 | 711:b2e1a2660ec2 | 824 | ble_error_t err = BLE_ERROR_NONE; |
rgrover1 | 711:b2e1a2660ec2 | 825 | if (callback) { |
rgrover1 | 711:b2e1a2660ec2 | 826 | if ((err = startRadioScan(_scanningParams)) == BLE_ERROR_NONE) { |
rgrover1 | 771:079b714e9c1a | 827 | scanningActive = true; |
rgrover1 | 711:b2e1a2660ec2 | 828 | onAdvertisementReport.attach(callback); |
rgrover1 | 711:b2e1a2660ec2 | 829 | } |
rgrover1 | 711:b2e1a2660ec2 | 830 | } |
rgrover1 | 711:b2e1a2660ec2 | 831 | |
rgrover1 | 711:b2e1a2660ec2 | 832 | return err; |
rgrover1 | 711:b2e1a2660ec2 | 833 | } |
rgrover1 | 711:b2e1a2660ec2 | 834 | |
rgrover1 | 711:b2e1a2660ec2 | 835 | /** |
rgrover1 | 711:b2e1a2660ec2 | 836 | * Same as above, but this takes an (object, method) pair for a callback. |
rgrover1 | 711:b2e1a2660ec2 | 837 | */ |
rgrover1 | 711:b2e1a2660ec2 | 838 | template<typename T> |
rgrover1 | 711:b2e1a2660ec2 | 839 | ble_error_t startScan(T *object, void (T::*callbackMember)(const AdvertisementCallbackParams_t *params)) { |
rgrover1 | 711:b2e1a2660ec2 | 840 | ble_error_t err = BLE_ERROR_NONE; |
rgrover1 | 711:b2e1a2660ec2 | 841 | if (object && callbackMember) { |
rgrover1 | 711:b2e1a2660ec2 | 842 | if ((err = startRadioScan(_scanningParams)) == BLE_ERROR_NONE) { |
rgrover1 | 771:079b714e9c1a | 843 | scanningActive = true; |
rgrover1 | 711:b2e1a2660ec2 | 844 | onAdvertisementReport.attach(object, callbackMember); |
rgrover1 | 711:b2e1a2660ec2 | 845 | } |
rgrover1 | 711:b2e1a2660ec2 | 846 | } |
rgrover1 | 711:b2e1a2660ec2 | 847 | |
rgrover1 | 711:b2e1a2660ec2 | 848 | return err; |
rgrover1 | 711:b2e1a2660ec2 | 849 | } |
rgrover1 | 711:b2e1a2660ec2 | 850 | |
rgrover1 | 754:0f60274cd3ad | 851 | /** |
rgrover1 | 754:0f60274cd3ad | 852 | * Initialize radio-notification events to be generated from the stack. |
vcoubard | 1049:efb29faf12fc | 853 | * This API doesn't need to be called directly. |
rgrover1 | 754:0f60274cd3ad | 854 | * |
rgrover1 | 754:0f60274cd3ad | 855 | * Radio Notification is a feature that enables ACTIVE and INACTIVE |
rgrover1 | 754:0f60274cd3ad | 856 | * (nACTIVE) signals from the stack that notify the application when the |
rgrover1 | 754:0f60274cd3ad | 857 | * radio is in use. |
rgrover1 | 754:0f60274cd3ad | 858 | * |
vcoubard | 1049:efb29faf12fc | 859 | * The ACTIVE signal is sent before the radio event starts. The nACTIVE |
vcoubard | 1049:efb29faf12fc | 860 | * signal is sent at the end of the radio event. These signals can be used |
rgrover1 | 754:0f60274cd3ad | 861 | * by the application programmer to synchronize application logic with radio |
rgrover1 | 754:0f60274cd3ad | 862 | * activity. For example, the ACTIVE signal can be used to shut off external |
vcoubard | 1049:efb29faf12fc | 863 | * devices, to manage peak current drawn during periods when the radio is on, |
rgrover1 | 754:0f60274cd3ad | 864 | * or to trigger sensor data collection for transmission in the Radio Event. |
rgrover1 | 754:0f60274cd3ad | 865 | * |
rgrover1 | 754:0f60274cd3ad | 866 | * @return BLE_ERROR_NONE on successful initialization, otherwise an error code. |
rgrover1 | 754:0f60274cd3ad | 867 | */ |
rgrover1 | 754:0f60274cd3ad | 868 | virtual ble_error_t initRadioNotification(void) { |
rgrover1 | 754:0f60274cd3ad | 869 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 754:0f60274cd3ad | 870 | } |
rgrover1 | 754:0f60274cd3ad | 871 | |
rgrover1 | 711:b2e1a2660ec2 | 872 | private: |
rgrover1 | 711:b2e1a2660ec2 | 873 | ble_error_t setAdvertisingData(void) { |
rgrover1 | 711:b2e1a2660ec2 | 874 | return setAdvertisingData(_advPayload, _scanResponse); |
rgrover1 | 711:b2e1a2660ec2 | 875 | } |
rgrover1 | 711:b2e1a2660ec2 | 876 | |
rgrover1 | 711:b2e1a2660ec2 | 877 | private: |
rgrover1 | 897:791741895cd8 | 878 | virtual ble_error_t setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse) = 0; |
rgrover1 | 897:791741895cd8 | 879 | virtual ble_error_t startAdvertising(const GapAdvertisingParams &) = 0; |
rgrover1 | 711:b2e1a2660ec2 | 880 | |
rgrover1 | 711:b2e1a2660ec2 | 881 | public: |
rgrover1 | 711:b2e1a2660ec2 | 882 | /** |
rgrover1 | 711:b2e1a2660ec2 | 883 | * Accessors to read back currently active advertising params. |
rgrover1 | 711:b2e1a2660ec2 | 884 | */ |
rgrover1 | 711:b2e1a2660ec2 | 885 | GapAdvertisingParams &getAdvertisingParams(void) { |
rgrover1 | 711:b2e1a2660ec2 | 886 | return _advParams; |
rgrover1 | 711:b2e1a2660ec2 | 887 | } |
rgrover1 | 711:b2e1a2660ec2 | 888 | const GapAdvertisingParams &getAdvertisingParams(void) const { |
rgrover1 | 711:b2e1a2660ec2 | 889 | return _advParams; |
rgrover1 | 711:b2e1a2660ec2 | 890 | } |
rgrover1 | 711:b2e1a2660ec2 | 891 | |
rgrover1 | 711:b2e1a2660ec2 | 892 | /** |
vcoubard | 1049:efb29faf12fc | 893 | * Set up a particular, user-constructed set of advertisement parameters for |
rgrover1 | 711:b2e1a2660ec2 | 894 | * the underlying stack. It would be uncommon for this API to be used |
rgrover1 | 711:b2e1a2660ec2 | 895 | * directly; there are other APIs to tweak advertisement parameters |
rgrover1 | 711:b2e1a2660ec2 | 896 | * individually. |
rgrover1 | 711:b2e1a2660ec2 | 897 | */ |
rgrover1 | 711:b2e1a2660ec2 | 898 | void setAdvertisingParams(const GapAdvertisingParams &newParams) { |
rgrover1 | 711:b2e1a2660ec2 | 899 | _advParams = newParams; |
rgrover1 | 711:b2e1a2660ec2 | 900 | } |
rgrover1 | 711:b2e1a2660ec2 | 901 | |
rgrover1 | 711:b2e1a2660ec2 | 902 | /* Event callback handlers. */ |
rgrover1 | 711:b2e1a2660ec2 | 903 | public: |
rgrover1 | 711:b2e1a2660ec2 | 904 | /** |
vcoubard | 1049:efb29faf12fc | 905 | * Set up a callback for timeout events. Refer to TimeoutSource_t for |
rgrover1 | 711:b2e1a2660ec2 | 906 | * possible event types. |
vcoubard | 1053:b55e1ad3e1b3 | 907 | * @note It is possible to unregister callbacks using onTimeout().detach(callback) |
rgrover1 | 711:b2e1a2660ec2 | 908 | */ |
vcoubard | 1053:b55e1ad3e1b3 | 909 | void onTimeout(TimeoutEventCallback_t callback) { |
vcoubard | 1053:b55e1ad3e1b3 | 910 | timeoutCallbackChain.add(callback); |
vcoubard | 1053:b55e1ad3e1b3 | 911 | } |
vcoubard | 1053:b55e1ad3e1b3 | 912 | |
vcoubard | 1053:b55e1ad3e1b3 | 913 | /** |
vcoubard | 1053:b55e1ad3e1b3 | 914 | * @brief provide access to the callchain of timeout event callbacks |
vcoubard | 1053:b55e1ad3e1b3 | 915 | * It is possible to register callbacks using onTimeout().add(callback); |
vcoubard | 1055:f59e5d9a992a | 916 | * It is possible to unregister callbacks using onTimeout().detach(callback) |
vcoubard | 1053:b55e1ad3e1b3 | 917 | * @return The timeout event callbacks chain |
vcoubard | 1053:b55e1ad3e1b3 | 918 | */ |
vcoubard | 1053:b55e1ad3e1b3 | 919 | TimeoutEventCallbackChain_t& onTimeout() { |
vcoubard | 1053:b55e1ad3e1b3 | 920 | return timeoutCallbackChain; |
vcoubard | 1053:b55e1ad3e1b3 | 921 | } |
rgrover1 | 711:b2e1a2660ec2 | 922 | |
rgrover1 | 711:b2e1a2660ec2 | 923 | /** |
rgrover1 | 830:9072de50087b | 924 | * Append to a chain of callbacks to be invoked upon GAP connection. |
vcoubard | 1053:b55e1ad3e1b3 | 925 | * @note It is possible to unregister callbacks using onConnection().detach(callback) |
rgrover1 | 711:b2e1a2660ec2 | 926 | */ |
rgrover1 | 830:9072de50087b | 927 | void onConnection(ConnectionEventCallback_t callback) {connectionCallChain.add(callback);} |
rgrover1 | 711:b2e1a2660ec2 | 928 | |
rgrover1 | 830:9072de50087b | 929 | template<typename T> |
rgrover1 | 830:9072de50087b | 930 | void onConnection(T *tptr, void (T::*mptr)(const ConnectionCallbackParams_t*)) {connectionCallChain.add(tptr, mptr);} |
rgrover1 | 711:b2e1a2660ec2 | 931 | |
rgrover1 | 711:b2e1a2660ec2 | 932 | /** |
vcoubard | 1053:b55e1ad3e1b3 | 933 | * @brief provide access to the callchain of connection event callbacks |
vcoubard | 1053:b55e1ad3e1b3 | 934 | * It is possible to register callbacks using onConnection().add(callback); |
vcoubard | 1055:f59e5d9a992a | 935 | * It is possible to unregister callbacks using onConnection().detach(callback) |
vcoubard | 1053:b55e1ad3e1b3 | 936 | * @return The connection event callbacks chain |
vcoubard | 1053:b55e1ad3e1b3 | 937 | */ |
vcoubard | 1055:f59e5d9a992a | 938 | ConnectionEventCallbackChain_t& onConnection() { |
vcoubard | 1053:b55e1ad3e1b3 | 939 | return connectionCallChain; |
vcoubard | 1053:b55e1ad3e1b3 | 940 | } |
vcoubard | 1053:b55e1ad3e1b3 | 941 | |
vcoubard | 1053:b55e1ad3e1b3 | 942 | /** |
rgrover1 | 830:9072de50087b | 943 | * Append to a chain of callbacks to be invoked upon GAP disconnection. |
vcoubard | 1053:b55e1ad3e1b3 | 944 | * @note It is possible to unregister callbacks using onDisconnection().detach(callback) |
rgrover1 | 817:2b4f0ef8c06e | 945 | */ |
rgrover1 | 830:9072de50087b | 946 | void onDisconnection(DisconnectionEventCallback_t callback) {disconnectionCallChain.add(callback);} |
rgrover1 | 817:2b4f0ef8c06e | 947 | |
rgrover1 | 711:b2e1a2660ec2 | 948 | template<typename T> |
rgrover1 | 830:9072de50087b | 949 | void onDisconnection(T *tptr, void (T::*mptr)(const DisconnectionCallbackParams_t*)) {disconnectionCallChain.add(tptr, mptr);} |
rgrover1 | 711:b2e1a2660ec2 | 950 | |
rgrover1 | 711:b2e1a2660ec2 | 951 | /** |
vcoubard | 1053:b55e1ad3e1b3 | 952 | * @brief provide access to the callchain of disconnection event callbacks |
vcoubard | 1053:b55e1ad3e1b3 | 953 | * It is possible to register callbacks using onDisconnection().add(callback); |
vcoubard | 1055:f59e5d9a992a | 954 | * It is possible to unregister callbacks using onDisconnection().detach(callback) |
vcoubard | 1053:b55e1ad3e1b3 | 955 | * @return The disconnection event callbacks chain |
vcoubard | 1053:b55e1ad3e1b3 | 956 | */ |
vcoubard | 1053:b55e1ad3e1b3 | 957 | DisconnectionEventCallbackChain_t& onDisconnection() { |
vcoubard | 1053:b55e1ad3e1b3 | 958 | return disconnectionCallChain; |
vcoubard | 1053:b55e1ad3e1b3 | 959 | } |
vcoubard | 1053:b55e1ad3e1b3 | 960 | |
vcoubard | 1053:b55e1ad3e1b3 | 961 | /** |
rgrover1 | 711:b2e1a2660ec2 | 962 | * Set the application callback for radio-notification events. |
rgrover1 | 711:b2e1a2660ec2 | 963 | * |
rgrover1 | 711:b2e1a2660ec2 | 964 | * Radio Notification is a feature that enables ACTIVE and INACTIVE |
rgrover1 | 711:b2e1a2660ec2 | 965 | * (nACTIVE) signals from the stack that notify the application when the |
rgrover1 | 754:0f60274cd3ad | 966 | * radio is in use. |
rgrover1 | 711:b2e1a2660ec2 | 967 | * |
vcoubard | 1049:efb29faf12fc | 968 | * The ACTIVE signal is sent before the radio event starts. The nACTIVE |
vcoubard | 1049:efb29faf12fc | 969 | * signal is sent at the end of the radio event. These signals can be used |
rgrover1 | 711:b2e1a2660ec2 | 970 | * by the application programmer to synchronize application logic with radio |
rgrover1 | 711:b2e1a2660ec2 | 971 | * activity. For example, the ACTIVE signal can be used to shut off external |
vcoubard | 1049:efb29faf12fc | 972 | * devices, to manage peak current drawn during periods when the radio is on, |
rgrover1 | 711:b2e1a2660ec2 | 973 | * or to trigger sensor data collection for transmission in the Radio Event. |
rgrover1 | 711:b2e1a2660ec2 | 974 | * |
rgrover1 | 711:b2e1a2660ec2 | 975 | * @param callback |
rgrover1 | 711:b2e1a2660ec2 | 976 | * The application handler to be invoked in response to a radio |
rgrover1 | 711:b2e1a2660ec2 | 977 | * ACTIVE/INACTIVE event. |
rgrover1 | 755:9b391fb5c5d7 | 978 | * |
vcoubard | 1049:efb29faf12fc | 979 | * Or in the other version: |
rgrover1 | 755:9b391fb5c5d7 | 980 | * |
rgrover1 | 755:9b391fb5c5d7 | 981 | * @param tptr |
rgrover1 | 755:9b391fb5c5d7 | 982 | * Pointer to the object of a class defining the member callback |
rgrover1 | 755:9b391fb5c5d7 | 983 | * function (mptr). |
rgrover1 | 755:9b391fb5c5d7 | 984 | * @param mptr |
rgrover1 | 755:9b391fb5c5d7 | 985 | * The member callback (within the context of an object) to be |
rgrover1 | 755:9b391fb5c5d7 | 986 | * invoked in response to a radio ACTIVE/INACTIVE event. |
rgrover1 | 711:b2e1a2660ec2 | 987 | */ |
rgrover1 | 754:0f60274cd3ad | 988 | void onRadioNotification(void (*callback)(bool param)) { |
rgrover1 | 754:0f60274cd3ad | 989 | radioNotificationCallback.attach(callback); |
rgrover1 | 754:0f60274cd3ad | 990 | } |
rgrover1 | 754:0f60274cd3ad | 991 | template <typename T> |
rgrover1 | 754:0f60274cd3ad | 992 | void onRadioNotification(T *tptr, void (T::*mptr)(bool)) { |
rgrover1 | 754:0f60274cd3ad | 993 | radioNotificationCallback.attach(tptr, mptr); |
rgrover1 | 754:0f60274cd3ad | 994 | } |
rgrover1 | 711:b2e1a2660ec2 | 995 | |
rgrover1 | 711:b2e1a2660ec2 | 996 | protected: |
rgrover1 | 711:b2e1a2660ec2 | 997 | Gap() : |
rgrover1 | 711:b2e1a2660ec2 | 998 | _advParams(), |
rgrover1 | 711:b2e1a2660ec2 | 999 | _advPayload(), |
rgrover1 | 711:b2e1a2660ec2 | 1000 | _scanningParams(), |
rgrover1 | 711:b2e1a2660ec2 | 1001 | _scanResponse(), |
rgrover1 | 711:b2e1a2660ec2 | 1002 | state(), |
rgrover1 | 771:079b714e9c1a | 1003 | scanningActive(false), |
vcoubard | 1053:b55e1ad3e1b3 | 1004 | timeoutCallbackChain(), |
rgrover1 | 711:b2e1a2660ec2 | 1005 | radioNotificationCallback(), |
rgrover1 | 711:b2e1a2660ec2 | 1006 | onAdvertisementReport(), |
rgrover1 | 817:2b4f0ef8c06e | 1007 | connectionCallChain(), |
rgrover1 | 711:b2e1a2660ec2 | 1008 | disconnectionCallChain() { |
rgrover1 | 711:b2e1a2660ec2 | 1009 | _advPayload.clear(); |
rgrover1 | 711:b2e1a2660ec2 | 1010 | _scanResponse.clear(); |
rgrover1 | 711:b2e1a2660ec2 | 1011 | } |
rgrover1 | 711:b2e1a2660ec2 | 1012 | |
rgrover1 | 711:b2e1a2660ec2 | 1013 | /* Entry points for the underlying stack to report events back to the user. */ |
rgrover1 | 711:b2e1a2660ec2 | 1014 | public: |
vcoubard | 1076:0d0dafb54bc9 | 1015 | void processConnectionEvent(Handle_t handle, |
vcoubard | 1076:0d0dafb54bc9 | 1016 | Role_t role, |
vcoubard | 1076:0d0dafb54bc9 | 1017 | BLEProtocol::AddressType::Type peerAddrType, |
vcoubard | 1076:0d0dafb54bc9 | 1018 | const Address_t peerAddr, |
vcoubard | 1076:0d0dafb54bc9 | 1019 | BLEProtocol::AddressType::Type ownAddrType, |
vcoubard | 1076:0d0dafb54bc9 | 1020 | const Address_t ownAddr, |
vcoubard | 1076:0d0dafb54bc9 | 1021 | const ConnectionParams_t *connectionParams) { |
rgrover1 | 711:b2e1a2660ec2 | 1022 | state.connected = 1; |
rgrover1 | 830:9072de50087b | 1023 | ConnectionCallbackParams_t callbackParams(handle, role, peerAddrType, peerAddr, ownAddrType, ownAddr, connectionParams); |
rgrover1 | 830:9072de50087b | 1024 | connectionCallChain.call(&callbackParams); |
rgrover1 | 711:b2e1a2660ec2 | 1025 | } |
rgrover1 | 711:b2e1a2660ec2 | 1026 | |
rgrover1 | 711:b2e1a2660ec2 | 1027 | void processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason) { |
rgrover1 | 711:b2e1a2660ec2 | 1028 | state.connected = 0; |
rgrover1 | 830:9072de50087b | 1029 | DisconnectionCallbackParams_t callbackParams(handle, reason); |
rgrover1 | 830:9072de50087b | 1030 | disconnectionCallChain.call(&callbackParams); |
rgrover1 | 711:b2e1a2660ec2 | 1031 | } |
rgrover1 | 711:b2e1a2660ec2 | 1032 | |
rgrover1 | 711:b2e1a2660ec2 | 1033 | void processAdvertisementReport(const Address_t peerAddr, |
rgrover1 | 711:b2e1a2660ec2 | 1034 | int8_t rssi, |
rgrover1 | 711:b2e1a2660ec2 | 1035 | bool isScanResponse, |
rgrover1 | 711:b2e1a2660ec2 | 1036 | GapAdvertisingParams::AdvertisingType_t type, |
rgrover1 | 711:b2e1a2660ec2 | 1037 | uint8_t advertisingDataLen, |
rgrover1 | 711:b2e1a2660ec2 | 1038 | const uint8_t *advertisingData) { |
rgrover1 | 711:b2e1a2660ec2 | 1039 | AdvertisementCallbackParams_t params; |
rgrover1 | 711:b2e1a2660ec2 | 1040 | memcpy(params.peerAddr, peerAddr, ADDR_LEN); |
rgrover1 | 711:b2e1a2660ec2 | 1041 | params.rssi = rssi; |
rgrover1 | 711:b2e1a2660ec2 | 1042 | params.isScanResponse = isScanResponse; |
rgrover1 | 711:b2e1a2660ec2 | 1043 | params.type = type; |
rgrover1 | 711:b2e1a2660ec2 | 1044 | params.advertisingDataLen = advertisingDataLen; |
rgrover1 | 711:b2e1a2660ec2 | 1045 | params.advertisingData = advertisingData; |
rgrover1 | 711:b2e1a2660ec2 | 1046 | onAdvertisementReport.call(¶ms); |
rgrover1 | 711:b2e1a2660ec2 | 1047 | } |
rgrover1 | 711:b2e1a2660ec2 | 1048 | |
rgrover1 | 711:b2e1a2660ec2 | 1049 | void processTimeoutEvent(TimeoutSource_t source) { |
vcoubard | 1053:b55e1ad3e1b3 | 1050 | if (timeoutCallbackChain) { |
vcoubard | 1053:b55e1ad3e1b3 | 1051 | timeoutCallbackChain(source); |
rgrover1 | 711:b2e1a2660ec2 | 1052 | } |
rgrover1 | 711:b2e1a2660ec2 | 1053 | } |
rgrover1 | 711:b2e1a2660ec2 | 1054 | |
rgrover1 | 711:b2e1a2660ec2 | 1055 | protected: |
rgrover1 | 711:b2e1a2660ec2 | 1056 | GapAdvertisingParams _advParams; |
rgrover1 | 711:b2e1a2660ec2 | 1057 | GapAdvertisingData _advPayload; |
rgrover1 | 711:b2e1a2660ec2 | 1058 | GapScanningParams _scanningParams; |
rgrover1 | 711:b2e1a2660ec2 | 1059 | GapAdvertisingData _scanResponse; |
rgrover1 | 711:b2e1a2660ec2 | 1060 | |
rgrover1 | 711:b2e1a2660ec2 | 1061 | GapState_t state; |
rgrover1 | 771:079b714e9c1a | 1062 | bool scanningActive; |
rgrover1 | 711:b2e1a2660ec2 | 1063 | |
rgrover1 | 711:b2e1a2660ec2 | 1064 | protected: |
vcoubard | 1053:b55e1ad3e1b3 | 1065 | TimeoutEventCallbackChain_t timeoutCallbackChain; |
vcoubard | 1053:b55e1ad3e1b3 | 1066 | RadioNotificationEventCallback_t radioNotificationCallback; |
vcoubard | 1053:b55e1ad3e1b3 | 1067 | AdvertisementReportCallback_t onAdvertisementReport; |
vcoubard | 1053:b55e1ad3e1b3 | 1068 | ConnectionEventCallbackChain_t connectionCallChain; |
vcoubard | 1053:b55e1ad3e1b3 | 1069 | DisconnectionEventCallbackChain_t disconnectionCallChain; |
rgrover1 | 711:b2e1a2660ec2 | 1070 | |
rgrover1 | 711:b2e1a2660ec2 | 1071 | private: |
vcoubard | 1049:efb29faf12fc | 1072 | /* Disallow copy and assignment. */ |
rgrover1 | 711:b2e1a2660ec2 | 1073 | Gap(const Gap &); |
rgrover1 | 711:b2e1a2660ec2 | 1074 | Gap& operator=(const Gap &); |
rgrover1 | 711:b2e1a2660ec2 | 1075 | }; |
rgrover1 | 711:b2e1a2660ec2 | 1076 | |
rgrover1 | 711:b2e1a2660ec2 | 1077 | #endif // ifndef __GAP_H__ |