From 220b8719fd105e5ae9549c4883c5da77ec68cc7c Mon Sep 17 00:00:00 2001 From: Stelios Tzelepis <stel.tze09@gmail.com> Date: Mon, 27 Dec 2021 12:28:40 +0000 Subject: [PATCH] ParameterService changes for ST[20] Integration --- .idea/vcs.xml | 3 +- CMakeLists.txt | 4 +- inc/ECSS_Definitions.hpp | 2 +- .../x86/Parameters/PlatformParameters.hpp | 24 ++++++++ .../x86/Parameters/SystemParameters.hpp | 61 ------------------- inc/Services/HousekeepingService.hpp | 3 +- inc/Services/ParameterService.hpp | 57 ++++++++++++++++- inc/Services/ParameterStatisticsService.hpp | 3 +- .../x86/Parameters/SystemParameters.cpp | 3 - .../x86/Services/ParameterService.cpp | 13 ++++ src/Services/HousekeepingService.cpp | 5 +- src/Services/ParameterService.cpp | 12 ++-- src/Services/ParameterStatisticsService.cpp | 5 +- test/Helpers/PlatformParameters.cpp | 24 ++++++++ test/Helpers/systemParameters.cpp | 22 ------- test/Services/HousekeepingService.cpp | 6 +- test/Services/ParameterService.cpp | 31 +++++----- test/Services/ParameterStatisticsService.cpp | 5 +- test/TestPlatform.cpp | 37 +++++++++++ 19 files changed, 195 insertions(+), 125 deletions(-) create mode 100644 inc/Platform/x86/Parameters/PlatformParameters.hpp delete mode 100644 inc/Platform/x86/Parameters/SystemParameters.hpp delete mode 100644 src/Platform/x86/Parameters/SystemParameters.cpp create mode 100644 src/Platform/x86/Services/ParameterService.cpp create mode 100644 test/Helpers/PlatformParameters.cpp delete mode 100644 test/Helpers/systemParameters.cpp diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 2be0729f..72b50578 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -7,5 +7,6 @@ <mapping directory="$PROJECT_DIR$/lib/Catch2" vcs="Git" /> <mapping directory="$PROJECT_DIR$/lib/etl" vcs="Git" /> <mapping directory="$PROJECT_DIR$/lib/logger" vcs="Git" /> + <mapping directory="$PROJECT_DIR$/lib/logger/lib/etl" vcs="Git" /> </component> -</project> +</project> \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 976a40f9..37cdc1f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,6 @@ add_library(common OBJECT src/Helpers/CRCHelper.cpp src/Helpers/TimeAndDate.cpp src/Helpers/TimeHelper.cpp - src/Platform/x86/Parameters/SystemParameters.cpp src/Services/EventReportService.cpp src/Services/MemoryManagementService.cpp src/Services/ParameterService.cpp @@ -47,7 +46,8 @@ add_library(common OBJECT ) # Specify the .cpp files for the executables -file(GLOB x86_main_SRC "src/Platform/x86/*.cpp" "lib/logger/src/Platform/x86/*.cpp") +file(GLOB x86_main_SRC "src/Platform/x86/*.cpp" "src/Platform/x86/Services/*.cpp" + "lib/logger/src/Platform/x86/*.cpp") add_executable(ecss_services $<TARGET_OBJECTS:common> diff --git a/inc/ECSS_Definitions.hpp b/inc/ECSS_Definitions.hpp index cf90152f..7f836e5c 100644 --- a/inc/ECSS_Definitions.hpp +++ b/inc/ECSS_Definitions.hpp @@ -140,7 +140,7 @@ inline const uint8_t ECSSFunctionMaxArgLength = 32; inline const uint16_t LoggerMaxMessageSize = 512; /** - * @brief Size of the array holding the Parameter objects for the ST[20] parameter service + * @brief Size of the map holding references to each Parameter object for the ST[20] parameter service */ inline const uint8_t ECSSParameterCount = 12; diff --git a/inc/Platform/x86/Parameters/PlatformParameters.hpp b/inc/Platform/x86/Parameters/PlatformParameters.hpp new file mode 100644 index 00000000..a1332949 --- /dev/null +++ b/inc/Platform/x86/Parameters/PlatformParameters.hpp @@ -0,0 +1,24 @@ +#ifndef ECSS_SERVICES_PLATFORMPARAMETERS_HPP +#define ECSS_SERVICES_PLATFORMPARAMETERS_HPP + +#include "Helpers/Parameter.hpp" + +/** + * This namespace was created for the purpose of initializing + * parameters used by ecss-services. + * It initializes parameters that are instances of the \ref Parameter class. + * \ref ParameterService class stores references to these parameters in the + * form of a map, using parameter IDs as keys. + * + * @note the parameters in this specific file are only used for testing purposes, + * different subsystems should have their own implementations of this namespace, + * containing all parameters of the specific subsystem, inside the inc/Platform + * directory of their main project. + */ +namespace PlatformParameters { + inline Parameter<uint8_t> parameter1(3); + inline Parameter<uint16_t> parameter2(7); + inline Parameter<uint32_t> parameter3(10); +} + +#endif \ No newline at end of file diff --git a/inc/Platform/x86/Parameters/SystemParameters.hpp b/inc/Platform/x86/Parameters/SystemParameters.hpp deleted file mode 100644 index 1ef75b41..00000000 --- a/inc/Platform/x86/Parameters/SystemParameters.hpp +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef ECSS_SERVICES_SYSTEMPARAMETERS_HPP -#define ECSS_SERVICES_SYSTEMPARAMETERS_HPP - -#include "Helpers/Parameter.hpp" -#include <optional> -#include "etl/vector.h" -/** - * @author Athanasios Theocharis <athatheoc@gmail.com> - */ - -/** - * This class was created for the purpose of initializing and storing explicitly - * parameters (that are instances of the \ref Parameter class). It stores all the parameters - * of the specific application. Different subsystems should have their own implementations of this class. - * The position of the parameter in the vector is also called the parameter ID. - * - * It is initialised statically. - * - * The parameters here are under the responsibility of \ref ParameterService. - */ -class SystemParameters { -public: - Parameter<uint8_t> parameter1 = Parameter<uint8_t>(3); - Parameter<uint16_t> parameter2 = Parameter<uint16_t>(7); - Parameter<uint32_t> parameter3 = Parameter<uint32_t>(10); - Parameter<uint32_t> parameter4 = Parameter<uint32_t>(5); - Parameter<uint8_t> parameter5 = Parameter<uint8_t>(11); - Parameter<uint32_t> parameter6 = Parameter<uint32_t>(23); - Parameter<uint32_t> parameter7 = Parameter<uint32_t>(53); - Parameter<uint8_t> parameter8 = Parameter<uint8_t>(55); - Parameter<uint16_t> parameter9 = Parameter<uint16_t>(32); - Parameter<uint32_t> parameter10 = Parameter<uint32_t>(43); - Parameter<uint32_t> parameter11 = Parameter<uint32_t>(91); - Parameter<uint8_t> parameter12 = Parameter<uint8_t>(1); - - /** - * The key of the array is the ID of the parameter as specified in PUS - */ - etl::array<std::reference_wrapper<ParameterBase>, ECSSParameterCount> parametersArray = { - parameter1, parameter2, parameter3, parameter4, parameter5, parameter6, - parameter7, parameter8, parameter9, parameter10, parameter11, parameter12}; - - SystemParameters() = default; - - /** - * This is a simple getter function, which returns a reference to a specified parameter, from the parametersArray. - * - * @param parameterId the id of the parameter, whose reference is to be returned. - */ - std::optional<std::reference_wrapper<ParameterBase>> getParameter(uint16_t parameterId) { - if (parameterId >= parametersArray.size()) { - ErrorHandler::reportInternalError(ErrorHandler::InternalErrorType::NonExistentParameter); - return {}; - } - return parametersArray[parameterId]; - } -}; - -extern SystemParameters systemParameters; - -#endif diff --git a/inc/Services/HousekeepingService.hpp b/inc/Services/HousekeepingService.hpp index a3a90212..4ee88691 100644 --- a/inc/Services/HousekeepingService.hpp +++ b/inc/Services/HousekeepingService.hpp @@ -5,7 +5,6 @@ #include "ECSS_Definitions.hpp" #include "Service.hpp" #include "ErrorHandler.hpp" -#include "Parameters/SystemParameters.hpp" #include "Helpers/HousekeepingStructure.hpp" /** @@ -131,4 +130,4 @@ public: void execute(Message& message); }; -#endif \ No newline at end of file +#endif diff --git a/inc/Services/ParameterService.hpp b/inc/Services/ParameterService.hpp index 11247643..c932f3c6 100644 --- a/inc/Services/ParameterService.hpp +++ b/inc/Services/ParameterService.hpp @@ -1,10 +1,12 @@ #ifndef ECSS_SERVICES_PARAMETERSERVICE_HPP #define ECSS_SERVICES_PARAMETERSERVICE_HPP +#include <optional> #include "ECSS_Definitions.hpp" #include "Service.hpp" #include "ErrorHandler.hpp" #include "Helpers/Parameter.hpp" +#include "etl/map.h" /** * Implementation of the ST[20] parameter management service, @@ -22,6 +24,26 @@ * The parameters to be managed are initialized and kept in \ref SystemParameters. */ class ParameterService : public Service { +private: + typedef etl::map<uint16_t, std::reference_wrapper<ParameterBase>, ECSSParameterCount> ParameterMap; + + /** + * Map storing the IDs and references to each parameter + * of the \ref PlatformParameters namespace. + * The key of the map is the ID of the parameter as specified in PUS. + * The parameters here are under the responsibility of \ref ParameterService. + */ + ParameterMap parameters; + + /** + * Different subsystems should have their own implementations of this function, + * inside the src/Platform directory of their main project. + * + * @return map containing the initial parameters drawn + * from \ref PlatformParameters namespace + */ + void initializeParameterMap(); + public: inline static const uint8_t ServiceType = 20; @@ -31,7 +53,40 @@ public: SetParameterValues = 3, }; - ParameterService() = default; + /** + * The Constructor initializes \var parameters + * by calling \fn initializeParametersArray + */ + ParameterService() { + initializeParameterMap(); + } + + /** + * Checks if \var parameters contains a reference to a parameter with + * the given parameter ID as key + * + * @param parameterId the given ID + * @return True if there is a reference to a parameter with the given ID, False otherwise + */ + bool parameterExists(uint16_t parameterId) const { + return parameters.find(parameterId) != parameters.end(); + } + + /** + * This is a simple getter function, which returns a reference to + * a specified parameter, from the \var parameters. + * + * @param parameterId the id of the parameter, whose reference is to be returned. + */ + std::optional<std::reference_wrapper<ParameterBase>> getParameter(uint16_t parameterId) const { + auto parameter = parameters.find(parameterId); + + if (parameter != parameters.end()) { + return parameter->second; + } else { + return {}; + } + } /** * This function receives a TC[20, 1] packet and returns a TM[20, 2] packet diff --git a/inc/Services/ParameterStatisticsService.hpp b/inc/Services/ParameterStatisticsService.hpp index b15c26a8..d4bcd8a6 100644 --- a/inc/Services/ParameterStatisticsService.hpp +++ b/inc/Services/ParameterStatisticsService.hpp @@ -4,7 +4,6 @@ #include "ECSS_Definitions.hpp" #include "Service.hpp" #include "ErrorHandler.hpp" -#include "Parameters/SystemParameters.hpp" #include "Helpers/Statistic.hpp" #include "etl/deque.h" #include "etl/map.h" @@ -111,4 +110,4 @@ public: void execute(Message& message); }; -#endif \ No newline at end of file +#endif diff --git a/src/Platform/x86/Parameters/SystemParameters.cpp b/src/Platform/x86/Parameters/SystemParameters.cpp deleted file mode 100644 index b5f68de3..00000000 --- a/src/Platform/x86/Parameters/SystemParameters.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "Parameters/SystemParameters.hpp" - -SystemParameters systemParameters; diff --git a/src/Platform/x86/Services/ParameterService.cpp b/src/Platform/x86/Services/ParameterService.cpp new file mode 100644 index 00000000..da7b4c43 --- /dev/null +++ b/src/Platform/x86/Services/ParameterService.cpp @@ -0,0 +1,13 @@ +#include "ECSS_Configuration.hpp" +#ifdef SERVICE_PARAMETER + +#include "Services/ParameterService.hpp" +#include "Parameters/PlatformParameters.hpp" + +void ParameterService::initializeParameterMap() { + parameters = {{static_cast<uint16_t>(0), PlatformParameters::parameter1}, + {static_cast<uint16_t>(1), PlatformParameters::parameter2}, + {static_cast<uint16_t>(2), PlatformParameters::parameter3}}; +} + +#endif \ No newline at end of file diff --git a/src/Services/HousekeepingService.cpp b/src/Services/HousekeepingService.cpp index 41888caa..1eefcbff 100644 --- a/src/Services/HousekeepingService.cpp +++ b/src/Services/HousekeepingService.cpp @@ -1,4 +1,5 @@ #include "Services/HousekeepingService.hpp" +#include "ServicePool.hpp" void HousekeepingService::createHousekeepingReportStructure(Message& request) { request.assertTC(ServiceType, MessageType::CreateHousekeepingReportStructure); @@ -119,7 +120,7 @@ void HousekeepingService::housekeepingParametersReport(uint8_t structureId) { housekeepingReport.appendUint8(structureId); for (auto id : housekeepingStructures.at(structureId).simplyCommutatedParameterIds) { - if (auto parameter = systemParameters.getParameter(id)) { + if (auto parameter = Services.parameterManagement.getParameter(id)) { parameter->get().appendValueToMessage(housekeepingReport); } } @@ -162,7 +163,7 @@ void HousekeepingService::appendParametersToHousekeepingStructure(Message& reque return; } uint16_t newParamId = request.readUint16(); - if (newParamId >= systemParameters.parametersArray.size()) { + if (!Services.parameterManagement.parameterExists(newParamId)) { ErrorHandler::reportError(request, ErrorHandler::ExecutionStartErrorType::GetNonExistingParameter); continue; } diff --git a/src/Services/ParameterService.cpp b/src/Services/ParameterService.cpp index 02c9d218..417debf6 100644 --- a/src/Services/ParameterService.cpp +++ b/src/Services/ParameterService.cpp @@ -3,7 +3,7 @@ #include "Services/ParameterService.hpp" #include "Helpers/Parameter.hpp" -#include "Parameters/SystemParameters.hpp" + void ParameterService::reportParameters(Message& paramIds) { // TM[20,2] @@ -20,7 +20,7 @@ void ParameterService::reportParameters(Message& paramIds) { uint16_t numOfIds = paramIds.readUint16(); uint16_t numberOfValidIds = 0; for (uint16_t i = 0; i < numOfIds; i++) { - if (paramIds.readUint16() < systemParameters.parametersArray.size()) { + if (parameterExists(paramIds.readUint16())) { numberOfValidIds++; } } @@ -30,9 +30,9 @@ void ParameterService::reportParameters(Message& paramIds) { numOfIds = paramIds.readUint16(); for (uint16_t i = 0; i < numOfIds; i++) { uint16_t currId = paramIds.readUint16(); - if (currId < systemParameters.parametersArray.size()) { + if (auto parameter = getParameter(currId)) { parameterReport.appendUint16(currId); - systemParameters.parametersArray[currId].get().appendValueToMessage(parameterReport); + parameter->get().appendValueToMessage(parameterReport); } else { ErrorHandler::reportError(paramIds, ErrorHandler::GetNonExistingParameter); } @@ -53,8 +53,8 @@ void ParameterService::setParameters(Message& newParamValues) { for (uint16_t i = 0; i < numOfIds; i++) { uint16_t currId = newParamValues.readUint16(); - if (currId < systemParameters.parametersArray.size()) { - systemParameters.parametersArray[currId].get().setValueFromMessage(newParamValues); + if (auto parameter = getParameter(currId)) { + parameter->get().setValueFromMessage(newParamValues); } else { ErrorHandler::reportError(newParamValues, ErrorHandler::SetNonExistingParameter); break; // Setting next parameters is impossible, since the size of value to be read is unknown diff --git a/src/Services/ParameterStatisticsService.cpp b/src/Services/ParameterStatisticsService.cpp index 1567f917..432be671 100644 --- a/src/Services/ParameterStatisticsService.cpp +++ b/src/Services/ParameterStatisticsService.cpp @@ -2,6 +2,7 @@ #include "ECSS_Configuration.hpp" #ifdef SERVICE_PARAMETER #include "Services/ParameterStatisticsService.hpp" +#include "ServicePool.hpp" void ParameterStatisticsService::reportParameterStatistics(Message& request) { request.assertTC(ServiceType, MessageType::ReportParameterStatistics); @@ -91,7 +92,7 @@ void ParameterStatisticsService::addOrUpdateStatisticsDefinitions(Message& reque uint16_t numOfIds = request.readUint16(); for (uint16_t i = 0; i < numOfIds; i++) { uint16_t currentId = request.readUint16(); - if (currentId >= systemParameters.parametersArray.size()) { + if (!Services.parameterManagement.parameterExists(currentId)) { ErrorHandler::reportError(request, ErrorHandler::ExecutionStartErrorType::SetNonExistingParameter); if (supportsSamplingInterval) { request.skipBytes(2); @@ -139,7 +140,7 @@ void ParameterStatisticsService::deleteStatisticsDefinitions(Message& request) { } for (uint16_t i = 0; i < numOfIds; i++) { uint16_t currentId = request.readUint16(); - if (currentId >= systemParameters.parametersArray.size()) { + if (!Services.parameterManagement.parameterExists(currentId)) { ErrorHandler::reportError(request, ErrorHandler::GetNonExistingParameter); continue; } diff --git a/test/Helpers/PlatformParameters.cpp b/test/Helpers/PlatformParameters.cpp new file mode 100644 index 00000000..adccb727 --- /dev/null +++ b/test/Helpers/PlatformParameters.cpp @@ -0,0 +1,24 @@ +#include "Platform/x86/Parameters/PlatformParameters.hpp" +#include "catch2/catch.hpp" +#include "../Services/ServiceTests.hpp" +#include "ECSS_Definitions.hpp" + +TEST_CASE("Getting a reference of a parameter") { + SECTION("Valid parameter requested") { + uint16_t parameterId = 7; + REQUIRE(static_cast<Parameter<uint16_t>&>(Services.parameterManagement.getParameter(parameterId)->get()) + .getValue() == 55); + + parameterId = 11; + REQUIRE(static_cast<Parameter<uint16_t>&>(Services.parameterManagement.getParameter(parameterId)->get()) + .getValue() == 1); + } + + SECTION("Invalid parameter requested") { + uint16_t parameterId = ECSSParameterCount + 1; + REQUIRE(not Services.parameterManagement.getParameter(parameterId)); + + parameterId = parameterId + 24; + REQUIRE(not Services.parameterManagement.getParameter(parameterId)); + } +} \ No newline at end of file diff --git a/test/Helpers/systemParameters.cpp b/test/Helpers/systemParameters.cpp deleted file mode 100644 index 8d5223ec..00000000 --- a/test/Helpers/systemParameters.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "Platform/x86/Parameters/SystemParameters.hpp" -#include "catch2/catch.hpp" -#include "../Services/ServiceTests.hpp" - -TEST_CASE("Getting a reference of a parameter") { - SECTION("Valid parameter requested") { - uint16_t parameterId = 7; - REQUIRE(static_cast<Parameter<uint16_t>&>(systemParameters.getParameter(parameterId)->get()).getValue() == 55); - - parameterId = 11; - REQUIRE(static_cast<Parameter<uint16_t>&>(systemParameters.getParameter(parameterId)->get()).getValue() == 1); - } - - SECTION("Invalid parameter requested") { - uint16_t parameterId = systemParameters.parametersArray.size() + 1; - REQUIRE(not systemParameters.getParameter(parameterId)); - - parameterId = parameterId + 24; - REQUIRE(not systemParameters.getParameter(parameterId)); - CHECK(ServiceTests::countThrownErrors(ErrorHandler::InternalErrorType::NonExistentParameter) == 2); - } -} \ No newline at end of file diff --git a/test/Services/HousekeepingService.cpp b/test/Services/HousekeepingService.cpp index 36980377..c26ce511 100644 --- a/test/Services/HousekeepingService.cpp +++ b/test/Services/HousekeepingService.cpp @@ -57,9 +57,9 @@ void storeSamplesToParameters(uint16_t id1, uint16_t id2, uint16_t id3) { Message samples(HousekeepingService::ServiceType, HousekeepingService::MessageType::ReportHousekeepingPeriodicProperties, Message::TM, 1); - static_cast<Parameter<uint16_t>&>(systemParameters.parametersArray[id1].get()).setValue(33); - static_cast<Parameter<uint8_t>&>(systemParameters.parametersArray[id2].get()).setValue(77); - static_cast<Parameter<uint32_t>&>(systemParameters.parametersArray[id3].get()).setValue(99); + static_cast<Parameter<uint16_t>&>(Services.parameterManagement.getParameter(id1)->get()).setValue(33); + static_cast<Parameter<uint8_t>&>(Services.parameterManagement.getParameter(id2)->get()).setValue(77); + static_cast<Parameter<uint32_t>&>(Services.parameterManagement.getParameter(id3)->get()).setValue(99); } /** diff --git a/test/Services/ParameterService.cpp b/test/Services/ParameterService.cpp index 9f9d5fe9..018bc9af 100644 --- a/test/Services/ParameterService.cpp +++ b/test/Services/ParameterService.cpp @@ -2,11 +2,12 @@ #include "Message.hpp" #include "ServiceTests.hpp" #include "Services/ParameterService.hpp" +#include "Parameters/PlatformParameters.hpp" static void resetParameterValues() { - systemParameters.parameter1.setValue(3); - systemParameters.parameter2.setValue(7); - systemParameters.parameter3.setValue(10); + PlatformParameters::parameter1.setValue(3); + PlatformParameters::parameter2.setValue(7); + PlatformParameters::parameter3.setValue(10); }; TEST_CASE("Parameter Report Subservice") { @@ -98,9 +99,9 @@ TEST_CASE("Parameter Setting Subservice") { CHECK(ServiceTests::countThrownErrors(ErrorHandler::SetNonExistingParameter) == 1); CHECK(ServiceTests::count() == 1); - CHECK(systemParameters.parameter1.getValue() == 3); - CHECK(systemParameters.parameter2.getValue() == 7); - CHECK(systemParameters.parameter3.getValue() == 10); + CHECK(PlatformParameters::parameter1.getValue() == 3); + CHECK(PlatformParameters::parameter2.getValue() == 7); + CHECK(PlatformParameters::parameter3.getValue() == 10); ServiceTests::reset(); Services.reset(); @@ -121,9 +122,9 @@ TEST_CASE("Parameter Setting Subservice") { CHECK(ServiceTests::countThrownErrors(ErrorHandler::SetNonExistingParameter) == 1); CHECK(ServiceTests::count() == 1); - CHECK(systemParameters.parameter1.getValue() == 1); - CHECK(systemParameters.parameter2.getValue() == 2); - CHECK(systemParameters.parameter3.getValue() == 10); + CHECK(PlatformParameters::parameter1.getValue() == 1); + CHECK(PlatformParameters::parameter2.getValue() == 2); + CHECK(PlatformParameters::parameter3.getValue() == 10); resetParameterValues(); @@ -146,9 +147,9 @@ TEST_CASE("Parameter Setting Subservice") { CHECK(ServiceTests::countThrownErrors(ErrorHandler::SetNonExistingParameter) == 1); CHECK(ServiceTests::count() == 1); - CHECK(systemParameters.parameter1.getValue() == 1); - CHECK(systemParameters.parameter2.getValue() == 7); - CHECK(systemParameters.parameter3.getValue() == 10); + CHECK(PlatformParameters::parameter1.getValue() == 1); + CHECK(PlatformParameters::parameter2.getValue() == 7); + CHECK(PlatformParameters::parameter3.getValue() == 10); resetParameterValues(); @@ -169,9 +170,9 @@ TEST_CASE("Parameter Setting Subservice") { MessageParser::execute(request); - CHECK(systemParameters.parameter1.getValue() == 1); - CHECK(systemParameters.parameter2.getValue() == 2); - CHECK(systemParameters.parameter3.getValue() == 3); + CHECK(PlatformParameters::parameter1.getValue() == 1); + CHECK(PlatformParameters::parameter2.getValue() == 2); + CHECK(PlatformParameters::parameter3.getValue() == 3); resetParameterValues(); diff --git a/test/Services/ParameterStatisticsService.cpp b/test/Services/ParameterStatisticsService.cpp index 2e32020a..fbc1c361 100644 --- a/test/Services/ParameterStatisticsService.cpp +++ b/test/Services/ParameterStatisticsService.cpp @@ -2,6 +2,7 @@ #include "catch2/catch.hpp" #include "Message.hpp" #include "ServiceTests.hpp" +#include "ECSS_Definitions.hpp" /** * System-statistics initialization, so there are actual statistics in the map to work with. @@ -263,8 +264,8 @@ TEST_CASE("Add/Update statistics definitions") { uint16_t paramId1 = 0; uint16_t paramId2 = 1; uint16_t paramId3 = 2; - uint16_t paramId4 = systemParameters.parametersArray.size() + 24; - uint16_t paramId5 = systemParameters.parametersArray.size() + 1; + uint16_t paramId4 = ECSSParameterCount + 24; + uint16_t paramId5 = ECSSParameterCount + 1; uint16_t paramId6 = 3; uint16_t interval1 = 14; diff --git a/test/TestPlatform.cpp b/test/TestPlatform.cpp index 68c6ecf4..d5df134f 100644 --- a/test/TestPlatform.cpp +++ b/test/TestPlatform.cpp @@ -5,6 +5,9 @@ #include <Service.hpp> #include <Logger.hpp> #include "Services/ServiceTests.hpp" +#include "Helpers/Parameter.hpp" +#include "Services/ParameterService.hpp" +#include "Parameters/PlatformParameters.hpp" // Explicit template specializations for the logError() function template void ErrorHandler::logError(const Message&, ErrorHandler::AcceptanceErrorType); @@ -57,4 +60,38 @@ struct ServiceTestsListener : Catch::TestEventListenerBase { ServiceTests::reset(); } }; + +/** + * Extension of x86's specific \ref PlatformParameters namespace. + * The parameters declared below are only used for testing purposes. + */ +namespace PlatformParameters { + inline Parameter<uint32_t> parameter4(5); + inline Parameter<uint8_t> parameter5(11); + inline Parameter<uint32_t> parameter6(23); + inline Parameter<uint32_t> parameter7(53); + inline Parameter<uint8_t> parameter8(55); + inline Parameter<uint16_t> parameter9(32); + inline Parameter<uint32_t> parameter10(43); + inline Parameter<uint32_t> parameter11(91); + inline Parameter<uint8_t> parameter12(1); +} + +/** + * Specific definition for \ref ParameterService's initialize function, for testing purposes. + */ +void ParameterService::initializeParameterMap() { + parameters = {{static_cast<uint16_t>(0), PlatformParameters::parameter1}, + {static_cast<uint16_t>(1), PlatformParameters::parameter2}, + {static_cast<uint16_t>(2), PlatformParameters::parameter3}, + {static_cast<uint16_t>(3), PlatformParameters::parameter4}, + {static_cast<uint16_t>(4), PlatformParameters::parameter5}, + {static_cast<uint16_t>(5), PlatformParameters::parameter6}, + {static_cast<uint16_t>(6), PlatformParameters::parameter7}, + {static_cast<uint16_t>(7), PlatformParameters::parameter8}, + {static_cast<uint16_t>(8), PlatformParameters::parameter9}, + {static_cast<uint16_t>(9), PlatformParameters::parameter10}, + {static_cast<uint16_t>(10), PlatformParameters::parameter11}, + {static_cast<uint16_t>(11), PlatformParameters::parameter12}}; +} CATCH_REGISTER_LISTENER(ServiceTestsListener) -- GitLab