diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ee0466937f6439a8ab12dd476a285c05929f32a..6844fc4ab6b2489b09ab3fb4bbdcb013820089ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,13 +15,15 @@ add_custom_target(check # Specify the .cpp files for the executables add_executable(ecss_services src/main.cpp src/Message.cpp src/Service.cpp - src/Services/TestService.cpp src/Services/RequestVerificationService.cpp src/Services/ParameterService.cpp) + src/Services/TestService.cpp src/Services/RequestVerificationService.cpp + src/Services/ParameterService.cpp) IF (EXISTS "${PROJECT_SOURCE_DIR}/lib/Catch2/CMakeLists.txt") add_subdirectory(lib/Catch2) add_executable(tests src/Message.cpp src/Services/TestService.cpp - src/Services/RequestVerificationService.cpp test/tests.cpp + src/Services/RequestVerificationService.cpp src/Services/ParameterService.cpp + test/tests.cpp test/Message.cpp test/TestPlatform.cpp test/Services/TestService.cpp - test/Services/RequestVerificationService.cpp) + test/Services/RequestVerificationService.cpp test/Services/ParameterService.cpp) target_link_libraries(tests Catch2::Catch2) ENDIF () diff --git a/inc/Services/ParameterService.hpp b/inc/Services/ParameterService.hpp index f7f2a04e73a4fb96520e0ec8992c35e99b20b9da..0992043fe91237cc5e2a0c787487037f3c98a5a0 100644 --- a/inc/Services/ParameterService.hpp +++ b/inc/Services/ParameterService.hpp @@ -2,6 +2,7 @@ #define ECSS_SERVICES_PARAMETERSERVICE_HPP #include "Service.hpp" +// #include "Services/RequestVerificationService.hpp" #define CONFIGLENGTH 5 @@ -42,6 +43,8 @@ class ParameterService : public Service { Parameter paramsList[CONFIGLENGTH]; // CONFIGLENGTH is just a dummy number for now, this should be statically set + // RequestVerificationService rvs; // request verification service for error reporting + public: ParameterService(); diff --git a/src/Services/ParameterService.cpp b/src/Services/ParameterService.cpp index 9875f01ab1f8e005f597a6e55bf62ffec2cd3ddf..49e1de6b7db56b2ffc32d7d6d0b54a33a98b433f 100644 --- a/src/Services/ParameterService.cpp +++ b/src/Services/ParameterService.cpp @@ -9,7 +9,7 @@ #endif -uint16_t numOfValidIds(Message idMsg); +uint16_t numOfValidIds(Message idMsg); //count the valid ids in a given TC[20, 1] ParameterService::ParameterService() { #ifdef DEMOMODE @@ -48,7 +48,7 @@ Message ParameterService::reportParameterIds(Message paramIds) { * @return A TM[20, 2] packet containing the valid parameter IDs and their settings. * @return Empty TM[20, 2] packet on wrong type. * - * @todo Generate failure notifs where needed when ST[06] is ready + * @todo Generate failure notifs where needed when ST[01] is ready * * NOTES: * Method for valid ID counting is a hack (clones the message and figures out the number @@ -71,14 +71,11 @@ Message ParameterService::reportParameterIds(Message paramIds) { if (currId < CONFIGLENGTH) { // check to prevent out-of-bounds access due to invalid id - reqParam.appendUint16(currId); // append it to the new packet + reqParam.appendUint16(currId); reqParam.appendUint32(paramsList[currId].settingData); - // right after that append the settings } else { - // generate failed execution notification - // (depends on execution reporting subservice ST[06]) - + // generate failure of execution notification for ST[06] continue; //ignore the invalid ID } } @@ -115,7 +112,7 @@ void ParameterService::setParameterIds(Message newParamValues) { paramsList[currId].settingData = newParamValues.readUint32(); } else { - // generate failure of execution with ST[06] + // generate failure of execution notification for ST[06] continue; // ignore the invalid ID } } diff --git a/src/main.cpp b/src/main.cpp index f11acf2130d3b6891d18b120066b65c905d81e7f..0cfdc6a1b01e692db4083ba32142f72075b88e0c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ #include <iostream> -#include <Services/TestService.hpp> +#include "Services/TestService.hpp" #include "Services/ParameterService.hpp" -#include <Services/RequestVerificationService.hpp> +#include "Services/RequestVerificationService.hpp" #include "Message.hpp" int main() { @@ -30,6 +30,7 @@ int main() { receivedPacket.appendUint16(7); testService.onBoardConnection(receivedPacket); + /* //ST[20] test ParameterService paramService; @@ -71,7 +72,7 @@ int main() { 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 diff --git a/test/Services/ParameterService.cpp b/test/Services/ParameterService.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c87cd7734c4b043078f61689324064b52c06a10a --- /dev/null +++ b/test/Services/ParameterService.cpp @@ -0,0 +1,47 @@ +#include "catch2/catch.hpp" +#include "Services/ParameterService.hpp" +#include "Message.hpp" + +#define CATCH_CONFIG_MAIN + +TEST_CASE("Parameter Report Subservice") { + + ParameterService pserv; + + SECTION("Faulty Instruction Ignorance Test") { + + //TODO: Find a better criterion than checking the first 16 bits + + Message request(20, 1, Message::TC, 1); + Message report(20, 2, Message::TM, 1); + + request.appendUint16(2); // number of requested IDs + request.appendUint16(34672); // faulty ID in this context + request.appendUint16(3); // valid + + report = pserv.reportParameterIds(request); + request.readPosition = 0; + + uint16_t repIdCount = report.readUint16(); + uint16_t reqIdCount = request.readUint16(); + + REQUIRE(repIdCount < reqIdCount); + // in case there are ignored IDs the number of IDs in the report + // will be smaller than the original + } + + SECTION("Wrong Message Type Handling Test") { + + Message falseRequest(15, 3, Message::TM, 1); //a totally wrong message + Message response = pserv.reportParameterIds(falseRequest); + CHECK(response.messageType == 2); + CHECK(response.serviceType == 20); + CHECK(response.packetType == Message::TM); + CHECK(response.readPosition == 0); // if empty, this should't change from 0 + } +} + +TEST_CASE("Parameter Setting Subservice") { + + +} \ No newline at end of file