上一次的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);
上面的过程是修改之后得到的,但是具体的原因我还没有理清楚,要好好理解下lwip协议。
所以修改有以下几步:
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协议。