diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index 2067190eaec6d45a943885194df8ac7cf5eb663e..bad8d216d4f5f2ce5c1425a91897b17edd9915b1 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -16,18 +16,18 @@ void EventActionService::addEventActionDefinitions(Message message) { uint8_t index = 0; uint8_t flag = 0; // used as boolean 0 is false, 1 is true for (uint16_t i = 0; i < N; i++) { - while (eventActionDefinitionArray[index].empty == 0){ - if (index == 255){ // 255 should be changed depending on size of the array + while (eventActionDefinitionArray[index].empty == 0) { + if (index == 255) { // 255 should be changed depending on size of the array flag = 1; break; } index++; } - if (flag == 1){ + if (flag == 1) { eventActionDefinitionArray[index].empty = 0; eventActionDefinitionArray[index].applicationId = message.readEnum16(); eventActionDefinitionArray[index].eventDefinitionID = message.readEnum16(); - message.readString(data, ECSS_MAX_STRING_SIZE); + message.readString(data, ECSS_MAX_STRING_SIZE); // ECSS_MAX_STRING_SIZE?? eventActionDefinitionArray[index].request = String<256>(data); index++; } @@ -39,7 +39,7 @@ void EventActionService::addEventActionDefinitions(Message message) { void EventActionService::deleteEventActionDefinitions(Message message) { // TC[19,2] if (message.messageType == 2 && message.packetType == Message::TC && message.serviceType - == 19) { + == 19) { uint16_t N = message.readUint16(); uint8_t index = 0; uint8_t flag = 0; // used as boolean 0 is false, 1 is true @@ -47,14 +47,14 @@ void EventActionService::deleteEventActionDefinitions(Message message) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); while (eventActionDefinitionArray[index].applicationId != applicationID || - eventActionDefinitionArray[index].eventDefinitionID != eventDefinitionID){ - if (index == 255){ // 255 should be changed depending on size of the array + eventActionDefinitionArray[index].eventDefinitionID != eventDefinitionID) { + if (index == 255) { // 255 should be changed depending on size of the array flag = 1; break; } index++; } - if (flag == 0){ // Found + if (flag == 0) { // Found eventActionDefinitionArray[index].empty = 1; eventActionDefinitionArray[index].eventDefinitionID = 65535; eventActionDefinitionArray[index].request = ""; @@ -71,7 +71,7 @@ void EventActionService::deleteAllEventActionDefinitions(Message message) { if (message.messageType == 3 && message.packetType == Message::TC && message.serviceType == 19) { for (uint16_t index = 0; index < 256; index++) { - if (eventActionDefinitionArray[index].empty == 0){ + if (eventActionDefinitionArray[index].empty == 0) { eventActionDefinitionArray[index].empty = 1; eventActionDefinitionArray[index].eventDefinitionID = 65535; eventActionDefinitionArray[index].request = ""; @@ -92,14 +92,14 @@ void EventActionService::enableEventActionDefinitions(Message message) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); while (eventActionDefinitionArray[index].applicationId != applicationID || - eventActionDefinitionArray[index].eventDefinitionID != eventDefinitionID){ - if (index == 255){ // 255 should be changed depending on size of the array + eventActionDefinitionArray[index].eventDefinitionID != eventDefinitionID) { + if (index == 255) { // 255 should be changed depending on size of the array flag = 1; break; } index++; } - if (flag == 0){ // Found + if (flag == 0) { // Found stateOfEventAction[index] = 1; } index = 0; @@ -119,14 +119,14 @@ void EventActionService::disableEventActionDefinitions(Message message) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); while (eventActionDefinitionArray[index].applicationId != applicationID || - eventActionDefinitionArray[index].eventDefinitionID != eventDefinitionID){ - if (index == 255){ // 255 should be changed depending on size of the array + eventActionDefinitionArray[index].eventDefinitionID != eventDefinitionID) { + if (index == 255) { // 255 should be changed depending on size of the array flag = 1; break; } index++; } - if (flag == 0){ // Found + if (flag == 0) { // Found stateOfEventAction[index] = 0; } index = 0; @@ -170,20 +170,21 @@ void EventActionService::disableEventActionFunction(Message message) { setEventActionFunctionStatus(EventActionFunctionStatus::disabledFunction); } } + // Should I use the name execute here instead of executeAction? void EventActionService::executeAction(uint16_t eventID) { // Custom function if (eventActionFunctionStatus == enabledFunction) { uint16_t i = 0; - while (i < 256){ - if (eventActionDefinitionArray[i].empty == 0){ - if (eventActionDefinitionArray[i].eventDefinitionID == eventID){ + while (i < 256) { + if (eventActionDefinitionArray[i].empty == 0) { + if (eventActionDefinitionArray[i].eventDefinitionID == eventID) { break; } } i++; } - if (i != 256){ // If i == 256 that means that no matching eventId was found + if (i != 256) { // If i == 256 that means that no matching eventId was found MessageParser messageParser; Message message = messageParser.parseRequestTC(eventActionDefinitionArray[i].request); messageParser.execute(message); diff --git a/src/Services/EventReportService.cpp b/src/Services/EventReportService.cpp index f24dfac7943da3a1f7d30853790976769b18fe78..2c243c25517806fd45b5acd1f012081d85c298ca 100644 --- a/src/Services/EventReportService.cpp +++ b/src/Services/EventReportService.cpp @@ -13,7 +13,7 @@ void EventReportService::informativeEventReport(Event eventID, String<64> data) report.appendEnum16(eventID); report.appendString(data); EventActionService eventActionService; -// eventActionService.executeAction(eventID); + eventActionService.executeAction(eventID); storeMessage(report); } diff --git a/test/Services/EventActionService.cpp b/test/Services/EventActionService.cpp index 3fe04d023f19545266c88eab2bc72289887357c0..676ba0eba9229eeb87cd92defd1f6ff48f40b4ad 100644 --- a/test/Services/EventActionService.cpp +++ b/test/Services/EventActionService.cpp @@ -7,10 +7,11 @@ TEST_CASE("Add event-action definitions TC[19,1]", "[service][st09]") { EventActionService eventActionService; Message message(19, 1, Message::TC, 0); + } TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st09]") { - + } TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st09]") {