I had some difficulty figuring out how to know that I'm sending the exact # of bytes when sending something like 4 byte signed ints over bluetooth serial. I have it figured out, but I'm wondering if there's a way I can routinely send variables with exact byte length.
For instance,
I'd like to write a function that accepts a variable and sends it out by inspecting its type.
Or is this the best I can do?
For instance,
Code:
#define STREAM_SERIAL Serial1
int32_t var = -2;
int32_t array[1] = {-1};
STREAM_SERIAL.write((uint8_t*)&var,sizeof(int32_t));
STREAM_SERIAL.write((uint8_t*)array,sizeof(array));
I'd like to write a function that accepts a variable and sends it out by inspecting its type.
Or is this the best I can do?
Code:
void send(int32_t var) {
STREAM_SERIAL.write((uint8_t*)&var,sizeof(int32_t));
}