@@ -29,6 +29,13 @@ BLEAdvertisingData::BLEAdvertisingData() :
2929 _flags(0 ),
3030 _hasFlags(false ),
3131 _localName(NULL ),
32+
33+ _minimumConnectionInterval(0 ),
34+ _maximumConnectionInterval(0 ),
35+ _hasConnectionInterval(false ),
36+ _TransmitPowerLevel(0 ),
37+ _hasTransmitPowerLevel(false ),
38+
3239 _manufacturerData(NULL ),
3340 _manufacturerDataLength(0 ),
3441 _manufacturerCompanyId(0 ),
@@ -73,6 +80,13 @@ void BLEAdvertisingData::clear()
7380 _rawDataLength = 0 ;
7481 _hasFlags = false ;
7582 _localName = NULL ;
83+
84+ _minimumConnectionInterval = 0 ;
85+ _maximumConnectionInterval = 0 ;
86+ _hasConnectionInterval = false ;
87+ _TransmitPowerLevel = 0 ;
88+ _hasTransmitPowerLevel = false ;
89+
7690 _manufacturerData = NULL ;
7791 _manufacturerDataLength = 0 ;
7892 _hasManufacturerCompanyId = false ;
@@ -90,6 +104,13 @@ void BLEAdvertisingData::copy(const BLEAdvertisingData& adv)
90104 _flags = adv._flags ;
91105 _hasFlags = adv._hasFlags ;
92106 _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+
93114 _manufacturerData = adv._manufacturerData ;
94115 _manufacturerDataLength = adv._manufacturerDataLength ;
95116 _manufacturerCompanyId = adv._manufacturerCompanyId ;
@@ -183,6 +204,29 @@ bool BLEAdvertisingData::setLocalName(const char *localName)
183204 return success;
184205}
185206
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+
186230bool BLEAdvertisingData::setRawData (const uint8_t * data, int length)
187231{
188232 if (length > MAX_AD_DATA_LENGTH) {
@@ -248,6 +292,14 @@ bool BLEAdvertisingData::updateData()
248292 if (_localName) {
249293 success &= addLocalName (_localName);
250294 }
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+ }
251303 return success;
252304}
253305
@@ -330,6 +382,19 @@ bool BLEAdvertisingData::addFlags(uint8_t flags)
330382 return addField (BLEFieldFlags, &flags, sizeof (flags));
331383}
332384
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+
333398bool BLEAdvertisingData::addField (BLEAdField field, const char * data)
334399{
335400 int dataLength = strlen (data);
0 commit comments