From 9655a099ccdf93457f3946742d6d75585e0a4805 Mon Sep 17 00:00:00 2001
From: Grigoris Pavlakis <grigpavl@ece.auth.gr>
Date: Tue, 29 Jan 2019 17:47:45 +0200
Subject: [PATCH] Rework setParameterIds() and numOfValidIds() to work with the
 map

---
 inc/Services/ParameterService.hpp |  2 +-
 src/Services/ParameterService.cpp | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/inc/Services/ParameterService.hpp b/inc/Services/ParameterService.hpp
index 8a10dd92..cfdb8401 100644
--- a/inc/Services/ParameterService.hpp
+++ b/inc/Services/ParameterService.hpp
@@ -44,7 +44,7 @@ class ParameterService : public Service {
 private:
 
 	etl::map<ParamId, Parameter, CONFIGLENGTH> paramsList;
-	static uint16_t numOfValidIds(Message idMsg);  //count the valid ids in a given TC[20, 1]
+	uint16_t numOfValidIds(Message idMsg);  //count the valid ids in a given TC[20, 1]
 
 public:
 	/**
diff --git a/src/Services/ParameterService.cpp b/src/Services/ParameterService.cpp
index 9186bcd6..e05888eb 100644
--- a/src/Services/ParameterService.cpp
+++ b/src/Services/ParameterService.cpp
@@ -49,8 +49,7 @@ void ParameterService::reportParameterIds(Message paramIds) {
 		for (int i = 0; i < ids; i++) {
 			uint16_t currId = paramIds.readUint16();      // current ID to be appended
 
-			etl::map<ParamId, Parameter, CONFIGLENGTH>::iterator iter = paramsList.find(currId);
-			if (iter != paramsList.end()) {
+			if (paramsList.find(currId) != paramsList.end()) {
 				reqParam.appendUint16(currId);
 				reqParam.appendUint32(paramsList[currId].settingData);
 			}
@@ -77,9 +76,13 @@ void ParameterService::setParameterIds(Message newParamValues) {
 		for (int i = 0; i < ids; i++) {
 			uint16_t currId = newParamValues.readUint16();
 
-			if (currId < CONFIGLENGTH) {  // crappy criterion, see numOfValidIds
+			if (paramsList.find(currId) != paramsList.end()) {
 				paramsList[currId].settingData = newParamValues.readUint32();
-			} else {
+			}
+
+//			if (currId < CONFIGLENGTH) {  // crappy criterion, see numOfValidIds
+//				paramsList[currId].settingData = newParamValues.readUint32();
+			else {
 								// generate failure of execution notification for ST[06]
 				continue;       // ignore the invalid ID
 			}
@@ -111,7 +114,10 @@ uint16_t ParameterService::numOfValidIds(Message idMsg) {
 
 		// FIXES: 1) Implement a linear search
 		// 2) (possibly better) Rewrite everything to use a hash map, since IDs are unique
-		if (currId < CONFIGLENGTH) {
+//		if (currId < CONFIGLENGTH) {
+//			validIds++;
+//		}
+		if (paramsList.find(currId) != paramsList.end()) {
 			validIds++;
 		}
 	}
-- 
GitLab