Nico De Witte / Mbed 2 deprecated tcp_machine_vision_server_single_client

Dependencies:   C12832 EthernetInterface mbed-rtos mbed ConfigFile

Revision:
6:6cbb21cc3884
Parent:
5:7a32c081a3fa
Child:
7:23c8d34000eb
--- a/main.cpp	Wed Mar 11 12:11:23 2015 +0000
+++ b/main.cpp	Fri Jun 12 12:47:37 2015 +0000
@@ -5,7 +5,6 @@
 #include "StatusIndicator.h"
 
 #define TCP_SERVER_PORT 6666
-
 #define LCD_LINE_HEIGHT 12
 
 Serial pc(USBTX,USBRX);
@@ -25,32 +24,34 @@
 int main (void) {
     pc.baud(115200);
 
-    // Setup ethernet interface    
-    EthernetInterface eth;
-    Log::v("Requesting IP address from DHCP\r\n");
-    eth.init();         //Use DHCP
-    
-    if (eth.connect() < 0) {
-        Log::w("Could not retrieve IP address from DHCP\r\n");
-        setLcdServerInfo("No ip address");
-    } else {
-        Log::v("IP Address is %s\r\n", eth.getIPAddress());
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Starting ...");
+
+    while (true) {
+        // Setup ethernet interface    
+        EthernetInterface eth;
+        Log::v("Bringing ethernet interface online\r\n");
+        
+        // eth.init();         //Use DHCP
+        int success = eth.init("10.0.0.1", "255.255.255.0", "10.0.0.254");
         
-        // Set ip on LCD
-        setLcdServerInfo(eth.getIPAddress());
-    
-        // Start the daemon
-        StatusIndicator status_indicator(p23, p24, p25);
-        TcpDaemon daemon(TCP_SERVER_PORT, LED2, LED3, p14, &status_indicator);
-        Log::v("TCP daemon listening @ TCP_SERVER_PORT = %d\r\n", TCP_SERVER_PORT);
-        daemon.startListening();
-    }
-    
-    // Should never be reached
-    while (true) {
-        error_led = 1;
-        wait(0.25);
-        error_led = 0;
-        wait(0.25);
+        if (success < 0 || eth.connect() < 0) {    // Default timeout of 15 seconds
+            Log::w("Could not bring ethernet interface online\r\n");
+            setLcdServerInfo("No ip address");
+        } else {
+            Log::v("IP Address is %s\r\n", eth.getIPAddress());
+            
+            // Set ip on LCD
+            setLcdServerInfo(eth.getIPAddress());
+        
+            // Start the daemon
+            StatusIndicator status_indicator(p23, p24, p25);
+            TcpDaemon daemon(TCP_SERVER_PORT, LED2, LED3, p14, &status_indicator);
+            Log::v("TCP daemon listening @ TCP_SERVER_PORT = %d\r\n", TCP_SERVER_PORT);
+            daemon.startListening();
+        }
+        
+        pc.printf("Fail");
     }
 }