From c7a4a7ad7fe8822d7ac635a68dfbcc6116888179 Mon Sep 17 00:00:00 2001 From: athatheocsd <vostidi@hotmail.com> Date: Wed, 16 Jan 2019 13:37:06 +0200 Subject: [PATCH] Additions as in 6.19 of the standard --- src/Services/EventActionService.cpp | 83 ++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index c84c1636..a7a23195 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -12,24 +12,37 @@ void EventActionService::addEventActionDefinitions(Message message) { if (message.messageType == 1 && message.packetType == Message::TC && message.serviceType == 19) { uint16_t index; + uint16_t applicationID = message.readEnum16(); + uint16_t eventDefinitionID = message.readEnum16(); + bool accepted = true; for (index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { - // @todo: throw an error if it's full - if (eventActionDefinitionArray[index].empty == true) { - break; + if (eventActionDefinitionArray[index].applicationId == applicationID && + eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID && + eventActionDefinitionArray[index].enabled == true) { + // @todo: throw a failed start of execution error + accepted = false; } } - if (index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE) { - eventActionDefinitionArray[index].empty = false; - eventActionDefinitionArray[index].enabled = true; - eventActionDefinitionArray[index].applicationId = message.readEnum16(); - eventActionDefinitionArray[index].eventDefinitionID = message.readEnum16(); - if (message.dataSize - 4 > ECSS_EVENT_SERVICE_STRING_SIZE) { - ErrorHandler::reportInternalError(ErrorHandler::InternalErrorType::MessageTooLarge); - } else { - char data[ECSS_EVENT_SERVICE_STRING_SIZE]; - message.readString(data, message.dataSize - 4); - eventActionDefinitionArray[index].request = String<ECSS_EVENT_SERVICE_STRING_SIZE>( - data); + if (accepted){ + for (index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { + // @todo: throw an error if it's full + if (eventActionDefinitionArray[index].empty == true) { + break; + } + } + if (index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE) { + eventActionDefinitionArray[index].empty = false; + eventActionDefinitionArray[index].enabled = false; + eventActionDefinitionArray[index].applicationId = applicationID; + eventActionDefinitionArray[index].eventDefinitionID = eventDefinitionID(); + if (message.dataSize - 4 > ECSS_EVENT_SERVICE_STRING_SIZE) { + ErrorHandler::reportInternalError(ErrorHandler::InternalErrorType::MessageTooLarge); + } else { + char data[ECSS_EVENT_SERVICE_STRING_SIZE]; + message.readString(data, message.dataSize - 4); + eventActionDefinitionArray[index].request = String<ECSS_EVENT_SERVICE_STRING_SIZE>( + data); + } } } } @@ -45,7 +58,8 @@ void EventActionService::deleteEventActionDefinitions(Message message) { uint16_t eventDefinitionID = message.readEnum16(); for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { if (eventActionDefinitionArray[index].applicationId == applicationID && - eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) { + eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID && + eventActionDefinitionArray[index].enabled == false) { eventActionDefinitionArray[index].empty = true; eventActionDefinitionArray[index].eventDefinitionID = 65535; eventActionDefinitionArray[index].request = ""; @@ -62,6 +76,7 @@ void EventActionService::deleteAllEventActionDefinitions(Message message) { // TC[19,3] if (message.messageType == 3 && message.packetType == Message::TC && message.serviceType == 19) { + setEventActionFunctionStatus(false); for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { if (eventActionDefinitionArray[index].empty == false) { eventActionDefinitionArray[index].empty = true; @@ -79,12 +94,20 @@ void EventActionService::enableEventActionDefinitions(Message message) { if (message.messageType == 4 && message.packetType == Message::TC && message.serviceType == 19) { uint16_t N = message.readUint16(); - for (uint16_t i = 0; i < N; i++) { - uint16_t applicationID = message.readEnum16(); - uint16_t eventDefinitionID = message.readEnum16(); + if (N != 0){ + for (uint16_t i = 0; i < N; i++) { + uint16_t applicationID = message.readEnum16(); + uint16_t eventDefinitionID = message.readEnum16(); + for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { + if (eventActionDefinitionArray[index].applicationId == applicationID && + eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) { + eventActionDefinitionArray[index].enabled = true; + } + } + } + } else { for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { - if (eventActionDefinitionArray[index].applicationId == applicationID && - eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) { + if (eventActionDefinitionArray[index].empty == false){ eventActionDefinitionArray[index].enabled = true; } } @@ -97,12 +120,20 @@ void EventActionService::disableEventActionDefinitions(Message message) { if (message.messageType == 5 && message.packetType == Message::TC && message.serviceType == 19) { uint16_t N = message.readUint16(); - for (uint16_t i = 0; i < N; i++) { - uint16_t applicationID = message.readEnum16(); - uint16_t eventDefinitionID = message.readEnum16(); + if (N != 0){ + for (uint16_t i = 0; i < N; i++) { + uint16_t applicationID = message.readEnum16(); + uint16_t eventDefinitionID = message.readEnum16(); + for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { + if (eventActionDefinitionArray[index].applicationId == applicationID && + eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) { + eventActionDefinitionArray[index].enabled = false; + } + } + } + } else { for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { - if (eventActionDefinitionArray[index].applicationId == applicationID && - eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) { + if (eventActionDefinitionArray[index].empty == false){ eventActionDefinitionArray[index].enabled = false; } } -- GitLab