From c45ad4b151cce9f8f3558e76b8ab9f881e8c156d Mon Sep 17 00:00:00 2001
From: athatheo <athatheoc@gmail.com>
Date: Thu, 23 Jun 2022 20:54:22 +0200
Subject: [PATCH] Add Dummy Service

---
 docs/ecss_overview.md                   |  8 +++++-
 inc/Platform/x86/ECSS_Configuration.hpp |  1 +
 inc/ServicePool.hpp                     | 23 ++++++++++-------
 inc/Services/DummyService.hpp           | 34 +++++++++++++++++++++++++
 test/Services/DummyService.cpp          | 17 +++++++++++++
 5 files changed, 73 insertions(+), 10 deletions(-)
 create mode 100644 inc/Services/DummyService.hpp
 create mode 100644 test/Services/DummyService.cpp

diff --git a/docs/ecss_overview.md b/docs/ecss_overview.md
index 82e00111..ba95f4d2 100644
--- a/docs/ecss_overview.md
+++ b/docs/ecss_overview.md
@@ -63,6 +63,8 @@ Each service is further divided into some **subservices** that are logical group
 large space mission may split every subservice into different parts of the hardware. However, this implementation _makes
 no distinction between subservices_.
 
+### Standard's Services
+
 <b>`ST[01]`: Request verification</b>
 
 Provides acknowledgement or failure reports for executed commands. This service essentially informs the operators about
@@ -182,7 +184,11 @@ Provides the capability of executing TCs when the spacecraft reaches a specific
 Provides the capability of managing on-board file systems, with functions such as *copy*, *move*, *delete*, or *create
 directory*.
 
-The capability also exists to define _custom_ services and message types, if needed for each mission.
+### Custom Services
+
+<b>`ST[128]`: Dummy Service</b>
+
+Provides the capability of storing log strings as ECSS Messages.
 
 ## Trivia
 - Version C of the standard contains 656 pages, often filled with verbose requirements and difficult definitions. Every
diff --git a/inc/Platform/x86/ECSS_Configuration.hpp b/inc/Platform/x86/ECSS_Configuration.hpp
index 6dbedb3a..1871be15 100644
--- a/inc/Platform/x86/ECSS_Configuration.hpp
+++ b/inc/Platform/x86/ECSS_Configuration.hpp
@@ -19,6 +19,7 @@
  */
 
 #define SERVICE_ALL                       ///< Enables compilation of all the ECSS services
+#define SERVICE_DUMMY                     ///<  Compile ST[128] dummy service
 #define SERVICE_EVENTACTION               ///<  Compile ST[19] event-action
 #define SERVICE_EVENTREPORT               ///<  Compile ST[05] event reporting
 #define SERVICE_FUNCTION                  ///<  Compile ST[08] function management
diff --git a/inc/ServicePool.hpp b/inc/ServicePool.hpp
index 47ff8595..b93a7dba 100644
--- a/inc/ServicePool.hpp
+++ b/inc/ServicePool.hpp
@@ -2,20 +2,21 @@
 #define ECSS_SERVICES_SERVICEPOOL_HPP
 
 #include "ECSS_Configuration.hpp"
-#include "Services/TimeBasedSchedulingService.hpp"
-#include "Services/LargePacketTransferService.hpp"
-#include "Services/RequestVerificationService.hpp"
-#include "Services/EventReportService.hpp"
+#include "Services/DummyService.hpp"
 #include "Services/EventActionService.hpp"
-#include "Services/ParameterService.hpp"
-#include "Services/TestService.hpp"
-#include "Services/MemoryManagementService.hpp"
+#include "Services/EventReportService.hpp"
 #include "Services/FunctionManagementService.hpp"
-#include "Services/StorageAndRetrievalService.hpp"
 #include "Services/HousekeepingService.hpp"
+#include "Services/LargePacketTransferService.hpp"
+#include "Services/MemoryManagementService.hpp"
+#include "Services/OnBoardMonitoringService.hpp"
+#include "Services/ParameterService.hpp"
 #include "Services/ParameterStatisticsService.hpp"
 #include "Services/RealTimeForwardingControlService.hpp"
-#include "Services/OnBoardMonitoringService.hpp"
+#include "Services/RequestVerificationService.hpp"
+#include "Services/StorageAndRetrievalService.hpp"
+#include "Services/TestService.hpp"
+#include "Services/TimeBasedSchedulingService.hpp"
 
 /**
  * Defines a class that contains instances of all Services.
@@ -39,6 +40,10 @@ class ServicePool {
 	uint16_t packetSequenceCounter = 0;
 
 public:
+#ifdef SERVICE_DUMMY
+	DummyService dummyService;
+#endif
+
 #ifdef SERVICE_EVENTACTION
 	EventActionService eventAction;
 #endif
diff --git a/inc/Services/DummyService.hpp b/inc/Services/DummyService.hpp
new file mode 100644
index 00000000..605825d7
--- /dev/null
+++ b/inc/Services/DummyService.hpp
@@ -0,0 +1,34 @@
+#ifndef ECSS_SERVICES_DUMMYSERVICE_HPP
+#define ECSS_SERVICES_DUMMYSERVICE_HPP
+
+#include "Logger_Definitions.hpp"
+#include "Service.hpp"
+
+/**
+ * This is a dummy Service used during testing. Its functionality is to contain LOG_ data but be sent through CAN bus.
+ * During the environmental tests, we will use both CAN and UART to send data from the MCU to the PC. However, the
+ * current CAN protocol does not accommodate random data strings. Therefore, we will use this dummy service to send such
+ * messages.
+ *
+ * Per the ECSS-E-ST-70-41C standard, p. 27-28, custom Services and Messages should start above 127.
+ */
+class DummyService : public Service {
+
+public:
+	inline static const uint8_t ServiceType = 128;
+	enum MessageType : uint8_t {
+		LogString = 128,
+	};
+
+	/**
+     * Send data as a part of a custom ECSS Message
+     * Creates a TM[128, 128]
+     */
+	void logAsECSSMessage(const etl::string<LOGGER_MAX_MESSAGE_SIZE>& data) {
+		Message log(ServiceType, MessageType::LogString, Message::TM, 1);
+		log.appendString(data);
+		storeMessage(log);
+	}
+};
+
+#endif //ECSS_SERVICES_DUMMYSERVICE_HPP
diff --git a/test/Services/DummyService.cpp b/test/Services/DummyService.cpp
new file mode 100644
index 00000000..188d1899
--- /dev/null
+++ b/test/Services/DummyService.cpp
@@ -0,0 +1,17 @@
+#include "Services/DummyService.hpp"
+#include <catch2/catch_all.hpp>
+#include "ServicePool.hpp"
+#include "ServiceTests.hpp"
+
+DummyService& dummyService = Services.dummyService;
+
+TEST_CASE("Log string as message TM[128, 128]", "[service][st128]") {
+	etl::string<LOGGER_MAX_MESSAGE_SIZE> log = "An amazing log that is very informative";
+	dummyService.logAsECSSMessage(log);
+	Message report = ServiceTests::get(0);
+	CHECK(report.serviceType == DummyService::ServiceType);
+	CHECK(report.messageType == DummyService::MessageType::LogString);
+	char logOutput[39];
+	report.readString(logOutput, 39);
+	CHECK(strcmp(logOutput, "An amazing log that is very informative") == 0);
+}
-- 
GitLab