The limit size of a BLE packet is 20 bytes. I need to transfer the following data over it:
struct Data {
uint16_t top;
uint16_t bottom;
float accX;
float accY;
float accZ;
float qx;
float qy;
float qz;
float qw;
};
Size of Data is 32 bytes. The precision of floats can not be sacrificed, since they represent accelerometers and quaternions, and would create a huge drift error if not represented precisely (data would be integrated over time).
I don't want to send 2 packets as well, as it's really important that whole data is taken at the same time.
I'm planning to take advantage of the range instead.
- Accelerometer are IEEE floats in the range of [-10, 10]
- Quaternions are IEEE floats in the range of [-1, 1]. We could remove w, as x^2 + y^2 + z^2 + w^2 = 1
- Top, and bottom are 10-bit each.
Knowing this information, how can I serialize Data using at most 20 bytes?