From 7650a178382df37f6f14f68d846151d18339696d Mon Sep 17 00:00:00 2001
From: Grigoris Pavlakis <grigpavl@ece.auth.gr>
Date: Sun, 25 Nov 2018 11:58:22 +0200
Subject: [PATCH] Update reportParameterIds() to be void and store the message
 instead of returning

---
 inc/Services/ParameterService.hpp  | 9 ++++-----
 src/Services/ParameterService.cpp  | 3 +--
 test/Services/ParameterService.cpp | 8 ++++++--
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/inc/Services/ParameterService.hpp b/inc/Services/ParameterService.hpp
index 3365dc82..c331ae27 100644
--- a/inc/Services/ParameterService.hpp
+++ b/inc/Services/ParameterService.hpp
@@ -35,7 +35,6 @@ 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 {
@@ -56,11 +55,11 @@ public:
 	 * **for the parameters specified in the carried valid IDs**.
 	 *
 	 * No sophisticated error checking for now, just whether the package is of the correct type
-	 * and whether the requested IDs are valid, ignoring the invalid ones.
+	 * and whether the requested IDs are valid, ignoring the invalid ones. If no IDs are correct,
+	 * the returned message shall be empty.
 	 *
 	 * @param paramId: a valid TC[20, 1] packet carrying the requested parameter IDs
-	 * @return A TM[20, 2] packet containing the valid parameter IDs and their settings.
-	 * @return Empty TM[20, 2] packet on wrong type.
+	 * @return None (messages are stored using storeMessage())
 	 *
 	 * @todo Generate failure notifs where needed when ST[01] is ready
 	 *
@@ -70,7 +69,7 @@ public:
 	 *
 	 * Everything apart from the setting data is uint16 (setting data are uint32 for now)
 	 */
-	Message reportParameterIds(Message paramIds);
+	void reportParameterIds(Message paramIds);
 
 	/**
 	 * This function receives a TC[20, 3] message and after checking whether its type is correct,
diff --git a/src/Services/ParameterService.cpp b/src/Services/ParameterService.cpp
index 8deebbc4..bf198819 100644
--- a/src/Services/ParameterService.cpp
+++ b/src/Services/ParameterService.cpp
@@ -28,7 +28,7 @@ ParameterService::ParameterService() {
 #endif
 }
 
-Message ParameterService::reportParameterIds(Message paramIds) {
+void ParameterService::reportParameterIds(Message paramIds) {
 	Message reqParam(20, 2, Message::TM, 1);    // empty TM[20, 2] parameter report message
 
 	if (paramIds.packetType == Message::TC && paramIds.serviceType == 20 &&
@@ -50,7 +50,6 @@ Message 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) {
diff --git a/test/Services/ParameterService.cpp b/test/Services/ParameterService.cpp
index 43038dbe..30c18adc 100644
--- a/test/Services/ParameterService.cpp
+++ b/test/Services/ParameterService.cpp
@@ -1,6 +1,7 @@
 #include "catch2/catch.hpp"
 #include "Services/ParameterService.hpp"
 #include "Message.hpp"
+#include "ServiceTests.hpp"
 
 #define CATCH_CONFIG_MAIN
 
@@ -19,7 +20,8 @@ TEST_CASE("Parameter Report Subservice") {
 		request.appendUint16(34672);  // faulty ID in this context
 		request.appendUint16(3);      // valid
 
-		report = pserv.reportParameterIds(request);
+		pserv.reportParameterIds(request);
+		report = ServiceTests::get(0);
 		request.resetRead();
 
 		uint16_t repIdCount = report.readUint16();
@@ -33,7 +35,9 @@ TEST_CASE("Parameter Report Subservice") {
 	SECTION("Wrong Message Type Handling Test") {
 
 		Message falseRequest(15, 3, Message::TM, 1);   //a totally wrong message
-		Message response = pserv.reportParameterIds(falseRequest);
+
+		pserv.reportParameterIds(falseRequest);
+		Message response = ServiceTests::get(0);
 		CHECK(response.messageType == 2);
 		CHECK(response.serviceType == 20);
 		CHECK(response.packetType == Message::TM);
-- 
GitLab