we need clamping while we wait for c++17

pull/8738/head
paul-szczepanek-arm 2018-11-12 09:11:17 +00:00 committed by Vincent Coubard
parent a3820c89c5
commit 216dd6dcc7
3 changed files with 25 additions and 20 deletions

View File

@ -32,6 +32,16 @@
namespace ble { namespace ble {
/* replace with std::clamp when it arrives */
template<typename T, typename R>
void clamp(T& value, const R& min, const R& max) {
if (value > max) {
value = max;
} else if (value < min) {
value = min;
}
}
/** /**
* Opaque reference to a connection. * Opaque reference to a connection.
* *

View File

@ -22,14 +22,6 @@
#include "blecommon.h" #include "blecommon.h"
#include "SafeEnum.h" #include "SafeEnum.h"
/* TODO: std::clamp */
#define CLAMP(value, min, max) \
if (value > max) { \
value = max; \
} else if (value < min) { \
value = min; \
}
/** /**
* @addtogroup ble * @addtogroup ble
* @{ * @{
@ -140,11 +132,11 @@ public:
_maxInterval = 0; _maxInterval = 0;
} else if (_advType == ble::ADV_NON_CONNECTABLE_UNDIRECTED) { } else if (_advType == ble::ADV_NON_CONNECTABLE_UNDIRECTED) {
/* Min interval is slightly larger than in other modes. */ /* Min interval is slightly larger than in other modes. */
CLAMP(_minInterval, GAP_ADV_PARAMS_INTERVAL_MIN_NONCON, GAP_ADV_PARAMS_INTERVAL_MAX); ble::clamp(_minInterval, GAP_ADV_PARAMS_INTERVAL_MIN_NONCON, GAP_ADV_PARAMS_INTERVAL_MAX);
CLAMP(_maxInterval, GAP_ADV_PARAMS_INTERVAL_MIN_NONCON, GAP_ADV_PARAMS_INTERVAL_MAX); ble::clamp(_maxInterval, GAP_ADV_PARAMS_INTERVAL_MIN_NONCON, GAP_ADV_PARAMS_INTERVAL_MAX);
} else { } else {
CLAMP(_minInterval, GAP_ADV_PARAMS_INTERVAL_MIN, GAP_ADV_PARAMS_INTERVAL_MAX); ble::clamp(_minInterval, GAP_ADV_PARAMS_INTERVAL_MIN, GAP_ADV_PARAMS_INTERVAL_MAX);
CLAMP(_maxInterval, GAP_ADV_PARAMS_INTERVAL_MIN, GAP_ADV_PARAMS_INTERVAL_MAX); ble::clamp(_maxInterval, GAP_ADV_PARAMS_INTERVAL_MIN, GAP_ADV_PARAMS_INTERVAL_MAX);
} }
/* Timeout checks. */ /* Timeout checks. */

View File

@ -59,6 +59,9 @@ public:
_scanInterval[phy_index] = scanInterval_us / 625; _scanInterval[phy_index] = scanInterval_us / 625;
_scanWindow[phy_index] = scanWindow_us / 625; _scanWindow[phy_index] = scanWindow_us / 625;
ble::clamp(_scanInterval[phy_index], 0x0004, 0xFFFF);
ble::clamp(_scanWindow[phy_index], 0x0006, 0x0C80);
return *this; return *this;
} }
@ -274,14 +277,14 @@ private:
ble::scanning_policy_mode_t _filterPolicy; ble::scanning_policy_mode_t _filterPolicy;
ble::own_address_type_t _ownAddressType; ble::own_address_type_t _ownAddressType;
uint16_t _scanInterval[MAX_PARAM_PHYS]; /* 0.625 */ uint16_t _scanInterval[MAX_PARAM_PHYS]; /* 0.625 ms */
uint16_t _scanWindow[MAX_PARAM_PHYS]; /* 0.625 */ uint16_t _scanWindow[MAX_PARAM_PHYS]; /* 0.625 ms */
uint16_t _minConnectionInterval[MAX_PARAM_PHYS]; /* 1.25 */ uint16_t _minConnectionInterval[MAX_PARAM_PHYS]; /* 1.25 ms */
uint16_t _maxConnectionInterval[MAX_PARAM_PHYS]; /* 1.25 */ uint16_t _maxConnectionInterval[MAX_PARAM_PHYS]; /* 1.25 ms */
uint16_t _slaveLatency[MAX_PARAM_PHYS]; /* 0.625 */ uint16_t _slaveLatency[MAX_PARAM_PHYS]; /* events */
uint16_t _connectionSupervisionTimeout[MAX_PARAM_PHYS]; /* 10 */ uint16_t _connectionSupervisionTimeout[MAX_PARAM_PHYS]; /* 10 ms */
uint16_t _minEventLength[MAX_PARAM_PHYS]; /* 0.625 */ uint16_t _minEventLength[MAX_PARAM_PHYS]; /* 0.625 ms */
uint16_t _maxEventLength[MAX_PARAM_PHYS]; /* 0.625 */ uint16_t _maxEventLength[MAX_PARAM_PHYS]; /* 0.625 ms */
bool _enabledPhy[MAX_PARAM_PHYS]; bool _enabledPhy[MAX_PARAM_PHYS];
}; };