test
Dependents: BLE_PowerBank_HeyFaradey
Fork of BLE_API by
ble/GapScanningParams.h@1179:4ab722f8dca0, 2016-04-06 (annotated)
- Committer:
- vcoubard
- Date:
- Wed Apr 06 19:15:30 2016 +0100
- Revision:
- 1179:4ab722f8dca0
- Parent:
- 1173:56507890f134
- Child:
- 1183:1589830dbdb7
Synchronized with git rev ca632aaf
Author: Andres Amaya Garcia
Update Gap state after advertising times out
The BLE API was not updating the Gap internal state when the advertising stops
because of a user timeout. This commit fixes the issue by updating the internal
state structure in Gap just before the registered callbacks are notified of the
advertising timeout.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vcoubard | 1173:56507890f134 | 1 | /* mbed Microcontroller Library |
vcoubard | 1173:56507890f134 | 2 | * Copyright (c) 2006-2013 ARM Limited |
vcoubard | 1173:56507890f134 | 3 | * |
vcoubard | 1173:56507890f134 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
vcoubard | 1173:56507890f134 | 5 | * you may not use this file except in compliance with the License. |
vcoubard | 1173:56507890f134 | 6 | * You may obtain a copy of the License at |
vcoubard | 1173:56507890f134 | 7 | * |
vcoubard | 1173:56507890f134 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
vcoubard | 1173:56507890f134 | 9 | * |
vcoubard | 1173:56507890f134 | 10 | * Unless required by applicable law or agreed to in writing, software |
vcoubard | 1173:56507890f134 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
vcoubard | 1173:56507890f134 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
vcoubard | 1173:56507890f134 | 13 | * See the License for the specific language governing permissions and |
vcoubard | 1173:56507890f134 | 14 | * limitations under the License. |
vcoubard | 1173:56507890f134 | 15 | */ |
vcoubard | 1173:56507890f134 | 16 | |
vcoubard | 1173:56507890f134 | 17 | #ifndef __GAP_SCANNING_PARAMS_H__ |
vcoubard | 1173:56507890f134 | 18 | #define __GAP_SCANNING_PARAMS_H__ |
vcoubard | 1173:56507890f134 | 19 | |
vcoubard | 1173:56507890f134 | 20 | class GapScanningParams { |
vcoubard | 1173:56507890f134 | 21 | public: |
vcoubard | 1173:56507890f134 | 22 | static const unsigned SCAN_INTERVAL_MIN = 0x0004; /**< Minimum Scan interval in 625us units - 2.5ms. */ |
vcoubard | 1173:56507890f134 | 23 | static const unsigned SCAN_INTERVAL_MAX = 0x4000; /**< Maximum Scan interval in 625us units - 10.24s. */ |
vcoubard | 1173:56507890f134 | 24 | static const unsigned SCAN_WINDOW_MIN = 0x0004; /**< Minimum Scan window in 625us units - 2.5ms. */ |
vcoubard | 1173:56507890f134 | 25 | static const unsigned SCAN_WINDOW_MAX = 0x4000; /**< Maximum Scan window in 625us units - 10.24s. */ |
vcoubard | 1173:56507890f134 | 26 | static const unsigned SCAN_TIMEOUT_MIN = 0x0001; /**< Minimum Scan timeout in seconds. */ |
vcoubard | 1173:56507890f134 | 27 | static const unsigned SCAN_TIMEOUT_MAX = 0xFFFF; /**< Maximum Scan timeout in seconds. */ |
vcoubard | 1173:56507890f134 | 28 | |
vcoubard | 1173:56507890f134 | 29 | public: |
vcoubard | 1173:56507890f134 | 30 | GapScanningParams(uint16_t interval = SCAN_INTERVAL_MAX, |
vcoubard | 1173:56507890f134 | 31 | uint16_t window = SCAN_WINDOW_MAX, |
vcoubard | 1173:56507890f134 | 32 | uint16_t timeout = 0, |
vcoubard | 1173:56507890f134 | 33 | bool activeScanning = false); |
vcoubard | 1173:56507890f134 | 34 | |
vcoubard | 1173:56507890f134 | 35 | static const uint16_t UNIT_0_625_MS = 625; /**< Number of microseconds in 0.625 milliseconds. */ |
vcoubard | 1173:56507890f134 | 36 | static uint16_t MSEC_TO_SCAN_DURATION_UNITS(uint32_t durationInMillis) { |
vcoubard | 1173:56507890f134 | 37 | return (durationInMillis * 1000) / UNIT_0_625_MS; |
vcoubard | 1173:56507890f134 | 38 | } |
vcoubard | 1173:56507890f134 | 39 | |
vcoubard | 1173:56507890f134 | 40 | ble_error_t setInterval(uint16_t newIntervalInMS); |
vcoubard | 1173:56507890f134 | 41 | |
vcoubard | 1173:56507890f134 | 42 | ble_error_t setWindow(uint16_t newWindowInMS); |
vcoubard | 1173:56507890f134 | 43 | |
vcoubard | 1173:56507890f134 | 44 | ble_error_t setTimeout(uint16_t newTimeout); |
vcoubard | 1173:56507890f134 | 45 | |
vcoubard | 1179:4ab722f8dca0 | 46 | void setActiveScanning(bool activeScanning); |
vcoubard | 1173:56507890f134 | 47 | |
vcoubard | 1173:56507890f134 | 48 | public: |
vcoubard | 1179:4ab722f8dca0 | 49 | /* @Note: The following return durations in units of 0.625ms */ |
vcoubard | 1179:4ab722f8dca0 | 50 | uint16_t getInterval(void) const {return _interval;} |
vcoubard | 1179:4ab722f8dca0 | 51 | uint16_t getWindow(void) const {return _window; } |
vcoubard | 1173:56507890f134 | 52 | |
vcoubard | 1179:4ab722f8dca0 | 53 | uint16_t getTimeout(void) const {return _timeout; } |
vcoubard | 1179:4ab722f8dca0 | 54 | bool getActiveScanning(void) const {return _activeScanning;} |
vcoubard | 1173:56507890f134 | 55 | |
vcoubard | 1173:56507890f134 | 56 | private: |
vcoubard | 1173:56507890f134 | 57 | uint16_t _interval; /**< Scan interval in units of 625us (between 2.5ms and 10.24s). */ |
vcoubard | 1173:56507890f134 | 58 | uint16_t _window; /**< Scan window in units of 625us (between 2.5ms and 10.24s). */ |
vcoubard | 1173:56507890f134 | 59 | uint16_t _timeout; /**< Scan timeout between 0x0001 and 0xFFFF in seconds; 0x0000 disables timeout. */ |
vcoubard | 1173:56507890f134 | 60 | bool _activeScanning; /**< Obtain the peer device's advertising data and (if possible) scanResponse. */ |
vcoubard | 1173:56507890f134 | 61 | |
vcoubard | 1173:56507890f134 | 62 | private: |
vcoubard | 1173:56507890f134 | 63 | /* Disallow copy constructor. */ |
vcoubard | 1173:56507890f134 | 64 | GapScanningParams(const GapScanningParams &); |
vcoubard | 1173:56507890f134 | 65 | GapScanningParams& operator =(const GapScanningParams &in); |
vcoubard | 1173:56507890f134 | 66 | }; |
vcoubard | 1173:56507890f134 | 67 | |
vcoubard | 1179:4ab722f8dca0 | 68 | #endif // ifndef __GAP_SCANNING_PARAMS_H__ |