OpenSprinkler Forums OpenSprinkler Unified Firmware [patch] Use the whole allocated buff for network transfers

  • This topic has 3 replies, 3 voices, and was last updated 7 years ago by ianf.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #34807

    ianf
    Participant

    Hi

    The Ethernet buffer is defined in defines.h as 850 octets, but in server.ino a hard-coded value of 512 octets is used for the file transfers. This patch increases the buffer utilization in file transfers. It also corrects the frame length in the enc26j60 driver to allow the full 1500 octet payload for the ATmega1284. Transfers are significantly faster as a result.

    BTW, is this the best place for user contributed patches?

    
    diff --git a/defines.h b/defines.h
    index 9416c19..c74d043 100644
    --- a/defines.h
    +++ b/defines.h
    @@ -188,7 +190,11 @@ typedef enum {
    #define DISPLAY_MSG_MS      2000  // message display time (milliseconds)
    
    // ====== Ethernet Defines ======
    +#if defined(__AVR_ATmega1284P__)
    +#define ETHER_BUFFER_SIZE   1500  // 1284P has 16K RAM
    +#else
    #define ETHER_BUFFER_SIZE   850  // if buffer size is increased, you must check the total RAM consumption
    +#endif
    // otherwise it may cause the program to crash
    #define TMP_BUFFER_SIZE     120  // scratch buffer size
    
    diff --git a/enc28j60.cpp b/enc28j60.cpp
    index 4fcfaef..5a87142 100644
    --- a/enc28j60.cpp
    +++ b/enc28j60.cpp
    @@ -246,7 +246,10 @@ bool ENC28J60::broadcast_enabled = false;
    
    // max frame length which the conroller will accept:
    // (note: maximum ethernet frame length would be 1518)
    -#define MAX_FRAMELEN 1500
    +// 1500 - Payload
    +// add 14 Bytes for MAC header
    +// add 4 Bytes for VLAN header
    +#define MAX_FRAMELEN 1514
    
    #define FULL_SPEED 1 // switch to full-speed SPI for bulk transfers
    
    diff --git a/examples/interval_program/server.ino b/examples/interval_program/server.ino
    index faef8ed..ca11dda 100644
    --- a/examples/interval_program/server.ino
    +++ b/examples/interval_program/server.ino
    @@ -1098,9 +1098,9 @@ byte streamfile (char* name) { //send a file to the buffer
    ether.httpServerReply_with_flags(bfill.position(), TCP_FLAGS_ACK_V);
    bfill = ether.tcpOffset();
    while(myfile.available()) {
    -    int nbytes = myfile.read(Ethernet::buffer+54, 512);
    +    int nbytes = myfile.read(Ethernet::buffer+54, ETHER_BUFFER_SIZE - 54);
    cur = nbytes;
    -    if (cur>=512) {
    +    if (cur>=ETHER_BUFFER_SIZE - 54) {
    ether.httpServerReply_with_flags(cur,TCP_FLAGS_ACK_V, 3);
    cur=0;
    } else {
    
    #34810

    Samer
    Keymaster

    Github is where all code should be posted. You may submit pull requests to the code.

    Update: By the way, I failed to say this earlier, thanks for the patches. Github helps keep all the code in one place so nothing is forgotten. The forums are threaded and finding something becomes very difficult over time. Also, the integrity of the code when using patches pasted as text in forums can introduce issues that can be avoided.

    #34817

    Ray
    Keymaster

    @ianf: thanks for the patches. I am currently traveling out of town, but I did bring a set of OpenSprinkler so I can try the patch as soon as possible. I was under the impression that each packet in the file stream function must be 512 bytes or less, but this was probably a wrong impression. Thanks for the discovery.

    #34824

    ianf
    Participant

    @Ray

    I’m pretty sure that was the case.  IIRC the early versions of the Ethercard library had a static buffer.  In fact for another project we chose UIPEthernet for its improved TCP/IP support.  There are still some hangovers from the early days in the Ethercard code – the MSS of 512 octets in the client code as an example.  Your project has finally given me the impetus to look into a bunch of stuff I’ve been meaning to get to for a long time.

    I’m building an OpenSprinkler for my Mom to replace the Toro DDC-6 I gave her years ago because it’s a pain to program, runs the backup battery down and forgets the settings whenever there’s a power failure.

    The OpenSprinkler is such a nice solution.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

OpenSprinkler Forums OpenSprinkler Unified Firmware [patch] Use the whole allocated buff for network transfers