TCP/IP based digital io controller for operating DigitalsOuts and reading DigitalIns.

Dependencies:   EthernetInterface NetworkAPI mbed-rtos mbed

Fork of NetRelais by Roy van Dam

Files at this revision

API Documentation at this revision

Comitter:
NegativeBlack
Date:
Thu Sep 27 10:00:27 2012 +0000
Parent:
10:22d49341340c
Commit message:
Updated project to latest revision of the NetworkAPI

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
NetworkAPI.lib Show annotated file Show diff for this revision Revisions of this file
controller.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.lib	Thu Jul 19 11:13:50 2012 +0000
+++ b/EthernetInterface.lib	Thu Sep 27 10:00:27 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#0063a5bac04f
+http://mbed.org/users/mbed_official/code/EthernetInterface/#a0ee3ae75cfa
--- a/NetworkAPI.lib	Thu Jul 19 11:13:50 2012 +0000
+++ b/NetworkAPI.lib	Thu Sep 27 10:00:27 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/NegativeBlack/code/NetworkAPI/#9796742904fa
+http://mbed.org/users/NegativeBlack/code/NetworkAPI/#cdee0f2b6ff0
--- a/controller.cpp	Thu Jul 19 11:13:50 2012 +0000
+++ b/controller.cpp	Thu Sep 27 10:00:27 2012 +0000
@@ -56,6 +56,7 @@
 {
     this->_network.server.close();
     this->_network.client.close();
+    return 0;
 }
 
 int
@@ -87,15 +88,15 @@
                     break;
                 
                 default:
-                    printf("Received %d bytes.\n\r%s\r", buffer.length(), (char *)buffer.pointer());
+                    printf("Received %d bytes.\n\r%s\r", buffer.length(), (char *)buffer.data());
                     
                     // Parse command
                     result = this->_parseCommand(buffer);
     
                     // Format reply code
                     buffer.flush();
-                    buffer.setLength(std::snprintf(
-                        (char *)buffer.pointer(), buffer.size(),
+                    buffer.length(std::snprintf(
+                        (char *)buffer.data(), buffer.size(),
                         "e;%i;", result));
                    
                     if (buffer.length() < 4) {
@@ -112,7 +113,9 @@
             this->_network.client.shutdown();
             this->_network.client.close();
         }
-    } 
+    }
+    
+    return 0;
 }
 
 int
@@ -120,7 +123,7 @@
 {
     int index = 0;
     network::Buffer response(32);
-    char *cursor = (char *)buffer.pointer();
+    char *cursor = (char *)buffer.data();
     
     enum Controller::ParseState state = Controller::S_Init;
     enum Controller::Command command = Controller::C_None;
@@ -128,14 +131,14 @@
     while (cursor != NULL) {
         switch (state) {
             case Controller::S_Init: {
-                if (((*cursor) == 'r') && ((*(cursor + 1)) == ';')) {
+                if (((*cursor) == 'r') && ((*(cursor + 1)) == ':')) {
                     command = Controller::C_Read;
                     state = Controller::S_Index;
                     cursor += 2;
                     continue;
                 }
                 
-                if (((*cursor) == 'w') && ((*(cursor + 1)) == ';')) {
+                if (((*cursor) == 'w') && ((*(cursor + 1)) == ':')) {
                     command = Controller::C_Write;
                     state = Controller::S_Index;
                     cursor += 2;
@@ -150,7 +153,19 @@
                     return Controller::E_InvalidFormat;
                 }
                 
-                char *offset = std::strchr(cursor, ';');
+                char *offset;
+                switch (command) {
+                    case Controller::C_Read: {
+                        offset = std::strchr(cursor, ';');
+                        break;
+                    }
+                    
+                    case Controller::C_Write: {
+                        offset = std::strchr(cursor, ':');
+                        break;
+                    }
+                }
+                
                 if (offset == NULL) {
                     return Controller::E_InvalidFormat;
                 }
@@ -168,9 +183,9 @@
                             return Controller::E_UnknownIndex;
                         }
                         
-                        response.setLength(std::snprintf(
-                            (char *)response.pointer(), response.size(),
-                            "r;%d;%d;", index, input->read()));
+                        response.length(std::snprintf(
+                            (char *)response.data(), response.size(),
+                            "r:%d:%d;", index, input->read()));
                        
                         if (response.length() < 6) {
                             printf("Warning: failed to format reply.\n\r");
--- a/mbed-rtos.lib	Thu Jul 19 11:13:50 2012 +0000
+++ b/mbed-rtos.lib	Thu Sep 27 10:00:27 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#01158bb7600c
+http://mbed.org/users/mbed_official/code/mbed-rtos/#9654a71f5a90