Hi,
I've been fighting for 2 days on something I don't understand and finally decided to ask for some help.
I'm using 2 MEGA here.
The code is very long so I'll try to explain instead of just pasting everything.
I'm trying to transfer multiple structure from one MEGA to Another using easytransfer library but due to some limitations (which I assume may come from my lack of skills), I decided to work the following way :
On both arduino, I created 2 structures each containing a buffer ; easytranfer will do its job and synch the structure.
- Arduino 1 : send buffer of 50 char // receive buffer of 50 char
- Arduino 2 : receive buffer of 50 char // send buffer of 50 char
This part is working as intended, I can write data in send buffer, find it in receive buffer and do what I want with it.
But now I want to copy a structure in the buffer, let easytransfer synch it for me and rebuild the structure on the other side.
All structures I need to transfer exists on both sides and are declared the exact same way. There is no compil error.
Here is the important part of the structure (same code on both arduino):
.
.
.
typedef struct GLOBAL{
unsigned long magic;
uint8_t struct_version;
uint16_t checksum;
char profile_name[9];
struct NETWORK_CONFIG network;
struct PLATFORM_CONFIG platform;
struct SERVO_CONFIG servo[8];
}config;
typedef struct NETWORK_CONFIG{
byte mac[6];
IPAddress ipV4;
uint16_t port;
IPAddress gateway;
IPAddress netmask;
IPAddress in_ipV4_min;
IPAddress in_ipV4_max;
};
typedef struct SYNCHRONIZED_BUFFER{
char buffer[50];
};
config active_profile;
config test_profile; //this one is just to play with data and is used as a proof of concept later in the code.
SYNCHRONIZED_BUFFER synchronized_buffer_rcv;
SYNCHRONIZED_BUFFER synchronized_buffer_send;
.
.
.
On arduino 1, the value of active_profile.network.port is 8704. In order to play around and understand how it works I made this code which will prepare a buffer with a set of command followed by the structure.
char s[sizeof(active_profile.network)];
char c[50]="md st n ";
memcpy(s, &active_profile.network, sizeof(active_profile.network));
memcpy(c+8, s, sizeof(s));
send_command_to_serial(c); //will transfer c to the receive buffer of the other arduino.
//code below is to make sure it's working as I think it should...
memcpy(&test_profile.network, c+8, sizeof(test_profile.network));
Serial.println("Port : ");
Serial.println(test_profile.network.port);
//test_profile.network.port = 8704 so test is OK for me, typicaly I just copied the data from a char array buy ignoring part of the array containg what i would call the "command".
Serial.println(c); //It returns this : md st n Þ¾ïþïK[03]À¨
//i'm now expecting to find the exact same thing in the buffer on the second arduino.
Now on the second arduino, I confirmed that the receive buffer is equal to md st n Þ¾ïþïK[03]À¨ so basicaly, exactly what I want.
Still on Arduino 2, I'm using the following code to take the structure data from the receive buffer into the test_profile :
memcpy(&test_profile.network, synchronized_buffer_rcv.buffer+8, sizeof(test_profile.network)); //the +8 is to start reading data structure after "md st n "
Serial.println("\nPort : ");
Serial.print(test_profile.network.port);
This is where i'm lost. As the memcpy worked on first arduino, i'm expecting to see it work on the second one. But test_profile.network.port = 0 instead of 8704 no matter what I try and no matter the fact that send buffer on one side is :
- md st n Þ¾ïþïK[03]À¨
and receive buffer on the over side is :
- md st n Þ¾ïþïK[03]À¨
It looks the same to me so i'm definitely missing something out.