adaptation for book and plug demo

Dependents:   BookAndPlug

Fork of BLE_API by Bluetooth Low Energy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GapScanningParams.cpp Source File

GapScanningParams.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "ble/Gap.h"
00018 #include "ble/GapScanningParams.h"
00019 
00020 GapScanningParams::GapScanningParams(uint16_t interval, uint16_t window, uint16_t timeout, bool activeScanning) :
00021     _interval(MSEC_TO_SCAN_DURATION_UNITS(interval)),
00022     _window(MSEC_TO_SCAN_DURATION_UNITS(window)),
00023     _timeout(timeout),
00024     _activeScanning(activeScanning) {
00025     /* stay within limits */
00026     if (_interval < SCAN_INTERVAL_MIN) {
00027         _interval = SCAN_INTERVAL_MIN;
00028     }
00029     if (_interval > SCAN_INTERVAL_MAX) {
00030         _interval = SCAN_INTERVAL_MAX;
00031     }
00032     if (_window < SCAN_WINDOW_MIN) {
00033         _window = SCAN_WINDOW_MIN;
00034     }
00035     if (_window > SCAN_WINDOW_MAX) {
00036         _window = SCAN_WINDOW_MAX;
00037     }
00038 }
00039 
00040 ble_error_t
00041 GapScanningParams::setInterval(uint16_t newIntervalInMS)
00042 {
00043     uint16_t newInterval = MSEC_TO_SCAN_DURATION_UNITS(newIntervalInMS);
00044     if ((newInterval >= SCAN_INTERVAL_MIN) && (newInterval < SCAN_INTERVAL_MAX)) {
00045         _interval = newInterval;
00046         return BLE_ERROR_NONE;
00047     }
00048 
00049     return BLE_ERROR_PARAM_OUT_OF_RANGE;
00050 }
00051 
00052 ble_error_t
00053 GapScanningParams::setWindow(uint16_t newWindowInMS)
00054 {
00055     uint16_t newWindow = MSEC_TO_SCAN_DURATION_UNITS(newWindowInMS);
00056     if ((newWindow >= SCAN_WINDOW_MIN) && (newWindow < SCAN_WINDOW_MAX)) {
00057         _window   = newWindow;
00058         return BLE_ERROR_NONE;
00059     }
00060 
00061     return BLE_ERROR_PARAM_OUT_OF_RANGE;
00062 }
00063 
00064 ble_error_t
00065 GapScanningParams::setTimeout(uint16_t newTimeout)
00066 {
00067     _timeout  = newTimeout;
00068     return BLE_ERROR_NONE;
00069 }
00070 
00071 void
00072 GapScanningParams::setActiveScanning(bool activeScanning)
00073 {
00074     _activeScanning = activeScanning;
00075 }