
Test
Revision 77:48c622bf903f, committed 2019-01-29
- Comitter:
- HelGast95
- Date:
- Tue Jan 29 09:23:00 2019 +0000
- Parent:
- 76:596c9924e51b
- Child:
- 78:bb7e309408a2
- Commit message:
- se actualiza el json
Changed in this revision
source/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/source/main.cpp Thu Jan 24 11:47:57 2019 +0000 +++ b/source/main.cpp Tue Jan 29 09:23:00 2019 +0000 @@ -1,4 +1,4 @@ -#define END_OF_JSON 0xFE +#define END_OF_JSON 0xFE #include "mbed.h" #include "picojson.h" @@ -11,6 +11,7 @@ #include "ble/DiscoveredService.h" bool serviceDiscovered = false; +char finalCharacterJSON = END_OF_JSON; typedef struct { string id; /* Id */ @@ -31,7 +32,7 @@ Thread threadBLE(osPriorityRealtime3, 1000); /** - * Tarea encargada de parpadear un LED continuamente + * Thread encargado de parpadear un LED continuamente */ void blinkLED3() { while(true) { @@ -56,13 +57,17 @@ * Thread encargado de enviar JSONs por el puerto serie */ void sendJsonOverSerial() { + char tmp[512]; // Vble auxiliar para el tratamiento de cadenas de char. string str; - char final = END_OF_JSON; + while(true) { + // Esperamos a un mensaje en la cola + picojson::object json; picojson::object event; picojson::object extraInfo; + int type = rand() % 3; int idEvent = rand() % 500; event["idEvent"] = picojson::value((double) idEvent); @@ -70,21 +75,21 @@ str = "E9:ED:F4:AC:BF:8E"; extraInfo["hazardousDevice"] = picojson::value(str); str = "D5:62:12:BF:B8:45"; + if(type != 0) extraInfo["affectedDevice"] = picojson::value(str); event["extraInfo"] = picojson::value(extraInfo); + json["Event"] = picojson::value(event); - //printf("Se serializa el string\r\n"); - str = picojson::value(event).serialize(); + str = picojson::value(json).serialize(); // Convertimos el string a char * strncpy(tmp, str.c_str(), sizeof(tmp)); - strncat(tmp, &final, sizeof(final)); // Añadimos el caracter al final + strncat(tmp, &finalCharacterJSON, sizeof(finalCharacterJSON)); // Añadimos el caracter al final tmp[sizeof(tmp) - 1] = 0; - //printf("Se envia un evento por el puesto serie\r\n"); sendCharArrayToSerial(tmp, &pcSerial); - wait(2); + wait(10); } } @@ -230,9 +235,9 @@ int main() { srand(time(NULL)); - threadLED.start(blinkLED3); - //threadBLE.start(BLEServiceManagment); - threadSerial.start(sendJsonOverSerial); + threadLED.start(callback(blinkLED3)); + //threadBLE.start(callback(BLEServiceManagment)); + threadSerial.start(callback(sendJsonOverSerial)); threadLED.join(); threadBLE.join();