From 67836050f2e548d06ac46e48d966a96dde2a3ec4 Mon Sep 17 00:00:00 2001 From: thodkatz <thodkatz@gmail.com> Date: Mon, 28 Jan 2019 18:05:25 +0200 Subject: [PATCH] Define stepID efficiently --- inc/ErrorHandler.hpp | 14 +++++++---- inc/Services/RequestVerificationService.hpp | 14 ++++++++--- src/ErrorHandler.cpp | 4 +-- src/Services/RequestVerificationService.cpp | 26 +++++++++++++++++--- src/main.cpp | 5 ++-- test/ErrorHandler.cpp | 6 ++--- test/Services/RequestVerificationService.cpp | 13 +++++----- 7 files changed, 54 insertions(+), 28 deletions(-) diff --git a/inc/ErrorHandler.hpp b/inc/ErrorHandler.hpp index 02625082..c5d57578 100644 --- a/inc/ErrorHandler.hpp +++ b/inc/ErrorHandler.hpp @@ -4,6 +4,8 @@ // Forward declaration of the class, since its header file depends on the ErrorHandler class Message; +#include <stdint.h> // for the uint_8t stepID + /** * A class that handles unexpected software errors, including internal errors or errors due to * invalid & incorrect input data. @@ -116,9 +118,9 @@ public: * * @todo configure step ID for the suitable requests */ - enum stepID { - UnknownStepID = 0 - }; + //enum stepID { + //UnknownStepID = 0 + //}; /** @@ -182,10 +184,12 @@ public: * @param message The incoming message that prompted the failure * @param errorCode The error's code, when a failed progress of the execution of a request * occurs - * @param step Step identifier + * @param stepID If the execution of a request is a long process, then we can divide + * the process into steps. Each step goes with its own definition, the stepID. Each value + * ,that the stepID is assigned, should be documented. */ static void reportProgressError(const Message &message, ExecutionProgressErrorType errorCode, - stepID step); + uint8_t stepID); /** * Report a failure that occurred internally, not due to a failure of a received packet. diff --git a/inc/Services/RequestVerificationService.hpp b/inc/Services/RequestVerificationService.hpp index 9f2b646e..3f78f83b 100644 --- a/inc/Services/RequestVerificationService.hpp +++ b/inc/Services/RequestVerificationService.hpp @@ -69,9 +69,12 @@ public: * @param request Contains the necessary data to send the report. * The data is actually some data members of Message that contain the basic info * of the telecommand packet that its progress of execution is successful - * @param step Step identifier + * @param stepID If the execution of a request is a long process, then we can divide + * the process into steps. Each step goes with its own definition, the stepID. + * @todo Each value,that the stepID is assigned, should be documented. + * @todo error handling for undocumented assigned values to stepID */ - void successProgressExecutionVerification(const Message &request, ErrorHandler::stepID step); + void successProgressExecutionVerification(const Message &request, uint8_t stepID); /** * TM[1,6] failed progress of execution verification report @@ -80,10 +83,13 @@ public: * The data is actually some data members of Message that contain the basic info * of the telecommand packet that its progress of execution has failed * @param errorCode The cause of creating this type of report - * @param step Step identifier + * @param stepID If the execution of a request is a long process, then we can divide + * the process into steps. Each step goes with its own definition, the stepID. + * @todo Each value,that the stepID is assigned, should be documented. + * @todo error handling for undocumented assigned values to stepID */ void failProgressExecutionVerification(const Message &request, - ErrorHandler::ExecutionProgressErrorType errorCode, ErrorHandler::stepID step); + ErrorHandler::ExecutionProgressErrorType errorCode, uint8_t stepID); /** * TM[1,7] successful completion of execution verification report diff --git a/src/ErrorHandler.cpp b/src/ErrorHandler.cpp index 2ba82fb3..d62eadd5 100644 --- a/src/ErrorHandler.cpp +++ b/src/ErrorHandler.cpp @@ -22,8 +22,8 @@ void ErrorHandler::reportError(const Message &message, ExecutionStartErrorType e } void ErrorHandler::reportProgressError(const Message &message, ExecutionProgressErrorType -errorCode, stepID step) { - requestVerificationService.failProgressExecutionVerification(message, errorCode, step); +errorCode, uint8_t stepID) { + requestVerificationService.failProgressExecutionVerification(message, errorCode, stepID); logError(message, errorCode); } diff --git a/src/Services/RequestVerificationService.cpp b/src/Services/RequestVerificationService.cpp index 6076cd28..cae7a05c 100644 --- a/src/Services/RequestVerificationService.cpp +++ b/src/Services/RequestVerificationService.cpp @@ -66,8 +66,26 @@ void RequestVerificationService::failStartExecutionVerification(const Message &r storeMessage(report); } +/** + * StepID documentation + * + * For example: + * + * steps of UnknownProcess1 and their IDs: + * 1)UnknownStep1 = 0 + * 2)UnknownStep2 = 1 + * + * steps of UnknownProcess2 and their IDs: + * 1)UnknownStep3 = 2 + * 2)UnknownStep4 = 3 + * 3)UnknownStep5 = 4 + * + * ... + * + */ + void RequestVerificationService::successProgressExecutionVerification(const Message &request, - ErrorHandler::stepID step) { + uint8_t stepID) { // TM[1,5] successful progress of execution verification report Message report = createTM(5); @@ -78,13 +96,13 @@ void RequestVerificationService::successProgressExecutionVerification(const Mess report.appendEnumerated(11, request.applicationId); // application process ID report.appendEnumerated(2, ECSS_SEQUENCE_FLAGS); // sequence flags report.appendBits(14, 0); // packet sequence count(not implemented) - report.appendEnum16(step); // step ID + report.appendByte(stepID); // step ID storeMessage(report); } void RequestVerificationService::failProgressExecutionVerification(const Message &request, - ErrorHandler::ExecutionProgressErrorType errorCode, ErrorHandler::stepID step) { + ErrorHandler::ExecutionProgressErrorType errorCode, uint8_t stepID) { // TM[1,6] failed progress of execution verification report Message report = createTM(6); @@ -95,7 +113,7 @@ void RequestVerificationService::failProgressExecutionVerification(const Message report.appendEnumerated(11, request.applicationId); // application process ID report.appendEnumerated(2, ECSS_SEQUENCE_FLAGS); // sequence flags report.appendBits(14, 0); // packet sequence count(not implemented) - report.appendEnum16(step); // step ID + report.appendByte(stepID); // step ID report.appendEnum16(errorCode); // error code storeMessage(report); diff --git a/src/main.cpp b/src/main.cpp index 59e7f153..3adfe696 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -127,12 +127,11 @@ int main() { ErrorHandler::UnknownExecutionStartError); receivedMessage = Message(1, 5, Message::TC, 3); - reqVerifService.successProgressExecutionVerification(receivedMessage, - ErrorHandler::UnknownStepID); + reqVerifService.successProgressExecutionVerification(receivedMessage, 0); receivedMessage = Message(1, 6, Message::TC, 3); reqVerifService.failProgressExecutionVerification(receivedMessage, - ErrorHandler::UnknownExecutionProgressError, ErrorHandler::UnknownStepID); + ErrorHandler::UnknownExecutionProgressError, 0); receivedMessage = Message(1, 7, Message::TC, 3); reqVerifService.successCompletionExecutionVerification(receivedMessage); diff --git a/test/ErrorHandler.cpp b/test/ErrorHandler.cpp index ee44e226..eb8be383 100644 --- a/test/ErrorHandler.cpp +++ b/test/ErrorHandler.cpp @@ -49,7 +49,7 @@ TEST_CASE("Error: Failed Execution Start", "[errors]") { TEST_CASE("Error: Failed Execution Progress", "[errors]") { Message failedMessage(38, 32, Message::TC, 56); ErrorHandler::reportProgressError(failedMessage, ErrorHandler::UnknownExecutionProgressError, - ErrorHandler::UnknownStepID); + 0); REQUIRE(ServiceTests::hasOneMessage()); Message report = ServiceTests::get(0); @@ -58,7 +58,7 @@ TEST_CASE("Error: Failed Execution Progress", "[errors]") { CHECK(report.serviceType == 1); CHECK(report.messageType == 6); CHECK(report.packetType == Message::TM); - REQUIRE(report.dataSize == 8); + REQUIRE(report.dataSize == 7); CHECK(report.readBits(3) == CCSDS_PACKET_VERSION); CHECK(report.readBits(1) == static_cast<uint16_t>(Message::TC)); @@ -67,7 +67,7 @@ TEST_CASE("Error: Failed Execution Progress", "[errors]") { CHECK(report.readBits(2) == ECSS_SEQUENCE_FLAGS); CHECK(report.readBits(14) == failedMessage.packetSequenceCount); CHECK(report.readEnum16() == ErrorHandler::UnknownExecutionProgressError); - CHECK(report.readEnum16() == ErrorHandler::UnknownStepID); + CHECK(report.readByte() == 0); // stepID } TEST_CASE("Error: Failed Execution Completion", "[errors]") { diff --git a/test/Services/RequestVerificationService.cpp b/test/Services/RequestVerificationService.cpp index 64c66def..3e804404 100644 --- a/test/Services/RequestVerificationService.cpp +++ b/test/Services/RequestVerificationService.cpp @@ -103,8 +103,7 @@ TEST_CASE("TM[1,5]", "[service][st01]") { RequestVerificationService reqVerifService; Message receivedMessage = Message(1, 5, Message::TC, 3); - reqVerifService.successProgressExecutionVerification(receivedMessage, - ErrorHandler::UnknownStepID); + reqVerifService.successProgressExecutionVerification(receivedMessage, 0); REQUIRE(ServiceTests::hasOneMessage()); Message response = ServiceTests::get(0); @@ -113,7 +112,7 @@ TEST_CASE("TM[1,5]", "[service][st01]") { CHECK(response.messageType == 5); CHECK(response.packetType == Message::TM); // packet type CHECK(response.applicationId == 0); - REQUIRE(response.dataSize == 6); // dataSize is the number of bytes of data array + REQUIRE(response.dataSize == 5); // dataSize is the number of bytes of data array // Check for the value that is stored in <<data>> array(data-member of object response) CHECK(response.readEnumerated(3) == CCSDS_PACKET_VERSION); // packet version number CHECK(response.readEnumerated(1) == Message::TC); // packet type @@ -121,7 +120,7 @@ TEST_CASE("TM[1,5]", "[service][st01]") { CHECK(response.readEnumerated(11) == 3); // application process ID CHECK(response.readEnumerated(2) == ECSS_SEQUENCE_FLAGS); // sequence flags CHECK(response.readBits(14) == 0); // packet sequence count - CHECK(response.readEnum16() == ErrorHandler::UnknownStepID); // step ID + CHECK(response.readByte() == 0); // step ID } TEST_CASE("TM[1,6]", "[service][st01]") { @@ -130,7 +129,7 @@ TEST_CASE("TM[1,6]", "[service][st01]") { Message receivedMessage = Message(1, 5, Message::TC, 3); reqVerifService.failProgressExecutionVerification(receivedMessage, ErrorHandler::UnknownExecutionProgressError, - ErrorHandler::UnknownStepID); + 0); REQUIRE(ServiceTests::hasOneMessage()); Message response = ServiceTests::get(0); @@ -139,7 +138,7 @@ TEST_CASE("TM[1,6]", "[service][st01]") { CHECK(response.messageType == 6); CHECK(response.packetType == Message::TM); // packet type CHECK(response.applicationId == 0); - REQUIRE(response.dataSize == 8); // dataSize is the number of bytes of data array + REQUIRE(response.dataSize == 7); // dataSize is the number of bytes of data array // Check for the value that is stored in <<data>> array(data-member of object response) CHECK(response.readEnumerated(3) == CCSDS_PACKET_VERSION); // packet version number CHECK(response.readEnumerated(1) == Message::TC); // packet type @@ -147,7 +146,7 @@ TEST_CASE("TM[1,6]", "[service][st01]") { CHECK(response.readEnumerated(11) == 3); // application process ID CHECK(response.readEnumerated(2) == ECSS_SEQUENCE_FLAGS); // sequence flags CHECK(response.readBits(14) == 0); // packet sequence count - CHECK(response.readEnum16() == ErrorHandler::UnknownStepID); // step ID + CHECK(response.readByte() == 0); // step ID CHECK(response.readEnum16() == ErrorHandler::UnknownExecutionProgressError); } -- GitLab