diff --git a/inc/MessageParser.hpp b/inc/MessageParser.hpp index a8cbaa4c3fca35d4d48469718474acd3759c2844..0a27dbf8df5ca596784e74d7425c79216b37ae95 100644 --- a/inc/MessageParser.hpp +++ b/inc/MessageParser.hpp @@ -35,18 +35,17 @@ public: * @param length The size of the message * @return A new object that represents the parsed message */ - Message parse(uint8_t * data, uint32_t length); + Message parse(uint8_t *data, uint32_t length); /** * @todo: elaborate on this comment * Create a message so that a string can be parsed + * + * Note: conversion of char* to unsigned char* should flow without any problems according to + * this great analysis: + * stackoverflow.com/questions/15078638/can-i-turn-unsigned-char-into-char-and-vice-versa */ - Message parseTC(String<256> data, ){ - Message message; - message.packetType = Message::TC; - parseTC(data, 15, message); - return message; - } + Message parseRequestTC(String<256> data); private: /** diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp index a355be1df790057d66e0312d37ca0a4fb4731350..b9c89043b575fc2ed6b017dee75547457c33a7f1 100644 --- a/inc/Services/EventActionService.hpp +++ b/inc/Services/EventActionService.hpp @@ -97,7 +97,7 @@ public: * Custom function that is called right after an event takes place, to initiate * the execution of the action */ - void executeAction(Message &message); + void executeAction(uint16_t eventID); /** * Setter for event-action function status diff --git a/src/MessageParser.cpp b/src/MessageParser.cpp index b27ee17973e6c266dff3f2c01012924059af31af..73a47bdb43b75b2e3d3fc9a89f936526bc956e53 100644 --- a/src/MessageParser.cpp +++ b/src/MessageParser.cpp @@ -75,3 +75,11 @@ void MessageParser::parseTC(uint8_t *data, uint16_t length, Message &message) { memcpy(message.data, data + 5, length); message.dataSize = length; } + +Message MessageParser::parseRequestTC(String<256> data) { + Message message; + uint8_t *dataInt = (unsigned char *) data.data(); + message.packetType = Message::TC; + parseTC(dataInt, 256, message); // Should length here be 256? + return message; +} diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index 51fb07503859e2fcdefa26eab9e4335bc064dc2d..edd688e411fccfe472b190cefd952dcddb11e5e5 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -171,9 +171,20 @@ void EventActionService::disableEventActionFunction(Message message) { } } // Should I use the name execute here instead of executeAction? -void EventActionService::execute(Message &message) { +void EventActionService::executeAction(uint16_t eventID) { // Custom function if (eventActionFunctionStatus == enabledFunction) { - + uint16_t i = 0; + while (i < 256){ + if (eventActionDefinitionArray[i].empty == 0){ + if (eventActionDefinitionArray[i].eventDefinitionID == eventID){ + break; + } + } + i++; + } + MessageParser messageParser; + Message message = messageParser.parseRequestTC(eventActionDefinitionArray[i].request); + messageParser.execute(message); } }