itsanjan / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Ethernet library transmit buffer free space #642

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
While checking the code in the ethernet library and the w5100 datasheet, I 
discovered a utility function that should be included in the ethernet library.

The w5100 datasheet specifies before writing to the transmit buffer, you must 
check the transmit buffer free space register first to insure enough space is 
available for the next data send.

The function is already available in the w5100.cpp file. getTXFreeSize();

It should be included in the Arduino ethernet library, since it is now possible 
to send large amounts of data from the SD. This would not be too apparent on a 
localnet, but when the internet bogs down, or bandwidth restrictions take 
effect, this could cause a problem.

I added this in Client.cpp below the Client::available() function and it works 
well.

int Client::free() {
  if (_sock != MAX_SOCK_NUM)
    return W5100.getTXFreeSize(_sock);
  return 0;
}

I added this in Client.h below the declaration for available()

virtual int free();

To find the transmit buffer free space remaining in the w5100, it is about like 
the Client::available() function.

int freeSpace = client.free();

The variable freeSpace would contain the transmit buffer free space remaining 
in bytes. 

Writing to the transmit buffer when there is insufficient room will cause 
errors.

Original issue reported on code.google.com by t...@prolectron.com on 16 Sep 2011 at 3:14

GoogleCodeExporter commented 8 years ago
I found some of the problem. Actually what I thought was a crash ended up being 
a blocking function in the Client::write() routine. It does not overflow the 
buffer. It checks the transmit buffer, and will wait until the transmit buffer 
has the space to take the next output.

This is blocking, and the processor seems to crash. With the addition of the 
Client::free() routine, it would not be blocking. The code could check if there 
is enough space before entering a potentially blocking function.

It also allows my code to determine if all data has been sent.

Original comment by t...@prolectron.com on 25 Sep 2011 at 12:36

GoogleCodeExporter commented 8 years ago
I had a similar issue where I would load a jpg image, and only receive half the 
image before the connection dropped. This was an instant fix to this issue, 
simply using the following statement surrounding the client.write command:

 while (client.free() > 0) {
    client.write(currentFile.read());
 }

Original comment by michael....@gmail.com on 27 Sep 2011 at 12:59

GoogleCodeExporter commented 8 years ago
Amigo você poderia me orientar como fazer estas mudanças na biblioteca do 
arduino, estou tentando a alguns dias enviar dados com arduino para um banco de 
dados mysql usando 3G e me parece que esta mudança na biblioteca resolve o 
problema.
Desde de ja se puder me orientar já agradeço..

Original comment by fabio.ol...@gmail.com on 20 Feb 2015 at 12:06