Minor temporary patch to allow DFU packet callback

Fork of BLE_API by Bluetooth Low Energy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GapScanningParams.h Source File

GapScanningParams.h

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 #ifndef __GAP_SCANNING_PARAMS_H__
00018 #define __GAP_SCANNING_PARAMS_H__
00019 
00020 #include "Gap.h"
00021 
00022 class GapScanningParams {
00023 public:
00024     static const unsigned SCAN_INTERVAL_MIN = 0x0004; /**< Minimum Scan interval in 625 us units, i.e. 2.5 ms. */
00025     static const unsigned SCAN_INTERVAL_MAX = 0x4000; /**< Maximum Scan interval in 625 us units, i.e. 10.24 s. */
00026     static const unsigned SCAN_WINDOW_MIN   = 0x0004; /**< Minimum Scan window in 625 us units, i.e. 2.5 ms. */
00027     static const unsigned SCAN_WINDOW_MAX   = 0x4000; /**< Maximum Scan window in 625 us units, i.e. 10.24 s. */
00028     static const unsigned SCAN_TIMEOUT_MIN  = 0x0001; /**< Minimum Scan timeout in seconds. */
00029     static const unsigned SCAN_TIMEOUT_MAX  = 0xFFFF; /**< Maximum Scan timeout in seconds. */
00030 
00031 public:
00032     GapScanningParams(uint16_t interval = SCAN_INTERVAL_MAX,
00033                       uint16_t window   = SCAN_WINDOW_MAX,
00034                       uint16_t timeout  = 0,
00035                       bool     activeScanning = false) : _interval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)),
00036                                                          _window(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(window)),
00037                                                          _timeout(timeout),
00038                                                          _activeScanning(activeScanning) {
00039         /* stay within limits */
00040         if (_interval < SCAN_INTERVAL_MIN) {
00041             _interval = SCAN_INTERVAL_MIN;
00042         }
00043         if (_interval > SCAN_INTERVAL_MAX) {
00044             _interval = SCAN_INTERVAL_MAX;
00045         }
00046         if (_window < SCAN_WINDOW_MIN) {
00047             _window = SCAN_WINDOW_MIN;
00048         }
00049         if (_window > SCAN_WINDOW_MAX) {
00050             _window = SCAN_WINDOW_MAX;
00051         }
00052         if (_timeout > SCAN_TIMEOUT_MAX) {
00053             _timeout = SCAN_TIMEOUT_MAX;
00054         }
00055     }
00056 
00057     ble_error_t setInterval(uint16_t newIntervalInMS) {
00058         uint16_t newInterval = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newIntervalInMS);
00059         if ((newInterval >= SCAN_INTERVAL_MIN) && (newInterval < SCAN_INTERVAL_MAX)) {
00060             _interval = newInterval;
00061             return BLE_ERROR_NONE;
00062         }
00063 
00064         return BLE_ERROR_PARAM_OUT_OF_RANGE;
00065     }
00066 
00067     ble_error_t setWindow(uint16_t newWindowInMS)     {
00068         uint16_t newWindow = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newWindowInMS);
00069         if ((newWindow >= SCAN_WINDOW_MIN) && (newWindow < SCAN_WINDOW_MAX)) {
00070             _window   = newWindow;
00071             return BLE_ERROR_NONE;
00072         }
00073 
00074         return BLE_ERROR_PARAM_OUT_OF_RANGE;
00075     }
00076 
00077     ble_error_t setTimeout(uint16_t newTimeout)   {
00078         if (newTimeout <= SCAN_TIMEOUT_MAX) {
00079             _timeout  = newTimeout;
00080             return BLE_ERROR_NONE;
00081         }
00082 
00083         return BLE_ERROR_PARAM_OUT_OF_RANGE;
00084     }
00085 
00086     void setActiveScanning(bool activeScanning) {
00087         _activeScanning = activeScanning;
00088     }
00089 
00090 
00091     /* @Note: The following return durations in units of 0.625 ms */
00092     uint16_t getInterval(void) const {return _interval;}
00093     uint16_t getWindow(void)   const {return _window;  }
00094 
00095     uint16_t getTimeout(void)  const {return _timeout; }
00096     bool     getActiveScanning(void) const {return _activeScanning;}
00097 
00098 private:
00099     uint16_t _interval; /**< Scan interval in units of 625us (between 2.5ms to 10.24s). */
00100     uint16_t _window;   /**< Scan window in units of 625us (between 2.5ms to 10.24s). */
00101     uint16_t _timeout;  /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
00102     bool     _activeScanning; /**< obtain not only the advertising data from the peer device, but also their scanResponse if possible. */
00103 
00104 private:
00105     /* disallow copy constructor */
00106     GapScanningParams(const GapScanningParams &);
00107     GapScanningParams& operator =(const GapScanningParams &in);
00108 };
00109 
00110 #endif // ifndef __GAP_SCANNING_PARAMS_H__