@@ -45,6 +45,7 @@ blePeripheralGattsEventHandler(ble_client_gatts_event_t event, struct ble_gatts_
45
45
46
46
BlePeripheral::BlePeripheral (void ) :
47
47
_state(BLE_PERIPH_STATE_NOT_READY),
48
+ _advertise_service_uuid(NULL ),
48
49
_appearance(0 ),
49
50
_central(this ),
50
51
_attributes(NULL ),
@@ -125,31 +126,7 @@ BlePeripheral::end()
125
126
BleStatus
126
127
BlePeripheral::setAdvertisedServiceUuid (const char * advertisedServiceUuid)
127
128
{
128
- BleUuid bleUuid = BleUuid (advertisedServiceUuid);
129
- struct bt_uuid uuid = bleUuid.uuid ();
130
-
131
-
132
- /* Append UUID to advertising data
133
- * TODO - we could pack multiple UUIDs of the same type together
134
- * to conserve bytes in the advertising data payload
135
- */
136
- if ((BT_UUID16 == uuid.type ) &&
137
- (_adv_data_len + 2 + sizeof (uint16_t ) <= BLE_MAX_ADV_SIZE)) {
138
- uint8_t *adv_tmp = &_adv_data[_adv_data_len];
139
- *adv_tmp++ = (1 + sizeof (uint16_t )); /* Segment data length */
140
- *adv_tmp++ = BLE_ADV_TYPE_INC_16_UUID;
141
- UINT16_TO_LESTREAM (adv_tmp, uuid.uuid16 );
142
- _adv_data_len += (2 + sizeof (uint16_t ));
143
- } else if ((BT_UUID128 == uuid.type ) &&
144
- (_adv_data_len + 2 + MAX_UUID_SIZE <= BLE_MAX_ADV_SIZE)) {
145
- uint8_t *adv_tmp = &_adv_data[_adv_data_len];
146
- *adv_tmp++ = (1 + MAX_UUID_SIZE); /* Segment data length */
147
- *adv_tmp++ = BLE_ADV_TYPE_INC_128_UUID;
148
- memcpy (adv_tmp, uuid.uuid128 , MAX_UUID_SIZE);
149
- _adv_data_len += (2 + MAX_UUID_SIZE);
150
- } else {
151
- /* Not enough space in advertising PDU for service UUID */
152
- }
129
+ _advertise_service_uuid = advertisedServiceUuid;
153
130
154
131
return BLE_STATUS_SUCCESS;
155
132
}
@@ -295,6 +272,25 @@ BlePeripheral::_advDataInit(void)
295
272
_adv_data_len += 4 ;
296
273
}
297
274
275
+ if (_advertise_service_uuid) {
276
+ BleUuid bleUuid = BleUuid (_advertise_service_uuid);
277
+ struct bt_uuid uuid = bleUuid.uuid ();
278
+
279
+ if (BT_UUID16 == uuid.type ) {
280
+ uint8_t *adv_tmp = &_adv_data[_adv_data_len];
281
+ *adv_tmp++ = (1 + sizeof (uint16_t )); /* Segment data length */
282
+ *adv_tmp++ = BLE_ADV_TYPE_INC_16_UUID;
283
+ UINT16_TO_LESTREAM (adv_tmp, uuid.uuid16 );
284
+ _adv_data_len += (2 + sizeof (uint16_t ));
285
+ } else if (BT_UUID128 == uuid.type ) {
286
+ uint8_t *adv_tmp = &_adv_data[_adv_data_len];
287
+ *adv_tmp++ = (1 + MAX_UUID_SIZE); /* Segment data length */
288
+ *adv_tmp++ = BLE_ADV_TYPE_INC_128_UUID;
289
+ memcpy (adv_tmp, uuid.uuid128 , MAX_UUID_SIZE);
290
+ _adv_data_len += (2 + MAX_UUID_SIZE);
291
+ }
292
+ }
293
+
298
294
/* Add device name (truncated if too long) */
299
295
uint8_t calculated_len;
300
296
adv_tmp = &_adv_data[_adv_data_len];
0 commit comments