你直接编写一个UDP/TCP程序和PC机通信,让PC机发送几百兆数据给设备,设备直接抛弃数据,在PC侧统计用时,用数据量/时间就是速率了,比TFTP统计还准。而且可以测试多线程下载,打开多条链路,看看多线程对协议栈传输的影响。
《ecos增值包》也中有TFTP源码,硬件无关。
这是《ecos增值包》中PC上位机的测试范例:
//此程序配合开发板webserver.c调试
#include <stdio.h> #include "winsock2.h" #include "windows.h"
void main() {
//---------------------- // Initialize Winsock. WSADATA wsaData; SOCKET ConnectSocket; struct sockaddr_in clientService; int bytesSent,numread,filesize; DWORD dwStart,dwEnd; double delta,rate; unsigned char sendbuf[1];
FILE *fp;
int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if( (fp = fopen( "c:y.pdf", "rb" )) == NULL ){ printf("Problem opening the file
"); return; }
filesize = 0;
if (iResult != NO_ERROR) printf("Error at WSAStartup()
");
//---------------------- // Create a SOCKET for connecting to server ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (ConnectSocket == INVALID_SOCKET) { printf("Error at socket(): %ld
", WSAGetLastError()); WSACleanup(); return; }
//---------------------- // The sockaddr_in structure specifies the address family, // IP address, and port of the server to be connected to. clientService.sin_family = AF_INET; clientService.sin_addr.s_addr = inet_addr( "192.168.0.6" ); clientService.sin_port = ntohs( 2280 );//2280 for 1 channel tcp test ; 2290 for multi tcp test
//---------------------- // Connect to server. if ( connect( ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR) { printf( "Failed to connect.
" ); WSACleanup(); return; }
dwStart = GetTickCount(); while( !feof( fp ) ){ numread = fread( sendbuf, sizeof( char ), sizeof(sendbuf), fp ); if( ferror( fp ) ) { perror( "Read error" ); break; } bytesSent = send( ConnectSocket, sendbuf, numread, 0 ); filesize = filesize + numread; } dwEnd = GetTickCount();
delta = (dwEnd - dwStart) / 1000.0; if(delta < 1E-6 && delta >= 0.0) rate = 0; else rate = filesize * 8 / 1000.0 / delta; printf("File size=%d(bytes) , trans time=%lf(s) , trans rate=%lf(Kbps)
",filesize,delta,rate);
printf("Press any key to continue...
"); getchar();
WSACleanup(); fclose(fp); return; }
上述文档可能不完整或已被更新,想获得该资料的最新最全版本,请访问:www.armecos.com
更多内容,详见: 我的培训中心 我的研发团队 我的技术顾问 文件系统整体解决方案咨询套餐 IP协议栈整体解决方案咨询套餐 USB整体解决方案咨询套餐 BootLoader整体解决方案咨询套餐 |