We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hallo,
I have a question to the topic ethernet. I have look at the exmaple LEDswitch Client and I don't understand why I need the following code: .. U8 p2val, cnt, lshf; .. p2val = 1; cnt = 0; lshf = 1; ... send_data(p2val); p2val = lshf ? (p2val << 1) : (p2val >> 1); if (p2val == 0x80) lshf = 0; if (p2val == 0x01) lshf = 1;
I don't find anything in the help from keil for what p2val stand and why I to hand this on my funktion send_data? Can something explain it.
Thank you for the explain. Now I have a i further problem with the function tcp_listen.
switch (protocol) { case TCP: tcp_socket = tcp_get_socket (TCP_TYPE_CLIENT | TCP_TYP_FLOW_CTRL, 0 5005, tcp_callback) break; } ... main { U8 *listenbuf ... if (tcp_socket != 0) { tcp_listen (tcp_socket, 5005) { listenbuf = tcp_get_buf(SENDLEN); for (i = 0; i<max; i+=2) { array[i] = listenbuf[i]; array[i+1] = listenbuf[i+1]; }... And now I have the problem, I want to save the data from the socket in a array but I don't have an idee to solve this problem. My Code dosn't functional. Can someone help me?
That is not code.
1) You did not follow the formatting rules for code.
2) You have a huge number of left-brace compared to the number of right-brace. If that is just a result of the unindent steps being cut off byt eh ellipsis, I can't tell, since I can't see any indenting unless you format your post correctly.
3) Save what data? Have you read the documentation for tcp_get_buf()? Are you sure that this function does what you think it does?
4) Copying of data from one buffer to another is normally done using memcpy() or memmove().
Sorry for the formatting. It slipped my mind but I'll definitely forget it again ;-)
I send data from a PC over a socket to the LPC in order to start something on the LPC. So I want to listen to the socket if I become the instructions from the PC. The function tcp_get_buf is only for sending data I have to skip it. Give it any buffer for the function tcp_listen or something else so that I can with e.g. the function memcpy() to copy it ?
I gave you a hint at your usage of the tcp_get_buf(), but you didn't take the time to check in the manual, and compare with your code.
The function allocates a block of memory for use as send buffer.
But if the function returns a block to an allocated memory block, why are you then using a for loop to copy the unknown data from the newly allocated block into another array? To send data, you must _set_ the contents of this buffer before you write it.
If you should use memcpy() or not when sending data depends on the situation. If the memory is available somewhere else, then memcpy() is an efficient method to move data from one buffer to another. If you are going to send data that you generate on-the-fly, then you do not need an extra buffer and buffer copy - you can build your packet directly into the allocated buffer you got from tcp_get_buf(). the The tcp_get_buf function allocates memory for the TCP send buffer into which your application can write the outgoing data packet.
Another thing - why do your for loop step two bytes at a time, and then perform two one-byte assigns? An attempt at loop unrolling? Only do loop unrolling if speed is critical. But if speed is critical, then memcpy() can copy the data in 32-bit chunks intead of picking up individual bytes. And memcpy() is often written in hand-optimized assembler.