however the output from the arduino serial console looks like this,
print vars
-7751
0.00
0
print vars
16664
0.00
123
print vars
0
ovf
8060929
print vars
0
9.50
123321
print vars
123
0.00
3787014424
print vars
1
0.00
1092091904
print vars
-7751
0.00
0
print vars
16664
0.00
123
print vars
0
ovf
8060929
print vars
0
9.50
123321
print vars
123
0.00
3787014424
print vars
1
0.00
1092091904
print vars
-7751
0.00
0
print vars
16664
0.00
123
print vars
0
ovf
8060929
print vars
0
9.50
123321
print vars
123
0.00
3787014424
some processors pad to a 16 bit boundary (adding an extra byte after var0) some don't
try adding another byte after var0?
for the time being i seem to have it working by define data size to uint32_t and the float works. i just have to make sure the receiving side dont corrupt the struct. im trying to think of how to add a tag to the beginning and end of the bytes sort of how i do with my udp communication.
i do this with udp to provide some integrity check,
void recPacket() {
int packetSize = Udp.parsePacket();
if (packetSize) {
int len = Udp.read(incomingPacket, 2000);
char verifyStart[7]; //NODEC1 plus null
char verifyEnd[7]; //C1NODE plus null
char _data[5];
strncpy (verifyStart, (char*)incomingPacket, 6);//6 bytes
strncpy (verifyEnd, (char *)incomingPacket + len - 6 , 6 );//6 bytes
verifyStart[6] = 0; //null terminate
verifyEnd[6] = 0; //null terminate
if (strcmp(verifyStart, "NODEUV") == 0) {
if (strcmp(verifyEnd, "VUNODE") == 0) {
memcpy(&_uvStruct, incomingPacket + 6 , sizeof(_uvStruct)); //copy 4 bytes to _data
Serial.println("uv packet");
}
}
and i write it like this,
Udp.beginPacket(Client5, ServerPort);
Udp.write("T1ONDE");
Udp.write((byte*)&valon, sizeof(valon)); //cast to bytes
Udp.write("UDT1ON");
Udp.endPacket();
how can i do something like this with these serial bytes?
i guess pretty much the same way
I guess checking the number of bytes received would be a first step.
You could try something simple like ANDing the first 3 longs and including the 4th long which is the AND of the first 3. Or even use the 4th long as a parity of the first 3, so that if the first 3 have one or 3 bits on for a given position the parity long has that bit on, but if there are 0 or 2 then the parity is zero. Lots of ways to do this - no idea whic is best.
you have an incrementing sequence number so you can check for lost or duplicate data and a CRC16 check set by the transmitter enabling the receiver to check for errors
if you wish to send a number of structures at the same time you could create a frame encoded so (with DLEs in the data being byte stuffed)
SYN DLE STX byte stuffed data CRC DLE ETX
the receiver looks for the start of a frame SYN DLE STX and reads data until frame terminator DLE ETX
the frame has its own CRC and the data and CRC is byte stuffed converting DLE to DLE DLE