This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C129ENCPDT: sending missing data using memcpy function

Part Number: TM4C129ENCPDT

Hello All,

I want to send 792 byte data from my gateway to the server using ethernet. I take all 792 data to the inside gateway.tcp_message which size is 1024. Before sending this datas to server, I put all data inside data buffer, to do that I use memcpy function. and then sending to server. But When I check the server,  only first 5 byte data is coming every time. other 787 data are missing. What may be the reason of that. What do you adcive to solve this problem?

Gateway.tcp_message_length=1024;

u8_t   data[1024];

memcpy(data,Gateway.tcp_message,Gateway.tcp_message_length);

thank you

BR,

Bekir

  • The problem was about databuffer[6]=0 . so when trying to send data, when it encounters to 6. byte. it just stop sending. that is why other data are missing. How to avoid this problem?because 0 value should be inside the buffer. if you have advice or idea, please let me know

    thank you

    Bekir

  • Hi,

      You are just showing a generic C library function memcpy. How are you sending data over the Ethernet which you did not show. There are several Ethernet client examples in this app note that you can reference. https://www.ti.com/lit/pdf/spna248

  • static err_t tcp_echoclient_connected(void *arg, struct tcp_pcb *tpcb, err_t err)
    {
        struct echoclient *es = NULL;
        uint16_t index2;
        if (err == ERR_OK)
        {
            /* allocate structure es to maintain tcp connection informations */
            es = (struct echoclient *)mem_malloc(sizeof(struct echoclient));
    
            if (es != NULL)
            {
                es->state = ES_CONNECTED;
                es->pcb = tpcb;
    
                if(ETH_Ctrl.connectTYPE == ETHERNET_POST)
                {
                    memcpy(data,Gateway.tcp_message,Gateway.tcp_message_length);
    
                    es->p_tx = pbuf_alloc(PBUF_TRANSPORT, 792 , PBUF_POOL);
    
                    if (es->p_tx)
                    {
                        /* copy data to pbuf */
                        pbuf_take(es->p_tx, (char*)data, strlen((char*)data));
    
                        /* pass newly allocated es structure as argument to tpcb */
                        tcp_arg(tpcb, es);
    
                        /* initialize LwIP tcp_recv callback function */
                        tcp_recv(tpcb, tcp_echoclient_recv);
    
                        /* initialize LwIP tcp_sent callback function */
                        tcp_sent(tpcb, tcp_echoclient_sent);
    
                        /* initialize LwIP tcp_poll callback function */
                        tcp_poll(tpcb, tcp_echoclient_poll, 1);
    
                        /* send data */
                        tcp_echoclient_send(tpcb,es);
    
                        return ERR_OK;
                    }
                }
                else if(ETH_Ctrl.connectTYPE == NTP_CONNECT)
                {
                    memset(data,0,sizeof(data));
    
                    /* allocate pbuf */
                    es->p_tx = pbuf_alloc(PBUF_TRANSPORT, strlen((char*)data) , PBUF_POOL);
    
                    if (es->p_tx)
                    {
                        /* copy data to pbuf */
                        pbuf_take(es->p_tx, (char*)data, strlen((char*)data));
    
                        /* pass newly allocated es structure as argument to tpcb */
                        tcp_arg(tpcb, es);
    
                        /* initialize LwIP tcp_recv callback function */
                        tcp_recv(tpcb, tcp_echoclient_recv);
    
                        /* initialize LwIP tcp_sent callback function */
                        tcp_sent(tpcb, tcp_echoclient_sent);
    
                        /* initialize LwIP tcp_poll callback function */
                        tcp_poll(tpcb, tcp_echoclient_poll, 1);
    
                        /* send data */
                        tcp_echoclient_send(tpcb,es);
    
                        ETH_Ctrl.status = ETH_STATUS_NTP_CONNECTED;
    
                        return ERR_OK;
                    }
                }
            }
            else
            {
                /* close connection */
                tcp_echoclient_connection_close(tpcb, es);
    
                /* return memory allocation error */
                return ERR_MEM;
            }
        }
        else
        {
            /* close connection */
            tcp_echoclient_connection_close(tpcb, es);
        }
        return err;
    }

    I guess it happens something in es->p_tx = pbuf_alloc(PBUF_TRANSPORT, 792 , PBUF_POOL).

    When I am checking by using debug mode, after passing pbuf_alloc command, tot_len which is normally 792 byte become 779 byte. When I look at the data buffer , I see that 779. byte is zero as you can see below.  So I thought that program understand null when it encounter zero. thus it stops putting data new buffer. thus length of new buffer become 779 . I guess this happening in pbuf_alloc function. But I cant find where it is happening

  • > pbuf_take(es->p_tx, (char*)data, strlen((char*)data));

    Maybe this should be something like

    > pbuf_take(es->p_tx, (char*)data, Gateway.tcp_message_length);

  • Hi Bruce,

      Thanks for your insight.  You are correct that the strlen function will only computes the length of the string up to, but not including the terminating null character. 

  • thank you. that was correct.