Official Sheffield ARMBand micro:bit program
microbit/microbit-dal/BLE_API/ble/GapScanningParams.h@0:b9164b348919, 2016-10-17 (annotated)
- Committer:
- MrBedfordVan
- Date:
- Mon Oct 17 12:41:20 2016 +0000
- Revision:
- 0:b9164b348919
Official Sheffield ARMBand Micro:bit program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MrBedfordVan | 0:b9164b348919 | 1 | /* mbed Microcontroller Library |
MrBedfordVan | 0:b9164b348919 | 2 | * Copyright (c) 2006-2013 ARM Limited |
MrBedfordVan | 0:b9164b348919 | 3 | * |
MrBedfordVan | 0:b9164b348919 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
MrBedfordVan | 0:b9164b348919 | 5 | * you may not use this file except in compliance with the License. |
MrBedfordVan | 0:b9164b348919 | 6 | * You may obtain a copy of the License at |
MrBedfordVan | 0:b9164b348919 | 7 | * |
MrBedfordVan | 0:b9164b348919 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
MrBedfordVan | 0:b9164b348919 | 9 | * |
MrBedfordVan | 0:b9164b348919 | 10 | * Unless required by applicable law or agreed to in writing, software |
MrBedfordVan | 0:b9164b348919 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
MrBedfordVan | 0:b9164b348919 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
MrBedfordVan | 0:b9164b348919 | 13 | * See the License for the specific language governing permissions and |
MrBedfordVan | 0:b9164b348919 | 14 | * limitations under the License. |
MrBedfordVan | 0:b9164b348919 | 15 | */ |
MrBedfordVan | 0:b9164b348919 | 16 | |
MrBedfordVan | 0:b9164b348919 | 17 | #ifndef __GAP_SCANNING_PARAMS_H__ |
MrBedfordVan | 0:b9164b348919 | 18 | #define __GAP_SCANNING_PARAMS_H__ |
MrBedfordVan | 0:b9164b348919 | 19 | |
MrBedfordVan | 0:b9164b348919 | 20 | class GapScanningParams { |
MrBedfordVan | 0:b9164b348919 | 21 | public: |
MrBedfordVan | 0:b9164b348919 | 22 | static const unsigned SCAN_INTERVAL_MIN = 0x0004; /**< Minimum Scan interval in 625us units - 2.5ms. */ |
MrBedfordVan | 0:b9164b348919 | 23 | static const unsigned SCAN_INTERVAL_MAX = 0x4000; /**< Maximum Scan interval in 625us units - 10.24s. */ |
MrBedfordVan | 0:b9164b348919 | 24 | static const unsigned SCAN_WINDOW_MIN = 0x0004; /**< Minimum Scan window in 625us units - 2.5ms. */ |
MrBedfordVan | 0:b9164b348919 | 25 | static const unsigned SCAN_WINDOW_MAX = 0x4000; /**< Maximum Scan window in 625us units - 10.24s. */ |
MrBedfordVan | 0:b9164b348919 | 26 | static const unsigned SCAN_TIMEOUT_MIN = 0x0001; /**< Minimum Scan timeout in seconds. */ |
MrBedfordVan | 0:b9164b348919 | 27 | static const unsigned SCAN_TIMEOUT_MAX = 0xFFFF; /**< Maximum Scan timeout in seconds. */ |
MrBedfordVan | 0:b9164b348919 | 28 | |
MrBedfordVan | 0:b9164b348919 | 29 | public: |
MrBedfordVan | 0:b9164b348919 | 30 | GapScanningParams(uint16_t interval = SCAN_INTERVAL_MAX, |
MrBedfordVan | 0:b9164b348919 | 31 | uint16_t window = SCAN_WINDOW_MAX, |
MrBedfordVan | 0:b9164b348919 | 32 | uint16_t timeout = 0, |
MrBedfordVan | 0:b9164b348919 | 33 | bool activeScanning = false); |
MrBedfordVan | 0:b9164b348919 | 34 | |
MrBedfordVan | 0:b9164b348919 | 35 | static const uint16_t UNIT_0_625_MS = 625; /**< Number of microseconds in 0.625 milliseconds. */ |
MrBedfordVan | 0:b9164b348919 | 36 | static uint16_t MSEC_TO_SCAN_DURATION_UNITS(uint32_t durationInMillis) { |
MrBedfordVan | 0:b9164b348919 | 37 | return (durationInMillis * 1000) / UNIT_0_625_MS; |
MrBedfordVan | 0:b9164b348919 | 38 | } |
MrBedfordVan | 0:b9164b348919 | 39 | |
MrBedfordVan | 0:b9164b348919 | 40 | ble_error_t setInterval(uint16_t newIntervalInMS); |
MrBedfordVan | 0:b9164b348919 | 41 | |
MrBedfordVan | 0:b9164b348919 | 42 | ble_error_t setWindow(uint16_t newWindowInMS); |
MrBedfordVan | 0:b9164b348919 | 43 | |
MrBedfordVan | 0:b9164b348919 | 44 | ble_error_t setTimeout(uint16_t newTimeout); |
MrBedfordVan | 0:b9164b348919 | 45 | |
MrBedfordVan | 0:b9164b348919 | 46 | void setActiveScanning(bool activeScanning); |
MrBedfordVan | 0:b9164b348919 | 47 | |
MrBedfordVan | 0:b9164b348919 | 48 | public: |
MrBedfordVan | 0:b9164b348919 | 49 | /* @Note: The following return durations in units of 0.625ms */ |
MrBedfordVan | 0:b9164b348919 | 50 | uint16_t getInterval(void) const {return _interval;} |
MrBedfordVan | 0:b9164b348919 | 51 | uint16_t getWindow(void) const {return _window; } |
MrBedfordVan | 0:b9164b348919 | 52 | |
MrBedfordVan | 0:b9164b348919 | 53 | uint16_t getTimeout(void) const {return _timeout; } |
MrBedfordVan | 0:b9164b348919 | 54 | bool getActiveScanning(void) const {return _activeScanning;} |
MrBedfordVan | 0:b9164b348919 | 55 | |
MrBedfordVan | 0:b9164b348919 | 56 | private: |
MrBedfordVan | 0:b9164b348919 | 57 | uint16_t _interval; /**< Scan interval in units of 625us (between 2.5ms and 10.24s). */ |
MrBedfordVan | 0:b9164b348919 | 58 | uint16_t _window; /**< Scan window in units of 625us (between 2.5ms and 10.24s). */ |
MrBedfordVan | 0:b9164b348919 | 59 | uint16_t _timeout; /**< Scan timeout between 0x0001 and 0xFFFF in seconds; 0x0000 disables timeout. */ |
MrBedfordVan | 0:b9164b348919 | 60 | bool _activeScanning; /**< Obtain the peer device's advertising data and (if possible) scanResponse. */ |
MrBedfordVan | 0:b9164b348919 | 61 | |
MrBedfordVan | 0:b9164b348919 | 62 | private: |
MrBedfordVan | 0:b9164b348919 | 63 | /* Disallow copy constructor. */ |
MrBedfordVan | 0:b9164b348919 | 64 | GapScanningParams(const GapScanningParams &); |
MrBedfordVan | 0:b9164b348919 | 65 | GapScanningParams& operator =(const GapScanningParams &in); |
MrBedfordVan | 0:b9164b348919 | 66 | }; |
MrBedfordVan | 0:b9164b348919 | 67 | |
MrBedfordVan | 0:b9164b348919 | 68 | #endif // ifndef __GAP_SCANNING_PARAMS_H__ |