D
Don
Hi NG. I have the code below my question.
I would like to copy the content of measuredata to the MyBuffer from place
nr 20 (MyBuffer[19]). The problem with this code is that between the two
structs I get two empty bytes :-(. Like measuredata.struct1.measure13 are
placed at MyBuffer[19+786] and when I print this it displays oxBF fine, but
when I print
MyBuffer[19+787],MyBuffer[19+788],MyBuffer[19+789] and MyBuffer[19+790], it
displays 0x00, 0x00, 0x12 and 0x34 :-(. And MyBuffer[19+791] and
MyBuffer[19+792] holds the rest of the integer 0x56 and 0x78. So I get these
two 0x00 and 0x00.....Can I workaround this or is this something to do with
the struct type???
Best Regards
Don
unsigned char MyBuffer[2000];
struct mystruct1{
unsigned char measure1[256];
unsigned short measure2[256];
unsigned char measure3;
unsigned short measure4;
unsigned short measure5;
unsigned short measure6;
unsigned short measure7;
unsigned short measure8;
unsigned short measure9;
unsigned char measure10;
unsigned char measure11;
unsigned char measure12;
unsigned char measure13;
};
struct mystruct2{
unsigned int measure14;
unsigned int measure15;
unsigned short measure16;
unsigned short measure17;
unsigned short measure18;
unsigned short measure19;
unsigned short measure20;
unsigned short measure21;
unsigned int measure22;
unsigned int measure23;
unsigned int measure24;
unsigned int measure25;
unsigned int measure26;
unsigned int measure27;
unsigned int measure28;
unsigned int measure29;
unsigned int measure30;
unsigned int measure31;
};
struct measurement_data{
struct mystruct1 struct1;
struct mystruct2 struct2;
}measuredata;
int main(){
int i= 0;
for(i=0;i<200;i++)
measuredata.struct1.measure1 = 0x55;
for(i=0;i<100;i++)
measuredata.struct1.measure2 = 0xFF11;
measuredata.struct1.measure9 = 0x1133;
measuredata.struct2.measure16 = 0x12345678;
measuredata.struct2.measure23 = 0xFFFFFFFF;
measuredata.struct2.measure26 = 0x08080808;
measuredata.struct2.measure30 = 0x00000001;
measuredata.struct2.measure31 = 0xDEADBEEF;
//The transition between struct1 and struct2
measuredata.struct1.measure13 = 0xBF;
measuredata.struct2.measure14 = 0x12345678;
//Copy measuredata struct with variable values to the MyBuffer
memcpy(&MyBuffer[19], (unsigned char *) &measuredata, sizeof(struct
measurement_data));
return 0;
}
I would like to copy the content of measuredata to the MyBuffer from place
nr 20 (MyBuffer[19]). The problem with this code is that between the two
structs I get two empty bytes :-(. Like measuredata.struct1.measure13 are
placed at MyBuffer[19+786] and when I print this it displays oxBF fine, but
when I print
MyBuffer[19+787],MyBuffer[19+788],MyBuffer[19+789] and MyBuffer[19+790], it
displays 0x00, 0x00, 0x12 and 0x34 :-(. And MyBuffer[19+791] and
MyBuffer[19+792] holds the rest of the integer 0x56 and 0x78. So I get these
two 0x00 and 0x00.....Can I workaround this or is this something to do with
the struct type???
Best Regards
Don
unsigned char MyBuffer[2000];
struct mystruct1{
unsigned char measure1[256];
unsigned short measure2[256];
unsigned char measure3;
unsigned short measure4;
unsigned short measure5;
unsigned short measure6;
unsigned short measure7;
unsigned short measure8;
unsigned short measure9;
unsigned char measure10;
unsigned char measure11;
unsigned char measure12;
unsigned char measure13;
};
struct mystruct2{
unsigned int measure14;
unsigned int measure15;
unsigned short measure16;
unsigned short measure17;
unsigned short measure18;
unsigned short measure19;
unsigned short measure20;
unsigned short measure21;
unsigned int measure22;
unsigned int measure23;
unsigned int measure24;
unsigned int measure25;
unsigned int measure26;
unsigned int measure27;
unsigned int measure28;
unsigned int measure29;
unsigned int measure30;
unsigned int measure31;
};
struct measurement_data{
struct mystruct1 struct1;
struct mystruct2 struct2;
}measuredata;
int main(){
int i= 0;
for(i=0;i<200;i++)
measuredata.struct1.measure1 = 0x55;
for(i=0;i<100;i++)
measuredata.struct1.measure2 = 0xFF11;
measuredata.struct1.measure9 = 0x1133;
measuredata.struct2.measure16 = 0x12345678;
measuredata.struct2.measure23 = 0xFFFFFFFF;
measuredata.struct2.measure26 = 0x08080808;
measuredata.struct2.measure30 = 0x00000001;
measuredata.struct2.measure31 = 0xDEADBEEF;
//The transition between struct1 and struct2
measuredata.struct1.measure13 = 0xBF;
measuredata.struct2.measure14 = 0x12345678;
//Copy measuredata struct with variable values to the MyBuffer
memcpy(&MyBuffer[19], (unsigned char *) &measuredata, sizeof(struct
measurement_data));
return 0;
}