diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp index 5c7dfc1321f83a775d440f49f0b110803f1df71f..59cc86937e06234bb28b268ee20b83b93a3b3cd1 100644 --- a/inc/Services/EventActionService.hpp +++ b/inc/Services/EventActionService.hpp @@ -4,6 +4,7 @@ #include "Service.hpp" #include "MessageParser.hpp" #include "etl/String.hpp" +#include <bitset> /** * Implementation of ST[19] event-action Service @@ -22,6 +23,7 @@ class EventActionService : public Service { private: uint8_t eventActionFunctionStatus; // Indicates if actions are enabled + std::bitset<256> stateOfEventAction; struct EventActionDefinition { uint8_t empty = 1; // 1 means empty, 0 means full uint16_t applicationId = 0; @@ -35,6 +37,7 @@ public: EventActionService() { serviceType = 19; eventActionFunctionStatus = enabledFunction; + stateOfEventAction.set(); } /** diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index 004e9694e706c20eaa24f11708e481caf13a4796..3dc67497705135ebdb5197b4aa7f2e4d53bb3fa9 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -86,8 +86,23 @@ void EventActionService::enableEventActionDefinitions(Message message) { if (message.messageType == 4 && message.packetType == Message::TC && message.serviceType == 19) { uint16_t N = message.readUint16(); + 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++) { - + 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 + flag = 1; + break; + } + index++; + } + if (flag == 0){ // Found + stateOfEventAction[index] = 1; + } + index = 0; } } @@ -98,10 +113,24 @@ void EventActionService::disableEventActionDefinitions(Message message) { if (message.messageType == 5 && message.packetType == Message::TC && message.serviceType == 19) { uint16_t N = message.readUint16(); + 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++) { - + 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 + flag = 1; + break; + } + index++; + } + if (flag == 0){ // Found + stateOfEventAction[index] = 0; + } + index = 0; } - } }