From 8670ad340543fa20ba4fb41b31a307974f82f9bb Mon Sep 17 00:00:00 2001 From: thodkatz <thodkatz@gmail.com> Date: Thu, 24 Jan 2019 10:49:50 +0200 Subject: [PATCH] Error code have been implemented for ST[01] reports that are responsible for failed events. The execute() of MessageParser needs to be redefined --- inc/MessageParser.hpp | 2 ++ inc/Services/RequestVerificationService.hpp | 19 +++++++----- src/ErrorHandler.cpp | 6 ++-- src/MessageParser.cpp | 9 +++--- src/Services/RequestVerificationService.cpp | 33 +++++++++++++-------- src/main.cpp | 20 ++++++------- 6 files changed, 51 insertions(+), 38 deletions(-) diff --git a/inc/MessageParser.hpp b/inc/MessageParser.hpp index 0af0afbf..485d42db 100644 --- a/inc/MessageParser.hpp +++ b/inc/MessageParser.hpp @@ -20,6 +20,8 @@ public: * * @todo The implementation of the execute function should correspond to the numbers of the * services/activities that have been created + * @todo execute() needs to be redefined. The /p message isn't enough to call some + * subservices. More arguments are needed. */ void execute(Message &message); diff --git a/inc/Services/RequestVerificationService.hpp b/inc/Services/RequestVerificationService.hpp index a3edf9a9..6fef8a64 100644 --- a/inc/Services/RequestVerificationService.hpp +++ b/inc/Services/RequestVerificationService.hpp @@ -38,7 +38,8 @@ public: * The data is actually some data members of Message that contain the basic * info of the telecommand packet that failed to be accepted */ - void failAcceptanceVerification(const Message &request); + void failAcceptanceVerification(const Message &request, ErrorHandler::AcceptanceErrorType + errorCode); /** * TM[1,3] successful start of execution verification report @@ -56,7 +57,8 @@ public: * The data is actually some data members of Message that contain the basic info * of the telecommand packet that its start of execution has failed */ - void failStartExecutionVerification(const Message &request); + void failStartExecutionVerification(const Message &request, ErrorHandler::ExecutionErrorType + errorCode); /** * TM[1,5] successful progress of execution verification report @@ -74,7 +76,8 @@ 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 */ - void failProgressExecutionVerification(const Message &request); + void failProgressExecutionVerification(const Message &request, + ErrorHandler::ExecutionErrorType errorCode); /** * TM[1,7] successful completion of execution verification report @@ -92,7 +95,8 @@ public: * The data is actually some data members of Message that contain the basic info of the * telecommand packet that failed to be executed completely */ - void failCompletionExecutionVerification(const Message &request); + void failCompletionExecutionVerification(const Message &request, + ErrorHandler::ExecutionErrorType errorCode); /** * TM[1,10] failed routing verification report @@ -101,7 +105,7 @@ public: * The data is actually some data members of Message that contain the basic info of the * telecommand packet that failed the routing */ - void failRoutingVerification(const Message &request); + void failRoutingVerification(const Message &request, ErrorHandler::RoutingErrorType errorCode); /** * It is responsible to call the suitable function that execute the proper subservice. The @@ -110,9 +114,10 @@ public: * * Note:The functions of this service takes dummy values as arguments for the time being * - * @todo Error handling for the switch() in the implementation of this execute function + * @todo execute() needs to be redefined. The /p message isn't enough to call some + * subservices. More arguments are needed. */ - void execute(const Message &message); + //void execute(const Message &message); /** * The purpose of this instance is to access the execute function of this service when a diff --git a/src/ErrorHandler.cpp b/src/ErrorHandler.cpp index 0cb0c203..1cb8e686 100644 --- a/src/ErrorHandler.cpp +++ b/src/ErrorHandler.cpp @@ -9,21 +9,21 @@ static RequestVerificationService requestVerificationService; template<> void ErrorHandler::reportError(const Message &message, AcceptanceErrorType errorCode) { - requestVerificationService.failAcceptanceVerification(message); + requestVerificationService.failAcceptanceVerification(message, errorCode); logError(message, errorCode); } template<> void ErrorHandler::reportError(const Message &message, ExecutionErrorType errorCode) { - requestVerificationService.failCompletionExecutionVerification(message); + requestVerificationService.failCompletionExecutionVerification(message, errorCode); logError(message, errorCode); } template<> void ErrorHandler::reportError(const Message &message, RoutingErrorType errorCode) { - requestVerificationService.failRoutingVerification(message); + requestVerificationService.failRoutingVerification(message, errorCode); logError(message, errorCode); } diff --git a/src/MessageParser.cpp b/src/MessageParser.cpp index fe2426e5..540738e5 100644 --- a/src/MessageParser.cpp +++ b/src/MessageParser.cpp @@ -10,15 +10,14 @@ RequestVerificationService RequestVerificationService::instance; void MessageParser::execute(Message &message) { switch (message.serviceType) { - case 1: - RequestVerificationService::instance.execute(message); - break; + //case 1: + //RequestVerificationService::instance.execute(message); + //break; case 17: TestService::instance.execute(message); break; default: - // cout is very bad for embedded systems - std::cout << "This service hasn't been implemented yet or it doesn't exist"; + ErrorHandler::reportInternalError(ErrorHandler::UnknownMessageType); break; } } diff --git a/src/Services/RequestVerificationService.cpp b/src/Services/RequestVerificationService.cpp index 33c06beb..3a2ed7b7 100644 --- a/src/Services/RequestVerificationService.cpp +++ b/src/Services/RequestVerificationService.cpp @@ -17,7 +17,8 @@ void RequestVerificationService::successAcceptanceVerification(const Message &re } void -RequestVerificationService::failAcceptanceVerification(const Message &request) { +RequestVerificationService::failAcceptanceVerification(const Message &request, + ErrorHandler::AcceptanceErrorType errorCode) { // TM[1,2] failed acceptance verification report Message report = createTM(2); @@ -28,12 +29,12 @@ RequestVerificationService::failAcceptanceVerification(const Message &request) { report.appendEnumerated(11, request.applicationId); // application process ID report.appendEnumerated(2, ECSS_SEQUENCE_FLAGS); // sequence flags(not implemented) report.appendBits(14, 0); // packet sequence count(not implemented) - report.appendEnum16(0); // error code(not implemented) + report.appendEnum16(errorCode); // error code storeMessage(report); } -void RequestVerificationService::successStartExecutionVerification(const Message &request){ +void RequestVerificationService::successStartExecutionVerification(const Message &request) { // TM[1,3] successful start of execution verification report Message report = createTM(3); @@ -43,12 +44,13 @@ void RequestVerificationService::successStartExecutionVerification(const Message report.appendBits(1, 0); // secondary header flag(not implemented) report.appendEnumerated(11, request.applicationId); // application process ID report.appendEnumerated(2, ECSS_SEQUENCE_FLAGS); // sequence flags(not implemented) - report.appendBits(14, 0); // packet sequence count(not implemented) + report.appendBits(14, 0); // packet sequence count storeMessage(report); } -void RequestVerificationService::failStartExecutionVerification(const Message &request){ +void RequestVerificationService::failStartExecutionVerification(const Message &request, + ErrorHandler::ExecutionErrorType errorCode) { // TM[1,4] failed start of execution verification report Message report = createTM(4); @@ -59,12 +61,12 @@ void RequestVerificationService::failStartExecutionVerification(const Message &r report.appendEnumerated(11, request.applicationId); // application process ID report.appendEnumerated(2, ECSS_SEQUENCE_FLAGS); // sequence flags(not implemented) report.appendBits(14, 0); // packet sequence count(not implemented) - report.appendEnum16(0); // error code(not implemented) + report.appendEnum16(errorCode); // error code storeMessage(report); } -void RequestVerificationService::successProgressExecutionVerification(const Message &request){ +void RequestVerificationService::successProgressExecutionVerification(const Message &request) { // TM[1,5] successful progress of execution verification report Message report = createTM(5); @@ -79,7 +81,8 @@ void RequestVerificationService::successProgressExecutionVerification(const Mess storeMessage(report); } -void RequestVerificationService::failProgressExecutionVerification(const Message &request){ +void RequestVerificationService::failProgressExecutionVerification(const Message &request, + ErrorHandler::ExecutionErrorType errorCode) { // TM[1,6] failed progress of execution verification report Message report = createTM(6); @@ -90,7 +93,7 @@ void RequestVerificationService::failProgressExecutionVerification(const Message report.appendEnumerated(11, request.applicationId); // application process ID report.appendEnumerated(2, ECSS_SEQUENCE_FLAGS); // sequence flags(not implemented) report.appendBits(14, 0); // packet sequence count(not implemented) - report.appendEnum16(0); // error code(not implemented) + report.appendEnum16(errorCode); // error code storeMessage(report); } @@ -111,7 +114,8 @@ void RequestVerificationService::successCompletionExecutionVerification(const Me } void -RequestVerificationService::failCompletionExecutionVerification(const Message &request) { +RequestVerificationService::failCompletionExecutionVerification(const Message &request, + ErrorHandler::ExecutionErrorType errorCode) { // TM[1,8] failed completion of execution verification report Message report = createTM(8); @@ -122,13 +126,14 @@ RequestVerificationService::failCompletionExecutionVerification(const Message &r report.appendEnumerated(11, request.applicationId); // application process ID report.appendEnumerated(2, ECSS_SEQUENCE_FLAGS); // sequence flags(not implemented) report.appendBits(14, 0); // packet sequence count(not implemented) - report.appendEnum16(0); // error code(not implemented) + report.appendEnum16(errorCode); // error code storeMessage(report); } void -RequestVerificationService::failRoutingVerification(const Message &request) { +RequestVerificationService::failRoutingVerification(const Message &request, + ErrorHandler::RoutingErrorType errorCode) { // TM[1,10] failed routing verification report Message report = createTM(10); @@ -139,11 +144,12 @@ RequestVerificationService::failRoutingVerification(const Message &request) { report.appendEnumerated(11, request.applicationId); // application process ID report.appendEnumerated(2, ECSS_SEQUENCE_FLAGS); // sequence flags(not implemented) report.appendBits(14, 0); // packet sequence count(not implemented) - report.appendEnum16(0); // error code(not implemented) + report.appendEnum16(errorCode); // error code storeMessage(report); } +/* void RequestVerificationService::execute(const Message &message) { switch (message.messageType) { case 1: @@ -178,3 +184,4 @@ void RequestVerificationService::execute(const Message &message) { break; } } + */ diff --git a/src/main.cpp b/src/main.cpp index 7649c4ab..1b395c00 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -117,28 +117,28 @@ int main() { reqVerifService.successAcceptanceVerification(receivedMessage); receivedMessage = Message(1, 2, Message::TC, 3); - reqVerifService.failAcceptanceVerification(receivedMessage); + reqVerifService.failAcceptanceVerification(receivedMessage, ErrorHandler::UnknownAcceptanceError); receivedMessage = Message(1, 3, Message::TC, 3); reqVerifService.successStartExecutionVerification(receivedMessage); receivedMessage = Message(1, 4, Message::TC, 3); - reqVerifService.failStartExecutionVerification(receivedMessage); + reqVerifService.failStartExecutionVerification(receivedMessage, ErrorHandler::UnknownExecutionError); receivedMessage = Message(1, 5, Message::TC, 3); reqVerifService.successProgressExecutionVerification(receivedMessage); receivedMessage = Message(1, 6, Message::TC, 3); - reqVerifService.failProgressExecutionVerification(receivedMessage); + reqVerifService.failProgressExecutionVerification(receivedMessage, ErrorHandler::UnknownExecutionError); receivedMessage = Message(1, 7, Message::TC, 3); reqVerifService.successCompletionExecutionVerification(receivedMessage); receivedMessage = Message(1, 8, Message::TC, 3); - reqVerifService.failCompletionExecutionVerification(receivedMessage); + reqVerifService.failCompletionExecutionVerification(receivedMessage, ErrorHandler::UnknownExecutionError); receivedMessage = Message(1, 10, Message::TC, 3); - reqVerifService.failRoutingVerification(receivedMessage); + reqVerifService.failRoutingVerification(receivedMessage, ErrorHandler::UnknownRoutingError); // ST[05] (5,1 to 5,4) test [works] const char eventReportData[12] = "Hello World"; @@ -165,15 +165,15 @@ int main() { // ST[01] test message = Message(1, 1, Message::TC, 3); - messageParser.execute(message); + //messageParser.execute(message); message = Message(1, 2, Message::TC, 3); - messageParser.execute(message); + //messageParser.execute(message); message = Message(1, 7, Message::TC, 3); - messageParser.execute(message); + //messageParser.execute(message); message = Message(1, 8, Message::TC, 3); - messageParser.execute(message); + //messageParser.execute(message); message = Message(1, 10, Message::TC, 3); - messageParser.execute(message); + //messageParser.execute(message); // ErrorHandler test std::cout << std::flush; -- GitLab