From 2d74207f0eeddb9c6cf923a3da37abed96be0f72 Mon Sep 17 00:00:00 2001
From: athatheocsd <athatheo@csd.auth.gr>
Date: Tue, 25 Dec 2018 19:41:09 +0200
Subject: [PATCH] Added Features

---
 inc/Services/EventActionService.hpp |  3 +++
 src/Services/EventActionService.cpp | 35 ++++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp
index 5c7dfc13..59cc8693 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 004e9694..3dc67497 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;
 		}
-
 	}
 }
 
-- 
GitLab