Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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