Machine Vision Status TCP Server

Dependencies:   C12832 EthernetInterface mbed-rtos mbed ConfigFile

Files at this revision

API Documentation at this revision

Comitter:
dwini
Date:
Mon Jun 15 12:07:05 2015 +0000
Parent:
7:23c8d34000eb
Child:
9:60ce5e733ea6
Commit message:
Use static ip

Changed in this revision

PlcStatusIndicator.h Show annotated file Show diff for this revision Revisions of this file
RGBStatusIndicator.cpp Show annotated file Show diff for this revision Revisions of this file
RGBStatusIndicator.h Show annotated file Show diff for this revision Revisions of this file
StatusIndicator.cpp Show diff for this revision Revisions of this file
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/PlcStatusIndicator.h	Sun Jun 14 10:45:10 2015 +0000
+++ b/PlcStatusIndicator.h	Mon Jun 15 12:07:05 2015 +0000
@@ -2,11 +2,12 @@
 #define PLC_STATUS_INDICATOR_HEADER
 
 #include "Indication.h"
+#include "StatusIndicator.h"
 #include "mbed.h"
 
 namespace MachineVision{
     
-    class PlcStatusIndicator{
+    class PlcStatusIndicator: public StatusIndicator{
         public:
 
         private:
@@ -14,7 +15,7 @@
 
         public:
             PlcStatusIndicator(PinName out_pin);
-            void setStatus(Indication indication); 
+            virtual void setStatus(Indication indication); 
     };
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RGBStatusIndicator.cpp	Mon Jun 15 12:07:05 2015 +0000
@@ -0,0 +1,40 @@
+#include "Indication.h"
+#include "RGBStatusIndicator.h"
+
+namespace MachineVision {
+    
+    RGBStatusIndicator::RGBStatusIndicator(PinName red_pin, PinName green_pin, PinName blue_pin)
+        : rOut(red_pin), gOut(green_pin), bOut(blue_pin) {
+        initializeRGB();       
+    }
+    
+    void RGBStatusIndicator::initializeRGB(void) {
+        rOut.period(0.001);  // set pwm period
+        clearRGB();
+    }
+    
+    void RGBStatusIndicator::setRGB(int r, int g, int b) {
+        rOut = r;
+        gOut = g;
+        bOut = b;
+    }
+    
+    void RGBStatusIndicator::clearRGB(void) {
+        setRGB(255, 255, 255);
+    }
+    
+    void RGBStatusIndicator::setStatus(Indication indication) {
+        switch (indication) {
+            case OK:
+                setRGB(255, 0, 255);
+                break;
+            case FAIL:
+                setRGB(0, 255, 255);
+                break;
+            case CLEAR:
+                clearRGB();
+                break;
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RGBStatusIndicator.h	Mon Jun 15 12:07:05 2015 +0000
@@ -0,0 +1,29 @@
+#ifndef RGB_STATUS_INDICATOR_HEADER
+#define RGB_STATUS_INDICATOR_HEADER
+
+#include "StatusIndicator.h"
+#include "mbed.h"
+
+namespace MachineVision{
+    
+    class RGBStatusIndicator: public StatusIndicator{
+        public:
+
+        private:
+            PwmOut rOut;
+            PwmOut gOut;
+            PwmOut bOut;
+
+        public:
+            RGBStatusIndicator(PinName red_pin, PinName green_pin, PinName blue_pin);
+            virtual void setStatus(Indication indication);  
+
+        private:
+            void initializeRGB(void);
+            void setRGB(int r, int g, int b);
+            void clearRGB(void);
+
+    };
+}
+
+#endif
--- a/StatusIndicator.cpp	Sun Jun 14 10:45:10 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-#include "Indication.h"
-#include "StatusIndicator.h"
-
-namespace MachineVision {
-    
-    StatusIndicator::StatusIndicator(PinName red_pin, PinName green_pin, PinName blue_pin)
-        : rOut(red_pin), gOut(green_pin), bOut(blue_pin) {
-        initializeRGB();       
-    }
-    
-    void StatusIndicator::initializeRGB(void) {
-        rOut.period(0.001);  // set pwm period
-        clearRGB();
-    }
-    
-    void StatusIndicator::setRGB(int r, int g, int b) {
-        rOut = r;
-        gOut = g;
-        bOut = b;
-    }
-    
-    void StatusIndicator::clearRGB(void) {
-        setRGB(255, 255, 255);
-    }
-    
-    void StatusIndicator::setStatus(Indication indication) {
-        switch (indication) {
-            case OK:
-                setRGB(255, 0, 255);
-                break;
-            case FAIL:
-                setRGB(0, 255, 255);
-                break;
-            case CLEAR:
-                clearRGB();
-                break;
-        }
-    }
-}
-
--- a/StatusIndicator.h	Sun Jun 14 10:45:10 2015 +0000
+++ b/StatusIndicator.h	Mon Jun 15 12:07:05 2015 +0000
@@ -6,21 +6,9 @@
 namespace MachineVision{
     
     class StatusIndicator{
-        public:
-
-        private:
-            PwmOut rOut;
-            PwmOut gOut;
-            PwmOut bOut;
 
         public:
-            StatusIndicator(PinName red_pin, PinName green_pin, PinName blue_pin);
-            void setStatus(Indication indication);  
-
-        private:
-            void initializeRGB(void);
-            void setRGB(int r, int g, int b);
-            void clearRGB(void);
+            virtual void setStatus(Indication indication) = 0;  
 
     };
 }
--- a/TcpDaemon.cpp	Sun Jun 14 10:45:10 2015 +0000
+++ b/TcpDaemon.cpp	Mon Jun 15 12:07:05 2015 +0000
@@ -11,7 +11,7 @@
      *
      * @server_port the port the daemon will be listening on
      */
-    TcpDaemon::TcpDaemon(int server_port, PinName accept_led_pin, PinName receive_led_pin, PlcStatusIndicator * indicator)
+    TcpDaemon::TcpDaemon(int server_port, PinName accept_led_pin, PinName receive_led_pin, StatusIndicator * indicator)
          : receive_led(receive_led_pin), accept_led(accept_led_pin) {
         this->server_port = server_port;
         this->keepListening = true;
--- a/TcpDaemon.h	Sun Jun 14 10:45:10 2015 +0000
+++ b/TcpDaemon.h	Mon Jun 15 12:07:05 2015 +0000
@@ -33,7 +33,7 @@
             DigitalOut receive_led;
             
             // Status Indicator
-            PlcStatusIndicator * status_indicator;
+            StatusIndicator * status_indicator;
 
         public:
             /*
@@ -41,7 +41,7 @@
              *
              * @server_port the port the daemon will be listening on
              */
-            TcpDaemon(int server_port, PinName accept_led_pin, PinName receive_led_pin, PlcStatusIndicator * indicator);
+            TcpDaemon(int server_port, PinName accept_led_pin, PinName receive_led_pin, StatusIndicator * indicator);
 
             /*
              * Make the daemon start listening for incoming connections
--- a/main.cpp	Sun Jun 14 10:45:10 2015 +0000
+++ b/main.cpp	Mon Jun 15 12:07:05 2015 +0000
@@ -37,7 +37,7 @@
         Log::v("Bringing ethernet interface online\r\n");
         
         
-//        int success = eth.init();         //Use DHCP
+        //int success = eth.init();         //Use DHCP
         int success = eth.init(IP_ADDRESS, NETMASK, GATEWAY);
         
         if (success < 0 || eth.connect() < 0) {    // Default timeout of 15 seconds
@@ -50,8 +50,8 @@
             setLcdServerInfo(eth.getIPAddress());
         
             // Start the daemon
-//            PlcStatusIndicator status_indicator(p21);
-            PlcStatusIndicator status_indicator(LED4);
+            PlcStatusIndicator status_indicator(p21);
+            //PlcStatusIndicator status_indicator(LED4);
             TcpDaemon daemon(TCP_SERVER_PORT, LED2, LED3, &status_indicator);
             Log::v("TCP daemon listening @ TCP_SERVER_PORT = %d\r\n", TCP_SERVER_PORT);
             daemon.startListening();