Sensos Module Updated
Fork of Middleware by
StringManager.cpp@4:c59485faea9f, 2015-12-10 (annotated)
- Committer:
- Jorge_Beltran
- Date:
- Thu Dec 10 03:03:11 2015 +0000
- Revision:
- 4:c59485faea9f
- Parent:
- 2:a56763667f20
Updated Sensors Module Added GetLightFuncion
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RoHe | 0:d1ff330c5128 | 1 | /* |
RoHe | 0:d1ff330c5128 | 2 | |
RoHe | 0:d1ff330c5128 | 3 | StringManager.cpp |
RoHe | 0:d1ff330c5128 | 4 | |
RoHe | 0:d1ff330c5128 | 5 | Only to improve the clarity of main .cpp |
RoHe | 0:d1ff330c5128 | 6 | This don't have any new classes |
RoHe | 0:d1ff330c5128 | 7 | |
RoHe | 0:d1ff330c5128 | 8 | This import is use to manage the strings |
RoHe | 0:d1ff330c5128 | 9 | |
RoHe | 0:d1ff330c5128 | 10 | Last update by RoHe 16/11/2015 |
RoHe | 0:d1ff330c5128 | 11 | */ |
RoHe | 0:d1ff330c5128 | 12 | |
RoHe | 1:fd355dc296b1 | 13 | #include <string.h> |
RoHe | 1:fd355dc296b1 | 14 | #include "StringManager.h" |
RoHe | 1:fd355dc296b1 | 15 | |
RoHe | 1:fd355dc296b1 | 16 | StringManager::StringManager() |
RoHe | 1:fd355dc296b1 | 17 | { |
RoHe | 1:fd355dc296b1 | 18 | varInt=5; |
RoHe | 1:fd355dc296b1 | 19 | } |
RoHe | 1:fd355dc296b1 | 20 | |
RoHe | 1:fd355dc296b1 | 21 | bool StringManager::is_good(void) |
RoHe | 1:fd355dc296b1 | 22 | { |
RoHe | 1:fd355dc296b1 | 23 | return true; |
RoHe | 1:fd355dc296b1 | 24 | } |
RoHe | 1:fd355dc296b1 | 25 | |
RoHe | 1:fd355dc296b1 | 26 | int StringManager::getVar(void) |
RoHe | 1:fd355dc296b1 | 27 | { |
RoHe | 1:fd355dc296b1 | 28 | return varInt; |
RoHe | 1:fd355dc296b1 | 29 | } |
RoHe | 1:fd355dc296b1 | 30 | |
RoHe | 1:fd355dc296b1 | 31 | char* StringManager::echo(void) |
RoHe | 1:fd355dc296b1 | 32 | { |
RoHe | 1:fd355dc296b1 | 33 | return "Hello from Library"; |
RoHe | 1:fd355dc296b1 | 34 | } |
RoHe | 1:fd355dc296b1 | 35 | |
RoHe | 1:fd355dc296b1 | 36 | char* StringManager::processString(char* cadena, char* ipServer) |
RoHe | 1:fd355dc296b1 | 37 | { |
RoHe | 1:fd355dc296b1 | 38 | /* |
RoHe | 1:fd355dc296b1 | 39 | largo = strlen(cadena) // Para obtener el largo de una cadena |
RoHe | 1:fd355dc296b1 | 40 | strcpy(destino, origen) // Copia el contenido de origen en destino |
RoHe | 1:fd355dc296b1 | 41 | // destino debe ser lo suficientemente grande |
RoHe | 1:fd355dc296b1 | 42 | strcat(destino, origen) // Agrega el contenido de origen al final de destino |
RoHe | 1:fd355dc296b1 | 43 | // destino debe ser lo suficientemente grande |
RoHe | 1:fd355dc296b1 | 44 | resultado = strcmp(cadena1, cadena2) // Compara dos cadenas |
RoHe | 1:fd355dc296b1 | 45 | // devuelve un valor menor, igual o mayor que 0 según si cadena1 es menor, |
RoHe | 1:fd355dc296b1 | 46 | // igual o mayor que cadena2, respectivamente. |
RoHe | 1:fd355dc296b1 | 47 | posicion = strchr(cadena, caracter) // Devuelve la posición en memoria de la primer |
RoHe | 1:fd355dc296b1 | 48 | // aparición de caracter dentro de cadena |
RoHe | 1:fd355dc296b1 | 49 | posicion = strstr(cadena,subcadena) // Devuelve la posición en memoria de la primer |
RoHe | 1:fd355dc296b1 | 50 | // aparición de subcadena dentro de cadena |
RoHe | 1:fd355dc296b1 | 51 | */ |
RoHe | 1:fd355dc296b1 | 52 | |
RoHe | 1:fd355dc296b1 | 53 | //Case: "set:light:1" -> light ON |
RoHe | 1:fd355dc296b1 | 54 | //if(strncmp(cadena,"set:light:1",strlen(cadena)-2)) { |
RoHe | 1:fd355dc296b1 | 55 | if(strcmp(cadena,"set:light:1\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 56 | int set_light = SetLight(true); |
RoHe | 1:fd355dc296b1 | 57 | //bool isOKLight = getLight(); |
RoHe | 1:fd355dc296b1 | 58 | return "reply:set:light:1:192.168.1.82:success"; |
RoHe | 1:fd355dc296b1 | 59 | //Case: "set:light:1" -> light ON |
RoHe | 1:fd355dc296b1 | 60 | } else if(strcmp(cadena,"set:light:0\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 61 | int set_light = SetLight(false); |
RoHe | 1:fd355dc296b1 | 62 | //bool isOKLight = readLight(); |
RoHe | 1:fd355dc296b1 | 63 | return "reply:set:light:0:192.168.1.82:succes"; |
RoHe | 1:fd355dc296b1 | 64 | } |
RoHe | 1:fd355dc296b1 | 65 | //Case: "get:people" |
RoHe | 1:fd355dc296b1 | 66 | else if(strcmp(cadena,"get:people\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 67 | return stringMakerGetPeople(ipServer); |
RoHe | 1:fd355dc296b1 | 68 | } |
RoHe | 1:fd355dc296b1 | 69 | //Case: "get:presence" |
RoHe | 1:fd355dc296b1 | 70 | else if(strcmp(cadena,"get:presence\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 71 | return stringMakerGetPresence(ipServer); |
RoHe | 1:fd355dc296b1 | 72 | } |
RoHe | 1:fd355dc296b1 | 73 | //Case: "get:door" -> 1 = open , 0 = close |
RoHe | 1:fd355dc296b1 | 74 | else if(strcmp(cadena,"get:door\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 75 | return stringMakerGetDoor(ipServer); |
RoHe | 1:fd355dc296b1 | 76 | } |
RoHe | 1:fd355dc296b1 | 77 | //Case: "get:light" -> 1 = ON , 0 = OFF |
RoHe | 1:fd355dc296b1 | 78 | else if(strcmp(cadena,"get:light\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 79 | return stringMakerGetLight(ipServer); |
RoHe | 1:fd355dc296b1 | 80 | } |
RoHe | 1:fd355dc296b1 | 81 | //Case: "get:window:1" |
RoHe | 1:fd355dc296b1 | 82 | else if(strcmp(cadena,"get:window:1\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 83 | return stringMakerGetWindow1(ipServer); |
RoHe | 1:fd355dc296b1 | 84 | } |
RoHe | 1:fd355dc296b1 | 85 | //Case: "get:window:2" |
RoHe | 1:fd355dc296b1 | 86 | else if(strcmp(cadena,"get:window:2\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 87 | return stringMakerGetWindow2(ipServer); |
RoHe | 1:fd355dc296b1 | 88 | } |
RoHe | 1:fd355dc296b1 | 89 | //Case: "get:window:3" |
RoHe | 1:fd355dc296b1 | 90 | else if(strcmp(cadena,"get:window:3\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 91 | return stringMakerGetWindow3(ipServer); |
RoHe | 1:fd355dc296b1 | 92 | } |
RoHe | 1:fd355dc296b1 | 93 | //Case: "get:room:<IPbroker>" |
RoHe | 1:fd355dc296b1 | 94 | else if(strcmp(cadena,"get:room\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 95 | return stringMakerGetRoom(ipServer); |
RoHe | 1:fd355dc296b1 | 96 | } |
RoHe | 1:fd355dc296b1 | 97 | return "Error,it does NOT in the correct format..."; |
RoHe | 1:fd355dc296b1 | 98 | } |
RoHe | 1:fd355dc296b1 | 99 | |
RoHe | 1:fd355dc296b1 | 100 | char* StringManager::stringMakerGetLight(char* ipServer) |
RoHe | 1:fd355dc296b1 | 101 | { |
RoHe | 1:fd355dc296b1 | 102 | bool get_light /*= getLight()*/; |
RoHe | 1:fd355dc296b1 | 103 | get_light=true; //HARDCODED please remove |
RoHe | 1:fd355dc296b1 | 104 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 105 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 106 | if(get_light) { |
RoHe | 1:fd355dc296b1 | 107 | strcat(initialString,":light:1"); |
RoHe | 1:fd355dc296b1 | 108 | } else { |
RoHe | 1:fd355dc296b1 | 109 | strcat(initialString,":light:0"); |
RoHe | 1:fd355dc296b1 | 110 | } |
RoHe | 1:fd355dc296b1 | 111 | return initialString; |
RoHe | 1:fd355dc296b1 | 112 | } |
RoHe | 1:fd355dc296b1 | 113 | |
RoHe | 1:fd355dc296b1 | 114 | char* StringManager::stringMakerGetDoor(char* ipServer) |
RoHe | 1:fd355dc296b1 | 115 | { |
RoHe | 1:fd355dc296b1 | 116 | bool get_door = GetDoorStatus(); |
RoHe | 1:fd355dc296b1 | 117 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 118 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 119 | if(get_door) { |
RoHe | 1:fd355dc296b1 | 120 | strcat(initialString,":door:1"); |
RoHe | 1:fd355dc296b1 | 121 | } else { |
RoHe | 1:fd355dc296b1 | 122 | strcat(initialString,":door:0"); |
RoHe | 1:fd355dc296b1 | 123 | } |
RoHe | 1:fd355dc296b1 | 124 | return initialString; |
RoHe | 1:fd355dc296b1 | 125 | } |
RoHe | 1:fd355dc296b1 | 126 | |
RoHe | 1:fd355dc296b1 | 127 | char* StringManager::stringMakerGetPresence(char* ipServer) |
RoHe | 1:fd355dc296b1 | 128 | { |
RoHe | 1:fd355dc296b1 | 129 | bool get_presence = GetPrescenceStatus(); |
RoHe | 1:fd355dc296b1 | 130 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 131 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 132 | if(get_presence) { |
RoHe | 1:fd355dc296b1 | 133 | strcat(initialString,":presence:1"); |
RoHe | 1:fd355dc296b1 | 134 | } else { |
RoHe | 1:fd355dc296b1 | 135 | strcat(initialString,":presence:0"); |
RoHe | 1:fd355dc296b1 | 136 | } |
RoHe | 1:fd355dc296b1 | 137 | return initialString; |
RoHe | 1:fd355dc296b1 | 138 | } |
RoHe | 1:fd355dc296b1 | 139 | char* StringManager::stringMakerGetWindow1(char* ipServer) |
RoHe | 1:fd355dc296b1 | 140 | { |
RoHe | 1:fd355dc296b1 | 141 | int get_window1 = GetWindowStatus(1); |
RoHe | 1:fd355dc296b1 | 142 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 143 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 144 | if(get_window1==1) { |
RoHe | 1:fd355dc296b1 | 145 | strcat(initialString,":window:1:1"); |
RoHe | 1:fd355dc296b1 | 146 | } else { |
RoHe | 1:fd355dc296b1 | 147 | strcat(initialString,":window:1:0"); |
RoHe | 1:fd355dc296b1 | 148 | } |
RoHe | 1:fd355dc296b1 | 149 | return initialString; |
RoHe | 1:fd355dc296b1 | 150 | } |
RoHe | 1:fd355dc296b1 | 151 | char* StringManager::stringMakerGetWindow2(char* ipServer) |
RoHe | 1:fd355dc296b1 | 152 | { |
RoHe | 1:fd355dc296b1 | 153 | int get_window2 = GetWindowStatus(2); |
RoHe | 1:fd355dc296b1 | 154 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 155 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 156 | if(get_window2==1) { |
RoHe | 1:fd355dc296b1 | 157 | strcat(initialString,":window:2:1"); |
RoHe | 1:fd355dc296b1 | 158 | } else { |
RoHe | 1:fd355dc296b1 | 159 | strcat(initialString,":window:2:0"); |
RoHe | 1:fd355dc296b1 | 160 | } |
RoHe | 1:fd355dc296b1 | 161 | return initialString; |
RoHe | 1:fd355dc296b1 | 162 | } |
RoHe | 1:fd355dc296b1 | 163 | char* StringManager::stringMakerGetWindow3(char* ipServer) |
RoHe | 1:fd355dc296b1 | 164 | { |
RoHe | 1:fd355dc296b1 | 165 | int get_window3 = GetWindowStatus(3); |
RoHe | 1:fd355dc296b1 | 166 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 167 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 168 | if(get_window3==1) { |
RoHe | 1:fd355dc296b1 | 169 | strcat(initialString,":window:3:1"); |
RoHe | 1:fd355dc296b1 | 170 | } else { |
RoHe | 1:fd355dc296b1 | 171 | strcat(initialString,":window:3:0"); |
RoHe | 1:fd355dc296b1 | 172 | } |
RoHe | 1:fd355dc296b1 | 173 | return initialString; |
RoHe | 1:fd355dc296b1 | 174 | } |
RoHe | 1:fd355dc296b1 | 175 | |
RoHe | 1:fd355dc296b1 | 176 | char* StringManager::stringMakerGetPeople(char* ipServer) |
RoHe | 1:fd355dc296b1 | 177 | { |
RoHe | 1:fd355dc296b1 | 178 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 179 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 180 | if(true) { |
RoHe | 1:fd355dc296b1 | 181 | strcat(initialString,":people:12"); |
RoHe | 1:fd355dc296b1 | 182 | } else { |
RoHe | 1:fd355dc296b1 | 183 | strcat(initialString,":people:0"); |
RoHe | 1:fd355dc296b1 | 184 | } |
RoHe | 1:fd355dc296b1 | 185 | return initialString; |
RoHe | 1:fd355dc296b1 | 186 | } |
RoHe | 1:fd355dc296b1 | 187 | |
RoHe | 1:fd355dc296b1 | 188 | char* StringManager::stringMakerGetRoom(char* ipServer) |
RoHe | 1:fd355dc296b1 | 189 | { |
RoHe | 1:fd355dc296b1 | 190 | bool get_light /*= getLight()*/; |
RoHe | 1:fd355dc296b1 | 191 | bool get_door = GetDoorStatus(); |
RoHe | 1:fd355dc296b1 | 192 | bool get_presence = GetPrescenceStatus(); |
RoHe | 1:fd355dc296b1 | 193 | int get_persons = GetPersonStatus(); |
RoHe | 1:fd355dc296b1 | 194 | int get_window1 = GetWindowStatus(1); |
RoHe | 1:fd355dc296b1 | 195 | int get_window2 = GetWindowStatus(2); |
RoHe | 1:fd355dc296b1 | 196 | int get_window3 = GetWindowStatus(3); |
RoHe | 1:fd355dc296b1 | 197 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 198 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 199 | //GET DOOR |
RoHe | 1:fd355dc296b1 | 200 | if(get_door) { |
RoHe | 1:fd355dc296b1 | 201 | strcat(initialString,":door:1"); |
RoHe | 1:fd355dc296b1 | 202 | } else { |
RoHe | 1:fd355dc296b1 | 203 | strcat(initialString,":door:0"); |
RoHe | 1:fd355dc296b1 | 204 | } |
RoHe | 1:fd355dc296b1 | 205 | //GET LIGHT |
RoHe | 1:fd355dc296b1 | 206 | get_light=true; //HARDCODED please remove |
RoHe | 1:fd355dc296b1 | 207 | if(get_light) { |
RoHe | 1:fd355dc296b1 | 208 | strcat(initialString,":light:1"); |
RoHe | 1:fd355dc296b1 | 209 | } else { |
RoHe | 1:fd355dc296b1 | 210 | strcat(initialString,":light:0"); |
RoHe | 1:fd355dc296b1 | 211 | } |
RoHe | 1:fd355dc296b1 | 212 | //GET WINDOW 1 |
RoHe | 1:fd355dc296b1 | 213 | if(get_window1==1) { |
RoHe | 1:fd355dc296b1 | 214 | strcat(initialString,":window:1:1"); |
RoHe | 1:fd355dc296b1 | 215 | } else { |
RoHe | 1:fd355dc296b1 | 216 | strcat(initialString,":window:1:0"); |
RoHe | 1:fd355dc296b1 | 217 | } |
RoHe | 1:fd355dc296b1 | 218 | //GET WINDOW 2 |
RoHe | 1:fd355dc296b1 | 219 | if(get_window2==1) { |
RoHe | 1:fd355dc296b1 | 220 | strcat(initialString,":2:1"); |
RoHe | 1:fd355dc296b1 | 221 | } else { |
RoHe | 1:fd355dc296b1 | 222 | strcat(initialString,":2:0"); |
RoHe | 1:fd355dc296b1 | 223 | } |
RoHe | 1:fd355dc296b1 | 224 | //GET WINDOW 3 |
RoHe | 1:fd355dc296b1 | 225 | if(get_window3==1) { |
RoHe | 1:fd355dc296b1 | 226 | strcat(initialString,":3:1"); |
RoHe | 1:fd355dc296b1 | 227 | } else { |
RoHe | 1:fd355dc296b1 | 228 | strcat(initialString,":3:0"); |
RoHe | 1:fd355dc296b1 | 229 | } |
RoHe | 1:fd355dc296b1 | 230 | //GET PEOPLE |
RoHe | 1:fd355dc296b1 | 231 | if(true) { |
RoHe | 1:fd355dc296b1 | 232 | strcat(initialString,":people:12"); |
RoHe | 1:fd355dc296b1 | 233 | } else { |
RoHe | 1:fd355dc296b1 | 234 | strcat(initialString,":people:0"); |
RoHe | 1:fd355dc296b1 | 235 | } |
RoHe | 1:fd355dc296b1 | 236 | //GET PRESENCE |
RoHe | 1:fd355dc296b1 | 237 | if(get_presence) { |
RoHe | 1:fd355dc296b1 | 238 | strcat(initialString,":presence:1"); |
RoHe | 1:fd355dc296b1 | 239 | } else { |
RoHe | 1:fd355dc296b1 | 240 | strcat(initialString,":presence:0"); |
RoHe | 1:fd355dc296b1 | 241 | } |
RoHe | 1:fd355dc296b1 | 242 | |
RoHe | 1:fd355dc296b1 | 243 | return initialString; |
RoHe | 1:fd355dc296b1 | 244 | |
RoHe | 1:fd355dc296b1 | 245 | } |