diff --git a/.gitignore b/.gitignore index 5ddd5cba48d9a98a06a1f957a7bcdadee296cce6..d30fcd4b531e90eeb63a8246bfd7d4261ac3f697 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Build files +build cmake-build-debug docs @@ -63,3 +64,4 @@ docs .idea/**/dynamic.xml .idea/**/uiDesigner.xml .idea/**/dbnavigator.xml +.idea/**/markdown-* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 43a618b00b7c767591edd5a8adefea26f455289a..e1d4353524db193088abb502e90d4887ecffd6c1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: rikorose/gcc-cmake +image: lycantropos/cmake stages: - build @@ -6,16 +6,19 @@ stages: before_script: - g++ --version + - cat /etc/*-release build: stage: build variables: GIT_SUBMODULE_STRATEGY: normal + GCC_COLORS: "error=31;1:warning=35;1:note=36;1:range1=32:range2=34:locus=39;1:quote=39;1:fixit-insert=32:fixit-delete=31:diff-filename=39;1:diff-hunk=32:diff-delete=31:diff-insert=32:type-diff=32;1" + CLICOLOR_FORCE: 1 # Necessary for cmake to output colours script: - - cmake . -DCMAKE_CXX_FLAGS="-Werror" + - cmake . -DCMAKE_CXX_FLAGS="-Werror -fdiagnostics-color=always" - make -j4 - make clean - - cmake . -DCMAKE_CXX_FLAGS="-Wall -Wextra" # Build again, but with more warnings + - cmake . -DCMAKE_CXX_FLAGS="-Wall -Wextra -fdiagnostics-color=always" # Build again, but with more warnings - make -j4 tests: @@ -38,7 +41,7 @@ cppcheck: - apt-get update -qq && apt-get install -y -qq cppcheck - cppcheck --version script: - - bash -x ci/cppcheck.sh + - ci/cppcheck.sh vera: stage: build @@ -47,12 +50,18 @@ vera: - vera++ --version - cp ci/vera.profile /usr/lib/vera++/profiles/custom script: - - bash -x ci/vera.sh + - ci/vera.sh clang-tidy: stage: build + variables: + GIT_SUBMODULE_STRATEGY: normal + TERM: xterm-color before_script: - - apt-get update -qq && apt-get install -y -qq clang-tidy-4.0 - - clang-tidy-4.0 --version + # Installing the `sid` repository to get the latest version of clang + - echo deb http://deb.debian.org/debian sid main > /etc/apt/sources.list + - apt-get update -qq && apt-get -t sid install -y -qq clang-tidy-7 + - clang-tidy-7 --version script: - - bash -x ci/clang-tidy.sh + # Running with `script` to give clang a tty so that it outputs colours + - script -c "bash -x ci/clang-tidy.sh" diff --git a/README.md b/README.md index 151d4910dfe86db694ea8f5d04cd2b175da94134..aab7c0ca428d51dcb3da71ce72b472023af475a1 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,7 @@ In this repository you can find the implementation of the ECSS services, based o - **inc**: All headers and libraries used in the code - **lib**: External libraries used in the code - **src**: All source files are included here -- **test**: Unit test implementation \ No newline at end of file +- **test**: Unit test implementation + +## Documentation +Full documentation about this project based on code comments is available at https://helit.org/ecss-docs/docs/html/. \ No newline at end of file diff --git a/ci/.clang-tidy b/ci/.clang-tidy index 6114218612a520f187515cdc7631f09629fa8b84..79406a31501a0c54cd823f6aa9f9d5f56d9d0715 100644 --- a/ci/.clang-tidy +++ b/ci/.clang-tidy @@ -1,9 +1,10 @@ --- Checks: > - clang-diagnostic-*, + -clang-diagnostic-error, clang-analyzer-*, bugprone-*, - cppcoreguidelines-*,-cppcoreguidelines-no-malloc,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-bounds-constant-array-index, + cert-*, + cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-bounds-constant-array-index, misc-*,-misc-non-private-member-variables-in-classes, fuchsia-multiple-inheritance, google-*,-google-readability-todo, @@ -17,8 +18,9 @@ Checks: > -misc-non-private-member-variables-in-classes, performance-*, readability-*, -WarningsAsErrors: '*,-misc-unused-parameters,-llvm-header-guard,-cppcoreguidelines-pro-type-member-init,-google-runtime-references,-clang-diagnostic-tautological-constant-out-of-range-compare,-readability-redundant-declaration' -HeaderFilterRegex: '.*' + zircon-* +WarningsAsErrors: '*,-misc-unused-parameters,-llvm-header-guard,-cppcoreguidelines-pro-type-member-init,-google-runtime-references,-clang-diagnostic-tautological-constant-out-of-range-compare,-readability-redundant-declaration,-modernize-use-equals-default,-fuchsia-statically-constructed-objects,-hicpp-signed-bitwise,-cert-err58-cpp' +HeaderFilterRegex: 'ecss-services\/((?!lib\/).)*$' AnalyzeTemporaryDtors: false ... diff --git a/ci/clang-tidy.sh b/ci/clang-tidy.sh index 1e676ce2d6926d700576c3a0fe69bad656c16389..bdff8166981a4312ab0a2c28423a5359af80ad59 100755 --- a/ci/clang-tidy.sh +++ b/ci/clang-tidy.sh @@ -10,5 +10,6 @@ echo -e "\033[0;34mRunning clang-tidy...\033[0m" cd "$(dirname "$0")" -clang-tidy-4.0 `find ../src/ -type f -regextype posix-egrep -regex '.*\.(cpp|hpp|c|h)'` \ - -extra-arg=-fcolor-diagnostics -- -std=c++14 -I../inc +clang-tidy-7 `find ../src/ -type f -regextype posix-egrep -regex '.*\.(cpp|hpp|c|h)'` \ + -extra-arg=-fcolor-diagnostics -- -std=c++17 -I../inc \ + -I/usr/include/c++/7/ -I/usr/include/x86_64-linux-gnu/c++/7 -I../lib/etl/include diff --git a/doxygen.conf b/doxygen.conf index 0898937f9a1208405c1f6dbdb1148d1c3a795906..4dc3effc360ce57b2ee5b120aa7a03c25188f54e 100644 --- a/doxygen.conf +++ b/doxygen.conf @@ -187,7 +187,7 @@ SHORT_NAMES = NO # description.) # The default value is: NO. -JAVADOC_AUTOBRIEF = NO +JAVADOC_AUTOBRIEF = YES # If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first # line (until the first dot) of a Qt-style comment as the brief description. If @@ -435,7 +435,7 @@ LOOKUP_CACHE_SIZE = 0 # normally produced when WARNINGS is set to YES. # The default value is: NO. -EXTRACT_ALL = NO +EXTRACT_ALL = YES # If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will # be included in the documentation. @@ -515,7 +515,7 @@ HIDE_IN_BODY_DOCS = NO # will be excluded. Set it to YES to include the internal documentation. # The default value is: NO. -INTERNAL_DOCS = NO +INTERNAL_DOCS = YES # If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file # names in lower-case letters. If set to YES, upper-case letters are also @@ -873,7 +873,7 @@ RECURSIVE = YES # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = +EXCLUDE = lib # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded @@ -1478,7 +1478,7 @@ DISABLE_INDEX = NO # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. -GENERATE_TREEVIEW = NO +GENERATE_TREEVIEW = YES # The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that # doxygen will group on one line in the generated HTML documentation. @@ -2331,7 +2331,7 @@ INCLUDED_BY_GRAPH = YES # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. -CALL_GRAPH = NO +CALL_GRAPH = YES # If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller # dependency graph for every global function or class method. @@ -2376,7 +2376,7 @@ DIRECTORY_GRAPH = YES # The default value is: png. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_IMAGE_FORMAT = png +DOT_IMAGE_FORMAT = svg # If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to # enable generation of interactive SVG images that allow zooming and panning. @@ -2388,7 +2388,7 @@ DOT_IMAGE_FORMAT = png # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. -INTERACTIVE_SVG = NO +INTERACTIVE_SVG = YES # The DOT_PATH tag can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found in the path. 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/lib/Catch2 b/lib/Catch2 index 62460fafe6b54c3173bc5cbc46d05a5f071017ff..d63307279412de3870cf97cc6802bae8ab36089e 160000 --- a/lib/Catch2 +++ b/lib/Catch2 @@ -1 +1 @@ -Subproject commit 62460fafe6b54c3173bc5cbc46d05a5f071017ff +Subproject commit d63307279412de3870cf97cc6802bae8ab36089e diff --git a/src/MessageParser.cpp b/src/MessageParser.cpp index fac5d76254c18bcd92477778c333d6c4aecdc98f..c80dfcb58b83e4d44cd4cce199e699e04bfc38f1 100644 --- a/src/MessageParser.cpp +++ b/src/MessageParser.cpp @@ -78,7 +78,7 @@ void MessageParser::parseTC(const uint8_t *data, uint16_t length, Message &messa 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;