Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: PicoTCP lpc1768-picotcp-eth mbed-rtos mbed
Revision 1:81060ee2ac04, committed 2013-10-03
- Comitter:
- tass
- Date:
- Thu Oct 03 07:05:52 2013 +0000
- Parent:
- 0:28a7ae57d114
- Commit message:
- UDP Rx Official Benchmark
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Jul 26 11:30:50 2013 +0000
+++ b/main.cpp Thu Oct 03 07:05:52 2013 +0000
@@ -1,6 +1,7 @@
#include "mbed.h"
#include "EthernetInterface.h"
+#define MEGA (1024*1024)
#define BUFFER_SIZE 1024
#define NUMBER_OF_SECONDS (20*1000u) // 20 seconds
@@ -12,6 +13,7 @@
{
int BytesReceived;
int FramesReceived;
+ int LostPackets;
};
struct UDPStat UDP_Statistics;
@@ -38,36 +40,34 @@
while(true)
{
unsigned int time = PICO_TIME_MS();
+ int index = -1;
memset(&UDP_Statistics,0x0,sizeof(struct UDPStat));
while( (time + NUMBER_OF_SECONDS) >= (unsigned int)PICO_TIME_MS())
{
int size;
size = server.receiveFrom(endp,buffer,sizeof(buffer));
- if(size <= 0)
+ if(size > 0)
{
- if(!size)
- printf("Receive timeout\n");
- else
- printf("Receive returned error\n");
- }
- else
- {
+ int _index;
UDP_Statistics.BytesReceived += size;
UDP_Statistics.FramesReceived++;
+ _index = *((int *)buffer);
+
+ if(index>0)
+ {
+ UDP_Statistics.LostPackets+= _index-index-1;
+ }
+ index = _index;
}
}
time = PICO_TIME_MS() - time;
time = time/1000;
- printf("Connection statistics for 20 seconds :\n");
+ printf("20 seconds Rx statistics\n");
printf("Total bytes received : %d\n",UDP_Statistics.BytesReceived);
- printf("Average bytes received :%.2f per sec\n",(float)(UDP_Statistics.BytesReceived)/time);
-
- printf("Total frames received :%d\n",UDP_Statistics.FramesReceived);
- printf("Average frames received :%.2f per sec\n",(float)(UDP_Statistics.FramesReceived)/time);
-
- printf("Loss percentage: %.2f %%\n\n\n",((NUMBER_OF_FRAMES - (float)UDP_Statistics.FramesReceived/time)/NUMBER_OF_FRAMES)*100);
+ printf("UDP Speed :%.3f Mbit/s\n",(UDP_Statistics.BytesReceived *8.0)/(20.0*MEGA));
+ printf("Loss percentage: %.2f %%\n\n\n",(UDP_Statistics.LostPackets*100.0)/(UDP_Statistics.LostPackets+UDP_Statistics.FramesReceived));
}
server.close();