Good evening,
to send some measured data I have to put values into an array together with the timestamps. The values and stamps differ in length and signedness. How should I properly put them together into one array and receive this array with a TCP socket?
On the receiving side I'm working with the recv()
function from winsock2.h and on the sending side my microcontroller tries to send through Server.write()
.
Code snippet from the sending side:
//example values. t can get really big
int32_t num0 = 1328;
int32_t num1 = 2222;
uint64_t tv = 100;
uint64_t buffer[3];
buffer[0] = num0;
buffer[1] = num1;
buffer[2] = tv;
server.write((uint8_t*) buffer, 4);
On the receiving side I tried solutions based on the answers to my previous post
For example something like this after calling recv():
uint64_t x = ((uint64_t) buffer[0] << 0)
| ((uint64_t) buffer[1] << 8)
| ((uint64_t) buffer[2] << 16)
| ((uint64_t) buffer[3] << 24);
uint32_t y = ((uint32_t) buffer[4] << 0)
| ((uint32_t) buffer[5] << 8)
| ((uint32_t) buffer[6] << 16)
| ((uint32_t) buffer[7] << 24);
uint32_t z = ((uint32_t) buffer[8] << 0)
| ((uint32_t) buffer[9] << 8)
| ((uint32_t) buffer[10] << 16)
| ((uint32_t) buffer[11] << 24);
I get garbage with this. Do I have to shift the bytes from the array position 8 - 11 to the front and so on, like in the following answer from blh64?
And how to receive arrays with more than 100 values? Do they all have to be shifted? Wouldn't that be a huge amount of code just shifting?