SENA HD1200 User Manual
Page 46
![background image](/manuals/292729/46/background.png)
Starter Kit and User Manual for the HelloDevice 1200
43
// Initialize length count
total_length=0;
// Start time measurement
start = clock();
// Loop of send/receive
for (j=0; j { // Send command to the HelloDevice err = sendto ( sock, &commandBuf, commandLen, 0, (struct sockaddr*)&clientAddr, sizeof(clientAddr) ; if (err == -1) { error\n"); exit (1); } // Response data = 4-byte address/length + data ResponseBuf = (unsigned char *) calloc(length+4, sizeof(char)) ; // Receive incomming packet.... lenReceived = recvfrom ( sock, 0, (struct sockaddr*)&clientAddr, &clientLen ); if (lenReceived < 0) { receiving???\n") ; exit(0) ; } // Accumulate Total data length received so far... total_length += length + 4 ; // Clear receive length lenReceived = 0 ; ; // Print progress count printf("%dth loop\r", j) ; // Finish the time measurment finish = clock(); // Measure elapsed time in second duration = (double)(finish - start) / CLOCKS_PER_SEC; // Print result printf("\n\n\n%2.3f seconds elapsed for %d loops...\n", duration, loop); bps = ((total_length*8.0)/duration)/1000.0 ; // total bytes * 8 bit/byte / duration sec / 1000 (Kbps) printf("Total %.1f Kbytes transferred...\n", (double)total_length/1000.0) ; printf("%.3f Kbps throughput measured...\n", bps) ; // Close TCP socket TCPSocketClose() ;
)
perror("\nsend
ResponseBuf,
length+4,
perror("\nError
free(ResponseBuf)
}