@@ -29,6 +29,13 @@ BLEAdvertisingData::BLEAdvertisingData() :
29
29
_flags(0 ),
30
30
_hasFlags(false ),
31
31
_localName(NULL ),
32
+
33
+ _minimumConnectionInterval(0 ),
34
+ _maximumConnectionInterval(0 ),
35
+ _hasConnectionInterval(false ),
36
+ _TransmitPowerLevel(0 ),
37
+ _hasTransmitPowerLevel(false ),
38
+
32
39
_manufacturerData(NULL ),
33
40
_manufacturerDataLength(0 ),
34
41
_manufacturerCompanyId(0 ),
@@ -73,6 +80,13 @@ void BLEAdvertisingData::clear()
73
80
_rawDataLength = 0 ;
74
81
_hasFlags = false ;
75
82
_localName = NULL ;
83
+
84
+ _minimumConnectionInterval = 0 ;
85
+ _maximumConnectionInterval = 0 ;
86
+ _hasConnectionInterval = false ;
87
+ _TransmitPowerLevel = 0 ;
88
+ _hasTransmitPowerLevel = false ;
89
+
76
90
_manufacturerData = NULL ;
77
91
_manufacturerDataLength = 0 ;
78
92
_hasManufacturerCompanyId = false ;
@@ -90,6 +104,13 @@ void BLEAdvertisingData::copy(const BLEAdvertisingData& adv)
90
104
_flags = adv._flags ;
91
105
_hasFlags = adv._hasFlags ;
92
106
_localName = adv._localName ;
107
+
108
+ _minimumConnectionInterval = adv._minimumConnectionInterval ;
109
+ _maximumConnectionInterval = adv._maximumConnectionInterval ;
110
+ _hasConnectionInterval = adv._hasConnectionInterval ;
111
+ _TransmitPowerLevel = adv._TransmitPowerLevel ;
112
+ _hasTransmitPowerLevel = adv._hasTransmitPowerLevel ;
113
+
93
114
_manufacturerData = adv._manufacturerData ;
94
115
_manufacturerDataLength = adv._manufacturerDataLength ;
95
116
_manufacturerCompanyId = adv._manufacturerCompanyId ;
@@ -183,6 +204,29 @@ bool BLEAdvertisingData::setLocalName(const char *localName)
183
204
return success;
184
205
}
185
206
207
+ bool BLEAdvertisingData::setAdvertisedConnectionInterval (uint16_t minimumConnectionInterval, uint16_t maximumConnectionInterval)
208
+ {
209
+ int previousLength = (_hasConnectionInterval) ? ( sizeof (_minimumConnectionInterval) + sizeof (_maximumConnectionInterval) + AD_FIELD_OVERHEAD) : 0 ;
210
+ bool success = updateRemainingLength (previousLength, (sizeof (minimumConnectionInterval) + sizeof (maximumConnectionInterval) + AD_FIELD_OVERHEAD));
211
+ if (success) {
212
+ _hasConnectionInterval = true ;
213
+ _minimumConnectionInterval = minimumConnectionInterval;
214
+ _maximumConnectionInterval = maximumConnectionInterval;
215
+ }
216
+ return success;
217
+ }
218
+
219
+ bool BLEAdvertisingData::setAdvertisedTransmitPowerLevel (uint8_t TransmitPowerLevel)
220
+ {
221
+ int previousLength = (_hasTransmitPowerLevel) ? ( sizeof (_TransmitPowerLevel) + AD_FIELD_OVERHEAD) : 0 ;
222
+ bool success = updateRemainingLength (previousLength, (sizeof (TransmitPowerLevel) + AD_FIELD_OVERHEAD));
223
+ if (success) {
224
+ _hasTransmitPowerLevel = true ;
225
+ _TransmitPowerLevel = TransmitPowerLevel;
226
+ }
227
+ return success;
228
+ }
229
+
186
230
bool BLEAdvertisingData::setRawData (const uint8_t * data, int length)
187
231
{
188
232
if (length > MAX_AD_DATA_LENGTH) {
@@ -248,6 +292,14 @@ bool BLEAdvertisingData::updateData()
248
292
if (_localName) {
249
293
success &= addLocalName (_localName);
250
294
}
295
+ // Try to add Slave Connection Interval into the current advertising packet
296
+ if (_hasConnectionInterval) {
297
+ success &= addAdvertisedConnectionInterval (_minimumConnectionInterval, _maximumConnectionInterval);
298
+ }
299
+ // Try to add Transmit Power Level into the current advertising packet
300
+ if (_hasTransmitPowerLevel) {
301
+ success &= addAdvertisedTransmitPowerLevel (_TransmitPowerLevel);
302
+ }
251
303
return success;
252
304
}
253
305
@@ -330,6 +382,19 @@ bool BLEAdvertisingData::addFlags(uint8_t flags)
330
382
return addField (BLEFieldFlags, &flags, sizeof (flags));
331
383
}
332
384
385
+ bool BLEAdvertisingData::addAdvertisedConnectionInterval (uint16_t minimumConnectionInterval, uint16_t maximumConnectionInterval)
386
+ {
387
+ uint8_t tempData[sizeof (minimumConnectionInterval) + sizeof (maximumConnectionInterval)];
388
+ memcpy (tempData, &minimumConnectionInterval, sizeof (minimumConnectionInterval));
389
+ memcpy (&tempData[sizeof (minimumConnectionInterval)], &maximumConnectionInterval, sizeof (maximumConnectionInterval));
390
+ return addField (BLEFieldConnectionInterval, tempData, sizeof (minimumConnectionInterval) + sizeof (maximumConnectionInterval));
391
+ }
392
+
393
+ bool BLEAdvertisingData::addAdvertisedTransmitPowerLevel (uint8_t TransmitPowerLevel)
394
+ {
395
+ return addField (BLEFieldTransmitPowerLevel, &TransmitPowerLevel, sizeof (TransmitPowerLevel));
396
+ }
397
+
333
398
bool BLEAdvertisingData::addField (BLEAdField field, const char * data)
334
399
{
335
400
int dataLength = strlen (data);
0 commit comments