Preliminary main mbed library for nexpaq development
features/FEATURE_BLE/ble/GapScanningParams.h@1:d96dbedaebdb, 2016-11-04 (annotated)
- Committer:
- nexpaq
- Date:
- Fri Nov 04 20:54:50 2016 +0000
- Revision:
- 1:d96dbedaebdb
- Parent:
- 0:6c56fb4bc5f0
Removed extra directories for other platforms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 0:6c56fb4bc5f0 | 1 | /* mbed Microcontroller Library |
nexpaq | 0:6c56fb4bc5f0 | 2 | * Copyright (c) 2006-2013 ARM Limited |
nexpaq | 0:6c56fb4bc5f0 | 3 | * |
nexpaq | 0:6c56fb4bc5f0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
nexpaq | 0:6c56fb4bc5f0 | 5 | * you may not use this file except in compliance with the License. |
nexpaq | 0:6c56fb4bc5f0 | 6 | * You may obtain a copy of the License at |
nexpaq | 0:6c56fb4bc5f0 | 7 | * |
nexpaq | 0:6c56fb4bc5f0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
nexpaq | 0:6c56fb4bc5f0 | 9 | * |
nexpaq | 0:6c56fb4bc5f0 | 10 | * Unless required by applicable law or agreed to in writing, software |
nexpaq | 0:6c56fb4bc5f0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
nexpaq | 0:6c56fb4bc5f0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
nexpaq | 0:6c56fb4bc5f0 | 13 | * See the License for the specific language governing permissions and |
nexpaq | 0:6c56fb4bc5f0 | 14 | * limitations under the License. |
nexpaq | 0:6c56fb4bc5f0 | 15 | */ |
nexpaq | 0:6c56fb4bc5f0 | 16 | |
nexpaq | 0:6c56fb4bc5f0 | 17 | #ifndef __GAP_SCANNING_PARAMS_H__ |
nexpaq | 0:6c56fb4bc5f0 | 18 | #define __GAP_SCANNING_PARAMS_H__ |
nexpaq | 0:6c56fb4bc5f0 | 19 | |
nexpaq | 0:6c56fb4bc5f0 | 20 | class GapScanningParams { |
nexpaq | 0:6c56fb4bc5f0 | 21 | public: |
nexpaq | 0:6c56fb4bc5f0 | 22 | static const unsigned SCAN_INTERVAL_MIN = 0x0004; /**< Minimum Scan interval in 625us units - 2.5ms. */ |
nexpaq | 0:6c56fb4bc5f0 | 23 | static const unsigned SCAN_INTERVAL_MAX = 0x4000; /**< Maximum Scan interval in 625us units - 10.24s. */ |
nexpaq | 0:6c56fb4bc5f0 | 24 | static const unsigned SCAN_WINDOW_MIN = 0x0004; /**< Minimum Scan window in 625us units - 2.5ms. */ |
nexpaq | 0:6c56fb4bc5f0 | 25 | static const unsigned SCAN_WINDOW_MAX = 0x4000; /**< Maximum Scan window in 625us units - 10.24s. */ |
nexpaq | 0:6c56fb4bc5f0 | 26 | static const unsigned SCAN_TIMEOUT_MIN = 0x0001; /**< Minimum Scan timeout in seconds. */ |
nexpaq | 0:6c56fb4bc5f0 | 27 | static const unsigned SCAN_TIMEOUT_MAX = 0xFFFF; /**< Maximum Scan timeout in seconds. */ |
nexpaq | 0:6c56fb4bc5f0 | 28 | |
nexpaq | 0:6c56fb4bc5f0 | 29 | public: |
nexpaq | 0:6c56fb4bc5f0 | 30 | /** |
nexpaq | 0:6c56fb4bc5f0 | 31 | * Construct an instance of GapScanningParams. |
nexpaq | 0:6c56fb4bc5f0 | 32 | * |
nexpaq | 0:6c56fb4bc5f0 | 33 | * @param[in] interval |
nexpaq | 0:6c56fb4bc5f0 | 34 | * The scan interval in milliseconds. Default is |
nexpaq | 0:6c56fb4bc5f0 | 35 | * GapScanningParams::SCAN_INTERVAL_MIN. |
nexpaq | 0:6c56fb4bc5f0 | 36 | * @param[in] window |
nexpaq | 0:6c56fb4bc5f0 | 37 | * The scan window in milliseconds. Default is |
nexpaq | 0:6c56fb4bc5f0 | 38 | * GapScanningParams::SCAN_WINDOW_MAX. |
nexpaq | 0:6c56fb4bc5f0 | 39 | * @param[in] timeout |
nexpaq | 0:6c56fb4bc5f0 | 40 | * The scan timeout in seconds. Default is 0. |
nexpaq | 0:6c56fb4bc5f0 | 41 | * @param[in] activeScanning |
nexpaq | 0:6c56fb4bc5f0 | 42 | * Set to True if active-scanning is required. This is used to |
nexpaq | 0:6c56fb4bc5f0 | 43 | * fetch the scan response from a peer if possible. Default is |
nexpaq | 0:6c56fb4bc5f0 | 44 | * false. |
nexpaq | 0:6c56fb4bc5f0 | 45 | */ |
nexpaq | 0:6c56fb4bc5f0 | 46 | GapScanningParams(uint16_t interval = SCAN_INTERVAL_MAX, |
nexpaq | 0:6c56fb4bc5f0 | 47 | uint16_t window = SCAN_WINDOW_MAX, |
nexpaq | 0:6c56fb4bc5f0 | 48 | uint16_t timeout = 0, |
nexpaq | 0:6c56fb4bc5f0 | 49 | bool activeScanning = false); |
nexpaq | 0:6c56fb4bc5f0 | 50 | |
nexpaq | 0:6c56fb4bc5f0 | 51 | static const uint16_t UNIT_0_625_MS = 625; /**< Number of microseconds in 0.625 milliseconds. */ |
nexpaq | 0:6c56fb4bc5f0 | 52 | /** |
nexpaq | 0:6c56fb4bc5f0 | 53 | * Convert milliseconds to units of 0.625ms. |
nexpaq | 0:6c56fb4bc5f0 | 54 | * |
nexpaq | 0:6c56fb4bc5f0 | 55 | * @param[in] durationInMillis |
nexpaq | 0:6c56fb4bc5f0 | 56 | * The number of milliseconds to convert. |
nexpaq | 0:6c56fb4bc5f0 | 57 | * |
nexpaq | 0:6c56fb4bc5f0 | 58 | * @return The value of @p durationInMillis in units of 0.625ms. |
nexpaq | 0:6c56fb4bc5f0 | 59 | */ |
nexpaq | 0:6c56fb4bc5f0 | 60 | static uint16_t MSEC_TO_SCAN_DURATION_UNITS(uint32_t durationInMillis) { |
nexpaq | 0:6c56fb4bc5f0 | 61 | return (durationInMillis * 1000) / UNIT_0_625_MS; |
nexpaq | 0:6c56fb4bc5f0 | 62 | } |
nexpaq | 0:6c56fb4bc5f0 | 63 | |
nexpaq | 0:6c56fb4bc5f0 | 64 | /** |
nexpaq | 0:6c56fb4bc5f0 | 65 | * Set the scan interval. |
nexpaq | 0:6c56fb4bc5f0 | 66 | * |
nexpaq | 0:6c56fb4bc5f0 | 67 | * @param[in] newIntervalInMS |
nexpaq | 0:6c56fb4bc5f0 | 68 | * New scan interval in milliseconds. |
nexpaq | 0:6c56fb4bc5f0 | 69 | * |
nexpaq | 0:6c56fb4bc5f0 | 70 | * @return BLE_ERROR_NONE if the new scan interval was set successfully. |
nexpaq | 0:6c56fb4bc5f0 | 71 | */ |
nexpaq | 0:6c56fb4bc5f0 | 72 | ble_error_t setInterval(uint16_t newIntervalInMS); |
nexpaq | 0:6c56fb4bc5f0 | 73 | |
nexpaq | 0:6c56fb4bc5f0 | 74 | /** |
nexpaq | 0:6c56fb4bc5f0 | 75 | * Set the scan window. |
nexpaq | 0:6c56fb4bc5f0 | 76 | * |
nexpaq | 0:6c56fb4bc5f0 | 77 | * @param[in] newWindowInMS |
nexpaq | 0:6c56fb4bc5f0 | 78 | * New scan window in milliseconds. |
nexpaq | 0:6c56fb4bc5f0 | 79 | * |
nexpaq | 0:6c56fb4bc5f0 | 80 | * @return BLE_ERROR_NONE if the new scan window was set successfully. |
nexpaq | 0:6c56fb4bc5f0 | 81 | */ |
nexpaq | 0:6c56fb4bc5f0 | 82 | ble_error_t setWindow(uint16_t newWindowInMS); |
nexpaq | 0:6c56fb4bc5f0 | 83 | |
nexpaq | 0:6c56fb4bc5f0 | 84 | /** |
nexpaq | 0:6c56fb4bc5f0 | 85 | * Set the scan timeout. |
nexpaq | 0:6c56fb4bc5f0 | 86 | * |
nexpaq | 0:6c56fb4bc5f0 | 87 | * @param[in] newTimeout |
nexpaq | 0:6c56fb4bc5f0 | 88 | * New scan timeout in seconds. |
nexpaq | 0:6c56fb4bc5f0 | 89 | * |
nexpaq | 0:6c56fb4bc5f0 | 90 | * @return BLE_ERROR_NONE if the new scan window was set successfully. |
nexpaq | 0:6c56fb4bc5f0 | 91 | */ |
nexpaq | 0:6c56fb4bc5f0 | 92 | ble_error_t setTimeout(uint16_t newTimeout); |
nexpaq | 0:6c56fb4bc5f0 | 93 | |
nexpaq | 0:6c56fb4bc5f0 | 94 | /** |
nexpaq | 0:6c56fb4bc5f0 | 95 | * Set active scanning. This is used to fetch the scan response from a peer |
nexpaq | 0:6c56fb4bc5f0 | 96 | * if possible. |
nexpaq | 0:6c56fb4bc5f0 | 97 | * |
nexpaq | 0:6c56fb4bc5f0 | 98 | * @param[in] activeScanning |
nexpaq | 0:6c56fb4bc5f0 | 99 | * The new boolean value of active scanning. |
nexpaq | 0:6c56fb4bc5f0 | 100 | */ |
nexpaq | 0:6c56fb4bc5f0 | 101 | void setActiveScanning(bool activeScanning); |
nexpaq | 0:6c56fb4bc5f0 | 102 | |
nexpaq | 0:6c56fb4bc5f0 | 103 | public: |
nexpaq | 0:6c56fb4bc5f0 | 104 | /** |
nexpaq | 0:6c56fb4bc5f0 | 105 | * Get the scan interval. |
nexpaq | 0:6c56fb4bc5f0 | 106 | * |
nexpaq | 0:6c56fb4bc5f0 | 107 | * @return the scan interval in units of 0.625ms. |
nexpaq | 0:6c56fb4bc5f0 | 108 | */ |
nexpaq | 0:6c56fb4bc5f0 | 109 | uint16_t getInterval(void) const { |
nexpaq | 0:6c56fb4bc5f0 | 110 | return _interval; |
nexpaq | 0:6c56fb4bc5f0 | 111 | } |
nexpaq | 0:6c56fb4bc5f0 | 112 | |
nexpaq | 0:6c56fb4bc5f0 | 113 | /** |
nexpaq | 0:6c56fb4bc5f0 | 114 | * Get the scan window. |
nexpaq | 0:6c56fb4bc5f0 | 115 | * |
nexpaq | 0:6c56fb4bc5f0 | 116 | * @return the scan window in units of 0.625ms. |
nexpaq | 0:6c56fb4bc5f0 | 117 | */ |
nexpaq | 0:6c56fb4bc5f0 | 118 | uint16_t getWindow(void) const { |
nexpaq | 0:6c56fb4bc5f0 | 119 | return _window; |
nexpaq | 0:6c56fb4bc5f0 | 120 | } |
nexpaq | 0:6c56fb4bc5f0 | 121 | |
nexpaq | 0:6c56fb4bc5f0 | 122 | /** |
nexpaq | 0:6c56fb4bc5f0 | 123 | * Get the scan timeout. |
nexpaq | 0:6c56fb4bc5f0 | 124 | * |
nexpaq | 0:6c56fb4bc5f0 | 125 | * @return The scan timeout in seconds. |
nexpaq | 0:6c56fb4bc5f0 | 126 | */ |
nexpaq | 0:6c56fb4bc5f0 | 127 | uint16_t getTimeout(void) const { |
nexpaq | 0:6c56fb4bc5f0 | 128 | return _timeout; |
nexpaq | 0:6c56fb4bc5f0 | 129 | } |
nexpaq | 0:6c56fb4bc5f0 | 130 | |
nexpaq | 0:6c56fb4bc5f0 | 131 | /** |
nexpaq | 0:6c56fb4bc5f0 | 132 | * Check whether active scanning is set. |
nexpaq | 0:6c56fb4bc5f0 | 133 | * |
nexpaq | 0:6c56fb4bc5f0 | 134 | * @return True if active scanning is set, false otherwise. |
nexpaq | 0:6c56fb4bc5f0 | 135 | */ |
nexpaq | 0:6c56fb4bc5f0 | 136 | bool getActiveScanning(void) const { |
nexpaq | 0:6c56fb4bc5f0 | 137 | return _activeScanning; |
nexpaq | 0:6c56fb4bc5f0 | 138 | } |
nexpaq | 0:6c56fb4bc5f0 | 139 | |
nexpaq | 0:6c56fb4bc5f0 | 140 | private: |
nexpaq | 0:6c56fb4bc5f0 | 141 | uint16_t _interval; /**< Scan interval in units of 625us (between 2.5ms and 10.24s). */ |
nexpaq | 0:6c56fb4bc5f0 | 142 | uint16_t _window; /**< Scan window in units of 625us (between 2.5ms and 10.24s). */ |
nexpaq | 0:6c56fb4bc5f0 | 143 | uint16_t _timeout; /**< Scan timeout between 0x0001 and 0xFFFF in seconds; 0x0000 disables timeout. */ |
nexpaq | 0:6c56fb4bc5f0 | 144 | bool _activeScanning; /**< Obtain the peer device's advertising data and (if possible) scanResponse. */ |
nexpaq | 0:6c56fb4bc5f0 | 145 | |
nexpaq | 0:6c56fb4bc5f0 | 146 | private: |
nexpaq | 0:6c56fb4bc5f0 | 147 | /* Disallow copy constructor. */ |
nexpaq | 0:6c56fb4bc5f0 | 148 | GapScanningParams(const GapScanningParams &); |
nexpaq | 0:6c56fb4bc5f0 | 149 | GapScanningParams& operator =(const GapScanningParams &in); |
nexpaq | 0:6c56fb4bc5f0 | 150 | }; |
nexpaq | 0:6c56fb4bc5f0 | 151 | |
nexpaq | 0:6c56fb4bc5f0 | 152 | #endif /* ifndef __GAP_SCANNING_PARAMS_H__ */ |