High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:53:02 2015 +0100
Revision:
674:923c47bd1547
Parent:
531:bdcd44b03974
Synchronized with git rev e74eb3b4
Author: Rohit Grover
moved GAP related members out of BLE and into GAP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 531:bdcd44b03974 1 /* mbed Microcontroller Library
rgrover1 531:bdcd44b03974 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 531:bdcd44b03974 3 *
rgrover1 531:bdcd44b03974 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 531:bdcd44b03974 5 * you may not use this file except in compliance with the License.
rgrover1 531:bdcd44b03974 6 * You may obtain a copy of the License at
rgrover1 531:bdcd44b03974 7 *
rgrover1 531:bdcd44b03974 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 531:bdcd44b03974 9 *
rgrover1 531:bdcd44b03974 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 531:bdcd44b03974 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 531:bdcd44b03974 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 531:bdcd44b03974 13 * See the License for the specific language governing permissions and
rgrover1 531:bdcd44b03974 14 * limitations under the License.
rgrover1 531:bdcd44b03974 15 */
rgrover1 531:bdcd44b03974 16
rgrover1 531:bdcd44b03974 17 #include "Gap.h"
rgrover1 531:bdcd44b03974 18 #include "GapScanningParams.h"
rgrover1 531:bdcd44b03974 19
rgrover1 531:bdcd44b03974 20 GapScanningParams::GapScanningParams(uint16_t interval, uint16_t window, uint16_t timeout, bool activeScanning) :
rgrover1 531:bdcd44b03974 21 _interval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)),
rgrover1 531:bdcd44b03974 22 _window(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(window)),
rgrover1 531:bdcd44b03974 23 _timeout(timeout),
rgrover1 531:bdcd44b03974 24 _activeScanning(activeScanning) {
rgrover1 531:bdcd44b03974 25 /* stay within limits */
rgrover1 531:bdcd44b03974 26 if (_interval < SCAN_INTERVAL_MIN) {
rgrover1 531:bdcd44b03974 27 _interval = SCAN_INTERVAL_MIN;
rgrover1 531:bdcd44b03974 28 }
rgrover1 531:bdcd44b03974 29 if (_interval > SCAN_INTERVAL_MAX) {
rgrover1 531:bdcd44b03974 30 _interval = SCAN_INTERVAL_MAX;
rgrover1 531:bdcd44b03974 31 }
rgrover1 531:bdcd44b03974 32 if (_window < SCAN_WINDOW_MIN) {
rgrover1 531:bdcd44b03974 33 _window = SCAN_WINDOW_MIN;
rgrover1 531:bdcd44b03974 34 }
rgrover1 531:bdcd44b03974 35 if (_window > SCAN_WINDOW_MAX) {
rgrover1 531:bdcd44b03974 36 _window = SCAN_WINDOW_MAX;
rgrover1 531:bdcd44b03974 37 }
rgrover1 531:bdcd44b03974 38 }
rgrover1 531:bdcd44b03974 39
rgrover1 531:bdcd44b03974 40 ble_error_t
rgrover1 531:bdcd44b03974 41 GapScanningParams::setInterval(uint16_t newIntervalInMS)
rgrover1 531:bdcd44b03974 42 {
rgrover1 531:bdcd44b03974 43 uint16_t newInterval = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newIntervalInMS);
rgrover1 531:bdcd44b03974 44 if ((newInterval >= SCAN_INTERVAL_MIN) && (newInterval < SCAN_INTERVAL_MAX)) {
rgrover1 531:bdcd44b03974 45 _interval = newInterval;
rgrover1 531:bdcd44b03974 46 return BLE_ERROR_NONE;
rgrover1 531:bdcd44b03974 47 }
rgrover1 531:bdcd44b03974 48
rgrover1 531:bdcd44b03974 49 return BLE_ERROR_PARAM_OUT_OF_RANGE;
rgrover1 531:bdcd44b03974 50 }
rgrover1 531:bdcd44b03974 51
rgrover1 531:bdcd44b03974 52 ble_error_t
rgrover1 531:bdcd44b03974 53 GapScanningParams::setWindow(uint16_t newWindowInMS)
rgrover1 531:bdcd44b03974 54 {
rgrover1 531:bdcd44b03974 55 uint16_t newWindow = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newWindowInMS);
rgrover1 531:bdcd44b03974 56 if ((newWindow >= SCAN_WINDOW_MIN) && (newWindow < SCAN_WINDOW_MAX)) {
rgrover1 531:bdcd44b03974 57 _window = newWindow;
rgrover1 531:bdcd44b03974 58 return BLE_ERROR_NONE;
rgrover1 531:bdcd44b03974 59 }
rgrover1 531:bdcd44b03974 60
rgrover1 531:bdcd44b03974 61 return BLE_ERROR_PARAM_OUT_OF_RANGE;
rgrover1 531:bdcd44b03974 62 }
rgrover1 531:bdcd44b03974 63
rgrover1 531:bdcd44b03974 64 ble_error_t
rgrover1 531:bdcd44b03974 65 GapScanningParams::setTimeout(uint16_t newTimeout)
rgrover1 531:bdcd44b03974 66 {
rgrover1 531:bdcd44b03974 67 _timeout = newTimeout;
rgrover1 531:bdcd44b03974 68 return BLE_ERROR_NONE;
rgrover1 531:bdcd44b03974 69 }
rgrover1 531:bdcd44b03974 70
rgrover1 531:bdcd44b03974 71 void
rgrover1 531:bdcd44b03974 72 GapScanningParams::setActiveScanning(bool activeScanning)
rgrover1 531:bdcd44b03974 73 {
rgrover1 531:bdcd44b03974 74 _activeScanning = activeScanning;
rgrover1 531:bdcd44b03974 75 }