Sensos Module Updated

Dependents:   SmartLabProyect

Fork of Middleware by Roberto Herrera

Revision:
1:fd355dc296b1
Parent:
0:d1ff330c5128
Child:
2:a56763667f20
--- a/StringManager.cpp	Sat Dec 05 17:43:29 2015 +0000
+++ b/StringManager.cpp	Wed Dec 09 04:44:37 2015 +0000
@@ -10,4 +10,263 @@
 Last update by RoHe 16/11/2015
 */
 
-#include <string.h>
\ No newline at end of file
+#include <string.h>
+#include "StringManager.h"
+
+StringManager::StringManager()
+{
+    varInt=5;
+}
+
+bool StringManager::is_good(void)
+{
+    return true;
+}
+
+int StringManager::getVar(void)
+{
+    return varInt;
+}
+
+char* StringManager::echo(void)
+{
+    return "Hello from Library";
+}
+
+char* StringManager::processString(char* cadena, char* ipServer)
+{
+
+    /*
+    //cadena = "set\n\r\0";
+    int comp = strncmp(cadena,"set",strlen(cadena)-2);
+    //no comparo las ultimos dos caracteres
+    if(comp<0) {
+        //0 si las cadenas son iguales s1<s2 = -X   s1>s2 = X
+        return "cadena is less than Str Received";
+    } else if(comp>0){ La cadena dos es menor
+        return "Str Received is less than cadena";
+    }else{
+        return "String equals XD";
+        }
+        */
+
+    /*
+    largo = strlen(cadena) // Para obtener el largo de una cadena
+    strcpy(destino, origen) // Copia el contenido de origen en destino
+                            // destino debe ser lo suficientemente grande
+    strcat(destino, origen) // Agrega el contenido de origen al final de destino
+                            // destino debe ser lo suficientemente grande
+    resultado = strcmp(cadena1, cadena2) // Compara dos cadenas
+                // devuelve un valor menor, igual o mayor que 0 según si cadena1 es menor,
+                // igual o mayor que cadena2, respectivamente.
+    posicion = strchr(cadena, caracter) // Devuelve la posición en memoria de la primer
+                // aparición de caracter dentro de cadena
+    posicion = strstr(cadena,subcadena) // Devuelve la posición en memoria de la primer
+                // aparición de subcadena dentro de cadena
+    */
+
+    //Case: "set:light:1" -> light ON
+    //if(strncmp(cadena,"set:light:1",strlen(cadena)-2)) {
+    if(strcmp(cadena,"set:light:1\r\n")==0) {
+        int set_light = SetLight(true);
+        //bool isOKLight = getLight();
+        return "reply:set:light:1:192.168.1.82:success";
+        //Case: "set:light:1" -> light ON
+    } else if(strcmp(cadena,"set:light:0\r\n")==0) {
+        int set_light = SetLight(false);
+        //bool isOKLight = readLight();
+        return "reply:set:light:0:192.168.1.82:succes";
+    }
+    //Case: "get:people"
+    else if(strcmp(cadena,"get:people\r\n")==0) {
+        return stringMakerGetPeople(ipServer);
+    }
+    //Case: "get:presence"
+    else if(strcmp(cadena,"get:presence\r\n")==0) {
+        return stringMakerGetPresence(ipServer);
+    }
+    //Case: "get:door" -> 1 = open , 0 = close
+    else if(strcmp(cadena,"get:door\r\n")==0) {
+        return stringMakerGetDoor(ipServer);
+    }
+    //Case: "get:light" -> 1 = ON , 0 = OFF
+    else if(strcmp(cadena,"get:light\r\n")==0) {
+        return stringMakerGetLight(ipServer);
+    }
+    //Case: "get:window:1"
+    else if(strcmp(cadena,"get:window:1\r\n")==0) {
+        return stringMakerGetWindow1(ipServer);
+    }
+    //Case: "get:window:2"
+    else if(strcmp(cadena,"get:window:2\r\n")==0) {
+        return stringMakerGetWindow2(ipServer);
+    }
+    //Case: "get:window:3"
+    else if(strcmp(cadena,"get:window:3\r\n")==0) {
+        return stringMakerGetWindow3(ipServer);
+    }
+    //Case: "get:room:<IPbroker>"
+    else if(strcmp(cadena,"get:room\r\n")==0) {
+        return stringMakerGetRoom(ipServer);
+    }
+    return "Error,it does NOT in the correct format...";
+}
+
+char* StringManager::stringMakerGetLight(char* ipServer)
+{
+    bool get_light /*= getLight()*/;
+    get_light=true; //HARDCODED please remove
+    strcpy(initialString,"reply:get:status:");
+    strcat(initialString,ipServer);
+    if(get_light) {
+        strcat(initialString,":light:1");
+    } else {
+        strcat(initialString,":light:0");
+    }
+    return initialString;
+}
+
+char* StringManager::stringMakerGetDoor(char* ipServer)
+{
+    bool get_door = GetDoorStatus();
+    strcpy(initialString,"reply:get:status:");
+    strcat(initialString,ipServer);
+    if(get_door) {
+        strcat(initialString,":door:1");
+    } else {
+        strcat(initialString,":door:0");
+    }
+    return initialString;
+}
+
+char* StringManager::stringMakerGetPresence(char* ipServer)
+{
+    bool get_presence = GetPrescenceStatus();
+    strcpy(initialString,"reply:get:status:");
+    strcat(initialString,ipServer);
+    if(get_presence) {
+        strcat(initialString,":presence:1");
+    } else {
+        strcat(initialString,":presence:0");
+    }
+    return initialString;
+}
+char* StringManager::stringMakerGetWindow1(char* ipServer)
+{
+    int get_window1 = GetWindowStatus(1);
+    strcpy(initialString,"reply:get:status:");
+    strcat(initialString,ipServer);
+    if(get_window1==1) {
+        strcat(initialString,":window:1:1");
+    } else {
+        strcat(initialString,":window:1:0");
+    }
+    return initialString;
+}
+char* StringManager::stringMakerGetWindow2(char* ipServer)
+{
+    int get_window2 = GetWindowStatus(2);
+    strcpy(initialString,"reply:get:status:");
+    strcat(initialString,ipServer);
+    if(get_window2==1) {
+        strcat(initialString,":window:2:1");
+    } else {
+        strcat(initialString,":window:2:0");
+    }
+    return initialString;
+}
+char* StringManager::stringMakerGetWindow3(char* ipServer)
+{
+    int get_window3 = GetWindowStatus(3);
+    strcpy(initialString,"reply:get:status:");
+    strcat(initialString,ipServer);
+    if(get_window3==1) {
+        strcat(initialString,":window:3:1");
+    } else {
+        strcat(initialString,":window:3:0");
+    }
+    return initialString;
+}
+
+char* StringManager::stringMakerGetPeople(char* ipServer)
+{
+    strcpy(initialString,"reply:get:status:");
+    strcat(initialString,ipServer);
+    if(true) {
+        strcat(initialString,":people:12");
+    } else {
+        strcat(initialString,":people:0");
+    }
+    return initialString;
+}
+
+char* StringManager::stringMakerGetRoom(char* ipServer)
+{
+    bool get_light /*= getLight()*/;
+    bool get_door = GetDoorStatus();
+    bool get_presence = GetPrescenceStatus();
+    int get_persons = GetPersonStatus();
+    int get_window1 = GetWindowStatus(1);
+    int get_window2 = GetWindowStatus(2);
+    int get_window3 = GetWindowStatus(3);
+    strcpy(initialString,"reply:get:status:");
+    strcat(initialString,ipServer);
+    //GET DOOR
+    if(get_door) {
+        strcat(initialString,":door:1");
+    } else {
+        strcat(initialString,":door:0");
+    }
+    //GET LIGHT
+    get_light=true; //HARDCODED please remove
+    if(get_light) {
+        strcat(initialString,":light:1");
+    } else {
+        strcat(initialString,":light:0");
+    }
+    //GET WINDOW 1
+    if(get_window1==1) {
+        strcat(initialString,":window:1:1");
+    } else {
+        strcat(initialString,":window:1:0");
+    }
+    //GET WINDOW 2
+    if(get_window2==1) {
+        strcat(initialString,":2:1");
+    } else {
+        strcat(initialString,":2:0");
+    }
+    //GET WINDOW 3
+    if(get_window3==1) {
+        strcat(initialString,":3:1");
+    } else {
+        strcat(initialString,":3:0");
+    }
+    //GET PEOPLE
+    if(true) {
+        strcat(initialString,":people:12");
+    } else {
+        strcat(initialString,":people:0");
+    }
+    //GET PRESENCE
+    if(get_presence) {
+        strcat(initialString,":presence:1");
+    } else {
+        strcat(initialString,":presence:0");
+    }
+
+    return initialString;
+
+    /*
+    bool get_door = GetDoorStatus();
+        bool get_presence = GetPrescenceStatus();
+        int get_persons = GetPersonStatus();
+        int get_window1 = GetWindowStatus(1);
+        int get_window2 = GetWindowStatus(2);
+        int get_window3 = GetWindowStatus(3);
+
+        return "reply:get:status:192.168.1.82:
+        door:1:light:1:window:1:1:2:1:3:1:people:12:presence:1";
+
+    */
+}