02 ZYNQ LWIP TCP_SERVER 发送设置

上一次的lwip 调通之后,用网络调试助手,将网路调试助手设为tcp_client 形式,通过网络助手向板子发送数据,板子会在接收到之后发回给网络助手。现在需要测出以太网的速度,思路是使板子一直向pc发送数据,根据30s接收的字节来计算每秒发送的速度。
所以修改有以下几步:
1 找到发送函数 tcp_write tcp_output
2 找到板和pc 连通时上述函数需要的参量pcb


修改过程如下:
1 在主程序中,设置发送数据databuf,增加函数tcp_write tcp_output 如下:
 char databuf1[1024]="this is a demo\r\n";
 while (1) {
  if (TcpFastTmrFlag) {


   tcp_fasttmr();
   TcpFastTmrFlag = 0;
  }
  if (TcpSlowTmrFlag) {
   tcp_slowtmr();
   TcpSlowTmrFlag = 0;
  }
  xemacif_input(echo_netif);
  transfer_data();
  tcp_write(serpcb, databuf1, 1024, 1);
  tcp_output(serpcb);

 }

 /* never reached */
 cleanup_platform();


 return 0;
}

2 在echo.c中添加serpcb ,找到err_t accept_callback(void *arg, struct tcp_pcb *newpcb, err_t err),将new pcb传递给 serpcb,并将serpcb 在main.c 中进行外部引用。

err_t accept_callback(void *arg, struct tcp_pcb *newpcb, err_t err)
{
static int connection = 1;


/* set the receive callback for this connection */
tcp_recv(newpcb, recv_callback);


/* just use an integer number indicating the connection id as the
  callback argument */
tcp_arg(newpcb, (void*)connection);


/* increment for subsequent accepted connections */
connection++;


serpcb=newpcb; // 将建立的pcb赋予全局变量ser_pcb;

return ERR_OK;
}

修改好上述两点后进行保存编译下载,连接网络助手,发现一直发送数据即可。

  
上面的过程是修改之后得到的,但是具体的原因我还没有理清楚,要好好理解下lwip协议。



  • 5
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值