From d1ced8ab2a0ca6be7e05652f720b1b2db519e713 Mon Sep 17 00:00:00 2001
From: athatheocsd <athatheo@csd.auth.gr>
Date: Thu, 29 Nov 2018 19:15:54 +0200
Subject: [PATCH] Added enum definition for event ID, changed tests to test the
 event ID enums. Tests passed.

---
 inc/Services/EventReportService.hpp  | 35 +++++++++++++++++++++++----
 src/Services/EventReportService.cpp  | 15 +++++++-----
 src/main.cpp                         | 20 +++++++++-------
 test/Services/EventReportService.cpp | 36 +++++++++++++++-------------
 4 files changed, 72 insertions(+), 34 deletions(-)

diff --git a/inc/Services/EventReportService.hpp b/inc/Services/EventReportService.hpp
index 828aa26d..8a1d8b35 100644
--- a/inc/Services/EventReportService.hpp
+++ b/inc/Services/EventReportService.hpp
@@ -5,6 +5,11 @@
 /**
  * Implementation of ST[05] event reporting service
  * @todo add enum event definition id (and maybe some appending?)
+ *
+ * @todo changes enums event IDs
+ *
+ * Note: enum IDs are these just for test purposes
+ *
  */
 #define CSS_EVENTS_MAX_COUNT 16
 #define ECSS_EVENTS_BITS 16
@@ -15,6 +20,25 @@ public:
 		serviceType = 5;
 	}
 
+	enum InformationEvent {
+		UnknownEvent = 0,
+		WWDGReset = 1,
+		AssertionFail = 2,
+		MCUStart = 3,
+	};
+
+	enum LowSeverityAnomalyEvent {
+		LowSeverityUnknownEvent = 1,
+	};
+
+	enum MediumSeverityAnomalyEvent {
+		MediumSeverityUnknownEvent = 2,
+	};
+
+	enum HighSeverityAnomalyEvent {
+		HighSeverityUnknownEvent = 3,
+	};
+
 	/**
 	 * TM[5,1] informative event report
 	 * Send report to inform the respective recipients about an event
@@ -25,7 +49,7 @@ public:
 	 * @param data the data of the report
 	 * @param length the length of the data
 	 */
-	void informativeEventReport(uint16_t eventID, const uint8_t *data, uint8_t length);
+	void informativeEventReport(InformationEvent eventID, const uint8_t *data, uint8_t length);
 
 	/**
 	 * TM[5,2] low severiity anomaly report
@@ -37,7 +61,8 @@ public:
 	 * @param data the data of the report
 	 * @param length the length of the data
 	 */
-	void lowSeverityAnomalyReport(uint16_t eventID, const uint8_t *data, uint8_t length);
+	void
+	lowSeverityAnomalyReport(LowSeverityAnomalyEvent eventID, const uint8_t *data, uint8_t length);
 
 	/**
 	 * TM[5,3] medium severity anomaly report
@@ -49,7 +74,8 @@ public:
 	 * @param data the data of the report
 	 * @param length the length of the data
 	 */
-	void mediumSeverityAnomalyReport(uint16_t eventID, const uint8_t *data, uint8_t length);
+	void mediumSeverityAnomalyReport(MediumSeverityAnomalyEvent eventID, const uint8_t *data,
+	                                 uint8_t length);
 
 	/**
 	 * TM[5,4] high severity anomaly report
@@ -61,7 +87,8 @@ public:
 	 * @param data the data of the report
 	 * @param length the length of the data
 	 */
-	void highSeverityAnomalyReport(uint16_t eventID, const uint8_t *data, uint8_t length);
+	void highSeverityAnomalyReport(HighSeverityAnomalyEvent eventID, const uint8_t *data,
+	                               uint8_t length);
 
 };
 
diff --git a/src/Services/EventReportService.cpp b/src/Services/EventReportService.cpp
index bb3b68e3..0a89f5c9 100644
--- a/src/Services/EventReportService.cpp
+++ b/src/Services/EventReportService.cpp
@@ -2,7 +2,7 @@
 #include "Message.hpp"
 
 
-void EventReportService::informativeEventReport(uint16_t eventID, const uint8_t *data,
+void EventReportService::informativeEventReport(InformationEvent eventID, const uint8_t *data,
                                                 uint8_t length) {
 	// TM[5,1]
 	Message report = createTM(1);
@@ -12,8 +12,9 @@ void EventReportService::informativeEventReport(uint16_t eventID, const uint8_t
 	storeMessage(report);
 }
 
-void EventReportService::lowSeverityAnomalyReport(uint16_t eventID, const uint8_t *data,
-                                                  uint8_t length) {
+void
+EventReportService::lowSeverityAnomalyReport(LowSeverityAnomalyEvent eventID, const uint8_t *data,
+                                             uint8_t length) {
 	// TM[5,2]
 	Message report = createTM(2);
 	report.appendEnum16(eventID);
@@ -22,7 +23,8 @@ void EventReportService::lowSeverityAnomalyReport(uint16_t eventID, const uint8_
 	storeMessage(report);
 }
 
-void EventReportService::mediumSeverityAnomalyReport(uint16_t eventID, const uint8_t *data,
+void EventReportService::mediumSeverityAnomalyReport(MediumSeverityAnomalyEvent eventID,
+                                                     const uint8_t *data,
                                                      uint8_t length) {
 	// TM[5,3]
 	Message report = createTM(3);
@@ -32,8 +34,9 @@ void EventReportService::mediumSeverityAnomalyReport(uint16_t eventID, const uin
 	storeMessage(report);
 }
 
-void EventReportService::highSeverityAnomalyReport(uint16_t eventID, const uint8_t *data,
-                                                   uint8_t length) {
+void
+EventReportService::highSeverityAnomalyReport(HighSeverityAnomalyEvent eventID, const uint8_t *data,
+                                              uint8_t length) {
 	// TM[5,4]
 	Message report = createTM(4);
 	report.appendEnum16(eventID);
diff --git a/src/main.cpp b/src/main.cpp
index 07d2c891..936f63cd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -67,13 +67,13 @@ int main() {
 	rcvPack.appendEnum8(MemoryManagementService::MemoryID::RAM); // Memory ID
 	rcvPack.appendUint16(3); // Iteration count
 	rcvPack.appendUint64(reinterpret_cast<uint64_t >(string)); // Start address
-	rcvPack.appendUint16(sizeof(string)/ sizeof(string[0])); // Data read length
+	rcvPack.appendUint16(sizeof(string) / sizeof(string[0])); // Data read length
 
 	rcvPack.appendUint64(reinterpret_cast<uint64_t >(anotherStr));
-	rcvPack.appendUint16(sizeof(anotherStr)/ sizeof(anotherStr[0]));
+	rcvPack.appendUint16(sizeof(anotherStr) / sizeof(anotherStr[0]));
 
 	rcvPack.appendUint64(reinterpret_cast<uint64_t >(yetAnotherStr));
-	rcvPack.appendUint16(sizeof(yetAnotherStr)/ sizeof(yetAnotherStr[0]));
+	rcvPack.appendUint16(sizeof(yetAnotherStr) / sizeof(yetAnotherStr[0]));
 	memMangService.rawDataMemorySubservice.dumpRawData(rcvPack);
 
 	rcvPack = Message(6, 2, Message::TC, 1);
@@ -86,7 +86,7 @@ int main() {
 	rcvPack.appendUint64(reinterpret_cast<uint64_t >(pStr + 1)); // Start address
 	rcvPack.appendOctetString(1, data);
 	memMangService.rawDataMemorySubservice.loadRawData(rcvPack);
-	
+
 
 	// ST[01] test
 	// parameters take random values and works as expected
@@ -100,10 +100,14 @@ int main() {
 	// ST[05] test [works]
 	const unsigned char eventReportData[12] = "Hello World";
 	EventReportService eventReportService;
-	eventReportService.informativeEventReport(1, eventReportData, 11);
-	eventReportService.lowSeverityAnomalyReport(2, eventReportData, 11);
-	eventReportService.mediumSeverityAnomalyReport(3, eventReportData, 11);
-	eventReportService.highSeverityAnomalyReport(4, eventReportData, 11);
+	eventReportService.informativeEventReport(EventReportService::UnknownEvent, eventReportData,
+	                                          11);
+	eventReportService.lowSeverityAnomalyReport(EventReportService::LowSeverityUnknownEvent,
+	                                            eventReportData, 11);
+	eventReportService.mediumSeverityAnomalyReport(EventReportService::MediumSeverityUnknownEvent,
+	                                               eventReportData, 11);
+	eventReportService.highSeverityAnomalyReport(EventReportService::HighSeverityUnknownEvent,
+	                                             eventReportData, 11);
 
 	return 0;
 }
diff --git a/test/Services/EventReportService.cpp b/test/Services/EventReportService.cpp
index 43ed7b5e..bef6e181 100644
--- a/test/Services/EventReportService.cpp
+++ b/test/Services/EventReportService.cpp
@@ -9,9 +9,10 @@
  */
 TEST_CASE("Informative Event Report TM[5,1]", "[service][st05]") {
 	EventReportService eventReportService;
-	const unsigned char eventReportData[]="HelloWorld";
+	const unsigned char eventReportData[] = "HelloWorld";
 	char checkString[255];
-	eventReportService.informativeEventReport(1, eventReportData, 10);
+	eventReportService.informativeEventReport(EventReportService::UnknownEvent, eventReportData,
+	                                          10);
 	REQUIRE(ServiceTests::hasOneMessage());
 
 	Message report = ServiceTests::get(0);
@@ -21,16 +22,17 @@ TEST_CASE("Informative Event Report TM[5,1]", "[service][st05]") {
 	CHECK(report.packetType == 0); // packet type(TM = 0, TC = 1)
 	REQUIRE(report.dataSize == 12);
 	// Check for the value that is stored in <<data>> array(data-member of object response)
-	CHECK(report.readEnum16() == 1);
+	CHECK(report.readEnum16() == 0);
 	report.readString(checkString, 10);
-	CHECK(strcmp(checkString, reinterpret_cast<const char*>(eventReportData)) == 0);
+	CHECK(strcmp(checkString, reinterpret_cast<const char *>(eventReportData)) == 0);
 }
 
 TEST_CASE("Loww Severity Anomaly Report TM[5,2]", "[service][st05]") {
 	EventReportService eventReportService;
-	const unsigned char eventReportData[]="HelloWorld";
+	const unsigned char eventReportData[] = "HelloWorld";
 	char checkString[255];
-	eventReportService.lowSeverityAnomalyReport(2, eventReportData, 10);
+	eventReportService.lowSeverityAnomalyReport(EventReportService::LowSeverityUnknownEvent,
+	                                            eventReportData, 10);
 	REQUIRE(ServiceTests::hasOneMessage());
 
 	Message report = ServiceTests::get(0);
@@ -40,16 +42,17 @@ TEST_CASE("Loww Severity Anomaly Report TM[5,2]", "[service][st05]") {
 	CHECK(report.packetType == 0); // packet type(TM = 0, TC = 1)
 	REQUIRE(report.dataSize == 12);
 	// Check for the value that is stored in <<data>> array(data-member of object response)
-	CHECK(report.readEnum16() == 2);
+	CHECK(report.readEnum16() == 1);
 	report.readString(checkString, 10);
-	CHECK(strcmp(checkString, reinterpret_cast<const char*>(eventReportData)) == 0);
+	CHECK(strcmp(checkString, reinterpret_cast<const char *>(eventReportData)) == 0);
 }
 
 TEST_CASE("Medium Severity Anomaly Report TM[5,3]", "[service][st05]") {
 	EventReportService eventReportService;
-	const unsigned char eventReportData[]="HelloWorld";
+	const unsigned char eventReportData[] = "HelloWorld";
 	char checkString[255];
-	eventReportService.mediumSeverityAnomalyReport(3, eventReportData, 10);
+	eventReportService.mediumSeverityAnomalyReport
+		(EventReportService::MediumSeverityUnknownEvent, eventReportData, 10);
 	REQUIRE(ServiceTests::hasOneMessage());
 
 	Message report = ServiceTests::get(0);
@@ -59,16 +62,17 @@ TEST_CASE("Medium Severity Anomaly Report TM[5,3]", "[service][st05]") {
 	CHECK(report.packetType == 0); // packet type(TM = 0, TC = 1)
 	REQUIRE(report.dataSize == 12);
 	// Check for the value that is stored in <<data>> array(data-member of object response)
-	CHECK(report.readEnum16() == 3);
+	CHECK(report.readEnum16() == 2);
 	report.readString(checkString, 10);
-	CHECK(strcmp(checkString, reinterpret_cast<const char*>(eventReportData)) == 0);
+	CHECK(strcmp(checkString, reinterpret_cast<const char *>(eventReportData)) == 0);
 }
 
 TEST_CASE("High Severity Anomaly Report TM[5,4]", "[service][st05]") {
 	EventReportService eventReportService;
-	const unsigned char eventReportData[]="HelloWorld";
+	const unsigned char eventReportData[] = "HelloWorld";
 	char checkString[255];
-	eventReportService.highSeverityAnomalyReport(4, eventReportData, 10);
+	eventReportService.highSeverityAnomalyReport(EventReportService::HighSeverityUnknownEvent,
+	                                             eventReportData, 10);
 	REQUIRE(ServiceTests::hasOneMessage());
 
 	Message report = ServiceTests::get(0);
@@ -78,7 +82,7 @@ TEST_CASE("High Severity Anomaly Report TM[5,4]", "[service][st05]") {
 	CHECK(report.packetType == 0); // packet type(TM = 0, TC = 1)
 	REQUIRE(report.dataSize == 12);
 	// Check for the value that is stored in <<data>> array(data-member of object response)
-	CHECK(report.readEnum16() == 4);
+	CHECK(report.readEnum16() == 3);
 	report.readString(checkString, 10);
-	CHECK(strcmp(checkString, reinterpret_cast<const char*>(eventReportData)) == 0);
+	CHECK(strcmp(checkString, reinterpret_cast<const char *>(eventReportData)) == 0);
 }
-- 
GitLab