Ftp client with w5500: trouble

#1

Hi!
I have some problem with FTP-client.
Device divided to 2 boards:

  1. Interface Board
  2. Controller board
    On interface Board the ethernet, wifi, gsm and microcontroller, that managing interfaces.
    On controller board some sensors and microcontroller, that contains some business-logic, and firmware-update mechanism.

Boards have interconnect: SPI, controller board - master;

Interface board give received from network-interfaces data by request from controller board;
ftp-protocol logic have realized on controllerboard, abstracted from interfaceboard (for support old version device, thats have only 1 board);
With GSM and Wifi i have no problem: they slow.
With Ethernet some problems, too fast. Controller board takes data slower than ethernet receives.

I trying read the next RxData only after accept-ack of receiving current data on controller-board:
In main loop i call method:

    void ProcessRxData()
	{
		if (_rxCount == 0)
		{
			_rxCount = GetData(_socketIndex, _rxBuffer);
		}
			
		if (_rxCount > 0)
		{
			bool res = false; // result of transmission, data accepted or not; 
			OnDataReceivedCallback(_socketIndex, _rxBuffer, _rxCount, res);
			if (res) 
			{
				Api::SendCommand(_socketIndex, Api::Socket::CommandRecv);
				_rxCount = 0;
			}
		}
	}
//implementation of GetData() method:
		unsigned int GetData(unsigned int socketIndex, unsigned char *rxBuffer)
		{
			unsigned int count = Api::GetRxCount(socketIndex);
			if (count > 0)
			{
				unsigned short rxPtr = Api::GetRxReadPtr(socketIndex);
				Api::ReadRxBuffer(socketIndex, rxBuffer, count, rxPtr);
				Api::SetRxReadPtr(socketIndex, count + rxPtr);
			}
				
			return count;
		}

And i have problem:
always i lost last file part from ftp-server in transport-connection;
Probably, the last data packet is lost due to the fact that the transport connection is immediately closed after file transmitting. But maybe not.
How i can hold connection until actual end of receive?

UPD. If i receiving data without confirmation, immediate, all content of file received, without any loss

#2

You may already be doing some of the things I suggest below, but I can’t tell for sure based on the information you’ve provided. In particular, it’s not clear whether your transmissions are fixed-size or variable. So, sorry if I’m telling you things you already know, I just can’t tell from your question.

  1. If messages are fixed-size and smaller than the W5500 Rx buffer, you can check the Socket n Received Size Register, Sn_RX_RSR0, to see how many bytes are available and wait until the entire message is in the Rx buffer before reading.

  2. If your messages are NOT fixed-length, you need a unique termination string at the end of the message to tell you when you’re done. Read repeatedly until you see that string. Alternately, you can put the length of the message at the beginning of the first packet of each transmission, as is done in HTTP. Read in a loop until all bytes have been received.

  3. Each socket has a 2KB receive buffer (by default; you can allocate the 16KB between the 8 sockets differently if you choose). If your messages are larger than 2KB, you’ll need to do multiple reads to get the entire message.

#3

Hi! Thank you for reply.
I read the reference manual and I know what you wrote.
The problem is as follows:

Size of file - about 200-350 kb and not known beforehand.
My W5500 driver receive all of data, except last packet. Last packet may have size from 1 to 2048 bytes, depend of file size.
And if i receive(only reading, not saving) data immediate, without confirmation from controller-board, i receive all file.

#4

Upd.
I solved problem:
I need to move Sn_RXPTR after confirmation by controller board, not before.

#5

Sound great!