Hi again !
Thanks a lot for all your reply. I'll test as soon as i'm back home later today ![]()
arduarn:
Serial.println(c); //It returns this : md st n Þ¾ïþïK[03]ˬYou need to print out the individual characters as hex values. Printing c as a C-string will only print to the first 0 byte and so may hide some of the content. (Won't solve your problem though.)
Edit: And how is send_command_to_serial(c) implemented? Does it stop at a 0 byte too?
Understood. So I will display the hex content of the buffer on both side and compare. If the problem comes from that, i'll definitely find a difference. That will be the first step to explain why it didn't work.
You asked me about the send_command_to_serial.
send_command_to_serial(char command[50]){
memset(synchronized_buffer_send.buffer, '\0', sizeof synchronized_buffer_send.buffer);
strcpy(synchronized_buffer_send.buffer,command);
ET_buffer_send.sendData(); \\this part is from the easytransfer library.
}
As far as I understand, the easytransfer library will replicate the buffer to the receive buffer on the other arduino, no matter the content and run a checksum to ensure that send and receive buffer content are the same. I checked the library, and I don't understand the checksum part... It looks like it's only counting the number of bytes to send and checking the number of bytes received on the other side... Meaning that the whole structure may be corrupted.
I'm using a checksum (real one) when reading data from EEPROM so I may implement something similar here.
Delta_G:
If you want to send the whole struct at once, make a union with it and a byte buffer and then you don't have to convert anything. Especially since both ends are Arduino and you can be relatively certain that they both put the struct together the same way in memory.On the sending end you would just send out the byte buffer view of the union. On the receive side you would read bytes in one by one into the byte buffer view of the union and on the very next line you can start treating it like the struct and using it as an object instead of a buffer full of bytes.
I didn't know UNION yet. So i've just read a tutorial here (in fr sorry) https://openclassrooms.com/courses/les-unions which proved to be very instructive. If I understand this concept correctly, all variable declared in the union are sharing the same address range and the range size is equal to the biggest "object" declared in the union. In your example, the memory range reserved would start at &asBuffer and end at &asBuffer[sizeof(MyStruct)] with &asBuffer = &asStruct. That would be indead very useful if I wanted to create my own library (which I will certainly do as a training purpose). That will be next step !
Jimmus:
You don't have to copy the data at all if you just typecast it.
Ok, noted. I understand what typecast is but I don't see yet how I can use your suggestion in my problem. Are you refering to the fact that I memcopy everything and that I could avoid doing this by using typecast ?
Robin2:
You don't even need to use a union.If you use the name of the struct as an address you can just write the values to successive addresses after that - something like this pseudo code
myStructAddr = &myStruct
newByte = Serial.read()
(myStructAddr + n) = newByte
n++
I'm not sure if I have the reference to myStruct correct and I can't immediately find the code where I did this. ...R
Got it, will use it when I build my own transfer library (which would be next step as said earlier).
So my next action will be to compare hex value of both buffers which will supposedly justify why it's not working. Based on what I discover, I will use your suggestions but the more I read your ideas the more I think a serial transfer "protocol" is missing to exchange data between arduino.
Thanks a lot for your time and help !