分类: 嵌入式
2013-03-19 15:41:03
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);
}