The bord that I use is a demo52233DEMO and I'm using the coldfire lite stack => TCP_client
and I want to send unicode-encoded textual messages (packets) to a tcp server. I can already do that, but the methode I use is far to mutch work. Also I want to detect several unicode messages how can I do that? And my final question is how can I send a fin pakket when I reset the board? This is an example of the methode that I use for sending stuf.
length = m_recv( emg_tcp_communication_socket, (char *)buffer, RX_BUFFER_SIZE );
//--------alive ---------
len = 54;
data_alive[0]= 'a';
data_alive[2]= 'l';
data_alive[4]= 'i';
data_alive[6]= 'v';
data_alive[8]= 'e';
data_alive[10]= ':';
data_alive[12]= 'S';
data_alive[14]= 't';
data_alive[16]= 'i';
data_alive[18]= 'l';
data_alive[20]= 'l';
data_alive[22]= ' ';
data_alive[24]= 'a';
data_alive[26]= 'l';
data_alive[28]= 'i';
data_alive[30]= 'v';
data_alive[32]= 'e';
data_alive[34]= ',';
data_alive[36]= ' ';
data_alive[38]= 's';
data_alive[40]= 'e';
data_alive[42]= 'r';
data_alive[44]= 'v';
data_alive[46]= 'e';
data_alive[48]= 'r';
data_alive[50]= '?';
data_alive[52]= '\01';
//----------------------
(void)m_send( emg_tcp_communication_socket, (char *)data_alive, len );
greets jonas
已解决! 转到解答。
> unicode looks like this in the pakket [.a.l.i.v.e.:.s.t.i.l.l. .a.l.l.i.v.e.,. .s.e.r.v.e.r.?./01].
Maybe I completely misunderstand you, but if you put the "L" in front of a character string, the compiler will allocate 16 bits (a wide character) for each character, rather than 8 bits (a normal character). This looks a lot like the ASCII portion of UCS-2 or UTF-16 unicode (but nothing like UTF-8).
In your original post, you showed the characters in "little endian" format, with the 'a' before its corresponding 0; in the example above, you show them in "big endian" format, with the 0 (presumably the '.') before its corresponding 'a'.
If you define:
unsigned short buffer = L"alive:still allive, server?\01";
You'll have a buffer with 16 bits per character, with the characters packed into the second byte of the 16 bits (i.e., big endian format, because ColdFire is big endian), just like in the example above (I assume you wanted an SOH with the \01). And the wide character functions I mentioned earlier are meant to manipulate these types of strings, just like the normal string functions manipulate 8 bit character strings.
If you need them in little-endian format, you just need to loop thru the shorts in the buffer and byteswap them -- byteswapping is a way of life when sending data off-board, since different CPUs have different endiannesses, so typically you'll have one routine that will do that for you just before sending the data out (or after receiving it in) -- remember, you only want to byteswap multi-byte quantities, and you have to know the size of the quantity to do it (in this case, you're byteswapping 16 bit quantities, so it is really easy).
> unicode looks like this in the pakket [.a.l.i.v.e.:.s.t.i.l.l. .a.l.l.i.v.e.,. .s.e.r.v.e.r.?./01].
Maybe I completely misunderstand you, but if you put the "L" in front of a character string, the compiler will allocate 16 bits (a wide character) for each character, rather than 8 bits (a normal character). This looks a lot like the ASCII portion of UCS-2 or UTF-16 unicode (but nothing like UTF-8).
In your original post, you showed the characters in "little endian" format, with the 'a' before its corresponding 0; in the example above, you show them in "big endian" format, with the 0 (presumably the '.') before its corresponding 'a'.
If you define:
unsigned short buffer = L"alive:still allive, server?\01";
You'll have a buffer with 16 bits per character, with the characters packed into the second byte of the 16 bits (i.e., big endian format, because ColdFire is big endian), just like in the example above (I assume you wanted an SOH with the \01). And the wide character functions I mentioned earlier are meant to manipulate these types of strings, just like the normal string functions manipulate 8 bit character strings.
If you need them in little-endian format, you just need to loop thru the shorts in the buffer and byteswap them -- byteswapping is a way of life when sending data off-board, since different CPUs have different endiannesses, so typically you'll have one routine that will do that for you just before sending the data out (or after receiving it in) -- remember, you only want to byteswap multi-byte quantities, and you have to know the size of the quantity to do it (in this case, you're byteswapping 16 bit quantities, so it is really easy).
I'm not 100% sure if this is what you are asking, but you can use wide character strings in Code Warrior, like:
unsigned short *xxx = L"hello world\n";
That is a bit different than what you packed up, because of endian issues -- you'd then have to byteswap each short if you wanted the low byte first, followed by the 0, prior to sending the data out of the MCU.
There are also all of the wide character manipulation functions, like:
#include <wchar.h>
int wcscmp(const wchar_t * str1, const wchar_t * str2);
-- Rich
hello,
I'm not shure to understand your issue. It seems you're looking for a better way to extract rxed buffer, and to fill tx buffer.
I'm not familiar with the unicode message, could you explain it, and what is in the odd indexes of your buffer? Is it '\0' marking the end of a string?
FB