Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read(buf, len) bug....Found error in code... #1752

Closed
glennkreisel opened this issue Dec 21, 2013 · 4 comments
Closed

read(buf, len) bug....Found error in code... #1752

glennkreisel opened this issue Dec 21, 2013 · 4 comments
Assignees
Labels
Component: Core Related to the code for the standard Arduino API Library: Wifi The Wifi Arduino library

Comments

@glennkreisel
Copy link

UPDATE*** I have fixed this code in the udp_dev version..

in ard_utils.c

bool getTcpData(uint8_t sock, void** payload, uint16_t* len)
{
        tData* p = NULL;
        p = get_pBuf(sock);
        if (p != NULL)
        {
                *payload = p->data;
                *len = p->len;
                return true;
        }
        return false;
}

This function should return only the unread contents but instead the whole buffer of old and new data is returned. Even though the read(buf, len) from arduino only asks for 10 bytes. This should accept a LENGTH var and return the data at the current p->idx location up to end of buffered data or LENGTH reached...
This makes the WiFi code on arduino fail for wificlient.read(buf, len)..
So currently you can ONLY read one byte at a time and it is very slow with all the SPI traffic for each byte.

This is called in: ard_spi.c
This routine should accept another param of LENGTH from the arduino and only read that many bytes in the call to GetTcpData.

cmd_spi_state_t get_databuf_tcp_cmd_cb(char* recv, char* reply, void* ctx, uint16_t* count) {

        uint8_t* data;
        uint16_t len;

    CHECK_ARD_NETIF(recv, reply, count);

    if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]<MAX_SOCK_NUM))
    {
            if (getTcpData((uint8_t)recv[4], (void**)&data, &len))
            {
                    CREATE_HEADER_REPLY(reply, recv, PARAM_NUMS_1);
                    PUT_BUFDATA_INT(data, len, reply, 3);
                    END_HEADER_REPLY(reply, 3+len+2+1, *count);
                    freeTcpData((uint8_t)recv[4]);
            }else{
                    CREATE_HEADER_REPLY(reply, recv, PARAM_NUMS_0);
                    END_HEADER_REPLY(reply, 3, *count);
            }
    }
    return SPI_CMD_DONE;
}
@fpoto
Copy link

fpoto commented Dec 27, 2013

Is this related to #1644 ?

@glennkreisel
Copy link
Author

Yes! the function was not implemented practically. I've submitted code but have not heard a word from anyone. I do not have the AVR32 compiler to compile HEX file.. etc.. Any help getting my modified code in?

@q2dg
Copy link

q2dg commented Aug 27, 2015

Well...I don't know if it is relate to this or not (it's more a complaint about documentation), but looking at https://www.arduino.cc/en/Reference/EthernetUDPRead it isn't very clear there are (well, should be) two "modes" in read() method:
-Without parameters: returns only one byte
-With (array,length) parameters: doesn't return anything because the data read is already in array??

Moreover, in example code appears the UDP_TX_PACKET_MAX_SIZE constant which isn't explained anywhere (shouldn't it be UDP_RX_PACKET_MAX_SIZE instead?????) . Little details that make life harder to newcomers...

@agdl
Copy link
Member

agdl commented Jul 12, 2016

This issue was moved to arduino-libraries/WiFi#27

@agdl agdl closed this as completed Jul 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core Related to the code for the standard Arduino API Library: Wifi The Wifi Arduino library
Projects
None yet
Development

No branches or pull requests

7 participants