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 发送数据

Guru**** 2344400 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/605555/rm48l952-lwip-raw-api-send-data

器件型号:RM48L952

大家好:

   我尝试实现以下 TCP/IP 连接状态。 现在,同时连接了五个客户端,我使用 usr-tcp232(TCP/IP) AP for PC 模拟回显服务器,服务器可以单独向客户端发送数据, 我创建 tcp_test_event()函数,在按下开关时调用它。

   在当前情况下、客户端无法向服务器发送数据、但当服务器向客户端发送数据时(Wireshark 不记录)。 客户端将与之前的数据一起返回到服务器。 (客户端发送到服务器数据已排队。)

例如:客户端3发送“abcdef”,服务器下次将数据发送到客户端3 (“12345678”),将接收 abcdef12345678

 

下面是我使用的代码:

静态 err_t tcp_echoclient_connected (void *arg、struct tcp_pcb、err_t err)

 struct echoclient *es = NULL;

  如果(err =ERR_OK)   

 {

  /*分配结构以维护 TCP 连接信息*/

  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、"正在发送 TCP 客户端消息%d \n\r"、tcp_message_count);  

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

   /*分配 pbuf */

   ES->p_tx = pbuf_alloc (PBUF_transport、strlen ((char*) tcp_data)、PBUF_pool);      

   如果(es->p_tx)

   {     

    /*将数据复制到 pbuf */

    pbuf_take (es->p_tx、(char*) tcp_data、strlen ((char*) tcp_data));

     

    /*将新分配的 es 结构作为参数传递给 tpcb */

    tcp_arg (tpcb、es);

  

    /*初始化 LwIP tcp_recv 回调函数*/  

    tcp_recv (tpcb、tcp_echclient_recv);

  

    /*初始化 LwIP tcp_sent 回调函数*/

    tcp_sent (tpcb、tcp_echclient_sent);

  

    /*初始化 LwIP tcp_poll 回调函数*/

    tcp_poll (tpcb、tcp_echoclient_poll、1);

   

    /*发送数据*/

    tcp_echoclient_send (tpcb、es);

     

    返回 ERR_OK;

   }

  }  

  其他

  {

   /*关闭连接*/

   tcp_echclient_connection_close (tpcb、es);

    

   /*返回内存分配错误*/

   返回 ERR_MEM;  

  }

 }

 其他

 {

  /*关闭连接*/

  tcp_echclient_connection_close (tpcb、es);

 }

 退货错误;

 

void tcp_test_event (void)(空)

struct echoclient *es = NULL;

u32_t i;

struct pbuf *p;

struct tcp_pcb *tpcb;

//表示延迟//

对于(i=0;i<5000000;i++)

_nop();

 

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

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

 

tcp_active_pcb = tpcb;

// tpcb = tcp_active_pcb;

ES->state = ES_Connected;

 

   ES->PCB = tpcb;

 

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

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

    

   /*分配 pbuf */

   ES->p_tx = pbuf_alloc (PBUF_transport、strlen ((char*) tcp_data)、PBUF_pool);

     

//   if (es->p_TX)

//   {     

    /*将数据复制到 pbuf */

    pbuf_take (es->p_tx、(char*) tcp_data、strlen ((char*) tcp_data));

     

    /*将新分配的 es 结构作为参数传递给 tpcb */

    tcp_arg (tpcb、es);

  

    /*初始化 LwIP tcp_recv 回调函数*/  

    tcp_recv (tpcb、tcp_echclient_recv);

     /*初始化 LwIP tcp_sent 回调函数*/

    tcp_sent (tpcb、tcp_echclient_sent);

      /*初始化 LwIP tcp_poll 回调函数*/

    tcp_poll (tpcb、tcp_echoclient_poll、1);

   

    /*发送数据*/

    tcp_echoclient_send (tpcb、es);

 

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

//   tcp_recved (tpcb、es->p_tx->t_t_len);  

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

//    tcp_sent (tpcb、NULL);     

//   }

 

 

我创建 tcp_test_event()函数,它在开关按压时调用

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好 Garg、由于这是原始帖子、您再次发布了修改后的帖子、我将关闭此主题。 如果有理由让它与您的其他帖子同时打开、请访问此链接 :e2e.ti.com/.../605669。 只需回复此主题、即可重新打开。