test

Dependents:   BLE_PowerBank_HeyFaradey

Fork of BLE_API by Bluetooth Low Energy

Committer:
vcoubard
Date:
Wed Apr 06 19:15:36 2016 +0100
Revision:
1183:1589830dbdb7
Parent:
1179:4ab722f8dca0
Synchronized with git rev 44cc6871
Author: Andres Amaya Garcia
Merge branch 'develop' into fix-doxy-warnings

Who changed what in which revision?

UserRevisionLine numberNew 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 1183:1589830dbdb7 30 /**
vcoubard 1183:1589830dbdb7 31 * Construct an instance of GapScanningParams.
vcoubard 1183:1589830dbdb7 32 *
vcoubard 1183:1589830dbdb7 33 * @param[in] interval
vcoubard 1183:1589830dbdb7 34 * The scan interval in milliseconds. Default is
vcoubard 1183:1589830dbdb7 35 * GapScanningParams::SCAN_INTERVAL_MIN.
vcoubard 1183:1589830dbdb7 36 * @param[in] window
vcoubard 1183:1589830dbdb7 37 * The scan window in milliseconds. Default is
vcoubard 1183:1589830dbdb7 38 * GapScanningParams::SCAN_WINDOW_MAX.
vcoubard 1183:1589830dbdb7 39 * @param[in] timeout
vcoubard 1183:1589830dbdb7 40 * The scan timeout in seconds. Default is 0.
vcoubard 1183:1589830dbdb7 41 * @param[in] activeScanning
vcoubard 1183:1589830dbdb7 42 * Set to True if active-scanning is required. This is used to
vcoubard 1183:1589830dbdb7 43 * fetch the scan response from a peer if possible. Default is
vcoubard 1183:1589830dbdb7 44 * false.
vcoubard 1183:1589830dbdb7 45 */
vcoubard 1173:56507890f134 46 GapScanningParams(uint16_t interval = SCAN_INTERVAL_MAX,
vcoubard 1173:56507890f134 47 uint16_t window = SCAN_WINDOW_MAX,
vcoubard 1173:56507890f134 48 uint16_t timeout = 0,
vcoubard 1173:56507890f134 49 bool activeScanning = false);
vcoubard 1173:56507890f134 50
vcoubard 1173:56507890f134 51 static const uint16_t UNIT_0_625_MS = 625; /**< Number of microseconds in 0.625 milliseconds. */
vcoubard 1183:1589830dbdb7 52 /**
vcoubard 1183:1589830dbdb7 53 * Convert milliseconds to units of 0.625ms.
vcoubard 1183:1589830dbdb7 54 *
vcoubard 1183:1589830dbdb7 55 * @param[in] durationInMillis
vcoubard 1183:1589830dbdb7 56 * The number of milliseconds to convert.
vcoubard 1183:1589830dbdb7 57 *
vcoubard 1183:1589830dbdb7 58 * @return The value of @p durationInMillis in units of 0.625ms.
vcoubard 1183:1589830dbdb7 59 */
vcoubard 1173:56507890f134 60 static uint16_t MSEC_TO_SCAN_DURATION_UNITS(uint32_t durationInMillis) {
vcoubard 1173:56507890f134 61 return (durationInMillis * 1000) / UNIT_0_625_MS;
vcoubard 1173:56507890f134 62 }
vcoubard 1173:56507890f134 63
vcoubard 1183:1589830dbdb7 64 /**
vcoubard 1183:1589830dbdb7 65 * Set the scan interval.
vcoubard 1183:1589830dbdb7 66 *
vcoubard 1183:1589830dbdb7 67 * @param[in] newIntervalInMS
vcoubard 1183:1589830dbdb7 68 * New scan interval in milliseconds.
vcoubard 1183:1589830dbdb7 69 *
vcoubard 1183:1589830dbdb7 70 * @return BLE_ERROR_NONE if the new scan interval was set successfully.
vcoubard 1183:1589830dbdb7 71 */
vcoubard 1173:56507890f134 72 ble_error_t setInterval(uint16_t newIntervalInMS);
vcoubard 1173:56507890f134 73
vcoubard 1183:1589830dbdb7 74 /**
vcoubard 1183:1589830dbdb7 75 * Set the scan window.
vcoubard 1183:1589830dbdb7 76 *
vcoubard 1183:1589830dbdb7 77 * @param[in] newWindowInMS
vcoubard 1183:1589830dbdb7 78 * New scan window in milliseconds.
vcoubard 1183:1589830dbdb7 79 *
vcoubard 1183:1589830dbdb7 80 * @return BLE_ERROR_NONE if the new scan window was set successfully.
vcoubard 1183:1589830dbdb7 81 */
vcoubard 1173:56507890f134 82 ble_error_t setWindow(uint16_t newWindowInMS);
vcoubard 1173:56507890f134 83
vcoubard 1183:1589830dbdb7 84 /**
vcoubard 1183:1589830dbdb7 85 * Set the scan timeout.
vcoubard 1183:1589830dbdb7 86 *
vcoubard 1183:1589830dbdb7 87 * @param[in] newTimeout
vcoubard 1183:1589830dbdb7 88 * New scan timeout in seconds.
vcoubard 1183:1589830dbdb7 89 *
vcoubard 1183:1589830dbdb7 90 * @return BLE_ERROR_NONE if the new scan window was set successfully.
vcoubard 1183:1589830dbdb7 91 */
vcoubard 1173:56507890f134 92 ble_error_t setTimeout(uint16_t newTimeout);
vcoubard 1173:56507890f134 93
vcoubard 1183:1589830dbdb7 94 /**
vcoubard 1183:1589830dbdb7 95 * Set active scanning. This is used to fetch the scan response from a peer
vcoubard 1183:1589830dbdb7 96 * if possible.
vcoubard 1183:1589830dbdb7 97 *
vcoubard 1183:1589830dbdb7 98 * @param[in] activeScanning
vcoubard 1183:1589830dbdb7 99 * The new boolean value of active scanning.
vcoubard 1183:1589830dbdb7 100 */
vcoubard 1183:1589830dbdb7 101 void setActiveScanning(bool activeScanning);
vcoubard 1173:56507890f134 102
vcoubard 1173:56507890f134 103 public:
vcoubard 1183:1589830dbdb7 104 /**
vcoubard 1183:1589830dbdb7 105 * Get the scan interval.
vcoubard 1183:1589830dbdb7 106 *
vcoubard 1183:1589830dbdb7 107 * @return the scan interval in units of 0.625ms.
vcoubard 1183:1589830dbdb7 108 */
vcoubard 1183:1589830dbdb7 109 uint16_t getInterval(void) const {
vcoubard 1183:1589830dbdb7 110 return _interval;
vcoubard 1183:1589830dbdb7 111 }
vcoubard 1183:1589830dbdb7 112
vcoubard 1183:1589830dbdb7 113 /**
vcoubard 1183:1589830dbdb7 114 * Get the scan window.
vcoubard 1183:1589830dbdb7 115 *
vcoubard 1183:1589830dbdb7 116 * @return the scan window in units of 0.625ms.
vcoubard 1183:1589830dbdb7 117 */
vcoubard 1183:1589830dbdb7 118 uint16_t getWindow(void) const {
vcoubard 1183:1589830dbdb7 119 return _window;
vcoubard 1183:1589830dbdb7 120 }
vcoubard 1173:56507890f134 121
vcoubard 1183:1589830dbdb7 122 /**
vcoubard 1183:1589830dbdb7 123 * Get the scan timeout.
vcoubard 1183:1589830dbdb7 124 *
vcoubard 1183:1589830dbdb7 125 * @return The scan timeout in seconds.
vcoubard 1183:1589830dbdb7 126 */
vcoubard 1183:1589830dbdb7 127 uint16_t getTimeout(void) const {
vcoubard 1183:1589830dbdb7 128 return _timeout;
vcoubard 1183:1589830dbdb7 129 }
vcoubard 1183:1589830dbdb7 130
vcoubard 1183:1589830dbdb7 131 /**
vcoubard 1183:1589830dbdb7 132 * Check whether active scanning is set.
vcoubard 1183:1589830dbdb7 133 *
vcoubard 1183:1589830dbdb7 134 * @return True if active scanning is set, false otherwise.
vcoubard 1183:1589830dbdb7 135 */
vcoubard 1183:1589830dbdb7 136 bool getActiveScanning(void) const {
vcoubard 1183:1589830dbdb7 137 return _activeScanning;
vcoubard 1183:1589830dbdb7 138 }
vcoubard 1173:56507890f134 139
vcoubard 1173:56507890f134 140 private:
vcoubard 1173:56507890f134 141 uint16_t _interval; /**< Scan interval in units of 625us (between 2.5ms and 10.24s). */
vcoubard 1173:56507890f134 142 uint16_t _window; /**< Scan window in units of 625us (between 2.5ms and 10.24s). */
vcoubard 1173:56507890f134 143 uint16_t _timeout; /**< Scan timeout between 0x0001 and 0xFFFF in seconds; 0x0000 disables timeout. */
vcoubard 1173:56507890f134 144 bool _activeScanning; /**< Obtain the peer device's advertising data and (if possible) scanResponse. */
vcoubard 1173:56507890f134 145
vcoubard 1173:56507890f134 146 private:
vcoubard 1173:56507890f134 147 /* Disallow copy constructor. */
vcoubard 1173:56507890f134 148 GapScanningParams(const GapScanningParams &);
vcoubard 1173:56507890f134 149 GapScanningParams& operator =(const GapScanningParams &in);
vcoubard 1173:56507890f134 150 };
vcoubard 1173:56507890f134 151
vcoubard 1183:1589830dbdb7 152 #endif /* ifndef __GAP_SCANNING_PARAMS_H__ */