Skip to content

Commit a66ffa3

Browse files
add constructor suggested by Vincent
1 parent 8b39071 commit a66ffa3

File tree

1 file changed

+61
-7
lines changed

1 file changed

+61
-7
lines changed

features/FEATURE_BLE/ble/gap/AdvertisingParameters.h

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,20 @@ class AdvertisingParameters {
123123
* @param[in] minInterval, maxInterval Time interval between two advertisement.
124124
* A range is provided to the LE subsystem, so it can adjust the advertising
125125
* interval with other transmission happening on the BLE radio.
126+
* @param[in] useLegacyPDU If true legacy PDU shall be used for advertising.
126127
*
127128
* @note If CONNECTABLE_UNDIRECTED or CONNECTABLE_DIRECTED advertising is used
128129
* you must use legacy PDU.
129130
*
130131
* @note If values in input are out of range, they will be normalized.
132+
*
133+
* @note If type selected is incompatible with non legacy PDU, legacy PDU will be used.
131134
*/
132135
AdvertisingParameters(
133136
advertising_type_t advType = advertising_type_t::CONNECTABLE_UNDIRECTED,
134137
adv_interval_t minInterval = adv_interval_t(DEFAULT_ADVERTISING_INTERVAL_MIN),
135-
adv_interval_t maxInterval = adv_interval_t(DEFAULT_ADVERTISING_INTERVAL_MAX)
138+
adv_interval_t maxInterval = adv_interval_t(DEFAULT_ADVERTISING_INTERVAL_MAX),
139+
bool useLegacyPDU = true
136140
) :
137141
_advType(advType),
138142
_minInterval(minInterval),
@@ -150,14 +154,47 @@ class AdvertisingParameters {
150154
_channel39(true),
151155
_anonymous(false),
152156
_notifyOnScan(false),
153-
_legacyPDU(true),
157+
_legacyPDU(useLegacyPDU),
154158
_includeHeaderTxPower(false)
155159
{
156-
/* Min interval is slightly larger than in other modes. */
157-
if (_advType == advertising_type_t::NON_CONNECTABLE_UNDIRECTED) {
158-
_minInterval = adv_interval_t(std::max(_minInterval.value(), GAP_ADV_PARAMS_INTERVAL_MIN_NONCON));
159-
_maxInterval = adv_interval_t(std::max(_maxInterval.value(), GAP_ADV_PARAMS_INTERVAL_MIN_NONCON));
160-
}
160+
normalize();
161+
}
162+
163+
/**
164+
* Construct an instance of GapAdvertisingParams.
165+
*
166+
* @param[in] advType Type of advertising.
167+
* @param[in] useLegacyPDU If true legacy PDU shall be used for advertising.
168+
*
169+
* @note If CONNECTABLE_UNDIRECTED or CONNECTABLE_DIRECTED advertising is used
170+
* you must use legacy PDU.
171+
*
172+
* @note If type selected is incompatible with non legacy PDU, legacy PDU will be used.
173+
*/
174+
AdvertisingParameters(
175+
advertising_type_t advType,
176+
bool useLegacyPDU
177+
) :
178+
_advType(advType),
179+
_minInterval(adv_interval_t(DEFAULT_ADVERTISING_INTERVAL_MIN)),
180+
_maxInterval(adv_interval_t(DEFAULT_ADVERTISING_INTERVAL_MAX)),
181+
_peerAddressType(target_peer_address_type_t::PUBLIC),
182+
_ownAddressType(own_address_type_t::RANDOM),
183+
_policy(advertising_filter_policy_t::NO_FILTER),
184+
_primaryPhy(phy_t::LE_1M),
185+
_secondaryPhy(phy_t::LE_1M),
186+
_peerAddress(),
187+
_txPower(127),
188+
_maxSkip(0),
189+
_channel37(true),
190+
_channel38(true),
191+
_channel39(true),
192+
_anonymous(false),
193+
_notifyOnScan(false),
194+
_legacyPDU(useLegacyPDU),
195+
_includeHeaderTxPower(false)
196+
{
197+
normalize();
161198
}
162199

163200
public:
@@ -552,6 +589,23 @@ class AdvertisingParameters {
552589
return _anonymous;
553590
}
554591

592+
private:
593+
/**
594+
* Enforce limits on parameters.
595+
*/
596+
void normalize()
597+
{
598+
/* Min interval is slightly larger than in other modes. */
599+
if (_advType == advertising_type_t::NON_CONNECTABLE_UNDIRECTED) {
600+
_minInterval = adv_interval_t(std::max(_minInterval.value(), GAP_ADV_PARAMS_INTERVAL_MIN_NONCON));
601+
_maxInterval = adv_interval_t(std::max(_maxInterval.value(), GAP_ADV_PARAMS_INTERVAL_MIN_NONCON));
602+
}
603+
if (_advType == advertising_type_t::CONNECTABLE_DIRECTED ||
604+
_advType == advertising_type_t::CONNECTABLE_UNDIRECTED) {
605+
_legacyPDU = true;
606+
}
607+
}
608+
555609
private:
556610
advertising_type_t _advType;
557611
/* The advertising interval in ADV duration units (in other words, 0.625ms). */

0 commit comments

Comments
 (0)