[STM32F1] lwip UDP实验遇到的问题

[复制链接]
1045|2
 楼主| wrnb11 发表于 2017-7-12 11:00 | 显示全部楼层 |阅读模式
我用的是STM32F107VCT6的芯片

u8 *replay = "I got a message!\n";
void APP_udp_server_init(void)
{
 //创建控制块
 if(pAppUdpSvrPcb == NULL)
 pAppUdpSvrPcb = udp_new();
 
  /* Bind the upcb to the UDP_PORT port */
   /* Using IP_ADDR_ANY allow the upcb to be used by any local interface */
   udp_bind(pAppUdpSvrPcb, IP_ADDR_ANY, udplocalport);
  
   /* Set a receive callback for the upcb */
   udp_recv(pAppUdpSvrPcb, APP_udp_callback, replay);     //注册回调函数APP_udp_callback,每当接收到网络调试助手发来的信息就会执行回调函数
}

//回调函数,功能是将I got a message!发回网络调试助手
void APP_udp_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{
    struct ip_addr destAddr = *addr;
    if(p != NULL)
   {
       /* Tell the client that we have accepted it */
        memset(p->payload,0,p->len);
        memcpy(p->payload,arg,strlen(arg));
        udp_sendto(upcb,p,&destAddr,port);
       /* Free the p buffer */
       pbuf_free(p);
       udp_disconnect(upcb); 
   }
}
理想的结果应该是显示I got a message!    然而结果却为I (I和一个空格)。也就是说每次发送都只能显示两个字符
后来我在memset和memcpy中间也加了udp_sendto(upcb,p,&destAddr,port);,结果变成了,先输出一个空格,再输出I got a message!

请各位大佬给我解释一下,出现这两种结果的原因,拜托了[img][/img]
hwboy05 发表于 2017-7-12 18:36 来自手机 | 显示全部楼层
这个问题你可以分成2个步骤来定位。首先把接收的数据在串口打印出来,看接收是否正确。然后回调函数中固定发一组数据,看调试助手收到的是否正确。
 楼主| wrnb11 发表于 2017-7-13 10:08 | 显示全部楼层
hwboy05 发表于 2017-7-12 18:36
这个问题你可以分成2个步骤来定位。首先把接收的数据在串口打印出来,看接收是否正确。然后回调函数中固定 ...

谢谢你的回答,我已经知道问题之所在了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

4

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部