lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] LWIP HTTP Issue sending multiple packets


From: connorla
Subject: [lwip-users] LWIP HTTP Issue sending multiple packets
Date: Thu, 28 May 2015 11:52:13 -0700 (MST)

I am new to lwip use as well as HTTP/TCP protocol. I am working on an Atmel
SAMD21J18A MCU and am utilizing the Atmel example http server. Through this
I am able to make an http connection just fine.

My goal is to read from a digital mems microphone and send this data over
Ethernet via the http connection. My issue resides in that something is
stopping me from sending more than 4 packets when I open the connection. I
have narrowed it down to possibly being the way/order the tcp callbacks are
called. Below is the http_recv function as well as the http_write function
and http_send_data function which are used for sending the data.

/**
 * \brief Core HTTP server receive function. Handle the request and process
it.
 *
 * \param arg Pointer to structure representing the HTTP state.
 * \param pcb Pointer to a TCP connection structure.
 * \param p Incoming request.
 * \param err Connection status.
 *
 * \return ERR_OK.
 */

static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t
err)
{
        char *buf;
        u16_t buflen;
        struct fs_file file;
        struct http_state *hs;
        http_handler_t cgi;

        hs = arg;

        if (err == ERR_OK && p != NULL) {
                /* Inform TCP that we have taken the buf. */
                //tcp_recved(pcb, p->tot_len);

                if (hs->file == NULL) {
                        g_hs = hs;
                        g_pcb = pcb;

                        buf = p->payload;
                        buflen = p->len;
                        memset(req_string, 0, sizeof(req_string));
                        http_getPageName(buf, buflen, req_string,
                                        sizeof(req_string));

                        if (req_string[0] == '\0') {
                                strcpy(req_string, HTTP_DEFAULT_PAGE);
                        }
                        
                        cgi = cgi_search(req_string, cgi_table);
                        if (cgi) {
                                if (cgi(req_string, buf, buflen) < 0) {
                                        http_sendInternalErr(HTTP_CONTENT_HTML);
                                        http_write(http_server_error,
                                                        
sizeof(http_server_error) - 1);
                                }
                        } else {
                                if (fs_open(req_string, &file) == 0) {
                                        http_write(http_html_hdr_404,
                                                        
sizeof(http_html_hdr_404) - 1);
                                } else {
                                        /* Send the HTML header. */
                                        int type = http_searchContentType(
                                                        req_string);
                                        http_sendOk(type);

                                        /* Send the HTML content. */

                                        int 
i,k,j,l,timecapture,sendcount,sendloop;
                                        
                        char **orderedIds;
                        char outbuf2[1536];
                        int ptr2,bufcount,sizecheck,sizecheck2,sizecheck3;
                        orderedIds = (char **)malloc(100 * sizeof(char*));
                                for(timecapture = 0; 
timecapture<100;timecapture++)     
                                {

                                        ptr2 = 0;
                                        for (i = 0; i<1536; i++)//2048
                                        {
                                                ReadI2Sbuf2[i] = 
i2s_serializer_read_wait(&i2s_instance,
I2S_SERIALIZER_0);
                                        }

                                        for (k = 0; k<1536; k++)//2048
                                        {
                                                ptr2 += snprintf(outbuf2 + 
ptr2, sizeof(outbuf2) - ptr2, "%d ",
ReadI2Sbuf2[k]);
                                        }
                                        orderedIds[timecapture] = (char 
*)malloc((1535+1) * sizeof(char));
                                        orderedIds[timecapture] = outbuf2;      
                                

                                }

                        for (bufcount = 0;bufcount<100;bufcount++)
                        {
                                http_write(orderedIds[bufcount],1536);
                                //free(orderedIds[bufcount]);
                        }
                          } 
                                
                        }
                }
        }
        tcp_recved(pcb, p->tot_len);
        pbuf_free(p);

        if (err == ERR_OK && p == NULL) {
                http_close_conn(pcb, hs);
        }

        return ERR_OK;
}

/**
 * \brief Write HTTP data.
 *
 * \param buf Buffer to write.
 * \param len Buffer length.
 */
static void http_write(const char *buf, u32_t len)
{
        g_hs->file = buf;
        g_hs->left = len;


        http_send_data(g_pcb, g_hs);

        /*
         * Tell TCP that we wish be to informed of buf that has been
         * successfully sent by a call to the http_sent() callback.
         */
        tcp_sent(g_pcb, http_sent);
}

/**
 * \brief Send HTTP data.
 *
 * \param pcb Pointer to a TCP connection structure.
 * \param hs Pointer to structure representing the HTTP state.
 */
static void http_send_data(struct tcp_pcb *pcb, struct http_state *hs)
{
        err_t err;
        u32_t len;

        /* We cannot send more data than space available in the send buffer. */
        if (tcp_sndbuf(pcb) < hs->left) {
                len = tcp_sndbuf(pcb);
        } else {
                len = hs->left;
        }

        do {
                /* Use copy flag to avoid using flash as a DMA source 
(forbidden). */
                err = tcp_write(pcb,hs->file,len, 
TCP_WRITE_FLAG_COPY);//replace back into
here hs->file,len
                if (err == ERR_MEM) {
                        len /= 2;
                }
        } while (err == ERR_MEM && len > 1);

        if (err == ERR_OK) {
                hs->file += len;
                hs->left -= len;
        }
}

As can be seen in the recv function, I am using a polling method to get the
mic data and then try to send all the data out in multiple packets. I
realize this is not the most efficient way but I had problems with the
interrupt method and am just looking for functionality. 

The data I receive is a full packet or two and then partial packets, with it
making to about 4 packets at max and then sends nothing else. I have tried
many things in terms of the way I send the data as well as switching around
some of the tcp callbacks but can't pinpoint it. 

Any help is appreciated.




--
View this message in context: 
http://lwip.100.n7.nabble.com/LWIP-HTTP-Issue-sending-multiple-packets-tp24534.html
Sent from the lwip-users mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]