Sensos Module Updated

Dependents:   SmartLabProyect

Fork of Middleware by Roberto Herrera

Revision:
1:fd355dc296b1
Parent:
0:d1ff330c5128
diff -r d1ff330c5128 -r fd355dc296b1 Threads.cpp
--- a/Threads.cpp	Sat Dec 05 17:43:29 2015 +0000
+++ b/Threads.cpp	Wed Dec 09 04:44:37 2015 +0000
@@ -12,8 +12,6 @@
 Last update by RoHe 16/11/2015
 
 */
-#include "Threads.h"
-
 #include "Initial.h"
 #include "rtos.h"
 #include "Ether.h"
@@ -21,7 +19,7 @@
 
 static void sw2_press(void)
 {
-    ledGREEN= !ledGREEN;
+    ledBLUE= !ledBLUE;
 
 }
 
@@ -33,17 +31,7 @@
             ledRED=1;//OFF
             ledBLUE=1;//OFF
             ledGREEN = !ledGREEN;
-        } else if(_isConnectedServer1 == true && _isConnectedServer2 == false) {
-            //Color BLUE
-            ledGREEN=1;//OFF
-            ledRED = 1; //OFF
-            ledBLUE = !ledBLUE;
-        } else if(_isConnectedServer1 == false && _isConnectedServer2 == true) {
-            //Color YELLOW  = RED and GREEN
-            ledBLUE =1; //OFF
-            ledRED = !ledRED;
-            ledGREEN = !ledGREEN;
-        } else if(_isConnectedServer1 == false && _isConnectedServer2 == false) {
+        } else {
             //Color RED
             ledGREEN=1;//OFF
             ledBLUE =1; //OFF
@@ -53,36 +41,38 @@
     }
 }
 
-/*
-static bool conect_Server(void)
-{
- ////////////////////// Body of the funtion////////////////////////
-     while (socketTCP1.connect(ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1) < 0) {
-         wait(0.5);
-         return false;
-    }
-return true;
- ////////////////////// end if the funtion////////////////////////
-}
-*/
-static void receivedFromServer1(void const *argument)
+
+static void messsageFromClient(void const *argument)
 {
 
     while (true) {
-        // Receive message from server1
-        n1 = socketTCP1.receive(buf1, 256);
-        buf1[n1] = '\0';
+        pc.printf("Wait for new connection...\n\r");
+        TCPSocketConnection client;
+        serverTCP.accept(client);
+        client.set_blocking(false, 1500); // Timeout after (1.5)s
+
+        pc.printf("Connection from: %s\n\r", client.get_address());
+        char buffer[256];
+        while (true) {
+            int n = client.receive(buffer, sizeof(buffer));
+            if (n <= 0) break;
 
-        if(n1>0) {
-            //pc.printf("Received message from server1 IF: '%s'\n\r", buf1);
-            socketTCP1.close();
-            //isConnectedServer1=false;
-        } else {
-            //_isConnectedServer1==false; //quiere decir que se desconecto del servidor
-            //pc.printf("Not received1 ELSE value of lenght: '%u'\n\r",strlen(buf1));
-            socketTCP1.close();
-            //isConnectedServer1=false;
+            // print received message to terminal
+            buffer[n] = '\0';
+            pc.printf("Received message from Client :'%s'\n\r",buffer);
+
+            // printing message sending to terminal
+            //char* bufferReply = "reply:get:status";
+            // strcat(bufferReply, ":");
+            char* bufferReply = stringManager.processString(buffer,eth.getIPAddress()); //eth.getIPAddress() = address server
+            //char* bufferReply="reply:get:status:192.168.1.71:window:1:0\0";
+            pc.printf("Sending message to Client: '%s'\n\r",bufferReply);
+
+            //Sending to Client
+            client.send_all(bufferReply, strlen(bufferReply));
+            if (n <= 0) break;
         }
+        client.close();
         Thread::wait(500);
     }