diff --git a/inc/Services/EventReportService.hpp b/inc/Services/EventReportService.hpp index 92c75eb2962c0dfba40d1723ab1ae893964e4031..0ecaf179e3468712fe49984cc3287fc643e32ee9 100644 --- a/inc/Services/EventReportService.hpp +++ b/inc/Services/EventReportService.hpp @@ -101,7 +101,7 @@ public: * @param data the data of the report * @param length the length of the data */ - void informativeEventReport(Event eventID, String<64> data); + void informativeEventReport(Event eventID, const String<64> & data); /** * TM[5,2] low severiity anomaly report @@ -113,7 +113,7 @@ public: * @param data the data of the report * @param length the length of the data */ - void lowSeverityAnomalyReport(Event eventID, String<64> data); + void lowSeverityAnomalyReport(Event eventID, const String<64> & data); /** * TM[5,3] medium severity anomaly report @@ -125,7 +125,7 @@ public: * @param data the data of the report * @param length the length of the data */ - void mediumSeverityAnomalyReport(Event eventID, String<64> data); + void mediumSeverityAnomalyReport(Event eventID, const String<64> & data); /** * TM[5,4] high severity anomaly report @@ -137,7 +137,7 @@ public: * @param data the data of the report * @param length the length of the data */ - void highSeverityAnomalyReport(Event eventID, String<64> data); + void highSeverityAnomalyReport(Event eventID, const String<64> & data); /** * TC[5,5] request to enable report generation diff --git a/src/MessageParser.cpp b/src/MessageParser.cpp index 6472871ece12c8b267aa1b421ea2a3ecb631697a..51451cf7e0a102213df999b4f7acc4b542904ce9 100644 --- a/src/MessageParser.cpp +++ b/src/MessageParser.cpp @@ -77,7 +77,7 @@ void MessageParser::parseTC(uint8_t *data, uint16_t length, Message &message) { Message MessageParser::parseRequestTC(String<ECSS_EVENT_SERVICE_STRING_SIZE> data) { Message message; - uint8_t *dataInt = reinterpret_cast<uint8_t *>(data.data()); + auto *dataInt = reinterpret_cast<uint8_t *>(data.data()); message.packetType = Message::TC; parseTC(dataInt, ECSS_EVENT_SERVICE_STRING_SIZE, message); return message; diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index 38e3b64ab22bbac6aca19d0fb3c3fab09cfdeb45..b61b16dcff7a92cbbeabfe226e983ee6fdc0eee7 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -18,7 +18,7 @@ void EventActionService::addEventActionDefinitions(Message message) { for (index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { if (eventActionDefinitionArray[index].applicationId == applicationID && eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID && - eventActionDefinitionArray[index].enabled == true) { + eventActionDefinitionArray[index].enabled) { // @todo: throw a failed start of execution error accepted = false; } @@ -26,7 +26,7 @@ void EventActionService::addEventActionDefinitions(Message message) { 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) { + if (eventActionDefinitionArray[index].empty) { break; } } @@ -59,7 +59,7 @@ void EventActionService::deleteEventActionDefinitions(Message message) { 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) { + eventActionDefinitionArray[index].enabled) { eventActionDefinitionArray[index].empty = true; eventActionDefinitionArray[index].eventDefinitionID = 65535; eventActionDefinitionArray[index].request = ""; @@ -78,7 +78,7 @@ void EventActionService::deleteAllEventActionDefinitions(Message message) { == 19) { setEventActionFunctionStatus(false); for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { - if (eventActionDefinitionArray[index].empty == false) { + if (not eventActionDefinitionArray[index].empty) { eventActionDefinitionArray[index].empty = true; eventActionDefinitionArray[index].enabled = false; eventActionDefinitionArray[index].eventDefinitionID = 65535; @@ -107,7 +107,7 @@ void EventActionService::enableEventActionDefinitions(Message message) { } } else { for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { - if (eventActionDefinitionArray[index].empty == false){ + if (not eventActionDefinitionArray[index].empty){ eventActionDefinitionArray[index].enabled = true; } } @@ -133,7 +133,7 @@ void EventActionService::disableEventActionDefinitions(Message message) { } } else { for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { - if (eventActionDefinitionArray[index].empty == false){ + if (not eventActionDefinitionArray[index].empty){ eventActionDefinitionArray[index].enabled = false; } } @@ -154,13 +154,13 @@ void EventActionService::eventActionStatusReport() { Message report = createTM(7); uint8_t count = 0; for (uint16_t i = 0; i < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; i++) { - if (eventActionDefinitionArray[i].empty == false) { + if (not eventActionDefinitionArray[i].empty) { count++; } } report.appendUint8(count); for (uint16_t i = 0; i < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; i++) { - if (eventActionDefinitionArray[i].empty == false) { + if (not eventActionDefinitionArray[i].empty) { report.appendEnum16(eventActionDefinitionArray[i].applicationId); report.appendEnum16(eventActionDefinitionArray[i].eventDefinitionID); report.appendBoolean(eventActionDefinitionArray[i].enabled); @@ -191,7 +191,7 @@ void EventActionService::executeAction(uint16_t eventID) { // Custom function if (eventActionFunctionStatus) { for (uint16_t i = 0; i < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; i++) { - if (eventActionDefinitionArray[i].empty == false && + if (not eventActionDefinitionArray[i].empty && eventActionDefinitionArray[i].enabled == true) { if (eventActionDefinitionArray[i].eventDefinitionID == eventID) { diff --git a/src/Services/EventReportService.cpp b/src/Services/EventReportService.cpp index 2c243c25517806fd45b5acd1f012081d85c298ca..162b4b2349e6f5a14f264d1cf5a027580282c960 100644 --- a/src/Services/EventReportService.cpp +++ b/src/Services/EventReportService.cpp @@ -6,9 +6,9 @@ * @todo: Add message type in TCs * @todo: this code is error prone, depending on parameters given, add fail safes (probably?) */ -void EventReportService::informativeEventReport(Event eventID, String<64> data) { +void EventReportService::informativeEventReport(Event eventID, const String<64> & data) { // TM[5,1] - if (stateOfEvents[static_cast<uint16_t> (eventID)] == 1) { + if (stateOfEvents[static_cast<uint16_t> (eventID)]) { Message report = createTM(1); report.appendEnum16(eventID); report.appendString(data); @@ -20,10 +20,10 @@ void EventReportService::informativeEventReport(Event eventID, String<64> data) } void -EventReportService::lowSeverityAnomalyReport(Event eventID, String<64> data) { +EventReportService::lowSeverityAnomalyReport(Event eventID, const String<64> & data) { lowSeverityEventCount++; // TM[5,2] - if (stateOfEvents[static_cast<uint16_t> (eventID)] == 1) { + if (stateOfEvents[static_cast<uint16_t> (eventID)]) { lowSeverityReportCount++; Message report = createTM(2); report.appendEnum16(eventID); @@ -36,10 +36,10 @@ EventReportService::lowSeverityAnomalyReport(Event eventID, String<64> data) { } } -void EventReportService::mediumSeverityAnomalyReport(Event eventID, String<64> data) { +void EventReportService::mediumSeverityAnomalyReport(Event eventID, const String<64> & data) { mediumSeverityEventCount++; // TM[5,3] - if (stateOfEvents[static_cast<uint16_t> (eventID)] == 1) { + if (stateOfEvents[static_cast<uint16_t> (eventID)]) { mediumSeverityReportCount++; Message report = createTM(3); report.appendEnum16(eventID); @@ -53,10 +53,10 @@ void EventReportService::mediumSeverityAnomalyReport(Event eventID, String<64> d } void -EventReportService::highSeverityAnomalyReport(Event eventID, String<64> data) { +EventReportService::highSeverityAnomalyReport(Event eventID, const String<64> & data) { highSeverityEventCount++; // TM[5,4] - if (stateOfEvents[static_cast<uint16_t> (eventID)] == 1) { + if (stateOfEvents[static_cast<uint16_t> (eventID)]) { highSeverityReportCount++; Message report = createTM(4); report.appendEnum16(eventID); @@ -82,7 +82,7 @@ void EventReportService::enableReportGeneration(Message message) { } if (length <= numberOfEvents) { for (uint16_t i = 0; i < length; i++) { - stateOfEvents[static_cast<uint16_t> (eventID[i])] = 1; + stateOfEvents[static_cast<uint16_t> (eventID[i])] = true; } } disabledEventsCount = stateOfEvents.size() - stateOfEvents.count(); @@ -103,7 +103,7 @@ void EventReportService::disableReportGeneration(Message message) { } if (length <= numberOfEvents) { for (uint16_t i = 0; i < length; i++) { - stateOfEvents[static_cast<uint16_t> (eventID[i])] = 0; + stateOfEvents[static_cast<uint16_t> (eventID[i])] = false; } } disabledEventsCount = stateOfEvents.size() - stateOfEvents.count(); diff --git a/src/main.cpp b/src/main.cpp index c62b168141de2c4034cac45420be4aa028f1313d..ea2a99af0ce752e6fdf312071f2970f1ce3505fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,7 +67,7 @@ int main() { // ST[06] testing char anotherStr[8] = "Fgthred"; char yetAnotherStr[2] = "F"; - char *pStr = static_cast<char *>(malloc(4)); + char pStr[4]; *pStr = 'T'; *(pStr + 1) = 'G'; *(pStr + 2) = '\0'; @@ -276,14 +276,14 @@ int main() { eventActionDefinition4.appendUint16(2); eventActionService.deleteEventActionDefinitions(eventActionDefinition4); - std::cout << "\nPositions 0,1 empty should be 11:" << (uint16_t) eventActionService - .eventActionDefinitionArray[0].empty - << (uint16_t) eventActionService.eventActionDefinitionArray[1].empty; + std::cout << "\nPositions 0,1 empty should be 11:" << static_cast<uint16_t>(eventActionService + .eventActionDefinitionArray[0].empty) + << static_cast<uint16_t>(eventActionService.eventActionDefinitionArray[1].empty); Message eventActionDefinition6(19, 3, Message::TC, 1); eventActionService.deleteAllEventActionDefinitions(eventActionDefinition6); - std::cout << "\nPositions 0,1 empty should be 1:" << (uint16_t) eventActionService - .eventActionDefinitionArray[0].empty; + std::cout << "\nPositions 0,1 empty should be 1:" << static_cast<uint16_t>(eventActionService + .eventActionDefinitionArray[0].empty); return 0;