0

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.

Moritz
  • 352
  • 1
  • 3
  • 15
  • *I need to iterate over that string, extract substrings of 3 bytes and convert those to one double value.* -- To solve this problem, does it require all of the prerequisite knowledge of where the data comes from? Couldn't you write a simple, standalone function that takes in a hardcoded string, and attempts to do what you are trying to do? – PaulMcKenzie Nov 02 '22 at 16:38
  • How is the `double` encoded in the 24 bits? – G.M. Nov 02 '22 at 16:45

0 Answers0