Machine Vision Status TCP Server

Dependencies:   C12832 EthernetInterface mbed-rtos mbed ConfigFile

Files at this revision

API Documentation at this revision

Comitter:
dwini
Date:
Wed Mar 11 12:11:23 2015 +0000
Parent:
4:339a85b66476
Child:
6:6cbb21cc3884
Commit message:
Add status indication using RGB leds

Changed in this revision

StatusIndicator.h Show annotated file Show diff for this revision Revisions of this file
TcpDaemon.cpp Show annotated file Show diff for this revision Revisions of this file
TcpDaemon.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/StatusIndicator.h	Wed Mar 11 10:26:35 2015 +0000
+++ b/StatusIndicator.h	Wed Mar 11 12:11:23 2015 +0000
@@ -3,10 +3,6 @@
 
 #include "mbed.h"
 
-#define STR_FAIL "FAIL"
-#define STR_OK "OK"
-#define STR_CLEAR "CLEAR"
-
 namespace MachineVision{
     
     enum Indication { OK, FAIL, CLEAR };
--- a/TcpDaemon.cpp	Wed Mar 11 10:26:35 2015 +0000
+++ b/TcpDaemon.cpp	Wed Mar 11 12:11:23 2015 +0000
@@ -1,5 +1,6 @@
 #include "TcpDaemon.h"
 #include "Log.h"
+#include "StatusIndicator.h"
 
 // Incoming message end
 #define END_MSG_SEQUENCE "\r\n"
@@ -10,12 +11,13 @@
      *
      * @server_port the port the daemon will be listening on
      */
-    TcpDaemon::TcpDaemon(int server_port, PinName accept_led_pin, PinName receive_led_pin, PinName trigger_pin)
+    TcpDaemon::TcpDaemon(int server_port, PinName accept_led_pin, PinName receive_led_pin, PinName trigger_pin, StatusIndicator * indicator)
          : receive_led(receive_led_pin), accept_led(accept_led_pin), trigger(trigger_pin) {
         this->server_port = server_port;
         this->keepListening = true;
         this->receive_led = 0;
         this->accept_led = 0;
+        this->status_indicator = indicator;
     }
 
     /*
@@ -122,6 +124,16 @@
                     } else {                           
                         // Full string received, lets do our thing
                         Log::v("Received: %s\r\n", buffer);
+                        
+                        if (strcmp(buffer, STR_OK) == 0) {
+                            status_indicator->setStatus(OK);
+                        } else if (strcmp(buffer, STR_FAIL) == 0) {
+                            status_indicator->setStatus(FAIL);
+                        }  else if (strcmp(buffer, STR_CLEAR) == 0) {
+                            status_indicator->setStatus(CLEAR);
+                        } else {
+                            Log::w("Received unknown message: %s\r\n", buffer);
+                        }
                     }
                 }
                 
--- a/TcpDaemon.h	Wed Mar 11 10:26:35 2015 +0000
+++ b/TcpDaemon.h	Wed Mar 11 12:11:23 2015 +0000
@@ -4,10 +4,15 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 #include "ExternalTrigger.h"
+#include "StatusIndicator.h"
 
 #define MAX_BACKLOG 1
 #define TRIGGER_MSG "TRIGGER\r\n"
 
+#define STR_FAIL "FAIL\r\n"
+#define STR_OK "OK\r\n"
+#define STR_CLEAR "CLEAR\r\n"
+
 namespace MachineVision{
     
     class TcpDaemon{
@@ -29,6 +34,9 @@
             DigitalOut receive_led;
             
             ExternalTrigger trigger;
+            
+            // Status Indicator
+            StatusIndicator * status_indicator;
 
         public:
             /*
@@ -36,7 +44,7 @@
              *
              * @server_port the port the daemon will be listening on
              */
-            TcpDaemon(int server_port, PinName accept_led_pin, PinName receive_led_pin, PinName trigger_pin);
+            TcpDaemon(int server_port, PinName accept_led_pin, PinName receive_led_pin, PinName trigger_pin, StatusIndicator * indicator);
 
             /*
              * Make the daemon start listening for incoming connections
--- a/main.cpp	Wed Mar 11 10:26:35 2015 +0000
+++ b/main.cpp	Wed Mar 11 12:11:23 2015 +0000
@@ -23,9 +23,6 @@
 }
 
 int main (void) {
-    StatusIndicator status_indicator(p23, p24, p25);
-//    status_indicator.setStatus(OK);
-    
     pc.baud(115200);
 
     // Setup ethernet interface    
@@ -43,7 +40,8 @@
         setLcdServerInfo(eth.getIPAddress());
     
         // Start the daemon
-        TcpDaemon daemon(TCP_SERVER_PORT, LED2, LED3, p14);
+        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();
     }