0
votes

Now i working on Bluetooth low energy devices i fully read office documentation and i downloaded sample source code from office website https://developer.android.com/guide/topics/connectivity/bluetooth-le.html

all are working perfectly but i don't know how they are take UUID number ex 'public static String HEART_RATE_MEASUREMENT = "00002a37-0000-1000-8000-00805f9b34fb".enter image description here

1
I am also saw in bluetooth.com/specifications/assigned-numbers. But i dont know howuser8574282
"i don't know how they are take UUID number"... this is confusing. Can you try to be a little more clear on what you are stuck oncodeMagic

1 Answers

0
votes

C++ functions using UUID require a pointer to a 16-byte structure (not a string).

If UUID is given as a string, it must be changed to a structure, like this:

String HEART_RATE_MEASUREMENT = "00002a37-0000-1000-8000-00805f9b34fb";

UUID Heart_Rate_UUID = { 0x00002a37, 0x0000, 0x1000, 0x00, 0x80, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb };

The struct UUID is { long, short[2], char[8] } so note, the 3rd group in the string (-8000-) must be reversed (0x00, 0x80) because of processor endianness.

The resulting binary code will actually be 37 2a 00 00 00 00 00 10 00 80 00 80 5f 9b 34 fb

The byte order is totally scrambled for the x86 processor.

For this reason, UUID are normally passed as text in web applications because the network byte order may be different from the processor-dependent byte order.

Microsoft compilers have some extensions such as MIDL (q.v.) that help with the conversion but a lot of programmers just re-write it by hand as I showed above.