Sensos Module Updated
Fork of Middleware by
StringManager.cpp@1:fd355dc296b1, 2015-12-09 (annotated)
- Committer:
- RoHe
- Date:
- Wed Dec 09 04:44:37 2015 +0000
- Revision:
- 1:fd355dc296b1
- Parent:
- 0:d1ff330c5128
- Child:
- 2:a56763667f20
ok
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 | /* |
RoHe | 1:fd355dc296b1 | 40 | //cadena = "set\n\r\0"; |
RoHe | 1:fd355dc296b1 | 41 | int comp = strncmp(cadena,"set",strlen(cadena)-2); |
RoHe | 1:fd355dc296b1 | 42 | //no comparo las ultimos dos caracteres |
RoHe | 1:fd355dc296b1 | 43 | if(comp<0) { |
RoHe | 1:fd355dc296b1 | 44 | //0 si las cadenas son iguales s1<s2 = -X s1>s2 = X |
RoHe | 1:fd355dc296b1 | 45 | return "cadena is less than Str Received"; |
RoHe | 1:fd355dc296b1 | 46 | } else if(comp>0){ La cadena dos es menor |
RoHe | 1:fd355dc296b1 | 47 | return "Str Received is less than cadena"; |
RoHe | 1:fd355dc296b1 | 48 | }else{ |
RoHe | 1:fd355dc296b1 | 49 | return "String equals XD"; |
RoHe | 1:fd355dc296b1 | 50 | } |
RoHe | 1:fd355dc296b1 | 51 | */ |
RoHe | 1:fd355dc296b1 | 52 | |
RoHe | 1:fd355dc296b1 | 53 | /* |
RoHe | 1:fd355dc296b1 | 54 | largo = strlen(cadena) // Para obtener el largo de una cadena |
RoHe | 1:fd355dc296b1 | 55 | strcpy(destino, origen) // Copia el contenido de origen en destino |
RoHe | 1:fd355dc296b1 | 56 | // destino debe ser lo suficientemente grande |
RoHe | 1:fd355dc296b1 | 57 | strcat(destino, origen) // Agrega el contenido de origen al final de destino |
RoHe | 1:fd355dc296b1 | 58 | // destino debe ser lo suficientemente grande |
RoHe | 1:fd355dc296b1 | 59 | resultado = strcmp(cadena1, cadena2) // Compara dos cadenas |
RoHe | 1:fd355dc296b1 | 60 | // devuelve un valor menor, igual o mayor que 0 según si cadena1 es menor, |
RoHe | 1:fd355dc296b1 | 61 | // igual o mayor que cadena2, respectivamente. |
RoHe | 1:fd355dc296b1 | 62 | posicion = strchr(cadena, caracter) // Devuelve la posición en memoria de la primer |
RoHe | 1:fd355dc296b1 | 63 | // aparición de caracter dentro de cadena |
RoHe | 1:fd355dc296b1 | 64 | posicion = strstr(cadena,subcadena) // Devuelve la posición en memoria de la primer |
RoHe | 1:fd355dc296b1 | 65 | // aparición de subcadena dentro de cadena |
RoHe | 1:fd355dc296b1 | 66 | */ |
RoHe | 1:fd355dc296b1 | 67 | |
RoHe | 1:fd355dc296b1 | 68 | //Case: "set:light:1" -> light ON |
RoHe | 1:fd355dc296b1 | 69 | //if(strncmp(cadena,"set:light:1",strlen(cadena)-2)) { |
RoHe | 1:fd355dc296b1 | 70 | if(strcmp(cadena,"set:light:1\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 71 | int set_light = SetLight(true); |
RoHe | 1:fd355dc296b1 | 72 | //bool isOKLight = getLight(); |
RoHe | 1:fd355dc296b1 | 73 | return "reply:set:light:1:192.168.1.82:success"; |
RoHe | 1:fd355dc296b1 | 74 | //Case: "set:light:1" -> light ON |
RoHe | 1:fd355dc296b1 | 75 | } else if(strcmp(cadena,"set:light:0\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 76 | int set_light = SetLight(false); |
RoHe | 1:fd355dc296b1 | 77 | //bool isOKLight = readLight(); |
RoHe | 1:fd355dc296b1 | 78 | return "reply:set:light:0:192.168.1.82:succes"; |
RoHe | 1:fd355dc296b1 | 79 | } |
RoHe | 1:fd355dc296b1 | 80 | //Case: "get:people" |
RoHe | 1:fd355dc296b1 | 81 | else if(strcmp(cadena,"get:people\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 82 | return stringMakerGetPeople(ipServer); |
RoHe | 1:fd355dc296b1 | 83 | } |
RoHe | 1:fd355dc296b1 | 84 | //Case: "get:presence" |
RoHe | 1:fd355dc296b1 | 85 | else if(strcmp(cadena,"get:presence\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 86 | return stringMakerGetPresence(ipServer); |
RoHe | 1:fd355dc296b1 | 87 | } |
RoHe | 1:fd355dc296b1 | 88 | //Case: "get:door" -> 1 = open , 0 = close |
RoHe | 1:fd355dc296b1 | 89 | else if(strcmp(cadena,"get:door\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 90 | return stringMakerGetDoor(ipServer); |
RoHe | 1:fd355dc296b1 | 91 | } |
RoHe | 1:fd355dc296b1 | 92 | //Case: "get:light" -> 1 = ON , 0 = OFF |
RoHe | 1:fd355dc296b1 | 93 | else if(strcmp(cadena,"get:light\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 94 | return stringMakerGetLight(ipServer); |
RoHe | 1:fd355dc296b1 | 95 | } |
RoHe | 1:fd355dc296b1 | 96 | //Case: "get:window:1" |
RoHe | 1:fd355dc296b1 | 97 | else if(strcmp(cadena,"get:window:1\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 98 | return stringMakerGetWindow1(ipServer); |
RoHe | 1:fd355dc296b1 | 99 | } |
RoHe | 1:fd355dc296b1 | 100 | //Case: "get:window:2" |
RoHe | 1:fd355dc296b1 | 101 | else if(strcmp(cadena,"get:window:2\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 102 | return stringMakerGetWindow2(ipServer); |
RoHe | 1:fd355dc296b1 | 103 | } |
RoHe | 1:fd355dc296b1 | 104 | //Case: "get:window:3" |
RoHe | 1:fd355dc296b1 | 105 | else if(strcmp(cadena,"get:window:3\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 106 | return stringMakerGetWindow3(ipServer); |
RoHe | 1:fd355dc296b1 | 107 | } |
RoHe | 1:fd355dc296b1 | 108 | //Case: "get:room:<IPbroker>" |
RoHe | 1:fd355dc296b1 | 109 | else if(strcmp(cadena,"get:room\r\n")==0) { |
RoHe | 1:fd355dc296b1 | 110 | return stringMakerGetRoom(ipServer); |
RoHe | 1:fd355dc296b1 | 111 | } |
RoHe | 1:fd355dc296b1 | 112 | return "Error,it does NOT in the correct format..."; |
RoHe | 1:fd355dc296b1 | 113 | } |
RoHe | 1:fd355dc296b1 | 114 | |
RoHe | 1:fd355dc296b1 | 115 | char* StringManager::stringMakerGetLight(char* ipServer) |
RoHe | 1:fd355dc296b1 | 116 | { |
RoHe | 1:fd355dc296b1 | 117 | bool get_light /*= getLight()*/; |
RoHe | 1:fd355dc296b1 | 118 | get_light=true; //HARDCODED please remove |
RoHe | 1:fd355dc296b1 | 119 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 120 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 121 | if(get_light) { |
RoHe | 1:fd355dc296b1 | 122 | strcat(initialString,":light:1"); |
RoHe | 1:fd355dc296b1 | 123 | } else { |
RoHe | 1:fd355dc296b1 | 124 | strcat(initialString,":light:0"); |
RoHe | 1:fd355dc296b1 | 125 | } |
RoHe | 1:fd355dc296b1 | 126 | return initialString; |
RoHe | 1:fd355dc296b1 | 127 | } |
RoHe | 1:fd355dc296b1 | 128 | |
RoHe | 1:fd355dc296b1 | 129 | char* StringManager::stringMakerGetDoor(char* ipServer) |
RoHe | 1:fd355dc296b1 | 130 | { |
RoHe | 1:fd355dc296b1 | 131 | bool get_door = GetDoorStatus(); |
RoHe | 1:fd355dc296b1 | 132 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 133 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 134 | if(get_door) { |
RoHe | 1:fd355dc296b1 | 135 | strcat(initialString,":door:1"); |
RoHe | 1:fd355dc296b1 | 136 | } else { |
RoHe | 1:fd355dc296b1 | 137 | strcat(initialString,":door:0"); |
RoHe | 1:fd355dc296b1 | 138 | } |
RoHe | 1:fd355dc296b1 | 139 | return initialString; |
RoHe | 1:fd355dc296b1 | 140 | } |
RoHe | 1:fd355dc296b1 | 141 | |
RoHe | 1:fd355dc296b1 | 142 | char* StringManager::stringMakerGetPresence(char* ipServer) |
RoHe | 1:fd355dc296b1 | 143 | { |
RoHe | 1:fd355dc296b1 | 144 | bool get_presence = GetPrescenceStatus(); |
RoHe | 1:fd355dc296b1 | 145 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 146 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 147 | if(get_presence) { |
RoHe | 1:fd355dc296b1 | 148 | strcat(initialString,":presence:1"); |
RoHe | 1:fd355dc296b1 | 149 | } else { |
RoHe | 1:fd355dc296b1 | 150 | strcat(initialString,":presence:0"); |
RoHe | 1:fd355dc296b1 | 151 | } |
RoHe | 1:fd355dc296b1 | 152 | return initialString; |
RoHe | 1:fd355dc296b1 | 153 | } |
RoHe | 1:fd355dc296b1 | 154 | char* StringManager::stringMakerGetWindow1(char* ipServer) |
RoHe | 1:fd355dc296b1 | 155 | { |
RoHe | 1:fd355dc296b1 | 156 | int get_window1 = GetWindowStatus(1); |
RoHe | 1:fd355dc296b1 | 157 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 158 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 159 | if(get_window1==1) { |
RoHe | 1:fd355dc296b1 | 160 | strcat(initialString,":window:1:1"); |
RoHe | 1:fd355dc296b1 | 161 | } else { |
RoHe | 1:fd355dc296b1 | 162 | strcat(initialString,":window:1:0"); |
RoHe | 1:fd355dc296b1 | 163 | } |
RoHe | 1:fd355dc296b1 | 164 | return initialString; |
RoHe | 1:fd355dc296b1 | 165 | } |
RoHe | 1:fd355dc296b1 | 166 | char* StringManager::stringMakerGetWindow2(char* ipServer) |
RoHe | 1:fd355dc296b1 | 167 | { |
RoHe | 1:fd355dc296b1 | 168 | int get_window2 = GetWindowStatus(2); |
RoHe | 1:fd355dc296b1 | 169 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 170 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 171 | if(get_window2==1) { |
RoHe | 1:fd355dc296b1 | 172 | strcat(initialString,":window:2:1"); |
RoHe | 1:fd355dc296b1 | 173 | } else { |
RoHe | 1:fd355dc296b1 | 174 | strcat(initialString,":window:2:0"); |
RoHe | 1:fd355dc296b1 | 175 | } |
RoHe | 1:fd355dc296b1 | 176 | return initialString; |
RoHe | 1:fd355dc296b1 | 177 | } |
RoHe | 1:fd355dc296b1 | 178 | char* StringManager::stringMakerGetWindow3(char* ipServer) |
RoHe | 1:fd355dc296b1 | 179 | { |
RoHe | 1:fd355dc296b1 | 180 | int get_window3 = GetWindowStatus(3); |
RoHe | 1:fd355dc296b1 | 181 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 182 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 183 | if(get_window3==1) { |
RoHe | 1:fd355dc296b1 | 184 | strcat(initialString,":window:3:1"); |
RoHe | 1:fd355dc296b1 | 185 | } else { |
RoHe | 1:fd355dc296b1 | 186 | strcat(initialString,":window:3:0"); |
RoHe | 1:fd355dc296b1 | 187 | } |
RoHe | 1:fd355dc296b1 | 188 | return initialString; |
RoHe | 1:fd355dc296b1 | 189 | } |
RoHe | 1:fd355dc296b1 | 190 | |
RoHe | 1:fd355dc296b1 | 191 | char* StringManager::stringMakerGetPeople(char* ipServer) |
RoHe | 1:fd355dc296b1 | 192 | { |
RoHe | 1:fd355dc296b1 | 193 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 194 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 195 | if(true) { |
RoHe | 1:fd355dc296b1 | 196 | strcat(initialString,":people:12"); |
RoHe | 1:fd355dc296b1 | 197 | } else { |
RoHe | 1:fd355dc296b1 | 198 | strcat(initialString,":people:0"); |
RoHe | 1:fd355dc296b1 | 199 | } |
RoHe | 1:fd355dc296b1 | 200 | return initialString; |
RoHe | 1:fd355dc296b1 | 201 | } |
RoHe | 1:fd355dc296b1 | 202 | |
RoHe | 1:fd355dc296b1 | 203 | char* StringManager::stringMakerGetRoom(char* ipServer) |
RoHe | 1:fd355dc296b1 | 204 | { |
RoHe | 1:fd355dc296b1 | 205 | bool get_light /*= getLight()*/; |
RoHe | 1:fd355dc296b1 | 206 | bool get_door = GetDoorStatus(); |
RoHe | 1:fd355dc296b1 | 207 | bool get_presence = GetPrescenceStatus(); |
RoHe | 1:fd355dc296b1 | 208 | int get_persons = GetPersonStatus(); |
RoHe | 1:fd355dc296b1 | 209 | int get_window1 = GetWindowStatus(1); |
RoHe | 1:fd355dc296b1 | 210 | int get_window2 = GetWindowStatus(2); |
RoHe | 1:fd355dc296b1 | 211 | int get_window3 = GetWindowStatus(3); |
RoHe | 1:fd355dc296b1 | 212 | strcpy(initialString,"reply:get:status:"); |
RoHe | 1:fd355dc296b1 | 213 | strcat(initialString,ipServer); |
RoHe | 1:fd355dc296b1 | 214 | //GET DOOR |
RoHe | 1:fd355dc296b1 | 215 | if(get_door) { |
RoHe | 1:fd355dc296b1 | 216 | strcat(initialString,":door:1"); |
RoHe | 1:fd355dc296b1 | 217 | } else { |
RoHe | 1:fd355dc296b1 | 218 | strcat(initialString,":door:0"); |
RoHe | 1:fd355dc296b1 | 219 | } |
RoHe | 1:fd355dc296b1 | 220 | //GET LIGHT |
RoHe | 1:fd355dc296b1 | 221 | get_light=true; //HARDCODED please remove |
RoHe | 1:fd355dc296b1 | 222 | if(get_light) { |
RoHe | 1:fd355dc296b1 | 223 | strcat(initialString,":light:1"); |
RoHe | 1:fd355dc296b1 | 224 | } else { |
RoHe | 1:fd355dc296b1 | 225 | strcat(initialString,":light:0"); |
RoHe | 1:fd355dc296b1 | 226 | } |
RoHe | 1:fd355dc296b1 | 227 | //GET WINDOW 1 |
RoHe | 1:fd355dc296b1 | 228 | if(get_window1==1) { |
RoHe | 1:fd355dc296b1 | 229 | strcat(initialString,":window:1:1"); |
RoHe | 1:fd355dc296b1 | 230 | } else { |
RoHe | 1:fd355dc296b1 | 231 | strcat(initialString,":window:1:0"); |
RoHe | 1:fd355dc296b1 | 232 | } |
RoHe | 1:fd355dc296b1 | 233 | //GET WINDOW 2 |
RoHe | 1:fd355dc296b1 | 234 | if(get_window2==1) { |
RoHe | 1:fd355dc296b1 | 235 | strcat(initialString,":2:1"); |
RoHe | 1:fd355dc296b1 | 236 | } else { |
RoHe | 1:fd355dc296b1 | 237 | strcat(initialString,":2:0"); |
RoHe | 1:fd355dc296b1 | 238 | } |
RoHe | 1:fd355dc296b1 | 239 | //GET WINDOW 3 |
RoHe | 1:fd355dc296b1 | 240 | if(get_window3==1) { |
RoHe | 1:fd355dc296b1 | 241 | strcat(initialString,":3:1"); |
RoHe | 1:fd355dc296b1 | 242 | } else { |
RoHe | 1:fd355dc296b1 | 243 | strcat(initialString,":3:0"); |
RoHe | 1:fd355dc296b1 | 244 | } |
RoHe | 1:fd355dc296b1 | 245 | //GET PEOPLE |
RoHe | 1:fd355dc296b1 | 246 | if(true) { |
RoHe | 1:fd355dc296b1 | 247 | strcat(initialString,":people:12"); |
RoHe | 1:fd355dc296b1 | 248 | } else { |
RoHe | 1:fd355dc296b1 | 249 | strcat(initialString,":people:0"); |
RoHe | 1:fd355dc296b1 | 250 | } |
RoHe | 1:fd355dc296b1 | 251 | //GET PRESENCE |
RoHe | 1:fd355dc296b1 | 252 | if(get_presence) { |
RoHe | 1:fd355dc296b1 | 253 | strcat(initialString,":presence:1"); |
RoHe | 1:fd355dc296b1 | 254 | } else { |
RoHe | 1:fd355dc296b1 | 255 | strcat(initialString,":presence:0"); |
RoHe | 1:fd355dc296b1 | 256 | } |
RoHe | 1:fd355dc296b1 | 257 | |
RoHe | 1:fd355dc296b1 | 258 | return initialString; |
RoHe | 1:fd355dc296b1 | 259 | |
RoHe | 1:fd355dc296b1 | 260 | /* |
RoHe | 1:fd355dc296b1 | 261 | bool get_door = GetDoorStatus(); |
RoHe | 1:fd355dc296b1 | 262 | bool get_presence = GetPrescenceStatus(); |
RoHe | 1:fd355dc296b1 | 263 | int get_persons = GetPersonStatus(); |
RoHe | 1:fd355dc296b1 | 264 | int get_window1 = GetWindowStatus(1); |
RoHe | 1:fd355dc296b1 | 265 | int get_window2 = GetWindowStatus(2); |
RoHe | 1:fd355dc296b1 | 266 | int get_window3 = GetWindowStatus(3); |
RoHe | 1:fd355dc296b1 | 267 | |
RoHe | 1:fd355dc296b1 | 268 | return "reply:get:status:192.168.1.82: |
RoHe | 1:fd355dc296b1 | 269 | door:1:light:1:window:1:1:2:1:3:1:people:12:presence:1"; |
RoHe | 1:fd355dc296b1 | 270 | |
RoHe | 1:fd355dc296b1 | 271 | */ |
RoHe | 1:fd355dc296b1 | 272 | } |