From 37bc19097ff70de2434014c7331237490f449b65 Mon Sep 17 00:00:00 2001
From: Grigoris Pavlakis <grigpavl@ece.auth.gr>
Date: Sun, 25 Nov 2018 01:49:59 +0200
Subject: [PATCH] Revert reportParameterIds() to original in order to not break
 the flow of testing until storeMessage() stores the messages somewhere. Also
 fixed formatting to conform to voted code style.

---
 inc/Services/ParameterService.hpp |  4 ++--
 src/Services/ParameterService.cpp | 19 ++-----------------
 src/main.cpp                      | 25 +------------------------
 3 files changed, 5 insertions(+), 43 deletions(-)

diff --git a/inc/Services/ParameterService.hpp b/inc/Services/ParameterService.hpp
index c0a16ba7..412b2080 100644
--- a/inc/Services/ParameterService.hpp
+++ b/inc/Services/ParameterService.hpp
@@ -19,7 +19,6 @@
  * ECSS-E-ST-70-41C, chapter 7.3
  */
 struct Parameter {
-
 	uint8_t ptc;            // Packet field type code (PTC)
 	uint8_t pfc;            // Packet field format code (PFC)
 	uint16_t paramId;       // Unique ID of the parameter
@@ -36,6 +35,7 @@ struct Parameter {
  * for parameter reporting and modification.
  *
  * @todo Ensure that the parameter list is sorted by ID
+ * @todo Convert reportParameterIds() to void when storeMessage() stores and doesn't print
  */
 
 class ParameterService : public Service {
@@ -47,7 +47,7 @@ private:
 public:
 	ParameterService();
 
-	void reportParameterIds(Message paramIds);
+	Message reportParameterIds(Message paramIds);
 
 	void setParameterIds(Message newParamValues);
 
diff --git a/src/Services/ParameterService.cpp b/src/Services/ParameterService.cpp
index 0d98eb00..6bfe6f50 100644
--- a/src/Services/ParameterService.cpp
+++ b/src/Services/ParameterService.cpp
@@ -32,8 +32,7 @@ ParameterService::ParameterService() {
 #endif
 }
 
-void ParameterService::reportParameterIds(Message paramIds) {
-
+Message ParameterService::reportParameterIds(Message paramIds) {
 	/**
 	 * This function receives a TC[20, 1] packet and returns a TM[20, 2] packet
 	 * containing the current configuration
@@ -59,20 +58,16 @@ void ParameterService::reportParameterIds(Message paramIds) {
 
 	if (paramIds.packetType == Message::TC && paramIds.serviceType == 20 &&
 	    paramIds.messageType == 1) {
-
 		uint16_t ids = paramIds.readUint16();
 		reqParam.appendUint16(numOfValidIds(paramIds));   // include the number of valid IDs
 
 		for (int i = 0; i < ids; i++) {
-
 			uint16_t currId = paramIds.readUint16();      // current ID to be appended
 
 			if (currId < CONFIGLENGTH) {  // check to prevent out-of-bounds access due to invalid id
-
 				reqParam.appendUint16(currId);
 				reqParam.appendUint32(paramsList[currId].settingData);
 			} else {
-
 								// generate failure of execution notification for ST[06]
 				continue;       //ignore the invalid ID
 			}
@@ -80,10 +75,10 @@ void ParameterService::reportParameterIds(Message paramIds) {
 	}
 
 	storeMessage(reqParam);
+	return reqParam;   // this has to stay for now because no other way for testing
 }
 
 void ParameterService::setParameterIds(Message newParamValues) {
-
 	/**
 	 * This function receives a TC[20, 3] message and after checking whether its type is correct,
 	 * iterates over all contained parameter IDs and replaces the settings for each valid parameter,
@@ -98,18 +93,14 @@ void ParameterService::setParameterIds(Message newParamValues) {
 
 	if (newParamValues.packetType == Message::TC && newParamValues.serviceType == 20 &&
 		newParamValues.messageType == 3) {
-
 		uint16_t ids = newParamValues.readUint16();  //get number of ID's
 
 		for (int i = 0; i < ids; i++) {
-
 			uint16_t currId = newParamValues.readUint16();
 
 			if (currId < CONFIGLENGTH) {
-
 				paramsList[currId].settingData = newParamValues.readUint32();
 			} else {
-
 								// generate failure of execution notification for ST[06]
 				continue;       // ignore the invalid ID
 			}
@@ -118,7 +109,6 @@ void ParameterService::setParameterIds(Message newParamValues) {
 }
 
 uint16_t ParameterService::numOfValidIds(Message idMsg) {
-
 	idMsg.resetRead();
 	// start reading from the beginning of the idMsg object
 	// (original obj. will not be influenced if this is called by value)
@@ -127,21 +117,16 @@ uint16_t ParameterService::numOfValidIds(Message idMsg) {
 	uint16_t validIds = 0;
 
 	for (int i = 0; i < ids; i++) {
-
 		uint16_t currId = idMsg.readUint16();
 
 		if (idMsg.messageType == 3) {
-
 			idMsg.readUint32();   //skip the 32bit settings blocks, we need only the IDs
 		}
 
 		if (currId < CONFIGLENGTH) {
-
 			validIds++;
 		}
-
 	}
 
 	return validIds;
-
 }
diff --git a/src/main.cpp b/src/main.cpp
index 62eb4031..53bb1158 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -39,21 +39,7 @@ int main() {
 	sentPacket.appendUint16(2);  //number of contained IDs
 	sentPacket.appendUint16(0);  //first ID
 	sentPacket.appendUint16(1);  //second ID
-	paramService.reportParameterIds(sentPacket);
-
-	/*
-	uint16_t numOfIds = returnedPacket.readUint16();
-
-	std::cout << std::endl << "Number of contained configs: " << numOfIds << std::endl;
-
-	for (int i = 0; i < numOfIds; i++) {
-
-		std::cout << "Parameter ID: " << std::dec << returnedPacket.readUint16() << std::endl
-		          << "Parameter value: " << std::dec << returnedPacket.readUint32() << std::endl;
-
-	}
-
-	std::cout << std::endl << "(First value is hours, second is minutes)" << std::endl;
+	Message returnedPacket = paramService.reportParameterIds(sentPacket);
 
 	//Test code for setParameter
 	Message sentPacket2 = Message(20, 3, Message::TC, 1);  //application id is a dummy number (1)
@@ -66,15 +52,6 @@ int main() {
 	paramService.setParameterIds(sentPacket2);
 	returnedPacket = paramService.reportParameterIds(sentPacket);
 
-	numOfIds = returnedPacket.readUint16();
-
-	for (int i = 0; i < numOfIds; i++) {
-
-		std::cout << "Parameter ID: " << std::dec << returnedPacket.readUint16() << std::endl
-		          << "Parameter value: " << std::dec << returnedPacket.readUint32() << std::endl;
-
-	}*/
-
 // ST[01] test
 	// parameters take random values and works as expected
 	RequestVerificationService reqVerifService;
-- 
GitLab