From e28b54b64d131c1372b3979e2b886daabe3140a2 Mon Sep 17 00:00:00 2001
From: Grigoris Pavlakis <grigpavl@ece.auth.gr>
Date: Sun, 11 Aug 2019 19:31:20 +0300
Subject: [PATCH] Rework the Parameter struct according to discussion

---
 inc/Services/ParameterService.hpp | 17 +++++----
 src/Services/ParameterService.cpp | 62 +++++++++++++++----------------
 2 files changed, 40 insertions(+), 39 deletions(-)

diff --git a/inc/Services/ParameterService.hpp b/inc/Services/ParameterService.hpp
index 73879332..4974dbc7 100644
--- a/inc/Services/ParameterService.hpp
+++ b/inc/Services/ParameterService.hpp
@@ -4,10 +4,13 @@
 #include "Service.hpp"
 #include "ErrorHandler.hpp"
 #include "etl/map.h"
+#include "etl/bitset.h"
 
 // Number of stored parameters. MAX_PARAMS is just a dummy number for now.
 #define MAX_PARAMS 5
 
+// Number of binary flags in every parameter.
+#define NUM_OF_FLAGS 5
 /**
  * Implementation of the ST[20] parameter management service,
  * as defined in ECSS-E-ST-70-41C
@@ -20,16 +23,14 @@
  * PTC and PFC for each parameter shall be specified as in
  * ECSS-E-ST-70-41C, chapter 7.3
  */
-
 typedef uint16_t ParamId; // parameter IDs are given sequentially
 struct Parameter {
-	uint8_t ptc; // Packet field type code (PTC)
-	uint8_t pfc; // Packet field format code (PFC)
-
-	uint32_t settingData;
-	// Actual data defining the operation of a peripheral or subsystem.
-	// Peripheral-dependent normally (void* maybe?) (it's a memory address according to spec).
-	// Dummy int for now.
+	uint8_t ptc;                       // Packet field type code (PTC)
+	uint8_t pfc;                       // Packet field format code (PFC)
+	void (*updatePtr)();               // Pointer to the function used to update the value
+	uint32_t currentValue;             // Last good value of the parameter
+	etl::bitset<NUM_OF_FLAGS> flags;   // Various flags (TBD which).
+	                                   // (Ideas: update with priority, do not poll, etc.)
 };
 
 /**
diff --git a/src/Services/ParameterService.cpp b/src/Services/ParameterService.cpp
index 44d76682..2bd6f638 100644
--- a/src/Services/ParameterService.cpp
+++ b/src/Services/ParameterService.cpp
@@ -1,37 +1,37 @@
 #include "Services/ParameterService.hpp"
 
-#define DEMOMODE
+//#define DEMOMODE
 
-#include <ctime>
-#include <cstdlib>
+//#include <ctime>
+//#include <cstdlib>
 
 ParameterService::ParameterService() {
-#ifdef DEMOMODE
-	// Test code, setting up some of the parameter fields
-
-	time_t currTime = time(nullptr);
-	struct tm* today = localtime(&currTime);
-
-	Parameter test1, test2;
-
-	test1.settingData = today->tm_hour; // the current hour
-	test1.ptc = 3; // unsigned int
-	test1.pfc = 14; // 32 bits
-
-	test2.settingData = today->tm_min; // the current minute
-	test2.ptc = 3; // unsigned int
-	test2.pfc = 14; // 32 bits
-
-	// MAKE SURE THE IDS ARE UNIQUE WHEN INSERTING!
-	/**
-	 * @todo: Make a separate insert() function for parameter insertion to protect from blunders
-	 * if needed to
-	 */
-
-	paramsList.insert(std::make_pair(0, test1));
-	paramsList.insert(std::make_pair(1, test2));
-
-#endif
+//#ifdef DEMOMODE
+//	// Test code, setting up some of the parameter fields
+//
+//	time_t currTime = time(nullptr);
+//	struct tm* today = localtime(&currTime);
+//
+//	Parameter test1, test2;
+//
+//	test1.currentValue = today->tm_hour; // the current hour
+//	test1.ptc = 3; // unsigned int
+//	test1.pfc = 14; // 32 bits
+//
+//	test2.currentValue = today->tm_min; // the current minute
+//	test2.ptc = 3; // unsigned int
+//	test2.pfc = 14; // 32 bits
+//
+//	// MAKE SURE THE IDS ARE UNIQUE WHEN INSERTING!
+//	/**
+//	 * @todo: Make a separate insert() function for parameter insertion to protect from blunders
+//	 * if needed to
+//	 */
+//
+//	paramsList.insert(std::make_pair(0, test1));
+//	paramsList.insert(std::make_pair(1, test2));
+//
+//#endif
 }
 
 void ParameterService::reportParameterIds(Message& paramIds) {
@@ -58,7 +58,7 @@ void ParameterService::reportParameterIds(Message& paramIds) {
 
 		if (paramsList.find(currId) != paramsList.end()) {
 			reqParam.appendUint16(currId);
-			reqParam.appendUint32(paramsList[currId].settingData);
+			reqParam.appendUint32(paramsList[currId].currentValue);
 		} else {
 			ErrorHandler::reportError(paramIds, ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError);
 			continue; // generate failed start of execution notification & ignore
@@ -87,7 +87,7 @@ void ParameterService::setParameterIds(Message& newParamValues) {
 		uint16_t currId = newParamValues.readUint16();
 
 		if (paramsList.find(currId) != paramsList.end()) {
-			paramsList[currId].settingData = newParamValues.readUint32();
+			paramsList[currId].currentValue = newParamValues.readUint32();
 		} else {
 			ErrorHandler::reportError(newParamValues,
 			                          ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError);
-- 
GitLab