lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] NETCONN UDP THREAD


From: mgirke
Subject: [lwip-users] NETCONN UDP THREAD
Date: Wed, 19 Oct 2016 07:10:11 -0700 (MST)

Hi,

I am trying to get my NETCONN UDP to work but it doesn´t. Help is very
appreciated. That´s my code so far:

void create_udp_task(uint16_t stack_depth_words,
                unsigned portBASE_TYPE task_priority)
{
        /* Create the task as described above. */
        xTaskCreate(udp_task, (const signed char *const) "UDP",
                        stack_depth_words, NULL, task_priority,
                        NULL);
}

static void udp_task(void *pvParameters)
{
        struct netconn *conn, *newconn;
        struct ip_addr addr;
        static volatile err_t err;
        /* Just to avoid compiler warnings. */
        UNUSED(pvParameters);


        /* Create a new UDP connection handle */
        conn = netconn_new(NETCONN_UDP);
        
        /* Bind to port 10001 with default IP address NULL*/
        err = netconn_bind(conn, NULL, 10001);

        err = netconn_connect(conn, NULL, 10001);

        do {
                if (err == ERR_OK) {
                /* Try to instanciate a new UDPreq task to handle the UDP 
request. */
                        if (NULL == sys_thread_new("UDP-req", udp_request, 
newconn,
UDP_TASK_STACK_SIZE, UDP_TASK_PRIORITY))
                        {
                                /* Failed to instanciate task, free netconn 
socket. NETCONN_CLOSE TCP
ONLY */
                                netconn_delete(newconn);
                        }
                }
        } while (err == ERR_OK);

        netconn_delete(conn);

        /* Delete the calling task. */
        vTaskDelete(NULL);
}

void udp_request(void *pvParameters)
{
        char req_string[80];
        struct netconn *conn;
        struct netbuf *inbuf;
        uint32_t i;
        static volatile err_t err;
        conn = pvParameters;
        
        while(1)
        {
                /* Read the data from the port, blocking if nothing yet there. 
*/
                /* We assume the request is in one netbuf. */
                if (ERR_OK == netconn_recv(conn, &inbuf))
                {
                        i=1;
                        uint8_t  buf1[100];
                        uint16_t buflen[100];
                        char     text[]="HalloWelt";
                        /* Read data from netbuf to the provided buffer. */
                        netbuf_data(inbuf, buf1, &buflen);
                        while(1){
                                if (pdTRUE == xSemaphoreTake(Sem_Timer, 
portMAX_DELAY))
                                {
                                        err = netconn_send(conn, text); 
                                }
                        }
                        
                }
        }


        /* Close the connection (server closes in HTTP). */
        //netconn_close(conn);

        /* Delete the buffer (netconn_recv gives us ownership, */
        /* so we have to make sure to deallocate the buffer). */
        netbuf_delete(inbuf);

        /* Free resource. */
        netconn_delete(conn);

        /* Delete the calling task. */
        vTaskDelete(NULL);
}



--
View this message in context: 
http://lwip.100.n7.nabble.com/NETCONN-UDP-THREAD-tp27622.html
Sent from the lwip-users mailing list archive at Nabble.com.



reply via email to

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