diff --git a/inc/ErrorHandler.hpp b/inc/ErrorHandler.hpp index b1c8d73679fc5afca721c73c08e8a98b7557a61b..e99782dd288fd27f96c689532228580e2e319dd3 100644 --- a/inc/ErrorHandler.hpp +++ b/inc/ErrorHandler.hpp @@ -138,231 +138,237 @@ public: UnknownExecutionStartError = 0, /** * In the Event Action Service, in the addEventActionDefinition function an attempt was - * made to add an event Action Definition with an eventActionDefinitionID that exists + * made to add an event Action Definition with an eventDefinitionID that exists */ - EventActionDefinitionIDExistsError = 1, + EventDefinitionIDExistsError = 1, + + /** + *In the Event Action Service, in the addEventActionDefinition function an attempt was + * made to add an event Action Definition that is already enabled + */ + EventActionEnabledError = 2, /** * In the Event Action Service, in the deleteEventActionDefinition function, an attempt * was made to delete an event action definition that was enabled */ - EventActionDeleteEnabledDefinitionError = 2, + EventActionDeleteEnabledDefinitionError = 3, /** * In the Event Action Service, an access attempt was made to an unknown event * action definition */ - EventActionUnknownEventDefinitionError = 3, + EventActionUnknownEventActionDefinitionError = 4, /** * EventAction refers to the service, EventActionIDefinitionID refers to the variable - * In the Event Action Service, an access attempt was made to an unknown eventActionDefinitionID + * In the Event Action Service, an access attempt was made to an unknown eventDefinitionID */ - EventActionUnknownEventActionDefinitionIDError = 4, - SubServiceExecutionStartError = 5, - InstructionExecutionStartError = 6, + EventActionUnknownEventActionDefinitionIDError = 5, + SubServiceExecutionStartError = 6, + InstructionExecutionStartError = 7, /** * Attempt to change the value of a non existing parameter (ST[20]) */ - SetNonExistingParameter = 7, + SetNonExistingParameter = 8, /** * Attempt to access a non existing parameter (ST[20]) */ - GetNonExistingParameter = 8, + GetNonExistingParameter = 9, /** * Attempt to access a packet store that does not exist (ST[15]) */ - NonExistingPacketStore = 9, + NonExistingPacketStore = 10, /** * Attempt to change the start time tag of a packet store, whose open retrieval status is in progress (ST[15]) */ - SetPacketStoreWithOpenRetrievalInProgress = 10, + SetPacketStoreWithOpenRetrievalInProgress = 11, /** * Attempt to resume open retrieval of a packet store, whose by-time-range retrieval is enabled (ST[15]) */ - SetPacketStoreWithByTimeRangeRetrieval = 11, + SetPacketStoreWithByTimeRangeRetrieval = 12, /** * Attempt to access a packet with by-time range retrieval enabled (ST[15]) */ - GetPacketStoreWithByTimeRangeRetrieval = 12, + GetPacketStoreWithByTimeRangeRetrieval = 13, /** * Attempt to start the by-time-range retrieval of packet store, whose open retrieval is in progress (ST[15]) */ - GetPacketStoreWithOpenRetrievalInProgress = 13, + GetPacketStoreWithOpenRetrievalInProgress = 14, /** * Attempt to start by-time-range retrieval when its already enabled (ST[15]) */ - ByTimeRangeRetrievalAlreadyEnabled = 14, + ByTimeRangeRetrievalAlreadyEnabled = 15, /** * Attempt to create packet store, whose ID already exists (ST[15]) */ - AlreadyExistingPacketStore = 15, + AlreadyExistingPacketStore = 16, /** * Attempt to create packet store, when the max number of packet stores is already reached (ST[15]) */ - MaxNumberOfPacketStoresReached = 16, + MaxNumberOfPacketStoresReached = 17, /** * Attempt to access a packet store with the storage status enabled (ST[15]) */ - GetPacketStoreWithStorageStatusEnabled = 17, + GetPacketStoreWithStorageStatusEnabled = 18, /** * Attempt to delete a packet whose by time range retrieval status is enabled (ST[15]) */ - DeletionOfPacketWithByTimeRangeRetrieval = 18, + DeletionOfPacketWithByTimeRangeRetrieval = 19, /** * Attempt to delete a packet whose open retrieval status is in progress (ST[15]) */ - DeletionOfPacketWithOpenRetrievalInProgress = 19, + DeletionOfPacketWithOpenRetrievalInProgress = 20, /** * Requested a time window where the start time is larger than the end time (ST[15]) */ - InvalidTimeWindow = 20, + InvalidTimeWindow = 21, /** * Attempt to copy a packet store to a destination packet store that is not empty (ST[15]) */ - DestinationPacketStoreNotEmtpy = 21, + DestinationPacketStoreNotEmtpy = 22, /** * Attempt to set a reporting rate which is smaller than the parameter sampling rate. * ST[04] */ - InvalidReportingRateError = 22, + InvalidReportingRateError = 23, /** * Attempt to add definition to the struct map but its already full.(ST[19]) */ - EventActionDefinitionsMapIsFull = 23, + EventActionDefinitionsMapIsFull = 24, /** * Attempt to report/delete non existing housekeeping structure (ST[03]) */ - RequestedNonExistingStructure = 24, + RequestedNonExistingStructure = 25, /** * Attempt to create already created structure (ST[03]) */ - RequestedAlreadyExistingStructure = 25, + RequestedAlreadyExistingStructure = 26, /** * Attempt to delete structure which has the periodic reporting status enabled (ST[03]) as per 6.3.3.5.2(d-2) */ - RequestedDeletionOfEnabledHousekeeping = 26, + RequestedDeletionOfEnabledHousekeeping = 27, /** * Attempt to append a new parameter ID to a housekeeping structure, but the ID is already in the structure * (ST[03]) */ - AlreadyExistingParameter = 27, + AlreadyExistingParameter = 28, /** * Attempt to append a new parameter id to a housekeeping structure, but the periodic generation status is * enabled (ST[03]) */ - RequestedAppendToEnabledHousekeeping = 28, + RequestedAppendToEnabledHousekeeping = 29, /** * Attempt to create a new housekeeping structure in Housekeeping Service, when the maximum number of * housekeeping structures is already reached (ST[03]) */ - ExceededMaxNumberOfHousekeepingStructures = 29, + ExceededMaxNumberOfHousekeepingStructures = 30, /** * Attempt to add a new simply commutated parameter in a specific housekeeping structure, but the maximum * number of simply commutated parameters for this structure is already reached (ST[03]) */ - ExceededMaxNumberOfSimplyCommutatedParameters = 30, + ExceededMaxNumberOfSimplyCommutatedParameters = 31, /** * Attempt to set a reporting rate which is smaller than the parameter sampling rate. * ST[04] */ - InvalidSamplingRateError = 31, + InvalidSamplingRateError = 32, /** * Attempt to add new statistic definition but the maximum number is already reached (ST[04]) */ - MaxStatisticDefinitionsReached = 32, + MaxStatisticDefinitionsReached = 33, /** * Attempt to set the virtual channel of a packet store to a invalid value (ST[15]) */ - InvalidVirtualChannel = 33, + InvalidVirtualChannel = 34, /** * Attempt to delete a packet store, whose storage status is enabled (ST[15]) */ - DeletionOfPacketStoreWithStorageStatusEnabled = 34, + DeletionOfPacketStoreWithStorageStatusEnabled = 35, /** * Attempt to copy packets from a packet store to another, but either no packet timestamp falls inside the * specified timestamp, or more than one boolean argument were given as true in the 'copyPacketsTo' function * (ST[15]) */ - CopyOfPacketsFailed = 35, + CopyOfPacketsFailed = 36, /** * Attempt to set a packet store size to a value that the available memory cannot handle (ST[15]). */ - UnableToHandlePacketStoreSize = 36, + UnableToHandlePacketStoreSize = 37, /** * Attempt to delete all parameter monitoring definitions but the Parameter Monitoring Function Status is * enabled. */ - InvalidRequestToDeleteAllParameterMonitoringDefinitions = 37, + InvalidRequestToDeleteAllParameterMonitoringDefinitions = 38, /** * Attempt to delete one parameter monitoring definition but its Parameter Monitoring Status is * enabled. */ - InvalidRequestToDeleteParameterMonitoringDefinition = 38, + InvalidRequestToDeleteParameterMonitoringDefinition = 39, /** * Attempt to add a parameter that already exists to the Parameter Monitoring List. */ - AddAlreadyExistingParameter = 39, + AddAlreadyExistingParameter = 40, /** * Attempt to add a parameter in the Parameter Monitoring List but it's full */ - ParameterMonitoringListIsFull = 40, + ParameterMonitoringListIsFull = 41, /** * Attempt to add or modify a limit check parameter monitoring definition, but the high limit is lower than * the low limit. */ - HighLimitIsLowerThanLowLimit = 41, + HighLimitIsLowerThanLowLimit = 42, /** * Attempt to add or modify a delta check parameter monitoring definition, but the high threshold is lower than * the low threshold. */ - HighThresholdIsLowerThanLowThreshold = 42, + HighThresholdIsLowerThanLowThreshold = 43, /** * Attempt to modify a non existent Parameter Monitoring definition. */ - ModifyParameterNotInTheParameterMonitoringList = 43, + ModifyParameterNotInTheParameterMonitoringList = 44, /** * Attempt to modify a parameter monitoring definition, but the instruction refers to a monitored parameter * that is not the one used in that parameter monitoring definition. */ - DifferentParameterMonitoringDefinitionAndMonitoredParameter = 44, + DifferentParameterMonitoringDefinitionAndMonitoredParameter = 45, /** * Attempt to get a parameter monitoring definition that does not exist. */ - GetNonExistingParameterMonitoringDefinition = 45, + GetNonExistingParameterMonitoringDefinition = 46, /** * Request to report a non existent parameter monitoring definition. */ - ReportParameterNotInTheParameterMonitoringList = 46, + ReportParameterNotInTheParameterMonitoringList = 47, /** * Attempt to add a new service type, when the addition of all service types is already enabled in the * Application Process configuration (ST[14]) */ - AllServiceTypesAlreadyAllowed = 47, + AllServiceTypesAlreadyAllowed = 48, /** * Attempt to add a new report type, when the max number of reports types allowed per service type * definition in the Application Process configuration is already reached (ST[14]) */ - MaxReportTypesReached = 48, + MaxReportTypesReached = 49, /** * Attempt to add a new service type, when the max number of service types allowed per application process * definition in the Application Process configuration is already reached (ST[14]) */ - MaxServiceTypesReached = 49, + MaxServiceTypesReached = 50, /** * Attempt to add a report/event definition/housekeeping report type, when the specified application process * ID is not controlled by the Service (ST[14]) */ - NotControlledApplication = 50, + NotControlledApplication = 51, /** * Parameter is requested, but the provider of the parameter value does not exist yet */ - ParameterValueMissing = 51, + ParameterValueMissing = 52, /** * Attempted to write to a read-only parameter */ - ParameterReadOnly = 52, + ParameterReadOnly = 53, /** * Attempted to read from a write-only parameter */ - ParameterWriteOnly = 53, + ParameterWriteOnly = 54, }; /** diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp index 0fd3dd04294fac86a27cdb2900f8486a178f959f..1d4776d90df5fdab48f2d22ee54c4c6bfd2e1d9d 100644 --- a/inc/Services/EventActionService.hpp +++ b/inc/Services/EventActionService.hpp @@ -12,31 +12,17 @@ * ECSS 8.19 && 6.19 * * @ingroup Services - * @note Make sure to check the note in the addEventActionDefinition() - * @note A third variable was added, the eventActionDefinitionID. This was added for the purpose of identifying - * various eventActionDefinitions that correspond to the same eventDefinitionID. The goal is to have multiple actions - * be executed when one event takes place. This defies the standard. + * * @note The application ID was decided to be abolished as an identifier of the event-action * definition * @attention Every event action definition ID should be different, regardless of the application ID - * - * @todo Since there are multiple actions per event and in delete/enable/disable functions are - * multiple instances are accessed, should I find a more efficient way to access them? - * @todo check if eventActionFunctionStatus should be private or not - * @todo check if eventAction map of definitions should be private or not */ class EventActionService : public Service { private: /** * Event-action function status */ - bool eventActionFunctionStatus = true; - - /** - * Custom function that is called right after an event takes place, to initiate - * the execution of the action - */ - void executeAction(uint16_t eventID); + bool eventActionFunctionStatus = false; public: inline static const uint8_t ServiceType = 19; @@ -54,11 +40,13 @@ public: }; struct EventActionDefinition { - bool enabled = false; - uint16_t applicationId = ApplicationId; - uint16_t eventDefinitionID = 65535; - uint16_t eventActionDefinitionID = 0; + uint16_t applicationID = 0; + inline static const uint16_t MaxDefinitionID = 65535; + uint16_t eventDefinitionID = MaxDefinitionID; String<ECSSTCRequestStringSize> request = ""; + bool enabled = false; + + EventActionDefinition(uint16_t applicationID, uint16_t eventDefinitionID, Message& message); }; friend EventReportService; @@ -66,16 +54,12 @@ public: etl::multimap<uint16_t, EventActionDefinition, ECSSEventActionStructMapSize> eventActionDefinitionMap; - EventActionService() { + EventActionService() : eventActionFunctionStatus(true) { serviceType = ServiceType; } /** * TC[19,1] add event-action definitions - * - * Note: We have abolished multiple additions in one Telecommand packet. Only one - * event-action definition will be added per TC packet. That means there will be just an - * application ID, an event definition ID and the TC request. */ void addEventActionDefinitions(Message& message); @@ -115,7 +99,7 @@ public: void enableEventActionFunction(Message& message); /** - * TC[19,9] disable the event-actioni function + * TC[19,9] disable the event-action function */ void disableEventActionFunction(Message& message); @@ -134,6 +118,12 @@ public: return eventActionFunctionStatus; } + /** + * Custom function that is called right after an event takes place, to initiate + * the execution of the action + */ + void executeAction(uint16_t eventDefinitionID); + /** * It is responsible to call the suitable function that executes a telecommand packet. The source of that packet * is the ground station. diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp old mode 100644 new mode 100755 index 427987bc8bc111c05ccae2a55c12f288bcda45df..d9ace2a4fcbc7666b9eaa5581a89c56772c4b01d --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -5,74 +5,72 @@ #include "MessageParser.hpp" #include "Services/EventActionService.hpp" +EventActionService::EventActionDefinition::EventActionDefinition(uint16_t applicationID, uint16_t eventDefinitionID, Message& message) + : applicationID(applicationID), eventDefinitionID(eventDefinitionID), request(message.data + message.readPosition) { + message.readPosition += ECSSTCRequestStringSize; +} void EventActionService::addEventActionDefinitions(Message& message) { + // TC[19,1] message.assertTC(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction); - uint16_t applicationID = message.readEnum16(); - uint16_t eventDefinitionID = message.readEnum16(); - uint16_t eventActionDefinitionID = message.readEnum16(); - bool canBeAdded = true; - if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap.end()) { - auto range = eventActionDefinitionMap.equal_range(eventDefinitionID); - for (auto& element = range.first; element != range.second; ++element) { - if (element->second.eventActionDefinitionID == eventActionDefinitionID) { - canBeAdded = false; - ErrorHandler::reportError(message, ErrorHandler::EventActionDefinitionIDExistsError); + uint8_t numberOfEventActionDefinitions = message.readUint8(); + while (numberOfEventActionDefinitions-- != 0) { + uint16_t applicationID = message.readEnum16(); + uint16_t eventDefinitionID = message.readEnum16(); + bool canBeAdded = true; + + for (auto& element: eventActionDefinitionMap) { + if (element.first == eventDefinitionID) { + if (element.second.enabled) { + canBeAdded = false; + ErrorHandler::reportError(message, ErrorHandler::EventActionEnabledError); + } else if (not element.second.enabled) { + eventActionDefinitionMap.erase(eventDefinitionID); + } + break; } } - } - - if ((message.dataSize - 6) > ECSSTCRequestStringSize) { - canBeAdded = false; - ErrorHandler::reportInternalError(ErrorHandler::MessageTooLarge); - } - if (canBeAdded) { - char data[ECSSTCRequestStringSize] = {0}; - message.readString(data, message.dataSize - 6); - EventActionDefinition temp; - temp.enabled = false; - temp.applicationId = applicationID; - temp.eventDefinitionID = eventDefinitionID; - temp.eventActionDefinitionID = eventActionDefinitionID; - temp.request = String<ECSSTCRequestStringSize>(data); - if (eventActionDefinitionMap.size() == ECSSEventActionStructMapSize) { - ErrorHandler::reportError(message, ErrorHandler::EventActionDefinitionsMapIsFull); - } else { - eventActionDefinitionMap.insert(std::make_pair(eventDefinitionID, temp)); + if (canBeAdded) { + if (eventActionDefinitionMap.size() == ECSSEventActionStructMapSize) { + ErrorHandler::reportError(message, ErrorHandler::EventActionDefinitionsMapIsFull); + } else { + EventActionDefinition temporaryEventActionDefinition(applicationID, eventDefinitionID, message); + eventActionDefinitionMap.insert(std::make_pair(eventDefinitionID, temporaryEventActionDefinition)); + } } } } void EventActionService::deleteEventActionDefinitions(Message& message) { + // TC[19,2] message.assertTC(EventActionService::ServiceType, EventActionService::MessageType::DeleteEventAction); - uint16_t numberOfEventActionDefinitions = message.readUint16(); - bool definitionIDexists = false; - for (uint16_t i = 0; i < numberOfEventActionDefinitions; i++) { - message.skipBytes(2); + uint8_t numberOfEventActionDefinitions = message.readUint8(); + while (numberOfEventActionDefinitions-- != 0) { + uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); - uint16_t eventActionDefinitionID = message.readEnum16(); - if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap.end()) { - auto range = eventActionDefinitionMap.equal_range(eventDefinitionID); - for (auto& element = range.first; element != range.second; ++element) { - if (element->second.eventActionDefinitionID == eventActionDefinitionID) { - definitionIDexists = true; - if (element->second.enabled) { - ErrorHandler::reportError(message, ErrorHandler::EventActionDeleteEnabledDefinitionError); - } else { - eventActionDefinitionMap.erase(element); - } + bool actionDefinitionExists = false; + + for (auto& element: eventActionDefinitionMap) { + if (element.first == eventDefinitionID) { + actionDefinitionExists = true; + if (element.second.applicationID != applicationID) { + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventActionDefinitionError); + } else if (element.second.enabled) { + ErrorHandler::reportError(message, ErrorHandler::EventActionDeleteEnabledDefinitionError); + } else { + eventActionDefinitionMap.erase(eventActionDefinitionMap.find(eventDefinitionID)); } + break; } - if (not definitionIDexists) { - ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventActionDefinitionIDError); - } - } else { - ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventDefinitionError); + } + if (not actionDefinitionExists) { + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventActionDefinitionError); } } } void EventActionService::deleteAllEventActionDefinitions(Message& message) { + // TC[19,3] message.assertTC(EventActionService::ServiceType, EventActionService::MessageType::DeleteAllEventAction); setEventActionFunctionStatus(false); @@ -80,28 +78,28 @@ void EventActionService::deleteAllEventActionDefinitions(Message& message) { } void EventActionService::enableEventActionDefinitions(Message& message) { + // TC[19,4] message.assertTC(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction); - uint16_t numberOfEventActionDefinitions = message.readUint16(); + uint8_t numberOfEventActionDefinitions = message.readUint8(); if (numberOfEventActionDefinitions != 0U) { - for (uint16_t i = 0; i < numberOfEventActionDefinitions; i++) { - message.skipBytes(2); // Skips reading the application ID + while (numberOfEventActionDefinitions-- != 0) { + uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); - uint16_t eventActionDefinitionID = message.readEnum16(); - if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap.end()) { - bool definitionIDexists = false; - auto range = eventActionDefinitionMap.equal_range(eventDefinitionID); - for (auto& element = range.first; element != range.second; ++element) { - if (element->second.eventActionDefinitionID == eventActionDefinitionID) { - element->second.enabled = true; - definitionIDexists = true; - break; + bool actionDefinitionExists = false; + + for (auto& element: eventActionDefinitionMap) { + if (element.first == eventDefinitionID) { + actionDefinitionExists = true; + if (element.second.applicationID != applicationID) { + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventActionDefinitionError); + } else { + element.second.enabled = true; } + break; } - if (not definitionIDexists) { - ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventActionDefinitionIDError); - } - } else { - ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventDefinitionError); + } + if (not actionDefinitionExists) { + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventActionDefinitionError); } } } else { @@ -112,27 +110,28 @@ void EventActionService::enableEventActionDefinitions(Message& message) { } void EventActionService::disableEventActionDefinitions(Message& message) { + // TC[19,5] message.assertTC(EventActionService::ServiceType, EventActionService::MessageType::DisableEventAction); - uint16_t numberOfEventActionDefinitions = message.readUint16(); + uint8_t numberOfEventActionDefinitions = message.readUint8(); if (numberOfEventActionDefinitions != 0U) { - for (uint16_t i = 0; i < numberOfEventActionDefinitions; i++) { - message.skipBytes(2); // Skips reading applicationID + while (numberOfEventActionDefinitions-- != 0) { + uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); - uint16_t eventActionDefinitionID = message.readEnum16(); - if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap.end()) { - bool definitionIDexists = false; - auto range = eventActionDefinitionMap.equal_range(eventDefinitionID); - for (auto& element = range.first; element != range.second; ++element) { - if (element->second.eventActionDefinitionID == eventActionDefinitionID) { - element->second.enabled = false; - definitionIDexists = true; + bool actionDefinitionExists = false; + + for (auto& element: eventActionDefinitionMap) { + if (element.first == eventDefinitionID) { + actionDefinitionExists = true; + if (element.second.applicationID != applicationID) { + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventActionDefinitionError); + } else { + element.second.enabled = false; } + break; } - if (not definitionIDexists) { - ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventActionDefinitionIDError); - } - } else { - ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventDefinitionError); + } + if (not actionDefinitionExists) { + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventActionDefinitionError); } } } else { @@ -143,41 +142,43 @@ void EventActionService::disableEventActionDefinitions(Message& message) { } void EventActionService::requestEventActionDefinitionStatus(Message& message) { + // TC[19,6] message.assertTC(EventActionService::ServiceType, EventActionService::MessageType::ReportStatusOfEachEventAction); eventActionStatusReport(); } void EventActionService::eventActionStatusReport() { + // TM[19,7] Message report = createTM(EventActionStatusReport); uint16_t count = eventActionDefinitionMap.size(); report.appendUint16(count); for (const auto& element: eventActionDefinitionMap) { - report.appendEnum16(element.second.applicationId); + report.appendEnum16(element.second.applicationID); report.appendEnum16(element.second.eventDefinitionID); - report.appendEnum16(element.second.eventActionDefinitionID); report.appendBoolean(element.second.enabled); } storeMessage(report); } void EventActionService::enableEventActionFunction(Message& message) { + // TC[19,8] message.assertTC(EventActionService::ServiceType, EventActionService::MessageType::EnableEventActionFunction); setEventActionFunctionStatus(true); } void EventActionService::disableEventActionFunction(Message& message) { + // TC[19,9] message.assertTC(EventActionService::ServiceType, EventActionService::MessageType::DisableEventActionFunction); setEventActionFunctionStatus(false); } -// TODO: Should I use applicationID too? -void EventActionService::executeAction(uint16_t eventID) { +void EventActionService::executeAction(uint16_t eventDefinitionID) { // Custom function if (eventActionFunctionStatus) { - auto range = eventActionDefinitionMap.equal_range(eventID); + auto range = eventActionDefinitionMap.equal_range(eventDefinitionID); for (auto& element = range.first; element != range.second; ++element) { if (element->second.enabled) { Message message = MessageParser::parseECSSTC(element->second.request); diff --git a/test/Services/EventActionServiceTests.cpp b/test/Services/EventActionServiceTests.cpp index 54fae2ddf3e3066135d2dcf3003fc4d2f0afd8e6..4b2365af7905526c060a8bde494a603e1266ceff 100644 --- a/test/Services/EventActionServiceTests.cpp +++ b/test/Services/EventActionServiceTests.cpp @@ -2,413 +2,533 @@ #include <ServicePool.hpp> #include <Services/EventActionService.hpp> #include <catch2/catch_all.hpp> -#include <cstring> #include <etl/String.hpp> #include "ServiceTests.hpp" EventActionService& eventActionService = Services.eventAction; +/** + * Initializes 9 Event Action Definitions with eventDefinitionIDs = {0, 4, 2, 12, 1, 5, 8, 23, 3} + */ +void initializeEventActionDefinitions() { + Message addDefinitions(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); + uint8_t numberOfEventActionDefinitions = 9; + uint16_t applicationIDs[] = {1, 0, 1, 0, 0, 2, 0, 1, 0}; + uint16_t eventDefinitionIDs[] = {0, 4, 2, 12, 1, 5, 8, 23, 3}; + String<ECSSTCRequestStringSize> data[] = {"\0", "1", "\0", "3", "4", "5", "6", "7", "8"}; + addDefinitions.appendUint8(numberOfEventActionDefinitions); + for (auto i = 0; i < numberOfEventActionDefinitions; i++) { + addDefinitions.appendEnum16(applicationIDs[i]); + addDefinitions.appendEnum16(eventDefinitionIDs[i]); + addDefinitions.appendFixedString(data[i]); + } + MessageParser::execute(addDefinitions); + + REQUIRE(eventActionService.eventActionDefinitionMap.size() == 9); + for (auto i = 0; i < numberOfEventActionDefinitions; i++) { + REQUIRE(eventActionService.eventActionDefinitionMap.find(eventDefinitionIDs[i]) != eventActionService.eventActionDefinitionMap.end()); + } +} + TEST_CASE("Add event-action definitions TC[19,1]", "[service][st19]") { + SECTION("Add an event-action definition to check if the values are inserted correctly") { + Message addDefinition(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); + addDefinition.appendUint8(1); + addDefinition.appendEnum16(0); + addDefinition.appendEnum16(2); + String<ECSSTCRequestStringSize> data = "12345abcdefg"; + addDefinition.appendFixedString(data); + MessageParser::execute(addDefinition); + + auto element = eventActionService.eventActionDefinitionMap.find(2); + CHECK(element->second.applicationID == 0); + CHECK(element->second.eventDefinitionID == 2); + CHECK(!element->second.enabled); + for (auto i = 0; i < data.size(); ++i) { + CHECK(data[i] == element->second.request[i]); + } + } + + SECTION("Adding multiple event-action definitions for different events") { + Message addDefinitions(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); + uint8_t numberOfEventActionDefinitions = 3; + uint16_t applicationIDs[] = {0, 1, 2}; + uint16_t eventDefinitionIDs[] = {3, 5, 4}; + String<ECSSTCRequestStringSize> dataArray[] = {"123", "456", "789"}; + addDefinitions.appendUint8(numberOfEventActionDefinitions); + for (auto i = 0; i < numberOfEventActionDefinitions; i++) { + addDefinitions.appendEnum16(applicationIDs[i]); + addDefinitions.appendEnum16(eventDefinitionIDs[i]); + addDefinitions.appendFixedString(dataArray[i]); + } + MessageParser::execute(addDefinitions); + + for (auto i = 0; i < numberOfEventActionDefinitions; i++) { + auto element = eventActionService.eventActionDefinitionMap.find(eventDefinitionIDs[i]); + CHECK(element->second.applicationID == applicationIDs[i]); + CHECK(element->second.eventDefinitionID == eventDefinitionIDs[i]); + CHECK(element->second.request.substr(0, 3) == dataArray[i]); + CHECK(!element->second.enabled); + CHECK(element->second.request.size() == ECSSTCRequestStringSize); + } + + eventActionService.eventActionDefinitionMap.clear(); + ServiceTests::reset(); + } - // Add a message that is too large to check for the corresponding error - Message message(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message.appendEnum16(0); - message.appendEnum16(1); - message.appendEnum16(1); - String<128> data = "0123456789012345678901234567890123456789012345678901234567890123456789"; - message.appendString(data); - - MessageParser::execute(message); - CHECK(ServiceTests::thrownError(ErrorHandler::MessageTooLarge)); - CHECK(ServiceTests::countErrors() == 1); - - // Add an event-action definition to check if the values are inserted correctly - Message message1(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message1.appendEnum16(0); - message1.appendEnum16(2); - message1.appendEnum16(1); - data = "01234"; - message1.appendString(data); - MessageParser::execute(message1); - - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(2)->second.applicationId == 0); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(2)->second.eventDefinitionID == 2); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(2)->second.enabled == 0); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(2)->second.request.compare(data) == 0); - - // Add a second event-action definition - Message message2(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message2.appendEnum16(1); - message2.appendEnum16(3); - message2.appendEnum16(1); - data = "456"; - message2.appendString(data); - MessageParser::execute(message2); - - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(3)->second.applicationId == 1); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(3)->second.eventDefinitionID == 3); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(3)->second.enabled == 0); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(3)->second.request.compare(data) == 0); - - // Adding the same message to check for error - Message message3(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message3.appendEnum16(1); - message3.appendEnum16(3); - message3.appendEnum16(1); - data = "456"; - message3.appendString(data); - MessageParser::execute(message3); - CHECK(ServiceTests::thrownError(ErrorHandler::EventActionDefinitionIDExistsError)); - CHECK(ServiceTests::countErrors() == 2); + SECTION("Add an event definition ID that already exists") { + Message addDefinitions(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); + addDefinitions.appendUint8(2); + addDefinitions.appendEnum16(1); + addDefinitions.appendEnum16(3); + String<ECSSTCRequestStringSize> data = "123"; + addDefinitions.appendFixedString(data); + addDefinitions.appendEnum16(6); + addDefinitions.appendEnum16(3); + data = "123"; + addDefinitions.appendFixedString(data); + MessageParser::execute(addDefinitions); + + addDefinitions.appendUint8(1); + addDefinitions.appendEnum16(3); + addDefinitions.appendEnum16(3); + data = "234"; + addDefinitions.appendFixedString(data); + MessageParser::execute(addDefinitions); + + auto element = eventActionService.eventActionDefinitionMap.find(3); + CHECK(element->second.applicationID == 3); + CHECK(element->second.request.substr(0, 3) == data); + + + eventActionService.eventActionDefinitionMap.clear(); + ServiceTests::reset(); + } + + SECTION("Add an event action definition that is already enabled") { + Message addDefinitions(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); + addDefinitions.appendUint8(1); + addDefinitions.appendEnum16(0); + addDefinitions.appendEnum16(3); + String<ECSSTCRequestStringSize> data = "456"; + addDefinitions.appendFixedString(data); + MessageParser::execute(addDefinitions); + + Message enableDefinitions(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); + + enableDefinitions.appendUint8(1); + enableDefinitions.appendEnum16(0); + enableDefinitions.appendEnum16(3); + MessageParser::execute(enableDefinitions); + + addDefinitions.appendUint8(1); + addDefinitions.appendEnum16(5); + addDefinitions.appendEnum16(3); + data = "456"; + addDefinitions.appendFixedString(data); + MessageParser::execute(addDefinitions); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionEnabledError)); + CHECK(ServiceTests::countErrors() == 1); + + eventActionService.eventActionDefinitionMap.clear(); + ServiceTests::reset(); + } + + SECTION("Add an event-action definition when the eventActionDefinitionMap is full") { + Message message(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); + String<ECSSTCRequestStringSize> data = "123"; + message.appendFixedString(data); + uint16_t applicationID = 257; + + for (uint16_t eventDefinitionID = 0; eventDefinitionID < 100; ++eventDefinitionID) { + EventActionService::EventActionDefinition temp(--applicationID, eventDefinitionID, message); + eventActionService.eventActionDefinitionMap.insert(std::make_pair(eventDefinitionID, temp)); + message.resetRead(); + } + + Message addDefinitions(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); + addDefinitions.appendUint8(2); + addDefinitions.appendEnum16(1); + addDefinitions.appendEnum16(100); + addDefinitions.appendEnum16(0); + addDefinitions.appendEnum16(101); + addDefinitions.appendFixedString(data); + MessageParser::execute(addDefinitions); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionDefinitionsMapIsFull)); + CHECK(ServiceTests::countErrors() == 2); + eventActionService.eventActionDefinitionMap.clear(); + } } -TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st19]") { +TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st19]") { + SECTION("Simple enable some event-action definitions") { + initializeEventActionDefinitions(); + + auto element = eventActionService.eventActionDefinitionMap.find(4); + REQUIRE(!element->second.enabled); + REQUIRE(!eventActionService.eventActionDefinitionMap.find(1)->second.enabled); + + Message enableDefinitions(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); + enableDefinitions.appendUint8(3); + enableDefinitions.appendEnum16(0); + enableDefinitions.appendEnum16(4); + enableDefinitions.appendEnum16(1); + enableDefinitions.appendEnum16(2); + enableDefinitions.appendEnum16(0); + enableDefinitions.appendEnum16(1); + MessageParser::execute(enableDefinitions); + + CHECK(element->second.enabled); + CHECK(eventActionService.eventActionDefinitionMap.find(1)->second.enabled); + } - // Add messages for the purpose of deleting them - Message message0(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message0.appendEnum16(1); - message0.appendEnum16(0); - message0.appendEnum16(1); - String<64> data = "0"; - message0.appendString(data); - MessageParser::execute(message0); - - Message message1(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message1.appendEnum16(1); - message1.appendEnum16(1); - message1.appendEnum16(1); - data = "1"; - message1.appendString(data); - MessageParser::execute(message1); - - Message message2(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message2.appendEnum16(1); - message2.appendEnum16(2); - message2.appendEnum16(1); - data = "2"; - message2.appendString(data); - MessageParser::execute(message2); - - Message message5(EventActionService::ServiceType, EventActionService::MessageType::DeleteEventAction, Message::TC, 0); - message5.appendUint16(1); - message5.appendEnum16(1); - message5.appendEnum16(2); - message5.appendEnum16(1); - MessageParser::execute(message5); - - // Checking the values after deleting some definitions - - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.applicationId == 1); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.eventDefinitionID == 0); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.request.compare("0") == 0); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.enabled == 0); - - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.applicationId == 1); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.eventDefinitionID == 1); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.request.compare("1") == 0); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.enabled == 0); - - CHECK(eventActionService.eventActionDefinitionMap.find(2) == eventActionService.eventActionDefinitionMap.end()); - - // Enabling a definition to check for errors in the case of an attempt to delete it - Message message8(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); - message8.appendUint16(1); - message8.appendEnum16(1); - message8.appendEnum16(1); - message8.appendEnum16(1); - MessageParser::execute(message8); - - Message message6(EventActionService::ServiceType, EventActionService::MessageType::DeleteEventAction, Message::TC, 0); - message6.appendUint16(1); - message6.appendEnum16(1); - message6.appendEnum16(1); - message6.appendEnum16(1); - MessageParser::execute(message6); - - // Checking for errors in the case mentioned above - CHECK(ServiceTests::thrownError(ErrorHandler::EventActionDeleteEnabledDefinitionError)); - CHECK(ServiceTests::countErrors() == 1); - - // Checking for errors in the case of an unknown definition - Message message7(EventActionService::ServiceType, EventActionService::MessageType::DeleteEventAction, Message::TC, 0); - message7.appendUint16(1); - message7.appendEnum16(1); - message7.appendEnum16(10); - message7.appendEnum16(1); - MessageParser::execute(message7); - - CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventDefinitionError)); - CHECK(ServiceTests::countErrors() == 2); - - Message message9(EventActionService::ServiceType, EventActionService::MessageType::DeleteEventAction, Message::TC, 0); - message9.appendUint16(1); - message9.appendEnum16(1); - message9.appendEnum16(1); - message9.appendEnum16(10); - MessageParser::execute(message9); - - CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventActionDefinitionIDError)); - CHECK(ServiceTests::countErrors() == 3); + SECTION("Trying to enable an unknown definition") { + Message enableDefinition(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); + enableDefinition.appendUint8(1); + enableDefinition.appendUint16(1); + enableDefinition.appendEnum16(7); + MessageParser::execute(enableDefinition); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventActionDefinitionError)); + CHECK(ServiceTests::countErrors() == 1); + } + + SECTION("Trying to enable an existing event-action definition with the wrong event definition ID") { + Message enableDefinitions(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); + enableDefinitions.appendUint8(2); + enableDefinitions.appendEnum16(1); + enableDefinitions.appendEnum16(4); + enableDefinitions.appendEnum16(1); + enableDefinitions.appendEnum16(3); + MessageParser::execute(enableDefinitions); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventActionDefinitionError)); + CHECK(ServiceTests::countErrors() == 2); + + eventActionService.eventActionDefinitionMap.clear(); + } + + SECTION("Enable all event action definitions") { + initializeEventActionDefinitions(); + + Message enableAllDefinitions(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); + enableAllDefinitions.appendUint8(0); + MessageParser::execute(enableAllDefinitions); + + for (const auto& iterator: eventActionService.eventActionDefinitionMap) { + CHECK(iterator.second.enabled); + } + + eventActionService.eventActionDefinitionMap.clear(); + } } -TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { +TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st19]") { + SECTION("Delete an event-action definition") { + initializeEventActionDefinitions(); + + Message deleteDefinition(EventActionService::ServiceType, EventActionService::MessageType::DeleteEventAction, Message::TC, 0); + deleteDefinition.appendUint8(2); + deleteDefinition.appendEnum16(1); + deleteDefinition.appendEnum16(2); + deleteDefinition.appendEnum16(2); + deleteDefinition.appendEnum16(5); + MessageParser::execute(deleteDefinition); + + REQUIRE(eventActionService.eventActionDefinitionMap.count(0) == 1); + REQUIRE(eventActionService.eventActionDefinitionMap.count(2) == 0); + REQUIRE(eventActionService.eventActionDefinitionMap.count(1) == 1); + REQUIRE(eventActionService.eventActionDefinitionMap.count(5) == 0); + } - // Adding event action definitions to delete them later - Message message0(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message0.appendEnum16(1); - message0.appendEnum16(0); - message0.appendEnum16(1); - String<64> data = "0"; - message0.appendString(data); - MessageParser::execute(message0); - - Message message1(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message1.appendEnum16(1); - message1.appendEnum16(1); - message1.appendEnum16(1); - data = "1"; - message1.appendString(data); - MessageParser::execute(message1); - - Message message2(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message2.appendEnum16(1); - message2.appendEnum16(2); - message2.appendEnum16(1); - data = "2"; - message2.appendString(data); - MessageParser::execute(message2); - - Message message3(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message3.appendEnum16(1); - message3.appendEnum16(3); - message3.appendEnum16(1); - data = "3"; - message3.appendString(data); - MessageParser::execute(message3); - - Message message4(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message4.appendEnum16(1); - message4.appendEnum16(4); - message4.appendEnum16(1); - data = "4"; - message4.appendString(data); - MessageParser::execute(message4); - - Message message(EventActionService::ServiceType, EventActionService::MessageType::DeleteAllEventAction, Message::TC, 0); - MessageParser::execute(message); - - // Checking the content of the map - for (int i = 0; i < 256; i++) { - CHECK(eventActionService.eventActionDefinitionMap.find(i) == eventActionService.eventActionDefinitionMap.end()); + SECTION("Trying to delete an enabled event-action definition") { + Message enableDefinition(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); + enableDefinition.appendUint8(1); + enableDefinition.appendEnum16(0); + enableDefinition.appendEnum16(1); + MessageParser::execute(enableDefinition); + + Message deleteDefinition(EventActionService::ServiceType, EventActionService::MessageType::DeleteEventAction, Message::TC, 0); + deleteDefinition.appendUint8(1); + deleteDefinition.appendEnum16(0); + deleteDefinition.appendEnum16(1); + MessageParser::execute(deleteDefinition); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionDeleteEnabledDefinitionError)); + CHECK(ServiceTests::countErrors() == 1); + } + + SECTION("Trying to delete an unknown event-action definition") { + Message deleteDefinition(EventActionService::ServiceType, EventActionService::MessageType::DeleteEventAction, Message::TC, 0); + deleteDefinition.appendUint8(1); + deleteDefinition.appendEnum16(1); + deleteDefinition.appendEnum16(8); + MessageParser::execute(deleteDefinition); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventActionDefinitionError)); + CHECK(ServiceTests::countErrors() == 1); + } + + SECTION("Trying to delete an existing event-action definition with the wrong event definition ID") { + Message deleteDefinition(EventActionService::ServiceType, EventActionService::MessageType::DeleteEventAction, Message::TC, 0); + deleteDefinition.appendUint8(2); + deleteDefinition.appendEnum16(0); + deleteDefinition.appendEnum16(0); + deleteDefinition.appendEnum16(0); + deleteDefinition.appendEnum16(5); + MessageParser::execute(deleteDefinition); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventActionDefinitionError)); + CHECK(ServiceTests::countErrors() == 2); + + eventActionService.eventActionDefinitionMap.clear(); } } -TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st19]") { +TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { + initializeEventActionDefinitions(); - // Adding event action definitions to enable them - Message message0(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message0.appendEnum16(1); - message0.appendEnum16(0); - message0.appendEnum16(1); - String<64> data = "0"; - message0.appendString(data); - MessageParser::execute(message0); - - Message message1(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message1.appendEnum16(1); - message1.appendEnum16(1); - message1.appendEnum16(1); - data = "00"; - message1.appendString(data); - MessageParser::execute(message1); - - // Checking their enabled status - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.enabled == 0); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.enabled == 0); - - // Creating a message to enable the previous messages - Message message3(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); - message3.appendUint16(2); - message3.appendEnum16(1); - message3.appendEnum16(0); - message3.appendEnum16(1); - message3.appendEnum16(1); - message3.appendEnum16(1); - message3.appendEnum16(1); - MessageParser::execute(message3); - - // Checking if the messages are enabled - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.enabled == 1); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.enabled == 1); - - // Checking for errors in the case of an attempt to enable an unknown definition - Message message7(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); - message7.appendUint16(1); - message7.appendEnum16(1); - message7.appendEnum16(6); - MessageParser::execute(message7); - - CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventDefinitionError)); - CHECK(ServiceTests::countErrors() == 1); - - // Checking for errors in the case of an attempt to enable an unknown definition - Message message8(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); - message8.appendUint16(1); - message8.appendEnum16(1); - message8.appendEnum16(1); - message8.appendEnum16(10); - MessageParser::execute(message8); - - CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventActionDefinitionIDError)); - CHECK(ServiceTests::countErrors() == 2); + REQUIRE(eventActionService.eventActionDefinitionMap.size() == 9); + + Message deleteAllDefinitions(EventActionService::ServiceType, EventActionService::MessageType::DeleteAllEventAction, Message::TC, 0); + MessageParser::execute(deleteAllDefinitions); + + CHECK(eventActionService.eventActionDefinitionMap.empty()); } TEST_CASE("Disable event-action definitions TC[19,5]", "[service][st19]") { + SECTION("Simple disable some event-action definitions") { + initializeEventActionDefinitions(); + + Message enableDefinitions(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); + enableDefinitions.appendUint8(4); + enableDefinitions.appendEnum16(0); + enableDefinitions.appendEnum16(4); + enableDefinitions.appendEnum16(1); + enableDefinitions.appendEnum16(2); + enableDefinitions.appendEnum16(0); + enableDefinitions.appendEnum16(1); + enableDefinitions.appendEnum16(1); + enableDefinitions.appendEnum16(23); + MessageParser::execute(enableDefinitions); + + auto range = eventActionService.eventActionDefinitionMap.find(4); + REQUIRE(range->second.enabled); + REQUIRE(eventActionService.eventActionDefinitionMap.find(1)->second.enabled); + + Message disableDefinitions(EventActionService::ServiceType, EventActionService::MessageType::DisableEventAction, Message::TC, 0); + disableDefinitions.appendUint8(4); + disableDefinitions.appendEnum16(0); + disableDefinitions.appendEnum16(4); + disableDefinitions.appendEnum16(2); + disableDefinitions.appendEnum16(5); + disableDefinitions.appendEnum16(1); + disableDefinitions.appendEnum16(2); + disableDefinitions.appendEnum16(0); + disableDefinitions.appendEnum16(1); + MessageParser::execute(disableDefinitions); + + CHECK(!range->second.enabled); + CHECK(!eventActionService.eventActionDefinitionMap.find(5)->second.enabled); + CHECK(!eventActionService.eventActionDefinitionMap.find(1)->second.enabled); + } + + SECTION("Trying to disable unknown definitions") { + Message disableDefinitions(EventActionService::ServiceType, EventActionService::MessageType::DisableEventAction, Message::TC, 0); + disableDefinitions.appendUint8(2); + disableDefinitions.appendUint16(1); + disableDefinitions.appendEnum16(6); + disableDefinitions.appendUint16(0); + disableDefinitions.appendEnum16(13); + MessageParser::execute(disableDefinitions); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventActionDefinitionError)); + CHECK(ServiceTests::countErrors() == 2); + } + + SECTION("Trying to disable an existing event-action definition with the wrong event definition ID") { + Message disableDefinitions(EventActionService::ServiceType, EventActionService::MessageType::DisableEventAction, Message::TC, 0); + disableDefinitions.appendUint8(2); + disableDefinitions.appendEnum16(1); + disableDefinitions.appendEnum16(5); + disableDefinitions.appendEnum16(0); + disableDefinitions.appendEnum16(5); + MessageParser::execute(disableDefinitions); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventActionDefinitionError)); + CHECK(ServiceTests::countErrors() == 2); + } + + SECTION("Disable all event action definitions") { + REQUIRE(!eventActionService.eventActionDefinitionMap.empty()); - // Adding event action definitions to enable them - Message message0(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message0.appendEnum16(1); - message0.appendEnum16(0); - message0.appendEnum16(1); - String<64> data = "0"; - message0.appendString(data); - MessageParser::execute(message0); - - Message message1(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message1.appendEnum16(1); - message1.appendEnum16(1); - message1.appendEnum16(1); - data = "00"; - message1.appendString(data); - MessageParser::execute(message1); - - // Checking their enabled status - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.enabled == 0); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.enabled == 0); - - // Creating a message to enable the previous messages - Message message3(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); - message3.appendUint16(2); - message3.appendEnum16(1); - message3.appendEnum16(0); - message3.appendEnum16(1); - message3.appendEnum16(1); - message3.appendEnum16(1); - message3.appendEnum16(1); - MessageParser::execute(message3); - - // Checking if the messages are enabled - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.enabled == 1); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.enabled == 1); - - // Creating a message to enable the previous messages - Message message4(EventActionService::ServiceType, EventActionService::MessageType::DisableEventAction, Message::TC, 0); - message4.appendUint16(2); - message4.appendEnum16(1); - message4.appendEnum16(0); - message4.appendEnum16(1); - message4.appendEnum16(1); - message4.appendEnum16(1); - message4.appendEnum16(1); - MessageParser::execute(message4); - - // Checking if the messages are enabled - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.enabled == 0); - CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.enabled == 0); - - // Checking for errors in the case of an attempt to enable an unknown definition - Message message7(EventActionService::ServiceType, EventActionService::MessageType::DisableEventAction, Message::TC, 0); - message7.appendUint16(1); - message7.appendEnum16(1); - message7.appendEnum16(6); - MessageParser::execute(message7); - - CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventDefinitionError)); - CHECK(ServiceTests::countErrors() == 1); - - // Checking for errors in the case of an attempt to enable an unknown definition - Message message8(EventActionService::ServiceType, EventActionService::MessageType::DisableEventAction, Message::TC, 0); - message8.appendUint16(1); - message8.appendEnum16(1); - message8.appendEnum16(1); - message8.appendEnum16(10); - MessageParser::execute(message8); - - CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventActionDefinitionIDError)); - CHECK(ServiceTests::countErrors() == 2); + Message enableAllDefinitions(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); + enableAllDefinitions.appendUint8(0); + MessageParser::execute(enableAllDefinitions); + + Message disableAllDefinitions(EventActionService::ServiceType, EventActionService::MessageType::DisableEventAction, Message::TC, 0); + disableAllDefinitions.appendUint8(0); + MessageParser::execute(disableAllDefinitions); + + for (const auto& iterator: eventActionService.eventActionDefinitionMap) { + CHECK(!iterator.second.enabled); + } + } } TEST_CASE("Request event-action definition status TC[19,6]", "[service][st19]") { - - // Creating a request for a report on the event action definitions - Message message(EventActionService::ServiceType, EventActionService::MessageType::ReportStatusOfEachEventAction, Message::TC, 0); - MessageParser::execute(message); + Message statusRequest(EventActionService::ServiceType, EventActionService::MessageType::ReportStatusOfEachEventAction, Message::TC, 0); + MessageParser::execute(statusRequest); REQUIRE(ServiceTests::hasOneMessage()); - // Checking that the report was made Message report = ServiceTests::get(0); CHECK(report.messageType == 7); } TEST_CASE("Event-action status report TM[19,7]", "[service][st19]") { - - // Adding event-action definitions to report them - Message message0(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message0.appendEnum16(1); - message0.appendEnum16(0); - message0.appendEnum16(1); - String<64> data = "0"; - message0.appendString(data); - MessageParser::execute(message0); - - Message message1(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); - message1.appendEnum16(1); - message1.appendEnum16(2); - message1.appendEnum16(1); + Message addDefinitions(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); + addDefinitions.appendUint8(2); + addDefinitions.appendEnum16(1); + addDefinitions.appendEnum16(0); + String<ECSSTCRequestStringSize> data = "0"; + addDefinitions.appendFixedString(data); + addDefinitions.appendEnum16(1); + addDefinitions.appendEnum16(2); data = "2"; - message1.appendString(data); - MessageParser::execute(message1); + addDefinitions.appendFixedString(data); + MessageParser::execute(addDefinitions); - // Enablilng one of the two - Message message2(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); - message2.appendUint16(1); - message2.appendEnum16(1); - message2.appendEnum16(0); - message2.appendEnum16(1); - eventActionService.enableEventActionDefinitions(message2); + Message enableDefinition(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, + 0); + enableDefinition.appendUint8(1); + enableDefinition.appendEnum16(1); + enableDefinition.appendEnum16(0); + MessageParser::execute(enableDefinition); eventActionService.eventActionStatusReport(); REQUIRE(ServiceTests::hasOneMessage()); - // Checking the contents of the report Message report = ServiceTests::get(0); CHECK(report.readUint16() == 2); CHECK(report.readEnum16() == 1); CHECK(report.readEnum16() == 0); - CHECK(report.readEnum16() == 1); CHECK(report.readBoolean() == 1); CHECK(report.readEnum16() == 1); CHECK(report.readEnum16() == 2); - CHECK(report.readEnum16() == 1); CHECK(report.readBoolean() == 0); } TEST_CASE("Enable event-action function TC[19,8]", "[service][st19]") { - - // A message to enable event action function - Message message(EventActionService::ServiceType, EventActionService::MessageType::EnableEventActionFunction, Message::TC, 0); eventActionService.enableEventActionFunction(message); CHECK(eventActionService.getEventActionFunctionStatus()); } TEST_CASE("Disable event-action function TC[19,9]", "[service][st19]") { - - // A message to disable event action function Message message(EventActionService::ServiceType, EventActionService::MessageType::DisableEventActionFunction, Message::TC, 0); eventActionService.disableEventActionFunction(message); CHECK(eventActionService.getEventActionFunctionStatus() == false); } TEST_CASE("Execute a TC request", "[service][st19]") { -} + SECTION("Action: Disable event-action definition") { + Message addDefinition(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); + addDefinition.appendUint8(1); + addDefinition.appendEnum16(0); + addDefinition.appendEnum16(15); + + Message messageToBeExecuted(EventActionService::ServiceType, EventActionService::MessageType::DisableEventAction, Message::TC, 0); + messageToBeExecuted.appendUint8(1); + messageToBeExecuted.appendEnum16(0); + messageToBeExecuted.appendEnum16(15); + addDefinition.appendMessage(messageToBeExecuted, ECSSTCRequestStringSize); + MessageParser::execute(addDefinition); + + Message enableDefinition(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); + enableDefinition.appendUint8(1); + enableDefinition.appendEnum16(0); + enableDefinition.appendEnum16(15); + MessageParser::execute(enableDefinition); + CHECK(eventActionService.eventActionDefinitionMap.find(15)->second.enabled); + + Message enableFunction(EventActionService::ServiceType, EventActionService::MessageType::EnableEventActionFunction, Message::TC, 0); + eventActionService.enableEventActionFunction(enableFunction); + REQUIRE(eventActionService.getEventActionFunctionStatus()); + + eventActionService.executeAction(15); + + CHECK(!eventActionService.eventActionDefinitionMap.find(15)->second.enabled); + CHECK(ServiceTests::countErrors() == 0); + + ServiceTests::reset(); + } + + SECTION("Action: Add event-action definition") { + Message addDefinition(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); + addDefinition.appendUint8(1); + addDefinition.appendEnum16(0); + addDefinition.appendEnum16(9); + + Message messageToBeExecuted(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); + messageToBeExecuted.appendUint8(1); + messageToBeExecuted.appendEnum16(0); + messageToBeExecuted.appendEnum16(74); + String<ECSSTCRequestStringSize> data = "12345"; + messageToBeExecuted.appendString(data); + addDefinition.appendMessage(messageToBeExecuted, ECSSTCRequestStringSize); + + MessageParser::execute(addDefinition); + + Message enableDefinition(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); + enableDefinition.appendUint8(1); + enableDefinition.appendEnum16(0); + enableDefinition.appendEnum16(9); + MessageParser::execute(enableDefinition); + + eventActionService.executeAction(9); + + auto element = eventActionService.eventActionDefinitionMap.find(74); + CHECK(element->second.applicationID == 0); + CHECK(element->second.eventDefinitionID == 74); + CHECK(!element->second.enabled); + CHECK(element->second.request.size() == ECSSTCRequestStringSize); + } + + SECTION("Action: ParameterService::ReportParameterValues") { + Message addDefinition(EventActionService::ServiceType, EventActionService::MessageType::AddEventAction, Message::TC, 0); + addDefinition.appendUint8(1); + addDefinition.appendEnum16(0); + addDefinition.appendEnum16(10); + + Message TCToBeExecuted = Message(ParameterService::ServiceType, ParameterService::MessageType::ReportParameterValues, + Message::TC, 1); + TCToBeExecuted.appendUint16(3); + TCToBeExecuted.appendUint16(0); + TCToBeExecuted.appendUint16(1); + TCToBeExecuted.appendUint16(2); + addDefinition.appendMessage(TCToBeExecuted, ECSSTCRequestStringSize); + + MessageParser::execute(addDefinition); + + Message enableDefinition(EventActionService::ServiceType, EventActionService::MessageType::EnableEventAction, Message::TC, 0); + enableDefinition.appendUint8(1); + enableDefinition.appendEnum16(0); + enableDefinition.appendEnum16(10); + MessageParser::execute(enableDefinition); + + eventActionService.executeAction(10); + + Message report = ServiceTests::get(0); + CHECK(report.serviceType == ParameterService::ServiceType); + CHECK(report.messageType == ParameterService::MessageType::ParameterValuesReport); + CHECK(report.readUint16() == 3); + CHECK(report.readUint16() == 0); + CHECK(report.readUint8() == 3); + CHECK(report.readUint16() == 1); + CHECK(report.readUint16() == 7); + CHECK(report.readUint16() == 2); + CHECK(report.readUint32() == 10); + } +} \ No newline at end of file