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.

RM48L952: LWIP RAW API send data

Part Number: RM48L952

Hi All:

      I try to implement below tcp/ip connect status. Now, Five clients are connected at the same time, I use usr-tcp232(TCP/IP AP for PC) to simulate echo server, and The server can send data to the client individually, I create tcp_test_event() function, it’s called on switch press.

     The current situation, the client can not send data to the server, but when the server send data to the client(wireshark not record). The client will return to the server along with the previous data. (client send to server data is queued. )

ex: Client 3 send “abcdef”, server send data to Client 3(“12345678”) at next time, Will receive the abcdef12345678

 

here is the code I am using:

static err_t tcp_echoclient_connected(void *arg, struct tcp_pcb *tpcb, err_t err)

{

  struct echoclient *es = NULL;

  if (err == ERR_OK)   

  {

    /* allocate structure es to maintain tcp connection informations */

    es = (struct echoclient *)mem_malloc(sizeof(struct echoclient)); 

es_add[es_count] = (u32_t *)es;

es_PCB[es_count] = (u32_t *)tpcb;

es_count++; 

    if (es != NULL)

    {

      es->state = ES_CONNECTED;

      es->pcb = tpcb;      

      sprintf((char*)tcp_data, "sending tcp client message %d \n\r", tcp_message_count); 

     sciSend( scilinREG, strlen((char *) tcp_data), tcp_data );        

      /* allocate pbuf */

      es->p_tx = pbuf_alloc(PBUF_TRANSPORT, strlen((char*)tcp_data) , PBUF_POOL);         

      if (es->p_tx)

      {       

        /* copy data to pbuf */

        pbuf_take(es->p_tx, (char*)tcp_data, strlen((char*)tcp_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

    {

      /* 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;

}

 

void tcp_test_event(void)

{

struct echoclient *es = NULL;

u32_t i;

struct pbuf *p;

struct tcp_pcb *tpcb;

// for delay //

for(i=0;i<5000000;i++)

__nop();

 

es = (struct echoclient *) es_add[2];

tpcb = (struct tcp_pcb *) es_PCB[2];

 

tcp_active_pcbs = tpcb;

// tpcb = tcp_active_pcbs;

es->state = ES_CONNECTED;

 

      es->pcb = tpcb;

 

      sprintf((char*)tcp_data, "abcdef\n\r");  

     sciSend( scilinREG, strlen((char *) tcp_data), tcp_data );

      

      /* allocate pbuf */

      es->p_tx = pbuf_alloc(PBUF_TRANSPORT, strlen((char*)tcp_data) , PBUF_POOL);

         

//      if (es->p_tx)

//      {       

        /* copy data to pbuf */

        pbuf_take(es->p_tx, (char*)tcp_data, strlen((char*)tcp_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);

 

// (tpcb)->flags |= TF_ACK_NOW;    

//     tcp_recved(tpcb, es->p_tx->tot_len); 

// tcp_write(tpcb, es->p_tx->payload, es->p_tx->len, 1);  

//        tcp_sent(tpcb, NULL);        

//      }

}

 

 

I create tcp_test_event() function, it’s called on switch press.