Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1121412
  • 博文数量: 141
  • 博客积分: 2853
  • 博客等级: 少校
  • 技术积分: 2266
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-04 12:03
文章分类

全部博文(141)

文章存档

2014年(3)

2013年(12)

2012年(126)

分类: 嵌入式

2013-03-19 15:41:03

Lwip是通过pcb控制块发送数据包的,类似于文件描述符fd.

我用stm32_wifi模块做服务器,接收电脑的连接。
问题:我必须等到电脑给我的模块发送数据时,调用的回调函数里面给电脑发送数据。不能随时随地的发。

解决办法,上代码,打字真麻烦呀主,要红色部分

struct tcp_pcb *pcb_uart2;//全局变量
static err_t
server_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
  /* Tell TCP that this is the structure we wish to be passed for our callbacks. */
  pcb_uart2=pcb;//必须在这里保存pcb而不是在tcp_server_init,这里的pcb和server_init里面的pcb不是同一个对象,和网络编程中的accept是一个道理
  tcp_arg(pcb, NULL);
  /* Tell TCP that we wish to be informed of incoming data by a call to the http_recv() function. */
  tcp_recv(pcb, server_recv);
  return ERR_OK;
}


void tcp_server_init(void)
{
  struct tcp_pcb *pcb;
  pcb = tcp_new();
  tcp_bind(pcb, IP_ADDR_ANY,2222);
  pcb = tcp_listen(pcb);
  tcp_accept(pcb, server_accept);

}

//用于发送串口2的返回包
void wifi_uart_send(u8 data)
{
 TCP_Data[0]=data;
 tcp_write(pcb_uart2,TCP_Data,1,0);
}


阅读(9053) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~