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 #include "ble/Gap.h"
Simon Cooksey 0:fb7af294d5d9 18 #include "ble/GapScanningParams.h"
Simon Cooksey 0:fb7af294d5d9 19
Simon Cooksey 0:fb7af294d5d9 20 GapScanningParams::GapScanningParams(uint16_t interval, uint16_t window, uint16_t timeout, bool activeScanning) :
Simon Cooksey 0:fb7af294d5d9 21 _interval(MSEC_TO_SCAN_DURATION_UNITS(interval)),
Simon Cooksey 0:fb7af294d5d9 22 _window(MSEC_TO_SCAN_DURATION_UNITS(window)),
Simon Cooksey 0:fb7af294d5d9 23 _timeout(timeout),
Simon Cooksey 0:fb7af294d5d9 24 _activeScanning(activeScanning) {
Simon Cooksey 0:fb7af294d5d9 25 /* stay within limits */
Simon Cooksey 0:fb7af294d5d9 26 if (_interval < SCAN_INTERVAL_MIN) {
Simon Cooksey 0:fb7af294d5d9 27 _interval = SCAN_INTERVAL_MIN;
Simon Cooksey 0:fb7af294d5d9 28 }
Simon Cooksey 0:fb7af294d5d9 29 if (_interval > SCAN_INTERVAL_MAX) {
Simon Cooksey 0:fb7af294d5d9 30 _interval = SCAN_INTERVAL_MAX;
Simon Cooksey 0:fb7af294d5d9 31 }
Simon Cooksey 0:fb7af294d5d9 32 if (_window < SCAN_WINDOW_MIN) {
Simon Cooksey 0:fb7af294d5d9 33 _window = SCAN_WINDOW_MIN;
Simon Cooksey 0:fb7af294d5d9 34 }
Simon Cooksey 0:fb7af294d5d9 35 if (_window > SCAN_WINDOW_MAX) {
Simon Cooksey 0:fb7af294d5d9 36 _window = SCAN_WINDOW_MAX;
Simon Cooksey 0:fb7af294d5d9 37 }
Simon Cooksey 0:fb7af294d5d9 38 }
Simon Cooksey 0:fb7af294d5d9 39
Simon Cooksey 0:fb7af294d5d9 40 ble_error_t
Simon Cooksey 0:fb7af294d5d9 41 GapScanningParams::setInterval(uint16_t newIntervalInMS)
Simon Cooksey 0:fb7af294d5d9 42 {
Simon Cooksey 0:fb7af294d5d9 43 uint16_t newInterval = MSEC_TO_SCAN_DURATION_UNITS(newIntervalInMS);
Simon Cooksey 0:fb7af294d5d9 44 if ((newInterval >= SCAN_INTERVAL_MIN) && (newInterval < SCAN_INTERVAL_MAX)) {
Simon Cooksey 0:fb7af294d5d9 45 _interval = newInterval;
Simon Cooksey 0:fb7af294d5d9 46 return BLE_ERROR_NONE;
Simon Cooksey 0:fb7af294d5d9 47 }
Simon Cooksey 0:fb7af294d5d9 48
Simon Cooksey 0:fb7af294d5d9 49 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Simon Cooksey 0:fb7af294d5d9 50 }
Simon Cooksey 0:fb7af294d5d9 51
Simon Cooksey 0:fb7af294d5d9 52 ble_error_t
Simon Cooksey 0:fb7af294d5d9 53 GapScanningParams::setWindow(uint16_t newWindowInMS)
Simon Cooksey 0:fb7af294d5d9 54 {
Simon Cooksey 0:fb7af294d5d9 55 uint16_t newWindow = MSEC_TO_SCAN_DURATION_UNITS(newWindowInMS);
Simon Cooksey 0:fb7af294d5d9 56 if ((newWindow >= SCAN_WINDOW_MIN) && (newWindow < SCAN_WINDOW_MAX)) {
Simon Cooksey 0:fb7af294d5d9 57 _window = newWindow;
Simon Cooksey 0:fb7af294d5d9 58 return BLE_ERROR_NONE;
Simon Cooksey 0:fb7af294d5d9 59 }
Simon Cooksey 0:fb7af294d5d9 60
Simon Cooksey 0:fb7af294d5d9 61 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Simon Cooksey 0:fb7af294d5d9 62 }
Simon Cooksey 0:fb7af294d5d9 63
Simon Cooksey 0:fb7af294d5d9 64 ble_error_t
Simon Cooksey 0:fb7af294d5d9 65 GapScanningParams::setTimeout(uint16_t newTimeout)
Simon Cooksey 0:fb7af294d5d9 66 {
Simon Cooksey 0:fb7af294d5d9 67 _timeout = newTimeout;
Simon Cooksey 0:fb7af294d5d9 68 return BLE_ERROR_NONE;
Simon Cooksey 0:fb7af294d5d9 69 }
Simon Cooksey 0:fb7af294d5d9 70
Simon Cooksey 0:fb7af294d5d9 71 void
Simon Cooksey 0:fb7af294d5d9 72 GapScanningParams::setActiveScanning(bool activeScanning)
Simon Cooksey 0:fb7af294d5d9 73 {
Simon Cooksey 0:fb7af294d5d9 74 _activeScanning = activeScanning;
Simon Cooksey 0:fb7af294d5d9 75 }