From 6de0de39c6c744a6cb7b5996d64c0a85ff8b7fd5 Mon Sep 17 00:00:00 2001 From: athatheocsd <athatheo@csd.auth.gr> Date: Thu, 27 Dec 2018 01:39:39 +0200 Subject: [PATCH] Added function in MessageParser Completed functions in EventActionService --- inc/MessageParser.hpp | 13 ++++++------- inc/Services/EventActionService.hpp | 2 +- src/MessageParser.cpp | 8 ++++++++ src/Services/EventActionService.cpp | 15 +++++++++++++-- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/inc/MessageParser.hpp b/inc/MessageParser.hpp index a8cbaa4c..0a27dbf8 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 a355be1d..b9c89043 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 b27ee179..73a47bdb 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 51fb0750..edd688e4 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); } } -- GitLab