High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Revision:
710:b2e1a2660ec2
Parent:
674:923c47bd1547
--- a/public/GapScanningParams.h	Fri Jun 19 15:53:06 2015 +0100
+++ b/public/GapScanningParams.h	Fri Jun 19 15:53:28 2015 +0100
@@ -17,6 +17,8 @@
 #ifndef __GAP_SCANNING_PARAMS_H__
 #define __GAP_SCANNING_PARAMS_H__
 
+#include "Gap.h"
+
 class GapScanningParams {
 public:
     static const unsigned SCAN_INTERVAL_MIN = 0x0004; /**< Minimum Scan interval in 625 us units, i.e. 2.5 ms. */
@@ -27,20 +29,58 @@
     static const unsigned SCAN_TIMEOUT_MAX  = 0xFFFF; /**< Maximum Scan timeout in seconds. */
 
 public:
-    GapScanningParams(uint16_t interval       = SCAN_INTERVAL_MAX,
-                      uint16_t window         = SCAN_WINDOW_MAX,
-                      uint16_t timeout        = 0,
-                      bool     activeScanning = false);
-
-    ble_error_t setInterval(uint16_t newIntervalInMS);
+    GapScanningParams(uint16_t interval = SCAN_INTERVAL_MAX,
+                      uint16_t window   = SCAN_WINDOW_MAX,
+                      uint16_t timeout  = 0,
+                      bool     activeScanning = false) : _interval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)),
+                                                         _window(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(window)),
+                                                         _timeout(timeout),
+                                                         _activeScanning(activeScanning) {
+        /* stay within limits */
+        if (_interval < SCAN_INTERVAL_MIN) {
+            _interval = SCAN_INTERVAL_MIN;
+        }
+        if (_interval > SCAN_INTERVAL_MAX) {
+            _interval = SCAN_INTERVAL_MAX;
+        }
+        if (_window < SCAN_WINDOW_MIN) {
+            _window = SCAN_WINDOW_MIN;
+        }
+        if (_window > SCAN_WINDOW_MAX) {
+            _window = SCAN_WINDOW_MAX;
+        }
+    }
 
-    ble_error_t setWindow(uint16_t newWindowInMS);
+    ble_error_t setInterval(uint16_t newIntervalInMS) {
+        uint16_t newInterval = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newIntervalInMS);
+        if ((newInterval >= SCAN_INTERVAL_MIN) && (newInterval < SCAN_INTERVAL_MAX)) {
+            _interval = newInterval;
+            return BLE_ERROR_NONE;
+        }
 
-    ble_error_t setTimeout(uint16_t newTimeout);
+        return BLE_ERROR_PARAM_OUT_OF_RANGE;
+    }
 
-    void        setActiveScanning(bool activeScanning);
+    ble_error_t setWindow(uint16_t newWindowInMS)     {
+        uint16_t newWindow = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newWindowInMS);
+        if ((newWindow >= SCAN_WINDOW_MIN) && (newWindow < SCAN_WINDOW_MAX)) {
+            _window   = newWindow;
+            return BLE_ERROR_NONE;
+        }
+
+        return BLE_ERROR_PARAM_OUT_OF_RANGE;
+    }
 
-public:
+    ble_error_t setTimeout(uint16_t newTimeout)   {
+        _timeout  = newTimeout;
+        return BLE_ERROR_NONE;
+    }
+
+    void setActiveScanning(bool activeScanning) {
+        _activeScanning = activeScanning;
+    }
+
+
     /* @Note: The following return durations in units of 0.625 ms */
     uint16_t getInterval(void) const {return _interval;}
     uint16_t getWindow(void)   const {return _window;  }