Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

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