First of all, I'm quite new to c++ programming, I only started last year with lots of inactive periods in between. I already implemented a bunch of features for my ESP32 but all based on the arduino framework (platformio). Now I'm trying to reimplement one of my programs to ESP-IDF and that's where my question comes from.
My Setup
- IDE: CLion 2020.1.2
- OS: Windows 10
- Toolchain ESP: WSL (Ubuntu 20.04), using CMake 3.16.3
- Compiler ESP: xtensa-esp32-elf-gcc (crosstool-NG esp-2020r3) 8.4.0
- Toolchain c++: WSL (Ubuntu 20.04), using CMake 3.16.3
- Compiler c++: /usr/bin/cc /usr/bin/c++ both (Ubuntu 9.3.0-10ubuntu2) 9.3.0
- MCU: ESP32-Wrover-B (on a little development board where you can change the MCU)
My Code
I created a git repo to share the code
Problem
I'm currently trying to implement a - for me - easier to use wrapper for BLE/nimble, following the blehr example. What I want is a simplified interface that I can always reuse later. Also I want to use custom UUIDs in the following 16 byte format:
Code: Select all
#define wtServiceUUID "8d50CAD0-0000-43c2-a33e-00f937249838"
Code: Select all
std::unordered_map<ble_gatt_svc_def, std::list<ble_gatt_chr_def>, ServiceHash, ServiceEqual> services;
- convert the UUID from const char* to ble_uuid_t or to be more specific in this case to ble_uuid128_t
- create a ble_gatt_svc_def entity and store the converted UUID into its .uuid field
- and finally store the ble_gatt_svc_def entity into the services map
Code: Select all
void BLEUtil::addService(const char *uuid) {
s_println("ADD SERVICE %s", uuid);
ble_uuid_t *bleUuid = convertUUID(uuid);
const ble_uuid128_t *test = (ble_uuid128_t *) bleUuid;
logUUID(*test);
logUUID(bleUuid);
ble_gatt_svc_def service{
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = bleUuid,
};
logUUID(service.uuid);
services.insert({service, std::list<ble_gatt_chr_def>()});
}
As the UUID of the services in the map didn't resemble the original UUID later in the program during a first test run, I tried to figure out what went wrong and added some log messages along the code (logUUID) and realized that the result was different pretty much every time.
Since - as I mentioned before - I'm currently quite fresh with c++ and still need to figure out how exactly key features like pointers etc. work in detail, I need to debug this code to get a better understanding. But unfortunately my JTAG Debugger hasn't been ordered yet (lazy) and needs a little while to be shipped from china. Therefore I tried to reimplement this part of the code in plain c++.ADD SERVICE 8d50CAD0-0000-43c2-a33e-00f937249838
convert uuid 8d50CAD0-0000-43c2-a33e-00f937249838
-> to 141802022080067194163620249553615256
141802022080067194163620249553615256
1416325130192128136513625500002550
566325130192128136513625500002550
But here is the problem: There was none!! All logouts are exactly the same and what I expected:
I only copy-pasted the code out into the new project and added some header files that contain the UUID and BLE Service structs, where I deleted everything that I didn't need for a better overview.ADD SERVICE 8d50CAD0-0000-43c2-a33e-00f937249838
convert uuid 8d50CAD0-0000-43c2-a33e-00f937249838
-> to 141802022080067194163620249553615256
141802022080067194163620249553615256
141802022080067194163620249553615256
141802022080067194163620249553615256
Maybe someone can see what's my mistake and if you find things worth to improve on the way it's always welcome.
If you need more information, don't hesitate to ask. Thanks in advance!