diff --git a/inc/ECSS_Definitions.hpp b/inc/ECSS_Definitions.hpp index 1f000979a32969565a7cdee0d7e91f63779da207..430e6bfe40f64f5f8b88b630ac44731ab2289df4 100644 --- a/inc/ECSS_Definitions.hpp +++ b/inc/ECSS_Definitions.hpp @@ -8,6 +8,13 @@ // 7.4.1 #define CCSDS_PACKET_VERSION 0 +/** + * @brief Maximum length of a String converted TC packet message + * @details This definition refers to the maximum length that an embedded TC packet, meaning a TC + * packet contained in a message request as a part of the request. + */ +#define ECSS_TC_REQUEST_STRING_SIZE 64 + // 7.4.4.1c #define ECSS_PUS_VERSION 2 diff --git a/inc/ErrorHandler.hpp b/inc/ErrorHandler.hpp index c61bce43f280e5a2b7f276befc132189e736d812..ad37a3d7ee5de3c9137177f2cd750b9a4e972b9e 100644 --- a/inc/ErrorHandler.hpp +++ b/inc/ErrorHandler.hpp @@ -110,20 +110,10 @@ public: */ EventActionDeleteEnabledDefinitionError = 2, /** - * In the Event Action Service, in the deleteEventActionDefinition function, an attempt - * was made to delete an unknown event action definition + * In the Event Action Service, an access attempt was made to an unknown event + * action definition */ - EventActionDeleteUnknownDefinitionError = 3, - /** - * In the Event Action Service, in the enableEventActionDefinition function, an attempt - * was made to enable an unknown event action definition - */ - EventActionEnableUnknownDefinitionError = 4, - /** - * In the Event Action Service, in the disableEventActionDefinition function, an attempt - * was made to disable an unknown event action definition - */ - EventActionDisableUnknownDefinitionError = 5, + EventActionUnknownDefinitionError = 3, }; /** diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp index e645175b994e032fe8b4fffc87a0694cbdaf7a45..f7a7dbb5cc6fa91680d05e5ccaf88c2c94fc3d06 100644 --- a/inc/Services/EventActionService.hpp +++ b/inc/Services/EventActionService.hpp @@ -47,7 +47,7 @@ private: public: struct EventActionDefinition { - //+@TODO: APID = 0 is the Ground Station APID. This should be changed + // TODO: APID = 0 is the Ground Station APID. This should be changed uint16_t applicationId = 0; uint16_t eventDefinitionID = 65535; String<64> request = ""; diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index eff760679cdbf55407aa4880aa220b2564f03c2b..37bc2bede8cd59a78afc7fd17960c84334d45baa 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -2,6 +2,9 @@ #include "Message.hpp" #include "MessageParser.hpp" +// todo: Replace the checks for the message.messageType, message.packetType and message +// .ServiceType with assertions + void EventActionService::addEventActionDefinitions(Message &message) { // TC[19,1] @@ -14,17 +17,17 @@ void EventActionService::addEventActionDefinitions(Message &message) { temp.enabled = true; temp.applicationId = applicationID; temp.eventDefinitionID = eventDefinitionID; - if (message.dataSize - 4 > ECSS_EVENT_SERVICE_STRING_SIZE) { - ErrorHandler::reportInternalError(ErrorHandler::InternalErrorType::MessageTooLarge); + if (message.dataSize - 4 > ECSS_TC_REQUEST_STRING_SIZE) { + ErrorHandler::reportInternalError(ErrorHandler::MessageTooLarge); } else { - char data[ECSS_EVENT_SERVICE_STRING_SIZE]; + char data[ECSS_TC_REQUEST_STRING_SIZE]; message.readString(data, message.dataSize - 4); - temp.request = String<ECSS_EVENT_SERVICE_STRING_SIZE>(data); + temp.request = String<ECSS_TC_REQUEST_STRING_SIZE>(data); } eventActionDefinitionMap.insert(std::make_pair(eventDefinitionID, temp)); } else { ErrorHandler::reportError(message, - ErrorHandler::ExecutionStartErrorType::EventActionAddExistingDefinitionError); + ErrorHandler::EventActionAddExistingDefinitionError); } } } @@ -44,13 +47,13 @@ void EventActionService::deleteEventActionDefinitions(Message &message) { eventActionDefinitionMap[eventDefinitionID].applicationId = applicationID; if (eventActionDefinitionMap[eventDefinitionID].enabled == true) { ErrorHandler::reportError(message, - ErrorHandler::ExecutionStartErrorType::EventActionDeleteEnabledDefinitionError); + ErrorHandler::EventActionDeleteEnabledDefinitionError); } else { eventActionDefinitionMap.erase(eventDefinitionID); } } else { ErrorHandler::reportError(message, - ErrorHandler::ExecutionStartErrorType::EventActionDeleteUnknownDefinitionError); + ErrorHandler::EventActionUnknownDefinitionError); } } } @@ -76,16 +79,13 @@ void EventActionService::enableEventActionDefinitions(Message &message) { uint16_t eventDefinitionID = message.readEnum16(); if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap .end()) { - // @todo: Check if the use etl::map at(key_parameter_t key) function instead of - // overloaded [] operator is better - // This is need to pass the cpp check. The applicationId should be used // somewhere eventActionDefinitionMap[eventDefinitionID].applicationId = applicationID; eventActionDefinitionMap[eventDefinitionID].enabled = true; } else { ErrorHandler::reportError(message, - ErrorHandler::ExecutionStartErrorType::EventActionEnableUnknownDefinitionError); + ErrorHandler::EventActionUnknownDefinitionError); } } } else { @@ -107,16 +107,13 @@ void EventActionService::disableEventActionDefinitions(Message &message) { uint16_t eventDefinitionID = message.readEnum16(); if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap .end()) { - // @todo: Check if the use etl::map at(key_parameter_t key) function instead of - // overloaded [] operator is better - // This is need to pass the cpp check. The applicationId should be used // somewhere eventActionDefinitionMap[eventDefinitionID].applicationId = applicationID; eventActionDefinitionMap[eventDefinitionID].enabled = false; } else { ErrorHandler::reportError(message, - ErrorHandler::ExecutionStartErrorType::EventActionDisableUnknownDefinitionError); + ErrorHandler::EventActionUnknownDefinitionError); } } } else { @@ -169,8 +166,6 @@ void EventActionService::executeAction(uint16_t eventID) { // Custom function if (eventActionFunctionStatus) { if (eventActionDefinitionMap.find(eventID) != eventActionDefinitionMap.end()) { - // @todo: Check if the use etl::map at(key_parameter_t key) function instead of - // overloaded [] operator is better if (eventActionDefinitionMap[eventID].enabled) { MessageParser messageParser; Message message = messageParser.parseRequestTC( diff --git a/test/Services/EventActionService.cpp b/test/Services/EventActionService.cpp index 9c9366ab3f0dcc6d54d817d014222af2765c9390..9faf7618a92aa8f3f22513ff755ab1a2622aedcb 100644 --- a/test/Services/EventActionService.cpp +++ b/test/Services/EventActionService.cpp @@ -10,7 +10,8 @@ EventActionService & eventActionService = Services.eventAction; -TEST_CASE("Add event-action definitions TC[19,1]", "[service][st09]") { +TEST_CASE("Add event-action definitions TC[19,1]", "[service][st19]") { + Message message(19, 1, Message::TC, 0); message.appendEnum16(0); message.appendEnum16(2); @@ -37,31 +38,35 @@ TEST_CASE("Add event-action definitions TC[19,1]", "[service][st09]") { CHECK(eventActionService.eventActionDefinitionMap[3].request.compare(data) == 0); } -TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st09]") { +TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st19]") { Message message0(19, 1, Message::TC, 0); message0.appendEnum16(1); message0.appendEnum16(0); String<64> data = "0"; message0.appendString(data); eventActionService.addEventActionDefinitions(message0); + Message message1(19, 1, Message::TC, 0); message1.appendEnum16(1); message1.appendEnum16(1); data = "1"; message1.appendString(data); eventActionService.addEventActionDefinitions(message1); + Message message2(19, 1, Message::TC, 0); message2.appendEnum16(1); message2.appendEnum16(2); data = "2"; message2.appendString(data); eventActionService.addEventActionDefinitions(message2); + Message message3(19, 1, Message::TC, 0); message3.appendEnum16(1); message3.appendEnum16(3); data = "3"; message3.appendString(data); eventActionService.addEventActionDefinitions(message3); + Message message4(19, 1, Message::TC, 0); message4.appendEnum16(1); message4.appendEnum16(4); @@ -76,6 +81,7 @@ TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st09]") { message.appendEnum16(1); message.appendEnum16(2); eventActionService.disableEventActionDefinitions(message); + Message message5(19, 2, Message::TC, 0); message5.appendUint16(2); message5.appendEnum16(1); @@ -111,31 +117,35 @@ TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st09]") { } -TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st09]") { +TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { Message message0(19, 1, Message::TC, 0); message0.appendEnum16(1); message0.appendEnum16(0); String<64> data = "0"; message0.appendString(data); eventActionService.addEventActionDefinitions(message0); + Message message1(19, 1, Message::TC, 0); message1.appendEnum16(1); message1.appendEnum16(1); data = "1"; message1.appendString(data); eventActionService.addEventActionDefinitions(message1); + Message message2(19, 1, Message::TC, 0); message2.appendEnum16(1); message2.appendEnum16(2); data = "2"; message2.appendString(data); eventActionService.addEventActionDefinitions(message2); + Message message3(19, 1, Message::TC, 0); message3.appendEnum16(1); message3.appendEnum16(3); data = "3"; message3.appendString(data); eventActionService.addEventActionDefinitions(message3); + Message message4(19, 1, Message::TC, 0); message4.appendEnum16(1); message4.appendEnum16(4); @@ -153,19 +163,21 @@ TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st09]") { } } -TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st09]") { +TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st19]") { Message message0(19, 1, Message::TC, 0); message0.appendEnum16(1); message0.appendEnum16(0); String<64> data = "0"; message0.appendString(data); eventActionService.addEventActionDefinitions(message0); + Message message1(19, 1, Message::TC, 0); message1.appendEnum16(1); message1.appendEnum16(1); data = "00"; message1.appendString(data); eventActionService.addEventActionDefinitions(message1); + Message message2(19, 5, Message::TC, 0); message2.appendUint16(2); message2.appendEnum16(1); @@ -173,6 +185,7 @@ TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st09]") { message2.appendEnum16(1); message2.appendEnum16(1); eventActionService.disableEventActionDefinitions(message2); + CHECK(eventActionService.eventActionDefinitionMap[0].enabled == 0); CHECK(eventActionService.eventActionDefinitionMap[1].enabled == 0); Message message3(19, 4, Message::TC, 0); @@ -182,33 +195,37 @@ TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st09]") { message3.appendEnum16(1); message3.appendEnum16(1); eventActionService.enableEventActionDefinitions(message3); + CHECK(eventActionService.eventActionDefinitionMap[0].enabled == 1); CHECK(eventActionService.eventActionDefinitionMap[1].enabled == 1); } -TEST_CASE("Disable event-action definitions TC[19,5]", "[service][st09]") { +TEST_CASE("Disable event-action definitions TC[19,5]", "[service][st19]") { Message message0(19, 1, Message::TC, 0); message0.appendEnum16(1); message0.appendEnum16(0); String<64> data = "0"; message0.appendString(data); eventActionService.addEventActionDefinitions(message0); + Message message1(19, 1, Message::TC, 0); message1.appendEnum16(1); message1.appendEnum16(0); data = "00"; message1.appendString(data); eventActionService.addEventActionDefinitions(message1); + Message message2(19, 5, Message::TC, 0); message2.appendUint16(1); message2.appendEnum16(1); message2.appendEnum16(0); eventActionService.disableEventActionDefinitions(message2); + CHECK(eventActionService.eventActionDefinitionMap[0].enabled == 0); CHECK(eventActionService.eventActionDefinitionMap[1].enabled == 0); } -TEST_CASE("Request event-action definition status TC[19,6]", "[service][st09]") { +TEST_CASE("Request event-action definition status TC[19,6]", "[service][st19]") { Message message(19, 6, Message::TC, 0); eventActionService.requestEventActionDefinitionStatus(message); REQUIRE(ServiceTests::hasOneMessage()); @@ -217,24 +234,27 @@ TEST_CASE("Request event-action definition status TC[19,6]", "[service][st09]") CHECK(report.messageType == 7); } -TEST_CASE("Event-action status report TM[19,7]", "[service][st09]") { +TEST_CASE("Event-action status report TM[19,7]", "[service][st19]") { Message message0(19, 1, Message::TC, 0); message0.appendEnum16(1); message0.appendEnum16(0); String<64> data = "0"; message0.appendString(data); eventActionService.addEventActionDefinitions(message0); + Message message1(19, 1, Message::TC, 0); message1.appendEnum16(1); message1.appendEnum16(2); data = "2"; message1.appendString(data); eventActionService.addEventActionDefinitions(message1); + Message message2(19, 5, Message::TC, 0); message2.appendUint16(1); message2.appendEnum16(1); message2.appendEnum16(0); eventActionService.disableEventActionDefinitions(message2); + eventActionService.eventActionStatusReport(); REQUIRE(ServiceTests::hasOneMessage()); @@ -248,18 +268,18 @@ TEST_CASE("Event-action status report TM[19,7]", "[service][st09]") { CHECK(report.readUint8() == 1); } -TEST_CASE("Enable event-action function TC[19,8]", "[service][st09]") { +TEST_CASE("Enable event-action function TC[19,8]", "[service][st19]") { Message message(19, 8, Message::TC, 0); eventActionService.enableEventActionFunction(message); CHECK(eventActionService.getEventActionFunctionStatus() == true); } -TEST_CASE("Disable event-action function TC[19,9]", "[service][st09]") { +TEST_CASE("Disable event-action function TC[19,9]", "[service][st19]") { Message message(19, 9, Message::TC, 0); eventActionService.disableEventActionFunction(message); CHECK(eventActionService.getEventActionFunctionStatus() == false); } -TEST_CASE("Execute a TC request", "[service][st09]"){ +TEST_CASE("Execute a TC request", "[service][st19]"){ }