BLE: Add setters to advertising_event_t and use it in GapExtendedAdvertisingParams.

pull/8738/head
Vincent Coubard 2018-11-08 14:22:36 +00:00
parent d1e3800e79
commit 2f53ee896c
2 changed files with 55 additions and 3 deletions

View File

@ -207,31 +207,83 @@ struct advertising_event_t {
}
}
advertising_event_t() : value(0) { }
bool connectable() const
{
return static_cast<bool>(value & (1 << 0));
}
advertising_event_t& connectable(bool v)
{
if (v) {
value |= (1 << 0);
} else {
value &= ~(1 << 0);
}
return *this;
}
bool scannable_advertising() const
{
return static_cast<bool>(value & (1 << 1));
}
advertising_event_t& scannable_advertising(bool v)
{
if (v) {
value |= (1 << 1);
} else {
value &= ~(1 << 1);
}
return *this;
}
bool directed_advertising() const
{
return static_cast<bool>(value & (1 << 2));
}
advertising_event_t& directed_advertising(bool v)
{
if (v) {
value |= (1 << 2);
} else {
value &= ~(1 << 2);
}
return *this;
}
bool scan_response() const
{
return static_cast<bool>(value & (1 << 3));
}
advertising_event_t& scan_response(bool v)
{
if (v) {
value |= (1 << 3);
} else {
value &= ~(1 << 3);
}
return *this;
}
bool legacy_advertising() const
{
return static_cast<bool>(value & (1 << 4));
}
advertising_event_t& legacy_advertising(bool v)
{
if (v) {
value |= (1 << 4);
} else {
value &= ~(1 << 4);
}
return *this;
}
advertising_data_status_t data_status() const
{
return static_cast<advertising_data_status_t::type>((value >> 5) & 0x03);

View File

@ -259,7 +259,7 @@ private:
class GapExtendedAdvertisingParams {
GapExtendedAdvertisingParams() :
_advType(ble::EXT_ADV_CONNECTABLE_UNDIRECTED),
_advType(ble::advertising_event_t().connectable(true).scannable_advertising(true)),
_minInterval(0),
_maxInterval(0),
_peerAddressType(),
@ -292,7 +292,7 @@ class GapExtendedAdvertisingParams {
*
* @return Advertising type.
*/
ble::advertising_type_t getType() {
ble::advertising_event_t getType() {
return _advType;
}
@ -479,7 +479,7 @@ class GapExtendedAdvertisingParams {
}
private:
ble::advertising_type_t _advType;
ble::advertising_event_t _advType;
uint32_t _minInterval;
uint32_t _maxInterval;
ble::peer_address_type_t _peerAddressType;