HAPSRG / Mbed OS UDP_Client_0003

Dependencies:   UsaClient

Files at this revision

API Documentation at this revision

Comitter:
cocorlow
Date:
Sat Nov 06 19:06:40 2021 +0000
Parent:
1:c050a4297deb
Commit message:
speed test

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Oct 28 05:26:27 2021 +0000
+++ b/main.cpp	Sat Nov 06 19:06:40 2021 +0000
@@ -5,8 +5,11 @@
 EthernetInterface net;
 DigitalIn button(PC_13);
 
+using namespace std::chrono;
+
 int main()
 {
+    printf("system start.\r\n");
     SocketAddress sockAddr;
     if (net.connect() != 0)
     {
@@ -17,20 +20,47 @@
     printf("IP: %s\r\n", sockAddr.get_ip_address() ? sockAddr.get_ip_address() : "No IP");
     
     
-    UsaClient udp(&net, "192.168.251.42", 10000); // server IP address, Port number
-    uint8_t send[6] = {1, 4, 9, 16, 25, 0};
-    uint8_t recv[6];
+    UsaClient udp(&net, "192.168.10.109", 10000); // server IP address, Port number
+    uint8_t send[200];
+    uint8_t recv[200];
+    
+    int wN = 100;
+    int rN = 100;
+    
+    Timer t;
     
     while (1)
     {
         if (button)
         {
-            send[5] += 1;
-            udp.Write(2, send, 6);
+            printf("\r\n##########################\r\n");
+            printf("write start\r\n");
+            printf("wN = %d\r\n", wN);
+            t.reset();
+            t.start();
+            for (int i = 0; i < wN; i++)
+            {   
+                send[0] = i;
+                udp.Write(0, send, 100);
+            }
+            t.stop();
+            printf("write: %llu us\r\n", duration_cast<microseconds>(t.elapsed_time()).count());
+            
+            ThisThread::sleep_for(chrono::milliseconds(1000));
+            
+            printf("read start\r\n");
+            printf("r = %d\r\n", wN);
+            t.reset();
+            t.start();
+            for (int i = 0; i < rN; i++)
+            {
+                udp.Read(0, recv, 100);
+            }
+            t.stop();
+            printf("%d\r\n", recv[0]);
+            printf("read : %llu us\r\n", duration_cast<microseconds>(t.elapsed_time()).count());
+            ThisThread::sleep_for(chrono::milliseconds(1000));
         }
-        udp.Read(2, recv, 6);
-        printf("%3d, %3d, %3d, %3d, %3d, %3d\r\n", recv[0], recv[1], recv[2], recv[3], recv[4], recv[5]);
-        ThisThread::sleep_for(chrono::milliseconds(100));
     }
 }
     
\ No newline at end of file