Arm Mbed OS support forum

Having trouble creating 128-bit UUID for BLE advertising service UUID

I am using the GattServer example as my reference, as found on GitHub.

We have a clock service and the UUID is provided as a char array.

_clock_service(
        /* uuid */ "51311102-030e-485f-b122-f8f381aa84ed",
        /* characteristics */ _clock_characteristics,
        /* numCharacteristics */ sizeof(_clock_characteristics) /
                                 sizeof(_clock_characteristics[0])

I now want to make reuse of this char array for the clock service.

However, when using the “AdvertisingDataBuilder” or “AdvertisingDataSimpleBuilder” class it is expecting the UUID to be in byte array only.

I tried to use getBaseUUID method from the UUID class but then when trying to apply the “mbed::make_Span” method it returns an error saying it does not have a template for the const char pointer returned by the getBaseUUID method.

This is in an attempt to use the following function

ble_error_t setLocalServiceList(
    mbed::Span<const UUID> data,
    bool complete = true
);

or

 ble_error_t setRequestedServiceList(mbed::Span<const UUID> data);

At the moment it just looks very messy and I’m struggling to get this to work.

So instead banging away aimlessly to resolve, I thought to open it up to the forum for guidance.

So what is the recommended method.

I at least resolved the code syntax error

uint8_t UUIDlen = _myUUID.getLen();
const uint8_t* uuidpntr = _myUUID.getBaseUUID();
setLocalServiceList(mbed::make_Span(uuidpntr,UUIDlen),1);

But this produces 2 new errors when compiling:

[Error] Span.h@679,9: cannot initialize a member subobject of type ‘mbed::Span<const UUID, -1>::pointer’ (aka ‘const UUID ') with an rvalue of type ‘mbed::Span<const unsigned char, -1>::pointer’ (aka 'const unsigned char ')
[Error] Span.h@681,9: static_assert failed due to requirement 'span_detail::is_convertible<unsigned char const (
)[1], UUID const (
)[1]>::value’ “OtherElementType()[] should be convertible to ElementType ()[]”

In file included from ./mbed-os/features/FEATURE_BLE/ble/BLETypes.h:24:
./mbed-os/platform/Span.h:679:9: error: cannot initialize a member subobject of type ‘mbed::Span<const UUID, -1>::pointer’ (aka ‘const UUID *’) with an rvalue of type ‘mbed::Span<const unsigned char, -1>::pointer’ (aka ‘const unsigned char *’)
_data(other.data()), _size(other.size())
./source/BLEProcess.h:193:47: note: in instantiation of function template specialization ‘mbed::Span<const UUID, -1>::Span<const unsigned char, -1>’ requested here
_adv_data_builder.setLocalServiceList(mbed::make_Span(uuidpntr,UUIDlen),1);

Unless someone else can confirm, but I think this is a shortcoming with the BLE library in that the function setLocalServiceList only caters for one type of UUID class, namely:

UUID(const UUID &source)
{
    type      = source.type;
    shortUUID = source.shortUUID;
    memcpy(baseUUID, source.baseUUID, LENGTH_OF_LONG_UUID);
}