Resolved: Does ethercard browseurl callback duplicate callback with persistTcpConnection ? – JeeLabs Café – JeeLabs . net

Am now starting to understand the browseurl and callback now – but still can’t find an explanation for all the parameters in the callback function.

static void my_callback (byte status, word off, word len)

‘ status ’ – I can not find explanation for this – please help if you know what values can be passed here, and what they mean / represent.

IF I understand this correctly :

When browseurl is first called, it runs asynchronous, until ethernet data arrives, and that buffer is then passed to the callback function.

The first callback has the offset = 54 and len = 512.
If this is the first call, why is there an offset ? Should the data not start at position 1 in the buffer ?

Next, with the use of persistTcpConnection, the browseurl will continue to run until the end of the stream of data ( in 512k blocks ) from the web server arrives.

Does the callback wait to complete its code before the next callback is activated ?

What happens if the second browseurl modifies the buffer while the code in the callback is still busy working with it.

For example, in my callback I have :

static void my_callback (byte status, word off, word len) {
    Serial.println("my_callback initiated");
    Serial.print("Status : ");   Serial.println(status);
    Serial.print("off : ");         Serial.println(off);
    Serial.print("len : ");         Serial.println(len);
    Serial.println((const char*) Ethernet::buffer + off);

    Ethernet::buffer[off+len] = 0;  // after the offset and the length, add an end marker .. is this correct ?  Sample codes showed [off + 300]

    WriteSDfile(2,0,((char*) Ethernet::buffer + off)); // now I need to write ( append ) the data in the buffer to an SD card file ( file number 2, no erase, data to append to file )

    Ethernet::buffer[0] = 0;  // set the end market to the start of the buffer so next received block of data is at the start of the buffer

        if(len != 512){  // if this is the last block of data ( less than len 512 ) then echo the SD Card Data to the Serial Monitor
        Serial.println("......................................");
            Serial.println("Reading Contents of File 2");
        Serial.println("......................................");
            ReadSDfile(2);
        }   
}

Or, is the code in the callback run, and must complete all of its code in the function before the callback can accept new data in the buffer in the next loop of the script execution ?

If this is the case, can the ethernet module modify the data in the ( existing ) buffer while the first instance of the callback function is still trying to process the code.

Would it be better to copy the buffer to a second byte array at the start of the callback, clear the buffer ( Ethernet::buffer[0] = 0; ) and then work with the copy array ?

I would really appreciate any advice here.

Source: Resolved: Does ethercard browseurl callback duplicate callback with persistTcpConnection ? – JeeLabs Café – JeeLabs . net

Resolved: Does ethercard browseurl callback duplicate callback with persistTcpConnection ? – JeeLabs Café – JeeLabs . net was last modified: July 13th, 2017 by Jovan Stosic