eth

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of FRDM_K64F-Ethernet by Rangel Alvarado

Revision:
2:ff5c01165824
Parent:
1:52ba06578336
Child:
3:5bb986247f20
diff -r 52ba06578336 -r ff5c01165824 main.cpp
--- a/main.cpp	Sun Apr 19 17:00:55 2015 +0000
+++ b/main.cpp	Thu Apr 23 18:33:11 2015 +0000
@@ -1,25 +1,22 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
-#include "gets.h"
+
+#define IP       "192.168.0.52"
+#define MASK   "255.255.255.0"
+#define GW      "0.0.0.0"
+#define PORT   80
 
- 
-#define MBED_DEV_IP       "192.168.0.52"
-#define MBED_DEV_MASK   "255.255.255.0"
-#define MBED_DEV_GW      "0.0.0.0"
-#define ECHO_SERVER_PORT   80
-// 5000
+void getsth(char a, EthernetInterface e, TCPSocketConnection cli);
 
-int main (void) {
-    
-    
+int main (void){
     EthernetInterface eth;
-    eth.init(MBED_DEV_IP, MBED_DEV_MASK, MBED_DEV_GW); //Assign a device ip, mask and gateway
-   // eth.init();
+    eth.init(IP, MASK, GW); //Assign a device ip, mask and gateway
+    // eth.init();
     eth.connect();
     printf("IP Address is %s\n", eth.getIPAddress()); //"192.168.0.52"
-    
+
     TCPSocketServer server;
-    server.bind(ECHO_SERVER_PORT);
+    server.bind(PORT);
     server.listen();
 
     while (true) {
@@ -27,15 +24,31 @@
         TCPSocketConnection client;
         server.accept(client);
         client.set_blocking(false, 1500); // Timeout after (1.5)s
-        
+
         printf("Connection from: %s\n", client.get_address());
         char buffer[256];
         while (true) {
             int n = client.receive(buffer, sizeof(buffer));
-            if(n>0){
-            getsth(buffer[0], eth, client);
-            n=0;
+            if(n>0) {
+                char a = buffer[0];
+                if(a == '1') {
+              client.send_all(eth.getIPAddress(),16);
+                } else if(a == '2') {
+               client.send_all(eth.getGateway(),16);
+                } else if(a == '3') {
+               client.send_all(eth.getMACAddress(),17);
+                } else if(a == '4') {
+               client.send_all(eth.getNetworkMask(),16);
+                }else if(a == 'c'){
+               client.close();
+                }
+                    client.send_all("\n",2);
+                    n=0;
+                    a='0';
+                    
+                }
+
+            }
         }
-     }
-    }
+    
 }