I'm using the SimpleBLE library (https://github.com/OpenBluetoothToolbox/SimpleBLE) to receive data via BLE using c++17.
I'm expecting 243 bytes which I need to convert into 81 24bit samples. The 243 bytes are represented as a std:string. I need to iterate over that string, extract substrings of 3 bytes and convert those to one double value.
I tried copying substrings to a char array, but got stuck at that point.
This is the function that I'm using:
peripheral.notify(uuids[selection.value()].first, uuids[selection.value()].second, [&](SimpleBLE::ByteArray bytes) {
std::cout << "Received: ";
bytes_received += 243;
Utils::print_byte_array(bytes);
for (std::string::size_type i = 0; i < bytes.size(); i+=6) {
std::string s = bytes.substr(i,6);
char char_array[6];
strcpy(char_array, s.c_str());
// convert char array to double
}
}
SimpleBLE::ByteArray is defined as: namespace SimpleBLE {using ByteArray = std::string;}
.
Does anybody have a hint on how to do this efficiently? Any hints are appreciated.