From 6ba14d926c3c6318cc11a3b1bb0332bf1d547300 Mon Sep 17 00:00:00 2001
From: Grigoris Pavlakis <grigpavl@ece.auth.gr>
Date: Tue, 20 Nov 2018 01:52:56 +0200
Subject: [PATCH] Complete rudimentary implementation of parameter reporting
 function, optimizations shall follow

---
 inc/Services/ParameterService.hpp |  1 +
 src/Services/ParameterService.cpp | 13 +++++++------
 src/main.cpp                      |  8 ++++++--
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/inc/Services/ParameterService.hpp b/inc/Services/ParameterService.hpp
index 5d8d5176..36050f2e 100644
--- a/inc/Services/ParameterService.hpp
+++ b/inc/Services/ParameterService.hpp
@@ -3,6 +3,7 @@
 
 #include "Service.hpp"
 #define CONFIGLENGTH 5
+
 /**
  * Implementation of the ST[20] parameter management service,
  * as defined in ECSS-E-ST-70-41C
diff --git a/src/Services/ParameterService.cpp b/src/Services/ParameterService.cpp
index 08b775ff..798888d5 100644
--- a/src/Services/ParameterService.cpp
+++ b/src/Services/ParameterService.cpp
@@ -12,7 +12,7 @@ ParameterService::ParameterService() {
 	 * This normally will be initialized with actual values on boot.
 	 */
 
-	for (int i = 0; i < 5; i++) {   // hack just to shut CLion up (warning about range-based for loops)
+	for (int i = 0; i < CONFIGLENGTH; i++) {
 
 		paramsList[i].paramId = 0;
 		paramsList[i].settingData = 0;
@@ -45,16 +45,16 @@ Message ParameterService::reportParameter(Message paramId) {
 	 */
 
 	Message reqParam(20, 2, Message::TM, 1);    // empty TM[20, 2] parameter report message
-	uint16_t reqParamId = paramId.readHalfword(); // parameter ID must be accessed only once
+	uint16_t reqParamId = paramId.readUint16(); // parameter ID must be accessed only once
 
 	if (paramId.packetType == Message::TC && paramId.serviceType == 20 && paramId.messageType == 1) {
 
-		for (int i = 0; i < 5; i++) {
+		for (int i = 0; i < CONFIGLENGTH; i++) {
 
 			if (paramsList[i].paramId == reqParamId) {
 
-				reqParam.appendHalfword(paramsList[i].paramId);
-				reqParam.appendWord(paramsList[i].settingData);
+				reqParam.appendUint16(paramsList[i].paramId);
+				reqParam.appendUint32(paramsList[i].settingData);
 				break;
 			}
 		}
@@ -65,4 +65,5 @@ Message ParameterService::reportParameter(Message paramId) {
 
 /*void ParameterService::setParamData(Message paramId) {
 
-}*/
\ No newline at end of file
+}*/
+
diff --git a/src/main.cpp b/src/main.cpp
index 62e5b60f..4d2f13c0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -31,9 +31,13 @@ int main() {
 	//ST[20] test
 	ParameterService paramService;
 	Message sentPacket = Message(20, 1, Message::TC, 1);  //application id is a dummy number (1)
-	sentPacket.appendHalfword(341);  //the packet sent contains the ID of the desired parameter
+	sentPacket.appendUint16(341);  //the packet sent contains the ID of the desired parameter
 	Message returnedPacket = paramService.reportParameter(sentPacket);
-	std::cout << "Parameter ID: " << returnedPacket.readHalfword() << "Parameter value: " << returnedPacket.readHalfword() << std::endl;
+
+	uint16_t id = returnedPacket.readUint16();
+	uint32_t val = returnedPacket.readUint32();
+
+	std::cout << "Parameter ID: " << std::dec << id << std::endl << "Parameter value: " << std::dec << val << std::endl;
 
 	return 0;
 }
-- 
GitLab