From 7b3c7b544db8f15bd4cee4f2519c067ef39275e3 Mon Sep 17 00:00:00 2001
From: athatheocsd <athatheo@csd.auth.gr>
Date: Tue, 8 Jan 2019 00:59:35 +0200
Subject: [PATCH] #define

---
 inc/MessageParser.hpp                |  3 ++-
 inc/Services/EventActionService.hpp  | 20 ++++++++++++--------
 src/MessageParser.cpp                |  5 +++--
 src/Services/EventActionService.cpp  | 20 ++++++++++----------
 test/Services/EventActionService.cpp |  4 ++--
 5 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/inc/MessageParser.hpp b/inc/MessageParser.hpp
index 9fc99d9c..0ffa87e3 100644
--- a/inc/MessageParser.hpp
+++ b/inc/MessageParser.hpp
@@ -1,6 +1,7 @@
 #ifndef ECSS_SERVICES_MESSAGEPARSER_HPP
 #define ECSS_SERVICES_MESSAGEPARSER_HPP
 
+#include <Services/EventActionService.hpp>
 #include "Message.hpp"
 
 /**
@@ -45,7 +46,7 @@ public:
 	 * this great analysis:
 	 * stackoverflow.com/questions/15078638/can-i-turn-unsigned-char-into-char-and-vice-versa
 	 */
-	Message parseRequestTC(String<64> data);
+	Message parseRequestTC(String<ECSS_EVENT_SERVICE_STRING_SIZE> data);
 
 private:
 	/**
diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp
index cc9f4823..b4e47c73 100644
--- a/inc/Services/EventActionService.hpp
+++ b/inc/Services/EventActionService.hpp
@@ -1,10 +1,13 @@
 #ifndef ECSS_SERVICES_EVENTACTIONSERVICE_HPP
 #define ECSS_SERVICES_EVENTACTIONSERVICE_HPP
 
+#define ECSS_EVENT_SERVICE_STRING_SIZE 64
+
 #include "Service.hpp"
 #include "MessageParser.hpp"
 #include "etl/String.hpp"
 #include <bitset>
+#include <Services/EventReportService.hpp>
 
 /**
  * Implementation of ST[19] event-action Service
@@ -15,7 +18,7 @@
  * initialization or rather the lack of it. Pay attention especially in parts of the code that I
  * use strings <3 .
  *
-
+ * @todo: (Possible) Use a etl::map for eventActionDefinitionArray
  * @todo: check if executeAction should accept applicationID too
  * @todo: Since there are multiple actions per event and in delete/enable/disable functions are
  * multiple instances are accessed, should I find a more efficient way to access them?
@@ -24,6 +27,13 @@
  * @todo: check size of eventActionDefinitionArray
  */
 class EventActionService : public Service {
+private:
+	/**
+	 * Custom function that is called right after an event takes place, to initiate
+	 * the execution of the action
+	 */
+	void executeAction(uint16_t eventID);
+
 public:
 	uint8_t eventActionFunctionStatus; // Indicates if actions are enabled
 	struct EventActionDefinition {
@@ -39,7 +49,7 @@ public:
 	// If the size is changed maybe then indexOfAvailableSlots as well as the initiating loop in the
 	// constructor should be changed from uint16_t
 	EventActionDefinition eventActionDefinitionArray[256];
-public:
+
 	EventActionService() {
 		serviceType = 19;
 		eventActionFunctionStatus = true;
@@ -99,12 +109,6 @@ public:
 	 */
 	void disableEventActionFunction(Message message);
 
-	/**
-	 * Custom function that is called right after an event takes place, to initiate
-	 * the execution of the action
-	 */
-	private void executeAction(uint16_t eventID);
-
 	/**
 	 * Setter for event-action function status
 	 */
diff --git a/src/MessageParser.cpp b/src/MessageParser.cpp
index 7466092a..05c45b4e 100644
--- a/src/MessageParser.cpp
+++ b/src/MessageParser.cpp
@@ -76,10 +76,11 @@ void MessageParser::parseTC(uint8_t *data, uint16_t length, Message &message) {
 	message.dataSize = length;
 }
 
-Message MessageParser::parseRequestTC(String<64> data) {
+Message MessageParser::parseRequestTC(String<ECSS_EVENT_SERVICE_STRING_SIZE> data) {
 	Message message;
 	uint8_t *dataInt = reinterpret_cast<uint8_t *>(data.data());
 	message.packetType = Message::TC;
-	parseTC(dataInt, 64, message); // Maybe instead of 256 should there be a variable?
+	parseTC(dataInt, ECSS_EVENT_SERVICE_STRING_SIZE,
+	        message); // Maybe instead of 256 should there be a variable?
 	return message;
 }
diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp
index e6207045..9d0e8a8f 100644
--- a/src/Services/EventActionService.cpp
+++ b/src/Services/EventActionService.cpp
@@ -4,7 +4,7 @@
 
 /**
  * @todo: Should a check be added for index to not exceed the size of eventActionDefinitionArray
- * ? Also check if there is needed a uint16_t (in case of changing the size of
+ * ? Also check if there a uint16_t is needed (in case of changing the size of
  * eventActionDefinitionArray
  */
 void EventActionService::addEventActionDefinitions(Message message) {
@@ -12,17 +12,16 @@ void EventActionService::addEventActionDefinitions(Message message) {
 
 	if (message.messageType == 1 && message.packetType == Message::TC && message.serviceType ==
 	                                                                     19) {
-		uint16_t index = 0;
-		uint8_t flag = 0; // used as boolean 0 is false, 1 is true
-		while (eventActionDefinitionArray[index].empty == false) {
-			if (index == 255) { // 255 should be changed depending on size of the array
-				flag = 1;
+		bool flag = true;
+		uint16_t index;
+		for (index = 0; index < 256; index++) {
+			if (eventActionDefinitionArray[index].empty == true) {
+				flag = false;
 				break;
 			}
-			index++;
 		}
-		if (flag == 0) {
-			char data[64];
+		if (!flag) {
+			char data[ECSS_EVENT_SERVICE_STRING_SIZE];
 			eventActionDefinitionArray[index].empty = false;
 			eventActionDefinitionArray[index].enabled = true;
 			eventActionDefinitionArray[index].applicationId = message.readEnum16();
@@ -30,7 +29,8 @@ void EventActionService::addEventActionDefinitions(Message message) {
 			// Tests pass with message.dataSize - 3, message.dataSize - 4, but not
 			// message.dataSize - 5
 			message.readString(data, message.dataSize);
-			eventActionDefinitionArray[index].request = String<64>(data);
+			eventActionDefinitionArray[index].request = String<ECSS_EVENT_SERVICE_STRING_SIZE>(
+				data);
 		}
 	}
 }
diff --git a/test/Services/EventActionService.cpp b/test/Services/EventActionService.cpp
index f1ba1e1b..be585f18 100644
--- a/test/Services/EventActionService.cpp
+++ b/test/Services/EventActionService.cpp
@@ -252,14 +252,14 @@ TEST_CASE("Enable event-action function TC[19,8]", "[service][st09]") {
 	EventActionService eventActionService;
 	Message message(19, 8, Message::TC, 0);
 	eventActionService.enableEventActionFunction(message);
-	CHECK(eventActionService.eventActionFunctionStatus == EventActionService::enabledFunction);
+	CHECK(eventActionService.eventActionFunctionStatus == true);
 }
 
 TEST_CASE("Disable event-action function TC[19,9]", "[service][st09]") {
 	EventActionService eventActionService;
 	Message message(19, 9, Message::TC, 0);
 	eventActionService.disableEventActionFunction(message);
-	CHECK(eventActionService.eventActionFunctionStatus == EventActionService::disabledFunction);
+	CHECK(eventActionService.eventActionFunctionStatus == false);
 }
 
 TEST_CASE("Execute a TC request", "[service][st09]"){
-- 
GitLab