From 650f996c85a51924018c112d05427c07cc1f80f1 Mon Sep 17 00:00:00 2001
From: athatheo <vostidi@hotmail.com>
Date: Fri, 5 Apr 2019 17:33:18 +0300
Subject: [PATCH] - Changed map to multimap - Added a new variable
 eventActionDefinitionID - Added the size of the multimap as #define in
 ECSS_Definitions.hpp

---
 inc/ECSS_Definitions.hpp            |  5 +++++
 inc/Services/EventActionService.hpp | 16 ++++++++--------
 src/Services/EventActionService.cpp |  6 ++++--
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/inc/ECSS_Definitions.hpp b/inc/ECSS_Definitions.hpp
index a0d12587..f5ea2b94 100644
--- a/inc/ECSS_Definitions.hpp
+++ b/inc/ECSS_Definitions.hpp
@@ -51,6 +51,11 @@
  */
 #define ECSS_TIME_MARGIN_FOR_ACTIVATION  60
 
+/**
+ * @brief Size of the multimap that holds every event-action definition
+ */
+#define ECSS_EVENT_ACTION_STRUCT_MAP_SIZE 256
+
 // todo: Define the maximum delta between the specified
 #define ECSS_MAX_DELTA_OF_RELEASE_TIME   60
 // release time and the actual release time
diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp
index 890c7c07..b7e9b6d3 100644
--- a/inc/Services/EventActionService.hpp
+++ b/inc/Services/EventActionService.hpp
@@ -1,22 +1,21 @@
 #ifndef ECSS_SERVICES_EVENTACTIONSERVICE_HPP
 #define ECSS_SERVICES_EVENTACTIONSERVICE_HPP
 
-
-#define ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE 256
-
 #include "Service.hpp"
 #include "MessageParser.hpp"
 #include "etl/String.hpp"
 #include <Services/EventReportService.hpp>
-#include "etl/map.h"
+#include "etl/multimap.h"
 
 /**
  * Implementation of ST[19] event-action Service
  *
  * ECSS 8.19 && 6.19
  *
- * Note: Make sure the check the note in the addEventActionDefintion()
- *
+ * Note: Make sure the check the note in the addEventActionDefinition()
+ * Note: A third variable was added, the eventActionDefinitionID. This was added for the purpose of identifying
+ * various eventActionDefinitions that correspond to the same eventDefinitionID. The goal is to have multiple actions
+ * be executed when one event takes place. This defies the standard.
  * Note: The application ID was decided to be abolished as an identifier of the event-action
  * definition
  * IMPORTANT: Every event action definition ID should be different, regardless of the application ID
@@ -48,14 +47,15 @@ public:
 	struct EventActionDefinition {
 		// TODO: APID = 0 is the Ground Station APID. This should be changed
 		uint16_t applicationId = 0;
-		uint16_t eventDefinitionID = 65535;
+		uint16_t eventDefinitionID = 65535; // The ID of the event that might take place
+		uint16_t eventActionDefinitionID = 0; // The ID of the event-action
 		String<64> request = "";
 		bool enabled = false;
 	};
 
 	friend EventReportService;
 
-	etl::map<uint16_t, EventActionDefinition, ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE>
+	etl::multimap<uint16_t, EventActionDefinition, ECSS_EVENT_ACTION_STRUCT_MAP_SIZE>
 		eventActionDefinitionMap;
 
 	EventActionService() {
diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp
index 697e2f2b..8cbcdf2d 100644
--- a/src/Services/EventActionService.cpp
+++ b/src/Services/EventActionService.cpp
@@ -9,16 +9,18 @@ void EventActionService::addEventActionDefinitions(Message &message) {
 	message.resetRead();
 	uint16_t applicationID = message.readEnum16();
 	uint16_t eventDefinitionID = message.readEnum16();
+	uint16_t eventActionDefinitionID = message.readEnum16();
 	if (eventActionDefinitionMap.find(eventDefinitionID) == eventActionDefinitionMap.end()) {
-		if (message.dataSize - 4 > ECSS_TC_REQUEST_STRING_SIZE) {
+		if (message.dataSize - 6 > ECSS_TC_REQUEST_STRING_SIZE) {
 			ErrorHandler::reportInternalError(ErrorHandler::MessageTooLarge);
 		} else {
 			char data[ECSS_TC_REQUEST_STRING_SIZE];
-			message.readString(data, message.dataSize - 4);
+			message.readString(data, message.dataSize - 6);
 			EventActionDefinition temp;
 			temp.enabled = false;
 			temp.applicationId = applicationID;
 			temp.eventDefinitionID = eventDefinitionID;
+			temp.eventActionDefinitionID = eventActionDefinitionID;
 			temp.request = String<ECSS_TC_REQUEST_STRING_SIZE>(data);
 			eventActionDefinitionMap.insert(std::make_pair(eventDefinitionID, temp));
 		}
-- 
GitLab