1

I'm following a tutorial and it says the UUID is 65210001-28D5-4B7B-BADF-7DEE1E8D1B6D then he adds it to the code in this format, without explaining how the conversion happened:

// Simple Service UUID: 65210001-28D5-4B7B-BADF-7DEE1E8D1B6D
static struct bt_uuid_128 simple_service_uuid =
    BT_UUID_INIT_128(0x6d, 0x1b, 0x8d, 0x1e, 0xee, 0x7d, 0xdf, 0xba, 0x7b,
             0x4b, 0xd5, 0x28, 0x01, 0x00, 0x21, 0x65);

I'm curious, what format is 0x6d, 0x1b, 0x8d, 0x1e, 0xee, 0x7d, 0xdf, 0xba, 0x7b,0x4b, 0xd5, 0x28, 0x01, 0x00, 0x21, 0x65 exactly? Hex?

How can I get from the UUID to the array? I've tried hex conversions and some other python encoding, but I can't create anything close. I'm looking to do the conversion in python.

exile97
  • 317
  • 3
  • 10
  • reverse `65210001-28D5-4B7B-BADF-7DEE1E8D1B6D` by taking 2 at a time: `6D 1B 8D 1E EE 7D ...` -> `BT_UUID_INIT_128(0x6d, 0x1b, 0x8d, 0x1e, 0xee, ...)` – Patrick Artner Jun 25 '21 at 04:57
  • Wow, I never noticed that, thanks! I am still curious, is the hex or byte data (or something else?). @PatrickArtner labeled python because I'm trying to do the conversion in python, sorry! – exile97 Jun 25 '21 at 04:58
  • 0x6d is 2 byte (16 bits) expressed as hex-number (the 0x in front letters a-f in the numbers are a giveaway) - and as to why it is reversed - google for the language used and BT_IIOD_INIT_128 to get more info about the stucture used. – Patrick Artner Jun 25 '21 at 05:00
  • Ok I see. I will write a python script to make the arrays for me now ;) Appreciate the help! – exile97 Jun 25 '21 at 05:01
  • Does this answer your question? [How to generate a random UUID which is reproducible (with a seed) in Python](https://stackoverflow.com/questions/41186818/how-to-generate-a-random-uuid-which-is-reproducible-with-a-seed-in-python) – Patrick Artner Jun 25 '21 at 05:02
  • Use the code from [the answer](https://stackoverflow.com/a/41186895/7505395) of dupe to make it and accept duplicate if it solved your problem. – Patrick Artner Jun 25 '21 at 05:02
  • 1
    This really depends on how `BT_UUID_INIT_128` is defined, and the struct it is applied to. Perhaps whatever library that is has documentation – M.M Jun 25 '21 at 05:04
  • For future reference: tagging c and pyhton without using both languages makes this closable as "needs clarification" and "looking for a tool or library or solution ..." is an exact closing reason. Be more specific and do not look for "tools or libraries ..." as that is offtopic. – Patrick Artner Jun 25 '21 at 05:06

1 Answers1

2

Here is the python solution thanks to Patrick Artners help:

    uuid = input('Enter a UUID: ')
    uuid = uuid.replace('-', '')
    uuid = uuid[::-1] #reverse the string
    hexArrayStr = ''
    splitToTwos = map(''.join, zip(*[iter(uuid)]*2))
    count = 0
    for v in splitToTwos:
        count+=1
        hexArrayStr = hexArrayStr + ('0x'+(v[::-1]).lower())
        if count != 16:
            hexArrayStr = hexArrayStr + ', '
    print(hexArrayStr)

prints 0x6d, 0x1b, 0x8d, 0x1e, 0xee, 0x7d, 0xdf, 0xba, 0x7b, 0x4b, 0xd5, 0x28, 0x01, 0x00, 0x21, 0x65

exile97
  • 317
  • 3
  • 10
  • @selbie some other guy told me it shouldn't be tagged python so I removed the tag..? I'll re-add it. (See comments on answer) – exile97 Jun 25 '21 at 05:24