UDP Experiment Server

Dependents:   Bezier_Trajectory_Follower Dolphin 2_131TEST Jerby ... more

Files at this revision

API Documentation at this revision

Comitter:
gbravop
Date:
Fri Jul 19 16:57:05 2019 +0000
Parent:
9:5a1f3abfca66
Commit message:
Updated For Mbed 5

Changed in this revision

ExperimentServer.cpp Show annotated file Show diff for this revision Revisions of this file
ExperimentServer.h Show annotated file Show diff for this revision Revisions of this file
diff -r 5a1f3abfca66 -r 20f31902ac9f ExperimentServer.cpp
--- a/ExperimentServer.cpp	Mon Sep 14 14:28:07 2015 +0000
+++ b/ExperimentServer.cpp	Fri Jul 19 16:57:05 2019 +0000
@@ -24,18 +24,38 @@
         _terminal->printf("\r\n==============================\r\nStarting Server\r\n");
         _terminal->printf("...Intializing Ethernet\r\n");
     }
-    _eth.init(ip_addr,subnet_mask,gateway);
     
-    if(_terminal!=NULL)
-        _terminal->printf("...Connecting\r\n");    
-    _eth.connect();
+    int code = _eth.set_network(ip_addr,subnet_mask,gateway);
+    if(_terminal!=NULL) {
+        _terminal->printf("...Connecting\r\n");
+        if(code!=0) 
+            _terminal->printf("Error Code = %d\r\n",code);
+    }
+       
+    code = _eth.connect();
+    if(_terminal!=NULL) {
+        _terminal->printf("...Ethernet IP Address is %s\r\n",_eth.get_ip_address());
+        if(code!=0) 
+            _terminal->printf("Error Code = %d\r\n",code);    
+    }
     
-    if(_terminal!=NULL)
-        _terminal->printf("...Ethernet IP Address is %s\r\n", _eth.getIPAddress());
+    SocketAddress sock;
+    sock.set_port(port);
+    sock.set_ip_address(ip_addr);
     
-    _server.bind(port);
-    if(_terminal!=NULL)
-        _terminal->printf("...Listening on Port %d\r\n", port);
+    code = _server.open(&_eth);
+    if(_terminal!=NULL) {
+        _terminal->printf("...Opened\n");
+        if(code!=0) 
+            _terminal->printf("Error Code = %d\r\n",code);    
+    }
+    
+    code = _server.bind(sock);
+    if(_terminal!=NULL) {
+        _terminal->printf("...Listening on Port %d\r\n",port);
+        if(code!=0) 
+            _terminal->printf("Error Code = %d\r\n",code);
+    }
 }
 
 int ExperimentServer::getParams(float params[], int num_params) {
@@ -44,7 +64,7 @@
         _terminal->printf("...Waiting for parameters...\r\n");
     }
         
-    int n = _server.receiveFrom(_client,(char *) params, num_params*sizeof(float));    
+    int n = _server.recvfrom(&_client,(char *) params, num_params*sizeof(float));    
     if ( (n% 4) > 0 ) {
         if(_terminal!=NULL) {
             _terminal->printf("ERROR: input data bad size\r\n");
@@ -61,7 +81,7 @@
     }
     
     if(_terminal!=NULL) {
-        _terminal->printf("...Received input from: %s\r\n", _client.get_address());
+        _terminal->printf("...Received input from: %s\r\n", _client.get_ip_address());
         _terminal->printf("...Parameters: \r\n");
         for ( int j = 0 ; j < n/sizeof(float) ; j++) {
             _terminal->printf("      %d) %f\r\n",j+1,params[j]);
@@ -71,7 +91,7 @@
 }
 void ExperimentServer::flushBuffer() {
     if(_data_cnt > 0) {
-         _server.sendTo(_client,(char*) _buffer, 4*_data_cnt );    
+         _server.sendto(_client,(char*) _buffer, 4*_data_cnt );    
         _data_cnt = 0;
     }
 }
@@ -87,5 +107,5 @@
 void ExperimentServer::setExperimentComplete() {
     flushBuffer();
     char buff[] = {'0'};
-    _server.sendTo(_client,buff,1);
+    _server.sendto(_client,buff,1);
 }   
\ No newline at end of file
diff -r 5a1f3abfca66 -r 20f31902ac9f ExperimentServer.h
--- a/ExperimentServer.h	Mon Sep 14 14:28:07 2015 +0000
+++ b/ExperimentServer.h	Fri Jul 19 16:57:05 2019 +0000
@@ -90,7 +90,7 @@
     void flushBuffer(); // Sends all data in buffer to the host
     
     EthernetInterface _eth; // Low level ethernet object
-    Endpoint _client;       // Stores client connected to server
+    SocketAddress _client;       // Stores client connected to server
     UDPSocket _server;      // Low level UDP server object
     Serial * _terminal;     // Pointer to attached terminal for debugging