From fad244298417d551c75ba3bb71ea7f98687258ea Mon Sep 17 00:00:00 2001 From: athatheocsd <athatheo@csd.auth.gr> Date: Tue, 1 Jan 2019 19:51:52 +0200 Subject: [PATCH] update executeAction and added comments --- inc/Services/EventActionService.hpp | 3 ++- src/MessageParser.cpp | 4 ++-- src/Services/EventActionService.cpp | 11 ++++------- test/Services/EventActionService.cpp | 14 ++++++++++++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp index 5f19cbb8..c551afed 100644 --- a/inc/Services/EventActionService.hpp +++ b/inc/Services/EventActionService.hpp @@ -15,7 +15,8 @@ * initialization or rather the lack of it. Pay attention especially in parts of the code that I * use strings <3 . * - * @todo: Do something with the applicationID. + + * @todo: check if executeAction should accept applicationID too * @todo: check if eventActionFunctionStatus should be private or not * @todo: check if eventAction array of definitions should be private or not * @todo: check size of eventActionDefinitionArray diff --git a/src/MessageParser.cpp b/src/MessageParser.cpp index 84f31620..9bf0b1d8 100644 --- a/src/MessageParser.cpp +++ b/src/MessageParser.cpp @@ -78,8 +78,8 @@ void MessageParser::parseTC(uint8_t *data, uint16_t length, Message &message) { Message MessageParser::parseRequestTC(String<64> data) { Message message; - uint8_t *dataInt = (unsigned char *) data.data(); + uint8_t* dataInt = reinterpret_cast<uint8_t *>(data.data()); message.packetType = Message::TC; - parseTC(dataInt, 256, message); // Should length here be 256? + parseTC(dataInt, 256, message); // maybe instead of 256 shoule there be a variable? return message; } diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index 3f819c74..c2940178 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -170,6 +170,7 @@ void EventActionService::disableEventActionFunction(Message message) { } // Should I use the name execute here instead of executeAction? +// Should I use applicationID too? void EventActionService::executeAction(uint16_t eventID) { // Custom function if (eventActionFunctionStatus == enabledFunction) { @@ -177,15 +178,11 @@ void EventActionService::executeAction(uint16_t eventID) { while (i < 256) { if (eventActionDefinitionArray[i].empty == 0) { if (eventActionDefinitionArray[i].eventDefinitionID == eventID) { - break; - } + MessageParser messageParser; + Message message = messageParser.parseRequestTC(eventActionDefinitionArray[i].request); + messageParser.execute(message); } } i++; } - if (i != 256) { // If i == 256 that means that no matching eventId was found - MessageParser messageParser; - Message message = messageParser.parseRequestTC(eventActionDefinitionArray[i].request); - messageParser.execute(message); - } } } diff --git a/test/Services/EventActionService.cpp b/test/Services/EventActionService.cpp index a57f2f59..1fac8d65 100644 --- a/test/Services/EventActionService.cpp +++ b/test/Services/EventActionService.cpp @@ -170,9 +170,19 @@ TEST_CASE("Event-action status report TM[19,7]", "[service][st09]") { } TEST_CASE("Enable event-action function TC[19,8]", "[service][st09]") { - + EventActionService eventActionService; + Message message(19, 8, Message::TC, 0); + eventActionService.enableEventActionFunction(message); + CHECK(eventActionService.eventActionFunctionStatus == EventActionService::enabledFunction); } TEST_CASE("Disable event-action function TC[19,1]", "[service][st09]") { - + EventActionService eventActionService; + Message message(19, 9, Message::TC, 0); + eventActionService.disableEventActionFunction(message); + CHECK(eventActionService.eventActionFunctionStatus == EventActionService::disabledFunction); } + +TEST_CASE("Execute a TC request", "[service][st09]"){ + +} \ No newline at end of file -- GitLab