LPC ETHERNET REMOTE SERVER

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC ETHERNET REMOTE SERVER

530 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rocketfuel on Tue Oct 07 19:14:18 MST 2014
Hi everyone.

At work I have been asked to build a remote server to watch/control an old TV broadcasting unit. Basically, all i have to do is to read 8 ADC values, a few digital outputs and to send a few commands to its digital inputs.

Currently i have a visual basic app wich sends and receives strings (commands). This app has been fully tested and works perfectly. It sends string commands in the following way:

COMMAND:|:

And receives a string in the following way:

COMMAND:|:VALUEADC1:|:VALUEADC2:|:VALUEADC3.......:|:DIGITALVALUE1:|:DIGITALVALUE2:|:....

Now talking about LPC1769 i did the following: i took EASYWEB example and modified it. At first i made it send a simple string containing values of ADC in an infinite loop and worked succesfully. But i had to implement input commands so right now im stuck at that point.

I decided to make the board to echo every command string i send. Here is the code (pay attention to red line):

void HTTPServer(void)
{
if (SocketStatus & SOCK_CONNECTED)
{
if (SocketStatus & SOCK_DATA_AVAILABLE)
{
memcpy(TCP_RX_BUFTEMP, TCP_RX_BUF, sizeof(TCP_RX_BUF));
TCPReleaseRxBuffer();

if (SocketStatus & SOCK_TX_BUF_RELEASED)
{
[color=#c03]HTTPBytesToSend = sizeof(TCP_RX_BUFTEMP)-1;[/color]
Buffer = (unsigned char*)TCP_RX_BUFTEMP;

if (HTTPBytesToSend > MAX_TCP_TX_DATA_SIZE)
{
memcpy(TCP_TX_BUF, Buffer, MAX_TCP_TX_DATA_SIZE);
HTTPBytesToSend -= MAX_TCP_TX_DATA_SIZE;
Buffer += MAX_TCP_TX_DATA_SIZE;

TCPTxDataCount = MAX_TCP_TX_DATA_SIZE;
TCPTransmitTxBuffer();
}
else
{
if (HTTPBytesToSend)
{
memcpy(TCP_TX_BUF, Buffer, HTTPBytesToSend);
TCPTxDataCount = HTTPBytesToSend;
TCPTransmitTxBuffer();
HTTPBytesToSend = 0;
}
}
}
}
}
}

What this code does is: It echoes only the first 3 characters unless i especify +something (+20 for example) in the red line but, of course, it will print the string + garbage because it doesnt know where the string finishes...

So Sizeof(TCP_RX_BUFTEMP) is not working and i am pretty sure its because TCP_RX_BUFTEMP is something different than a simple array like it comes with easyweb. I cant understand how RX BUFFER is implemented.

Any help would be much appreciated!
Labels (1)
0 Kudos
4 Replies

477 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rocketfuel on Thu Oct 09 07:07:59 MST 2014
Thank you LabRat... now i see im copying the address pointed by TCP_RX_BUF to TCP_RX_BUFTEMP, not the contents of the array...
0 Kudos

477 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Wed Oct 08 17:59:26 MST 2014

Quote: rocketfuel
I declared TCP_RX_BUFTEMP to copy the entire RX Buffer before i clear it to send data because its needed to get ACKs according to easyweb docs.



:quest:

TCP_RX_BUFTEMP is just another pointer to the same array 

So

memcpy(TCP_RX_BUFTEMP, TCP_RX_BUF, sizeof(TCP_RX_BUF));


is totally nonsense...
0 Kudos

477 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rocketfuel on Wed Oct 08 17:12:58 MST 2014
Hi! Thank you for your reply!

sizeof() can't 'go wrong... i know, i meant thats the line im having the problem with... it returns 4 as you say.

Here i post TCPIP.H declarations from easyweb example:

[color=#0f0]

#define MAX_TCP_RX_DATA_SIZE 1024                // max. incoming TCP data size (even!)

extern unsigned short _RxTCPBuffer[MAX_TCP_RX_DATA_SIZE/2];     // space for incoming TCP-data

#define RxTCPBuffer   ((unsigned char *)_RxTCPBuffer)
#define TCP_RX_BUF      ((unsigned char *)RxTCPBuffer)
#define TCP_RX_BUFTEMP  ((unsigned char *)RxTCPBuffer)

[/color]

What i understand is... when i send a command (a string), it is stored in an array which seems to be _RxTCPBuffer[]. But that array should have my data + tcpip data, am i right?

Going on with definitions i see, RxTCPBuffer ((unsigned char *)_RxTCPBuffer). So what i understand here is that RxTCPBuffer is a pointer to that array with a cast to a different data type. But then i have TCP_RX_BUF ((unsigned char *)RxTCPBuffer) wich points to the last pointer but same cast. I declared TCP_RX_BUFTEMP to copy the entire RX Buffer before i clear it to send data because its needed to get ACKs according to easyweb docs.

I think all my problem is because i can not fully understand those pointers...
0 Kudos

477 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Tue Oct 07 23:46:12 MST 2014
sizeof() can't 'go wrong'. It is defined as a constant, being the size, in bytes, of the variable/type. It is calculated at COMPILE TIME.

Without seeing the definition TCP_RX_BUFTEMP, we cannot know for certain, but my guess is that it is defined as a char *, meaning it is a pointer to a character and, being a pointer, has a fixed size of 4. Again, I don't know what your buffer contains, but if it is a C character array (string), you probably want to use strlen(Buffer) - obviously re-ordering the code... If it is NOT a character array, you need to calculate the size in a different way.

0 Kudos