From 18921d364a32369719786cb8368184eaa49ecf0f Mon Sep 17 00:00:00 2001 From: athatheocsd <athatheo@csd.auth.gr> Date: Mon, 31 Dec 2018 22:29:42 +0200 Subject: [PATCH] Updated add event action definition function, ignoring standard --- inc/MessageParser.hpp | 2 +- inc/Services/EventActionService.hpp | 8 +++++-- src/MessageParser.cpp | 2 +- src/Services/EventActionService.cpp | 33 ++++++++++++++++++++++------ src/main.cpp | 22 +++++++++++++++++++ test/Services/EventActionService.cpp | 28 +++++++++++++++++++++-- 6 files changed, 82 insertions(+), 13 deletions(-) diff --git a/inc/MessageParser.hpp b/inc/MessageParser.hpp index 0a27dbf8..9fc99d9c 100644 --- a/inc/MessageParser.hpp +++ b/inc/MessageParser.hpp @@ -45,7 +45,7 @@ public: * this great analysis: * stackoverflow.com/questions/15078638/can-i-turn-unsigned-char-into-char-and-vice-versa */ - Message parseRequestTC(String<256> data); + Message parseRequestTC(String<64> data); private: /** diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp index b9c89043..5f19cbb8 100644 --- a/inc/Services/EventActionService.hpp +++ b/inc/Services/EventActionService.hpp @@ -21,14 +21,14 @@ * @todo: check size of eventActionDefinitionArray */ class EventActionService : public Service { -private: +public: uint8_t eventActionFunctionStatus; // Indicates if actions are enabled std::bitset<256> stateOfEventAction; struct EventActionDefinition { uint8_t empty = 1; // 1 means empty, 0 means full uint16_t applicationId = 0; uint16_t eventDefinitionID = 65535; - String<ECSS_MAX_STRING_SIZE> request = ""; + String<64> request = ""; }; // If the size is changed maybe then indexOfAvailableSlots as well as the initiating loop in the // constructor should be changed from uint16_t @@ -50,6 +50,10 @@ public: /** * 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); diff --git a/src/MessageParser.cpp b/src/MessageParser.cpp index 73a47bdb..84f31620 100644 --- a/src/MessageParser.cpp +++ b/src/MessageParser.cpp @@ -76,7 +76,7 @@ void MessageParser::parseTC(uint8_t *data, uint16_t length, Message &message) { message.dataSize = length; } -Message MessageParser::parseRequestTC(String<256> data) { +Message MessageParser::parseRequestTC(String<64> data) { Message message; uint8_t *dataInt = (unsigned char *) data.data(); message.packetType = Message::TC; diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index bad8d216..e724b39f 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -9,11 +9,12 @@ */ void EventActionService::addEventActionDefinitions(Message message) { // TC[19,1] - if (message.messageType == 1 && message.packetType == Message::TC && message.serviceType - == 19) { - uint8_t *data; + + if (message.messageType == 1 && message.packetType == Message::TC && message.serviceType == + 19) { + char x[64]; uint16_t N = message.readUint16(); - uint8_t index = 0; + uint16_t index = 0; uint8_t flag = 0; // used as boolean 0 is false, 1 is true for (uint16_t i = 0; i < N; i++) { while (eventActionDefinitionArray[index].empty == 0) { @@ -21,19 +22,37 @@ void EventActionService::addEventActionDefinitions(Message message) { flag = 1; break; } + std::cout << "index: " << index << " empty: " << (unsigned) + eventActionDefinitionArray[index].empty << " \n"; index++; } - if (flag == 1) { + + + if (flag == 0) { + char data[128]; + std::cout << "Inside the flag == 0 " << "index: " << index << " empty: " << + (unsigned) + eventActionDefinitionArray[index].empty << " \n"; eventActionDefinitionArray[index].empty = 0; eventActionDefinitionArray[index].applicationId = message.readEnum16(); eventActionDefinitionArray[index].eventDefinitionID = message.readEnum16(); - message.readString(data, ECSS_MAX_STRING_SIZE); // ECSS_MAX_STRING_SIZE?? - eventActionDefinitionArray[index].request = String<256>(data); + if (index == 0){ + message.readString(data, 3); // ECSS_MAX_STRING_SIZE?? + } else { + message.readString(data, 3); // ECSS_MAX_STRING_SIZE?? + } + eventActionDefinitionArray[index].request = String<64>(data); + std::cout << "char data: " << data << " String<64>(data): " << String<64>(data) + .data() << " \n"; + std::cout << "String: " << eventActionDefinitionArray[index].request.data() << " \n"; index++; + } } } + //std::cout << eventActionDefinitionArray[0].empty; + } void EventActionService::deleteEventActionDefinitions(Message message) { diff --git a/src/main.cpp b/src/main.cpp index bcc262ed..580f97e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -200,5 +200,27 @@ int main() { eventReportService.enableReportGeneration(eventMessage2); eventReportService.requestListOfDisabledEvents(eventMessage3); + //ST[19] test + + EventActionService eventActionService; + char checkstring[256]; + Message eventActionDefinition(19, 1, Message::TC, 1); + eventActionDefinition.appendUint16(2); + eventActionDefinition.appendEnum16(0); + eventActionDefinition.appendEnum16(2); + String<64> TCdata = "hi"; + + eventActionDefinition.appendString(TCdata); + eventActionService.addEventActionDefinitions(eventActionDefinition); +// message.readString(checkstring, 2); +// std::cout << eventActionService.eventActionDefinitionArray[0].empty;// + // .compare + // (checkstring) + // ==0); +// CHECK(message.readEnum16() == 1); +// CHECK(message.readEnum16() == 3); +// message.readString(checkstring, 3); +// CHECK(eventActionService.eventActionDefinitionArray[1].request.compare(data) == 0); + return 0; } diff --git a/test/Services/EventActionService.cpp b/test/Services/EventActionService.cpp index 676ba0eb..171fb5a2 100644 --- a/test/Services/EventActionService.cpp +++ b/test/Services/EventActionService.cpp @@ -2,12 +2,36 @@ #include <Services/EventActionService.hpp> #include <Message.hpp> #include "ServiceTests.hpp" +#include <etl/String.hpp> #include <cstring> - +#include <iostream> TEST_CASE("Add event-action definitions TC[19,1]", "[service][st09]") { EventActionService eventActionService; + char checkstring[256]; Message message(19, 1, Message::TC, 0); - + message.appendUint16(2); + message.appendEnum16(0); + message.appendEnum16(2); + String<64> data = "123"; + message.appendString(data); + + message.appendEnum16(1); + message.appendEnum16(3); + data = "456"; + message.appendString(data); + // Should I check byte by byte or check the contents of the EventActionDefinitionArray + eventActionService.addEventActionDefinitions(message); + CHECK(message.readUint16() == 2); + CHECK(eventActionService.eventActionDefinitionArray[0].empty == 0); + message.readEnum16(); + CHECK(message.readEnum16() == 2); + message.readString(checkstring, 3); + CHECK(eventActionService.eventActionDefinitionArray[0].request.compare(checkstring) == 0); + CHECK(message.readEnum16() == 1); + CHECK(message.readEnum16() == 3); + message.readString(checkstring, 3); + std::cout << checkstring; + CHECK(eventActionService.eventActionDefinitionArray[1].request.compare(checkstring) == 0); } TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st09]") { -- GitLab