Skip to content

Commit 661fc89

Browse files
committed
Correct advertised service uuid
1 parent fe78397 commit 661fc89

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

libraries/CurieBle/src/BlePeripheral.cpp

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ blePeripheralGattsEventHandler(ble_client_gatts_event_t event, struct ble_gatts_
4545

4646
BlePeripheral::BlePeripheral(void) :
4747
_state(BLE_PERIPH_STATE_NOT_READY),
48+
_advertise_service_uuid(NULL),
4849
_appearance(0),
4950
_central(this),
5051
_attributes(NULL),
@@ -125,31 +126,7 @@ BlePeripheral::end()
125126
BleStatus
126127
BlePeripheral::setAdvertisedServiceUuid(const char* advertisedServiceUuid)
127128
{
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;
153130

154131
return BLE_STATUS_SUCCESS;
155132
}
@@ -295,6 +272,25 @@ BlePeripheral::_advDataInit(void)
295272
_adv_data_len += 4;
296273
}
297274

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+
298294
/* Add device name (truncated if too long) */
299295
uint8_t calculated_len;
300296
adv_tmp = &_adv_data[_adv_data_len];

libraries/CurieBle/src/BlePeripheral.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class BlePeripheral {
174174

175175
BlePeripheralState _state;
176176

177+
const char* _advertise_service_uuid;
177178
char _local_name[BLE_MAX_DEVICE_NAME+1];
178179
uint16_t _appearance;
179180
uint8_t _adv_data[BLE_MAX_ADV_SIZE];

0 commit comments

Comments
 (0)