From 40099599bbca71e899c31ed311acf3f3471d0253 Mon Sep 17 00:00:00 2001
From: athatheocsd <athatheo@csd.auth.gr>
Date: Mon, 24 Dec 2018 00:53:23 +0200
Subject: [PATCH] Some Progress

---
 inc/Services/EventActionService.hpp | 30 ++++++++++++++++++++++++++---
 src/Services/EventActionService.cpp | 19 ++++++++++++++++--
 2 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp
index 6314b2e0..7456b705 100644
--- a/inc/Services/EventActionService.hpp
+++ b/inc/Services/EventActionService.hpp
@@ -2,21 +2,39 @@
 #define ECSS_SERVICES_EVENTACTIONSERVICE_HPP
 
 #include "Service.hpp"
+#include "MessageParser.hpp"
+#include "etl/String.hpp"
 /**
  * Implementation of ST[19] event-action Service
  *
+ * ECSS 8.19 && 6.19
+ *
+ * Note towards the reviewers: Please double-check the string sizes that I use, the string
+ * initialization or rather the lack of it. Pay attention especially in parts of the code that I
+ * use strings <3 .
+ *
  * @todo: Do something with the applicationID.
+ * @todo: check if eventActionFunctionStatus should be private or not
+ * @todo: check if eventAction array of definitions should be private or not
+ * @todo: check size of eventActionDefinitionArray
  */
 class EventActionService : public Service {
-/**
- * @todo: check if this should be private or not
- */
 private:
+	uint16_t nextEventDefinitionIndex;
 	uint8_t eventActionFunctionStatus;
+	// Maybe an array of available slots??? Coz there will be random empty slots after deletion
+	struct EventActionDefinition {
+		uint8_t empty = 1; // 1 means empty, 0 means full
+		uint16_t applicationId = 0;
+		uint16_t eventDefinitionID = 65535;
+		String<ECSS_MAX_STRING_SIZE> request = "";
+	};
+	EventActionDefinition eventActionDefinitionArray[256];
 public:
 	EventActionService() {
 		serviceType = 19;
 		eventActionFunctionStatus = enabledFunction;
+		nextEventDefinitionIndex = 0;
 	}
 
 	/**
@@ -71,6 +89,12 @@ public:
 	 */
 	void disableEventActionFunction(Message message);
 
+	/**
+	 * Custom function that is called right after an event takes place, to initiate
+	 * the execution of the action
+	 */
+	void executeAction();
+
 	/**
 	 * Setter for event-action function status
 	 */
diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp
index e11548d0..a6a6bbb4 100644
--- a/src/Services/EventActionService.cpp
+++ b/src/Services/EventActionService.cpp
@@ -1,14 +1,22 @@
 #include "Services/EventActionService.hpp"
 #include "Message.hpp"
 #include "MessageParser.hpp"
-
+/**
+ * @todo: Should a check be added for lastAddedEventDefinitionIndex to not exceed the
+ * eventActionDefinitionArray ?
+ */
 void EventActionService::addEventActionDefinitions(Message message){
 	// TC[19,1]
 	if (message.messageType == 1 && message.packetType == Message::TC && message.serviceType
 	                                                                     == 19){
+		uint8_t *data;
 		uint16_t N = message.readUint16();
 		for (uint16_t i = 0; i < N; i++){
-
+			eventActionDefinitionArray[].applicationId = message
+				.readEnum16();
+			eventActionDefinitionArray[].eventDefinitionID = message.readEnum16();
+			message.readString(data,ECSS_MAX_STRING_SIZE);
+			eventActionDefinitionArray[].request = String<256>(data);
 		}
 
 	}
@@ -88,3 +96,10 @@ void EventActionService::disableEventActionFunction(Message message) {
 		setEventActionFunctionStatus(EventActionFunctionStatus::disabledFunction);
 	}
 }
+
+void EventActionService::executeAction() {
+	// Custom function
+	if (enabledFunction){
+
+	}
+}
-- 
GitLab