Click to See Complete Forum and Search --> : formatting of hex values
subathira
February 18th, 2006, 12:03 AM
In our application header and trailor to be added to message and sent of fixed length. The header and trailor are to be sent as hex constant values. so that
it is interpreted on hex on another end...
ex Field1 - 00E7 - size 2 bytes.
Field2- 0002 - size 2 bytes.
On other end too the hex they look for 00E70002..... which should be equivalent to buffer data of ..
Tried formatting by assigning hex values to char array.but
it is not properly interpreted on other end. In addition null gets added to length and they receive one byte addition to expected
length and error out.
please provide how this can be done avoiding the addition of null at End of string and adding 1 byte to length..can this be done with memcpy...tried byt getting different values..
anantwakode
February 18th, 2006, 12:16 AM
ex Field1 - 00E7 - size 2 bytes.
Field2- 0002 - size 2 bytes.
On other end too the hex they look for 00E70002..... which should be equivalent to buffer data of ..
How you are assigning hex to char ?
try this
int hexCodeF1,hexCodeF2;
hexCodeF1=0x00E7;
hexCodeF2=0x0002;
Or
char ch[4];
ch[0]=0x00;
ch[1]=0xE7;
ch[2]=0x00;
ch[3]=0x02;
and you can send this directly.
-Anant
ZuK
February 18th, 2006, 02:22 AM
You have to tell us a little bit more about your code.
I don't see any reason why you should receive 5 bytes when you only send 4.
Then I don't understand what you mean by sending hex-values.
Do you mean that you try to send short ints as hex-strings ?
Please show some code.
Kurt
subathira
February 18th, 2006, 10:24 AM
Let me be little more clear
we have the struct defining the message fields
{
char MesgLen [3]; //2 bytes
char Reserve[3] // 2bytes
.
.
.
Data[23] //22 bytes
..
trailor [3] // 2bytes
}
In my program as anandt specified have populated the fields with char array
like MesgLen[0]=0x00;
MesgLen[1]=0xE7;
and so on....
we are to sent the message of 28 bytes length..expected out on other end
00E70002AB.....Data.....1C1A The header and trailor have to be hex .Most of the fields gets populated properly...but now the output on other end becomes
20202000.......data...1C1A00
Regarding the mesg length expected number of bytes on other end was 28 bytes but they receive 29 bytes.On my mesg above u can se at the end 00-representing null field.when i get bufferlen on my side it is 28 but i think because of string format null gets added.
Can anything be done to avoid the above problem with memcpy..or any other suggestions ....hope i am clear...please let me know your thoughts
anantwakode
February 19th, 2006, 10:38 PM
Hi,
Is the size of structure on both end is same.
sizeof(msgStruct) ?
Are you using same exe for sending/Recieving Data ?
Or both application are difft.
-Anant
subathira
February 20th, 2006, 09:22 PM
These are 2 different applications.My application interface with other through TCP/IP socket. The message structure at both ends are same.
anantwakode
February 21st, 2006, 02:50 AM
What about the struct size on both end ? is it same ?
because sometimes due the different setting of struct member alignment creats trouble.
You can check it from
Project -> Setting -> C/C++ Tab -> Code Genration ->Struct Member alignment.
-Anant
subathira
February 21st, 2006, 10:33 PM
Thanks Anandt for the answers.atlast found the way to do it..
using memcpy instead of strncpy populated the values and got the response
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.