TASS Belgium / Mbed 2 deprecated PicoTCP_Official_TCP_Rx_Benchmark

Dependencies:   PicoTCP lpc1768-picotcp-eth mbed-rtos mbed

Committer:
tass
Date:
Wed Oct 02 08:03:28 2013 +0000
Revision:
0:609212dfbf2a
TCP Official Rx Benchmark

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tass 0:609212dfbf2a 1
tass 0:609212dfbf2a 2 #include <mbed.h>
tass 0:609212dfbf2a 3 #include <stdarg.h>
tass 0:609212dfbf2a 4 #include "EthernetInterface.h"
tass 0:609212dfbf2a 5
tass 0:609212dfbf2a 6 #define ECHO_SERVER_PORT 7
tass 0:609212dfbf2a 7 #define BUFFER_QUANTITY (1024*1024)
tass 0:609212dfbf2a 8 #define BUFFER_SIZE (1024)
tass 0:609212dfbf2a 9
tass 0:609212dfbf2a 10
tass 0:609212dfbf2a 11 EthernetInterface eth;
tass 0:609212dfbf2a 12
tass 0:609212dfbf2a 13 int main()
tass 0:609212dfbf2a 14 {
tass 0:609212dfbf2a 15 TCPSocketServer server;
tass 0:609212dfbf2a 16
tass 0:609212dfbf2a 17 printf("Started PicoTCP Rx Benchmark....\n");
tass 0:609212dfbf2a 18
tass 0:609212dfbf2a 19 eth.init();
tass 0:609212dfbf2a 20 printf("Waiting for DHCP server to give IP...\n");
tass 0:609212dfbf2a 21
tass 0:609212dfbf2a 22 while(eth.connect() != 0);
tass 0:609212dfbf2a 23 printf("IP address assigned : %s\n",eth.getIPAddress());
tass 0:609212dfbf2a 24
tass 0:609212dfbf2a 25 server.bind(ECHO_SERVER_PORT);
tass 0:609212dfbf2a 26 server.listen();
tass 0:609212dfbf2a 27 printf("Local server listening on port : %d\n",ECHO_SERVER_PORT);
tass 0:609212dfbf2a 28
tass 0:609212dfbf2a 29
tass 0:609212dfbf2a 30 while (true) {
tass 0:609212dfbf2a 31 printf("\n>>> You can start PicoTCP_Official_TCP_Rx_Benchmark.py\n");
tass 0:609212dfbf2a 32
tass 0:609212dfbf2a 33 TCPSocketConnection client;
tass 0:609212dfbf2a 34 uint32_t startTime, stopTime;
tass 0:609212dfbf2a 35 server.accept(client);
tass 0:609212dfbf2a 36 client.set_blocking(false, 1500); // Timeout after (1.5)s
tass 0:609212dfbf2a 37
tass 0:609212dfbf2a 38 char buffer[BUFFER_SIZE];
tass 0:609212dfbf2a 39 int dataReceived = 0;
tass 0:609212dfbf2a 40
tass 0:609212dfbf2a 41 startTime = PICO_TIME_MS();
tass 0:609212dfbf2a 42 while(dataReceived < BUFFER_QUANTITY)
tass 0:609212dfbf2a 43 {
tass 0:609212dfbf2a 44 int n = client.receive(buffer, sizeof(buffer));
tass 0:609212dfbf2a 45 if (n <= 0) {
tass 0:609212dfbf2a 46 break;
tass 0:609212dfbf2a 47 }
tass 0:609212dfbf2a 48 dataReceived += n;
tass 0:609212dfbf2a 49 }
tass 0:609212dfbf2a 50 stopTime = PICO_TIME_MS();
tass 0:609212dfbf2a 51
tass 0:609212dfbf2a 52 if(dataReceived == BUFFER_QUANTITY)
tass 0:609212dfbf2a 53 {
tass 0:609212dfbf2a 54 printf("PicoTCP Rx Throughput is : %.3f Mbit/s\n" , (float)((BUFFER_QUANTITY*8.0)/(1000*(stopTime - startTime))));
tass 0:609212dfbf2a 55 }
tass 0:609212dfbf2a 56 else
tass 0:609212dfbf2a 57 {
tass 0:609212dfbf2a 58 printf("Benchmark failed !\n");
tass 0:609212dfbf2a 59 }
tass 0:609212dfbf2a 60 }
tass 0:609212dfbf2a 61 }