From 2395d29157d1e26f4765702208d7d2c4e4376ae1 Mon Sep 17 00:00:00 2001
From: Grigoris Pavlakis <grigpavl@ece.auth.gr>
Date: Wed, 26 Dec 2018 20:37:26 +0200
Subject: [PATCH] Start work on ST[08]

Add a basic wrapper struct for function argument handling

Pacify Vera and (hopefully) cppcheck
---
 inc/Services/FunctionManagementService.hpp | 47 ++++++++++++++++++++++
 src/Services/FunctionManagementService.cpp |  1 +
 2 files changed, 48 insertions(+)
 create mode 100644 inc/Services/FunctionManagementService.hpp
 create mode 100644 src/Services/FunctionManagementService.cpp

diff --git a/inc/Services/FunctionManagementService.hpp b/inc/Services/FunctionManagementService.hpp
new file mode 100644
index 00000000..ddf7ab3d
--- /dev/null
+++ b/inc/Services/FunctionManagementService.hpp
@@ -0,0 +1,47 @@
+#ifndef ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP
+#define ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP
+
+#include <stdint.h>
+#include "etl/map.h"
+#include "etl/String.hpp"
+#include "Message.hpp"
+
+/**
+ * Implementation of the ST[08] function management service
+ *
+ * This class implements a basic framework for the ST[08] service as described in ECSS-E-ST-70-41C,
+ * pages 157-159. Actual implementation is dependent on subsystem requirements which are, as of this
+ * writing, undefined yet.
+ *
+ * <b>WARNING!</b> Due to the class's usage of the custom string class by Konstantinos Kanavouras,
+ * <b>the function name passed in the message shall be stripped of its trailing NULL character!</b>
+ *
+ * @todo Ignore the ending NULL in passed strings
+ * @todo Revamp the method used to store the argument types, it's hacky AF and a (memory) space hog
+ *
+ * @author Grigoris Pavlakis <grigpavl@ece.auth.gr>
+ */
+
+#define FUNCMAPSIZE 5       // size of the function map (temporary, arbitrary)
+#define MAXFUNCNAMELEN 128  // max length of the function (temporary, arbitrary)
+#define MAXFUNCARGS 64      // maximum arguments that a function can hold
+#define MAXARGLENGTH 32     // maximum argument name length
+
+typedef struct {
+	void (*funcPtr)(void);                      // a generic function pointer
+	String<MAXARGLENGTH> args[MAXFUNCARGS];     // the argument types with their original sequence
+} Function;
+
+class FunctionManagementService {
+	etl::map<String<MAXFUNCNAMELEN>,
+	    Function, FUNCMAPSIZE> funcPtrIndex;  // map of function names to their pointers
+
+public:
+	/**
+	 * Calls the function described in the TC[8,1] message *msg*, passing the arguments contained
+	 * @param msg A TC[8,1] message
+	 */
+	void call(Message msg);
+};
+
+#endif //ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP
diff --git a/src/Services/FunctionManagementService.cpp b/src/Services/FunctionManagementService.cpp
new file mode 100644
index 00000000..033ef021
--- /dev/null
+++ b/src/Services/FunctionManagementService.cpp
@@ -0,0 +1 @@
+#include "Services/FunctionManagementService.hpp"
-- 
GitLab