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