BLE: remove not required prefixes in ble::ConnectionParameters.

pull/8738/head
Vincent Coubard 2018-11-15 15:45:58 +00:00
parent c1cd5ede84
commit 7123364674
1 changed files with 60 additions and 73 deletions

View File

@ -34,7 +34,7 @@ class ConnectionParameters {
public: public:
ConnectionParameters() : ConnectionParameters() :
_filterPolicy(initiator_filter_policy_t::NO_FILTER), _filterPolicy(initiator_filter_policy_t::NO_FILTER),
_ownAddressType(ble::own_address_type_t::PUBLIC) _ownAddressType(own_address_type_t::PUBLIC)
{ {
for (uint8_t i = 0; i < MAX_PARAM_PHYS; ++i) { for (uint8_t i = 0; i < MAX_PARAM_PHYS; ++i) {
_scanInterval[i] = 4; _scanInterval[i] = 4;
@ -52,9 +52,9 @@ public:
/* setters */ /* setters */
ConnectionParameters &setScanParameters( ConnectionParameters &setScanParameters(
ble::scan_interval_t scanInterval, scan_interval_t scanInterval,
ble::scan_window_t scanWindow, scan_window_t scanWindow,
ble::phy_t phy = ble::phy_t::LE_1M phy_t phy = phy_t::LE_1M
) )
{ {
uint8_t phy_index = handlePhyToggle(phy, true); uint8_t phy_index = handlePhyToggle(phy, true);
@ -66,15 +66,13 @@ public:
} }
ConnectionParameters &setConnectionParameters( ConnectionParameters &setConnectionParameters(
ble::conn_interval_t minConnectionInterval, conn_interval_t minConnectionInterval,
ble::conn_interval_t maxConnectionInterval, conn_interval_t maxConnectionInterval,
ble::slave_latency_t slaveLatency, slave_latency_t slaveLatency,
ble::supervision_timeout_t connectionSupervisionTimeout, supervision_timeout_t connectionSupervisionTimeout,
ble::phy_t phy = ble::phy_t::LE_1M, phy_t phy = phy_t::LE_1M,
ble::conn_event_length_t minEventLength = ble::conn_event_length_t(0), conn_event_length_t minEventLength = conn_event_length_t(0),
ble::conn_event_length_t maxEventLength = ble::conn_event_length_t( conn_event_length_t maxEventLength = conn_event_length_t(0xFFFF)
0xFFFF
)
) )
{ {
uint8_t phy_index = handlePhyToggle(phy, true); uint8_t phy_index = handlePhyToggle(phy, true);
@ -95,9 +93,7 @@ public:
return *this; return *this;
} }
ConnectionParameters &setOwnAddressType( ConnectionParameters &setOwnAddressType(own_address_type_t ownAddress)
ble::own_address_type_t ownAddress
)
{ {
_ownAddressType = ownAddress; _ownAddressType = ownAddress;
@ -111,31 +107,23 @@ public:
return *this; return *this;
} }
ConnectionParameters &togglePhy( ConnectionParameters &togglePhy(bool phy1M, bool phy2M, bool phyCoded)
bool phy1M,
bool phy2M,
bool phyCoded
)
{ {
handlePhyToggle(ble::phy_t::LE_1M, phy1M); handlePhyToggle(phy_t::LE_1M, phy1M);
handlePhyToggle(ble::phy_t::LE_2M, phy2M); handlePhyToggle(phy_t::LE_2M, phy2M);
handlePhyToggle(ble::phy_t::LE_CODED, phyCoded); handlePhyToggle(phy_t::LE_CODED, phyCoded);
return *this; return *this;
} }
ConnectionParameters &disablePhy( ConnectionParameters &disablePhy(phy_t phy = phy_t::LE_1M)
ble::phy_t phy = ble::phy_t::LE_1M
)
{ {
handlePhyToggle(phy, false); handlePhyToggle(phy, false);
return *this; return *this;
} }
ConnectionParameters &enablePhy( ConnectionParameters &enablePhy(phy_t phy = phy_t::LE_1M)
ble::phy_t phy = ble::phy_t::LE_1M
)
{ {
handlePhyToggle(phy, true); handlePhyToggle(phy, true);
@ -144,7 +132,7 @@ public:
/* getters */ /* getters */
ble::own_address_type_t getOwnAddressType() const own_address_type_t getOwnAddressType() const
{ {
return _ownAddressType; return _ownAddressType;
} }
@ -157,18 +145,18 @@ public:
uint8_t getNumberOfEnabledPhys() const uint8_t getNumberOfEnabledPhys() const
{ {
return ( return (
_enabledPhy[ble::phy_t::LE_1M] * 1 + _enabledPhy[phy_t::LE_1M] * 1 +
_enabledPhy[ble::phy_t::LE_2M] * 1 + _enabledPhy[phy_t::LE_2M] * 1 +
_enabledPhy[ble::phy_t::LE_CODED] * 1 _enabledPhy[phy_t::LE_CODED] * 1
); );
} }
uint8_t getPhySet() const uint8_t getPhySet() const
{ {
ble::phy_set_t set( phy_set_t set(
_enabledPhy[ble::phy_t::LE_1M], _enabledPhy[phy_t::LE_1M],
_enabledPhy[ble::phy_t::LE_2M], _enabledPhy[phy_t::LE_2M],
_enabledPhy[ble::phy_t::LE_CODED] _enabledPhy[phy_t::LE_CODED]
); );
return set.value(); return set.value();
} }
@ -218,17 +206,16 @@ public:
private: private:
uint8_t getFirstEnabledIndex() const uint8_t getFirstEnabledIndex() const
{ {
if (_enabledPhy[ble::phy_t::LE_1M]) { if (_enabledPhy[phy_t::LE_1M]) {
return 0; return 0;
} else if (_enabledPhy[ble::phy_t::LE_2M]) { } else if (_enabledPhy[phy_t::LE_2M]) {
return 1; return 1;
} else if (_enabledPhy[ble::phy_t::LE_CODED]) { } else if (_enabledPhy[phy_t::LE_CODED]) {
return 2; return 2;
} }
/* this should never happen, it means you were trying to start a connection with a blank set /* this should never happen, it means you were trying to start a connection with a blank set
* of paramters - you need to enabled at least one phy */ * of paramters - you need to enabled at least one phy */
MBED_ASSERT( MBED_ASSERT("Trying to use connection parameters without any PHY defined.");
"Trying to use connection parameters without any PHY defined.");
return 0; return 0;
} }
@ -238,7 +225,7 @@ private:
* @param enable On or Off. * @param enable On or Off.
* @return The index to the array of settings. * @return The index to the array of settings.
*/ */
uint8_t handlePhyToggle(ble::phy_t phy, bool enable) uint8_t handlePhyToggle(phy_t phy, bool enable)
{ {
uint8_t index = phy.value(); uint8_t index = phy.value();
@ -259,7 +246,7 @@ private:
swapCodedAnd2M(); swapCodedAnd2M();
} }
if (is_swapped && phy == ble::phy_t::LE_CODED) { if (is_swapped && phy == phy_t::LE_CODED) {
index -= 1; index -= 1;
} }
@ -269,46 +256,46 @@ private:
bool isSwapped() const bool isSwapped() const
{ {
return ( return (
_enabledPhy[ble::phy_t::LE_1M] && _enabledPhy[phy_t::LE_1M] &&
!_enabledPhy[ble::phy_t::LE_2M] && !_enabledPhy[phy_t::LE_2M] &&
_enabledPhy[ble::phy_t::LE_CODED] _enabledPhy[phy_t::LE_CODED]
); );
} }
/** Handle the swapping of 2M and CODED so that the array is ready for the pal call. */ /** Handle the swapping of 2M and CODED so that the array is ready for the pal call. */
void swapCodedAnd2M() void swapCodedAnd2M()
{ {
uint16_t scanInterval = _scanInterval[ble::phy_t::LE_2M]; uint16_t scanInterval = _scanInterval[phy_t::LE_2M];
uint16_t scanWindow = _scanWindow[ble::phy_t::LE_2M]; uint16_t scanWindow = _scanWindow[phy_t::LE_2M];
uint16_t minConnectionInterval = _minConnectionInterval[ble::phy_t::LE_2M]; uint16_t minConnectionInterval = _minConnectionInterval[phy_t::LE_2M];
uint16_t maxConnectionInterval = _maxConnectionInterval[ble::phy_t::LE_2M]; uint16_t maxConnectionInterval = _maxConnectionInterval[phy_t::LE_2M];
uint16_t slaveLatency = _maxConnectionInterval[ble::phy_t::LE_2M]; uint16_t slaveLatency = _maxConnectionInterval[phy_t::LE_2M];
uint16_t connectionSupervisionTimeout = _connectionSupervisionTimeout[ble::phy_t::LE_2M]; uint16_t connectionSupervisionTimeout = _connectionSupervisionTimeout[phy_t::LE_2M];
uint16_t minEventLength = _minEventLength[ble::phy_t::LE_2M]; uint16_t minEventLength = _minEventLength[phy_t::LE_2M];
uint16_t maxEventLength = _maxEventLength[ble::phy_t::LE_2M]; uint16_t maxEventLength = _maxEventLength[phy_t::LE_2M];
_scanInterval[ble::phy_t::LE_2M] = _scanInterval[ble::phy_t::LE_CODED]; _scanInterval[phy_t::LE_2M] = _scanInterval[phy_t::LE_CODED];
_scanWindow[ble::phy_t::LE_2M] = _scanWindow[ble::phy_t::LE_CODED]; _scanWindow[phy_t::LE_2M] = _scanWindow[phy_t::LE_CODED];
_minConnectionInterval[ble::phy_t::LE_2M] = _minConnectionInterval[ble::phy_t::LE_CODED]; _minConnectionInterval[phy_t::LE_2M] = _minConnectionInterval[phy_t::LE_CODED];
_maxConnectionInterval[ble::phy_t::LE_2M] = _maxConnectionInterval[ble::phy_t::LE_CODED]; _maxConnectionInterval[phy_t::LE_2M] = _maxConnectionInterval[phy_t::LE_CODED];
_slaveLatency[ble::phy_t::LE_2M] = _slaveLatency[ble::phy_t::LE_CODED]; _slaveLatency[phy_t::LE_2M] = _slaveLatency[phy_t::LE_CODED];
_connectionSupervisionTimeout[ble::phy_t::LE_2M] = _connectionSupervisionTimeout[ble::phy_t::LE_CODED]; _connectionSupervisionTimeout[phy_t::LE_2M] = _connectionSupervisionTimeout[phy_t::LE_CODED];
_minEventLength[ble::phy_t::LE_2M] = _minEventLength[ble::phy_t::LE_CODED]; _minEventLength[phy_t::LE_2M] = _minEventLength[phy_t::LE_CODED];
_maxEventLength[ble::phy_t::LE_2M] = _maxEventLength[ble::phy_t::LE_CODED]; _maxEventLength[phy_t::LE_2M] = _maxEventLength[phy_t::LE_CODED];
_scanInterval[ble::phy_t::LE_CODED] = scanInterval; _scanInterval[phy_t::LE_CODED] = scanInterval;
_scanWindow[ble::phy_t::LE_CODED] = scanWindow; _scanWindow[phy_t::LE_CODED] = scanWindow;
_minConnectionInterval[ble::phy_t::LE_CODED] = minConnectionInterval; _minConnectionInterval[phy_t::LE_CODED] = minConnectionInterval;
_maxConnectionInterval[ble::phy_t::LE_CODED] = maxConnectionInterval; _maxConnectionInterval[phy_t::LE_CODED] = maxConnectionInterval;
_slaveLatency[ble::phy_t::LE_CODED] = slaveLatency; _slaveLatency[phy_t::LE_CODED] = slaveLatency;
_connectionSupervisionTimeout[ble::phy_t::LE_CODED] = connectionSupervisionTimeout; _connectionSupervisionTimeout[phy_t::LE_CODED] = connectionSupervisionTimeout;
_minEventLength[ble::phy_t::LE_CODED] = minEventLength; _minEventLength[phy_t::LE_CODED] = minEventLength;
_maxEventLength[ble::phy_t::LE_CODED] = maxEventLength; _maxEventLength[phy_t::LE_CODED] = maxEventLength;
} }
private: private:
initiator_filter_policy_t _filterPolicy; initiator_filter_policy_t _filterPolicy;
ble::own_address_type_t _ownAddressType; own_address_type_t _ownAddressType;
uint16_t _scanInterval[MAX_PARAM_PHYS]; /* 0.625 ms */ uint16_t _scanInterval[MAX_PARAM_PHYS]; /* 0.625 ms */
uint16_t _scanWindow[MAX_PARAM_PHYS]; /* 0.625 ms */ uint16_t _scanWindow[MAX_PARAM_PHYS]; /* 0.625 ms */