diff --git a/.gitignore b/.gitignore index d30fcd4b531e90eeb63a8246bfd7d4261ac3f697..051810d3f334d430727a431c6daba6ae1a37e196 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,13 @@ build cmake-build-debug docs +# Dump and continuous integration files +*.dump +__pycache__ +/ci/cppcheckdata.py +/ci/misra.py +/ci/report.msr + # Prerequisites *.d @@ -65,3 +72,6 @@ docs .idea/**/uiDesigner.xml .idea/**/dbnavigator.xml .idea/**/markdown-* + +# IDEs +.vscode \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e1d4353524db193088abb502e90d4887ecffd6c1..43881eb98b8aab6424bcec2d2fb27f5a5f1c16e9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,11 +38,22 @@ tests: cppcheck: stage: build before_script: - - apt-get update -qq && apt-get install -y -qq cppcheck + - echo deb http://deb.debian.org/debian testing main > /etc/apt/sources.list + - apt-get update -qq && apt-get -t testing install -y cppcheck - cppcheck --version script: - ci/cppcheck.sh +cppcheck-misra: + stage: build + before_script: + # install cppcheck from the testing repos in order to get the latest version + - echo deb http://deb.debian.org/debian testing main > /etc/apt/sources.list + - apt-get update -qq && apt-get -t testing install -y cppcheck && apt-get -t testing install -y python3 + - cppcheck --version + script: + - ci/cppcheck-misra.sh + vera: stage: build before_script: @@ -64,4 +75,4 @@ clang-tidy: - clang-tidy-7 --version script: # Running with `script` to give clang a tty so that it outputs colours - - script -c "bash -x ci/clang-tidy.sh" + - script -ec "bash -x ci/clang-tidy.sh" diff --git a/CMakeLists.txt b/CMakeLists.txt index f5888fa54ba244b843987eae903e58f884b39941..044b9c0d8c9dc3adb125ddb46b8bfd6ace9e6b9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ add_custom_target(check COMMAND ./cppcheck.sh COMMAND ./vera.sh COMMAND ./clang-tidy.sh + COMMAND ./cppcheck-misra.sh WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/ci") # Specify the .cpp files common across all targets diff --git a/ci/cppcheck-misra.sh b/ci/cppcheck-misra.sh new file mode 100755 index 0000000000000000000000000000000000000000..1389882e300451d43b623d1bc6fbad31392dadd7 --- /dev/null +++ b/ci/cppcheck-misra.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# +# Static code analysis for MISRA C-2012 compliance using cppcheck +# +# Usage: +# $ ci/cppcheck-misra.sh +# + +# make sure we are in the correct directory, regardless of where the script was called from +cd "$(dirname "$0")/.." + +echo -e "\u001b[34;1mGetting prerequisites...\u001b[0m" +# grab the MISRA addon and the cppcheck addon interface from github +curl https://raw.githubusercontent.com/danmar/cppcheck/f4b5b156d720c712f6ce99f6e01d8c1b3f800d52/addons/misra.py > ci/misra.py +curl https://raw.githubusercontent.com/danmar/cppcheck/f4b5b156d720c712f6ce99f6e01d8c1b3f800d52/addons/cppcheckdata.py > ci/cppcheckdata.py + +# clean up old files +echo -e "\u001b[34;1mRemoving old files...\u001b[0m" +echo > ci/report.msr # clear the report file +find inc/ src/ -type f -name "*.dump" | xargs rm + +# generate dump files (XML representations of AST etc.) for all headers, source files etc. +echo -e "\u001b[34;1mGenerating dump files...\u001b[0m" +find inc/ src/ -type f \( -iname "*.cpp" -or -iname "*.hpp" \) | xargs cppcheck --dump + +# run the MISRA checks against the dumps and send the results to a file +echo -e "\u001b[34;1mRunning MISRA C(2012) rule compliance tests...\u001b[0m" +find inc/ src/ -type f -name "*.dump" | xargs python3 ci/misra.py >> ci/report.msr 2>&1 + +# pre-process the generated report to remove all useless strings +echo -e "\u001b[34;1mPre-processing report...\u001b[0m" +sed -i -r 's/(.*Script.*)|(.*Checking.*)|(.*MISRA.*)//gm; /(^$)/d; s/(\s\(.*\)\s)//gm; s/(\]|\[)//gm; s/(misra-c2012-)//gm' ci/report.msr + +# run the summarizer for a nice, clean summary of errors +echo -e "\u001b[34;1mSummarizing results...\u001b[0m" +python3 ci/summarizer.py --report ci/report.msr --suppress 3.1 5.1 5.2 5.3 12.3 14.4 15.5 16.3 18.8 + diff --git a/ci/cppcheck.sh b/ci/cppcheck.sh index d6bcded38887bd666573d5e012d057287e91b32e..527e10d7670bdb8b14326b2616fe5eb15253d6c8 100755 --- a/ci/cppcheck.sh +++ b/ci/cppcheck.sh @@ -1,13 +1,15 @@ #!/usr/bin/env bash # -# Static code analysis using cppchecl +# Static code analysis using cppcheck # # Usage: # $ ci/cppcheck.sh # -echo -e "\033[0;34mRunning cppcheck...\033[0m" +echo -e "\u001b[34;1mStarting cppcheck...\u001b[0m" + +echo -e "\u001b[34;1mRunning cppcheck with default checklist...\u001b[0m" cd "$(dirname "$0")/.." cppcheck --enable=all --inline-suppr --suppress=unusedFunction --suppress=missingIncludeSystem \ diff --git a/ci/summarizer.py b/ci/summarizer.py new file mode 100755 index 0000000000000000000000000000000000000000..15e48d03c61bffd4caeb8c43804393abbf00016e --- /dev/null +++ b/ci/summarizer.py @@ -0,0 +1,131 @@ +#!/bin/env python3 + +import os +from argparse import ArgumentParser + +""" +Naive parser and pretty printer for the MISRA reports by cppcheck. + +Usage: +python3 summarizer.py --report <report-file-generated-from-cppcheck-misra.sh> +--suppress <list-of-rule-numbers-to-be-suppressed> (as they are given on the +MISRA handbook) + +e.g.: python3 summarizer.py --report ci/report.msr --suppress 5.2 10.4 15.5 + +You can also mark lines you wish to be skipped by adding +"// Ignore-MISRA" at a suitable position on the line you want to ignore +from assessing (NOTE: the double slashes are part of the string!) + +(Credits to @dimst23 for the feature!) + +TODO: Keep track of line numbers and filenames of suppressed lines. +""" + + +class Summarizer(object): + def __init__(self, report_name, suppression_list): + with open(report_name, 'r') as f: + self.file_lines = f.readlines() # read the report file + f.close() + + self.red = "\033[91m" # terminal colors + self.yellow = "\033[93m" + self.green = "\033[92m" + self.bold = "\033[1m" + self.end = "\033[0m" + + self.violations_map = {} # dictionary containing filenames, rule violations and line where the violation + # occurred + self.suppression_list = suppression_list # list of rule numbers to be suppressed + + def analyze(self): + """ + A really dumb parser for the pre-processed report generated by cppcheck + """ + + lines_seen = set() # contains the unique lines from the file + + for line in self.file_lines: # remove duplicate lines + if line not in lines_seen: + lines_seen.add(line) + + line_contents = line.split(':') + file_name = line_contents[0] # first part is the filename (index 0) + violation = (line_contents[1], line_contents[2].strip( + '\n')) # index 1 is the line number, index 2 is the number of violated rule (both are strings) + + with open(os.path.abspath(file_name)) as code_file: + code_lines = code_file.readlines() # Read the source code file + line_of_interest = code_lines[int(violation[0]) - 1] # Get the desired violation line + if line_of_interest.find("// Ignore-MISRA") >= 0: + continue + + if file_name not in self.violations_map.keys(): + self.violations_map[ + file_name] = list() # create a new list for the new filename and append the tuple w/ line & + # rule no. + self.violations_map[file_name].append(violation) + else: + self.violations_map[file_name].append(violation) # do not create a key if it already exists + + for e in self.suppression_list: + for file_name in self.violations_map.keys(): + self.violations_map[file_name] = [x for x in self.violations_map[file_name] if x[1] != str(e)] + # replace the list of infractions with a new one, containing everything except the suppressed rules + + self.violations_map = {k: v for (k, v) in self.violations_map.items() if len(v) != 0} + # "delete" all keys whose lists are empty + + + def pretty_print_violations(self): + """ + Just a pretty printing function, no fancy logic here. + """ + print(self.bold + self.red + "=========================================================\n" + self.end) + print(self.bold + self.red + " Static analysis results: Infraction summary \n" + self.end) + for file_name in self.violations_map: + print("") + for violation in sorted(self.violations_map[file_name], key=lambda x: int(x[0])): + + name_string = f"{self.bold}{self.red}File {self.yellow}{file_name}{self.red}" + rule_violated_string = f"violates rule {self.yellow}#{violation[1]}{self.red} " \ + f"of the MISRA C 2012 standard" + line_number_string = f"at line {self.yellow}{violation[0]}{self.end}" + + print(f"{name_string.ljust(75)} {rule_violated_string} {line_number_string}") + + print("") + print("") + print(self.bold + self.red + "=================================================" + self.end) + + def suppression_info(self): + """ + Pretty-prints the suppressed rule numbers. + """ + if (len(self.suppression_list) != 0): + print("\n") + print(self.bold + self.yellow + "WARNING: Suppressed infractions of rules: ", end="") + print(f", ".join(self.suppression_list), end=".") + print("") + print("") + else: + print(self.bold + self.green + "All available rules enforced - no suppressions") + + +if __name__ == "__main__": + cli = ArgumentParser() + cli.add_argument("--report", nargs=1, default="./report.msr") + cli.add_argument("--suppress", nargs="*", type=str, default="") + + args = cli.parse_args() + s = Summarizer(str(args.report[0]), args.suppress) + s.analyze() + s.suppression_info() + + if len(s.violations_map) != 0: + s.pretty_print_violations() + exit(127) + elif len(s.violations_map) == 0: + print(s.bold + s.green + "Static analysis for MISRA compliance complete. No infractions found." + s.end) + exit(0) diff --git a/inc/ECSS_Definitions.hpp b/inc/ECSS_Definitions.hpp index 047db0f70cda0a66d4069ffb7aacd3c780e45baf..01584367845db270942762e8dc52e0ededadb021 100644 --- a/inc/ECSS_Definitions.hpp +++ b/inc/ECSS_Definitions.hpp @@ -1,11 +1,11 @@ #ifndef ECSS_SERVICES_ECSS_DEFINITIONS_H #define ECSS_SERVICES_ECSS_DEFINITIONS_H -#define ECSS_MAX_MESSAGE_SIZE 1024 +#define ECSS_MAX_MESSAGE_SIZE 1024u -#define ECSS_MAX_STRING_SIZE 256 +#define ECSS_MAX_STRING_SIZE 256u -#define ECSS_MAX_FIXED_OCTET_STRING_SIZE 256 // For the ST13 large packet transfer service +#define ECSS_MAX_FIXED_OCTET_STRING_SIZE 256u // For the ST13 large packet transfer service // 7.4.1 #define CCSDS_PACKET_VERSION 0 @@ -34,7 +34,7 @@ #define ECSS_TC_REQUEST_STRING_SIZE 64 // todo: Define the maximum number of activities -#define ECSS_MAX_NUMBER_OF_TIME_SCHED_ACTIVITIES 10 +#define ECSS_MAX_NUMBER_OF_TIME_SCHED_ACTIVITIES 10 /** * @brief Time margin used in the time based command scheduling service ST[11] @@ -42,10 +42,10 @@ * have in order * @todo Define the time margin for the command activation */ -#define ECSS_TIME_MARGIN_FOR_ACTIVATION 60 +#define ECSS_TIME_MARGIN_FOR_ACTIVATION 60 // todo: Define the maximum delta between the specified -#define ECSS_MAX_DELTA_OF_RELEASE_TIME 60 +#define ECSS_MAX_DELTA_OF_RELEASE_TIME 60 // release time and the actual release time -#endif //ECSS_SERVICES_ECSS_DEFINITIONS_H +#endif // ECSS_SERVICES_ECSS_DEFINITIONS_H diff --git a/inc/ErrorHandler.hpp b/inc/ErrorHandler.hpp index 4f50837588ce77417bc2818c2093b675a9bfd267..1f2fdbf6b68a65d2df08f2e312987693be2444c2 100644 --- a/inc/ErrorHandler.hpp +++ b/inc/ErrorHandler.hpp @@ -2,12 +2,11 @@ #define PROJECT_ERRORHANDLER_HPP #include <type_traits> +#include <stdint.h> // for the uint_8t stepID // Forward declaration of the class, since its header file depends on the ErrorHandler class Message; -#include <stdint.h> // for the uint_8t stepID - /** * A class that handles unexpected software errors, including internal errors or errors due to * invalid & incorrect input data. @@ -19,13 +18,13 @@ private: /** * Log the error to a logging facility. Platform-dependent. */ - template<typename ErrorType> - static void logError(const Message &message, ErrorType errorType); + template <typename ErrorType> + static void logError(const Message& message, ErrorType errorType); /** * Log an error without a Message to a logging facility. Platform-dependent. */ - template<typename ErrorType> + template <typename ErrorType> static void logError(ErrorType errorType); public: @@ -35,45 +34,45 @@ public: * While writing (creating) a message, an amount of bytes was tried to be added but * resulted in failure, since the message storage was not enough. */ - MessageTooLarge = 1, + MessageTooLarge = 1, /** * Asked to append a number of bits larger than supported */ - TooManyBitsAppend = 2, + TooManyBitsAppend = 2, /** * Asked to append a byte, while the previous byte was not complete */ - ByteBetweenBits = 3, + ByteBetweenBits = 3, /** * A string is larger than the largest allowed string */ - StringTooLarge = 4, + StringTooLarge = 4, /** * An error in the header of a packet makes it unable to be parsed */ - UnacceptablePacket = 5, + UnacceptablePacket = 5, /** - * A date that isn't valid according to the Gregorian calendar or cannot be parsed by the - * TimeHelper - */ - InvalidDate = 6, + * A date that isn't valid according to the Gregorian calendar or cannot be parsed by the + * TimeHelper + */ + InvalidDate = 6, /** * Asked a Message type that doesn't exist */ - UnknownMessageType = 7, + UnknownMessageType = 7, /** * Asked to append unnecessary spare bits */ - InvalidSpareBits = 8, + InvalidSpareBits = 8, /** * A function received a Message that was not of the correct type */ - OtherMessageType = 9, + OtherMessageType = 9, /** * Attempt to insert new function in a full function map (ST[08]) */ - FunctionMapFull = 10, + FunctionMapFull = 10, }; /** @@ -87,19 +86,19 @@ public: /** * The received message does not contain enough information as specified */ - MessageTooShort = 1, + MessageTooShort = 1, /** * Asked to read a number of bits larger than supported */ - TooManyBitsRead = 2, + TooManyBitsRead = 2, /** * Cannot read a string, because it is larger than the largest allowed string */ - StringTooShort = 4, + StringTooShort = 4, /** * Cannot parse a Message, because there is an error in its secondary header */ - UnacceptableMessage = 5, + UnacceptableMessage = 5, }; /** @@ -135,11 +134,11 @@ public: /** * Checksum comparison failed */ - ChecksumFailed = 1, + ChecksumFailed = 1, /** * Address of a memory is out of the defined range for the type of memory */ - AddressOutOfRange = 2, + AddressOutOfRange = 2, }; /** @@ -149,7 +148,7 @@ public: * changes. */ enum RoutingErrorType { - UnknownRoutingError = 0 + UnknownRoutingError = 0, }; /** @@ -161,7 +160,7 @@ public: ExecutionStart, ExecutionProgress, ExecutionCompletion, - Routing + Routing, }; /** @@ -173,24 +172,23 @@ public: * @param errorCode The error's code, as defined in ErrorHandler * @todo See if this needs to include InternalErrorType */ - template<typename ErrorType> - static void reportError(const Message &message, ErrorType errorCode); + template <typename ErrorType> + static void reportError(const Message& message, ErrorType errorCode); /** - * Report a failure about the progress of the execution of a request - * - * @note This function is different from reportError, because we need one more \p stepID - * to call the proper function for reporting the progress of the execution of a request - * - * @param message The incoming message that prompted the failure - * @param errorCode The error's code, when a failed progress of the execution of a request - * occurs - * @param stepID If the execution of a request is a long process, then we can divide + * Report a failure about the progress of the execution of a request + * + * @note This function is different from reportError, because we need one more \p stepID + * to call the proper function for reporting the progress of the execution of a request + * + * @param message The incoming message that prompted the failure + * @param errorCode The error's code, when a failed progress of the execution of a request + * occurs + * @param stepID If the execution of a request is a long process, then we can divide * the process into steps. Each step goes with its own definition, the stepID. Each value * ,that the stepID is assigned, should be documented. - */ - static void reportProgressError(const Message &message, ExecutionProgressErrorType errorCode, - uint8_t stepID); + */ + static void reportProgressError(const Message& message, ExecutionProgressErrorType errorCode, uint8_t stepID); /** * Report a failure that occurred internally, not due to a failure of a received packet. @@ -220,8 +218,8 @@ public: * * Creates an error if \p condition is false. The created error corresponds to a \p message. */ - template<typename ErrorType> - static void assertRequest(bool condition, const Message &message, ErrorType errorCode) { + template <typename ErrorType> + static void assertRequest(bool condition, const Message& message, ErrorType errorCode) { if (not condition) { reportError(message, errorCode); } @@ -233,26 +231,29 @@ public: * @param error An error code of a specific type * @return The corresponding ErrorSource */ - template<typename ErrorType> + template <typename ErrorType> inline static ErrorSource findErrorSource(ErrorType error) { // Static type checking + ErrorSource source = Internal; + if (std::is_same<ErrorType, AcceptanceErrorType>()) { - return Acceptance; + source = Acceptance; } if (std::is_same<ErrorType, ExecutionStartErrorType>()) { - return ExecutionStart; + source = ExecutionStart; } if (std::is_same<ErrorType, ExecutionProgressErrorType>()) { - return ExecutionProgress; + source = ExecutionProgress; } if (std::is_same<ErrorType, ExecutionCompletionErrorType>()) { - return ExecutionCompletion; + source = ExecutionCompletion; } if (std::is_same<ErrorType, RoutingErrorType>()) { - return Routing; + source = Routing; } - return Internal; + + return source; } }; -#endif //PROJECT_ERRORHANDLER_HPP +#endif // PROJECT_ERRORHANDLER_HPP diff --git a/inc/Helpers/CRCHelper.hpp b/inc/Helpers/CRCHelper.hpp index aa7149846b762498ac4e13979afbbe215119b3bd..7f60fbaad836cfdbbd9062bc7078c5eb87b9518b 100644 --- a/inc/Helpers/CRCHelper.hpp +++ b/inc/Helpers/CRCHelper.hpp @@ -4,7 +4,6 @@ #include <cstdint> class CRCHelper { - /** * CRC16 calculation helper class * This class declares a function which calculates the CRC16 checksum of the given data. @@ -19,7 +18,7 @@ class CRCHelper { * @author (class code & dox) Grigoris Pavlakis <grigpavl@ece.auth.gr> */ -// TODO: Change this to hardware implementation or a trusted software one + // TODO: Change this to hardware implementation or a trusted software one public: /** * Actual CRC calculation function. @@ -36,7 +35,7 @@ public: * @param length (in bytes, plus 2 bytes for the CRC checksum) * @return 0 when the data is valid, a nonzero uint16 when the data is corrupted */ - static uint16_t validateCRC(const uint8_t* message, uint32_t length); + static uint16_t validateCRC(const uint8_t* message, uint32_t length); }; -#endif //ECSS_SERVICES_CRCHELPER_HPP +#endif // ECSS_SERVICES_CRCHELPER_HPP diff --git a/inc/Helpers/TimeAndDate.hpp b/inc/Helpers/TimeAndDate.hpp index 8ddc566973bddfbf78c6fa695d141935d12c06d7..03fb0833d3d542b81d48b0f9d31e707220a88fa7 100644 --- a/inc/Helpers/TimeAndDate.hpp +++ b/inc/Helpers/TimeAndDate.hpp @@ -32,8 +32,7 @@ public: * @param minute UTC minutes * @param second UTC seconds */ - TimeAndDate(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t - second); + TimeAndDate(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second); /** * Compare two timestamps. @@ -41,7 +40,7 @@ public: * @param Date the date that will be compared with the pointer `this` * @return true if the pointer `this` is smaller than \p Date */ - bool operator<(const TimeAndDate &Date); + bool operator<(const TimeAndDate& Date); /** * Compare two timestamps. @@ -49,15 +48,15 @@ public: * @param Date the date that will be compared with the pointer `this` * @return true if the pointer `this` is greater than \p Date */ - bool operator>(const TimeAndDate &Date); + bool operator>(const TimeAndDate& Date); /** - * Compare two timestamps. - * - * @param Date the date that will be compared with the pointer `this` - * @return true if the pointer `this` is equal to \p Date - */ - bool operator==(const TimeAndDate &Date); + * Compare two timestamps. + * + * @param Date the date that will be compared with the pointer `this` + * @return true if the pointer `this` is equal to \p Date + */ + bool operator==(const TimeAndDate& Date); /** * Compare two timestamps. @@ -65,7 +64,7 @@ public: * @param Date the date that will be compared with the pointer `this` * @return true if the pointer `this` is smaller than or equal to \p Date */ - bool operator<=(const TimeAndDate &Date); + bool operator<=(const TimeAndDate& Date); /** * Compare two timestamps. @@ -73,7 +72,7 @@ public: * @param Date the date that will be compared with the pointer `this` * @return true if the pointer `this` is greater than or equal to \p Date */ - bool operator>=(const TimeAndDate &Date); + bool operator>=(const TimeAndDate& Date); }; -#endif //ECSS_SERVICES_TIMEANDDATE_HPP +#endif // ECSS_SERVICES_TIMEANDDATE_HPP diff --git a/inc/Helpers/TimeHelper.hpp b/inc/Helpers/TimeHelper.hpp index b9039cf346c410ae15563810f67e39685903716b..5131d4e94f63fc4959c44c0b73efade52a5607a7 100644 --- a/inc/Helpers/TimeHelper.hpp +++ b/inc/Helpers/TimeHelper.hpp @@ -5,9 +5,9 @@ #include <Message.hpp> #include "TimeAndDate.hpp" -#define SECONDS_PER_MINUTE 60 -#define SECONDS_PER_HOUR 3600 -#define SECONDS_PER_DAY 86400 +#define SECONDS_PER_MINUTE 60u +#define SECONDS_PER_HOUR 3600u +#define SECONDS_PER_DAY 86400u /** * This class formats the spacecraft time and cooperates closely with the ST[09] time management. @@ -39,33 +39,33 @@ public: static bool IsLeapYear(uint16_t year); /** - * Convert UTC date to elapsed seconds since Unix epoch (1/1/1970 00:00:00). - * - * This is a reimplemented mktime() of <ctime> library in an embedded systems way - * - * @note - * This function can convert UTC dates after 1 January 2019 to elapsed seconds since Unix epoch - * - * @param TimeInfo the time information/data from the RTC (UTC format) - * @return the elapsed seconds between a given UTC date (after the Unix epoch) and Unix epoch - * @todo check if we need to change the epoch to the recommended one from the standard, 1 - * January 1958 - */ - static uint32_t utcToSeconds(TimeAndDate &TimeInfo); + * Convert UTC date to elapsed seconds since Unix epoch (1/1/1970 00:00:00). + * + * This is a reimplemented mktime() of <ctime> library in an embedded systems way + * + * @note + * This function can convert UTC dates after 1 January 2019 to elapsed seconds since Unix epoch + * + * @param TimeInfo the time information/data from the RTC (UTC format) + * @return the elapsed seconds between a given UTC date (after the Unix epoch) and Unix epoch + * @todo check if we need to change the epoch to the recommended one from the standard, 1 + * January 1958 + */ + static uint32_t utcToSeconds(TimeAndDate& TimeInfo); /** - * Convert elapsed seconds since Unix epoch to UTC date. - * - * This is a reimplemented gmtime() of <ctime> library in an embedded systems way - * - * @note - * This function can convert elapsed seconds since Unix epoch to UTC dates after 1 January 2019 - * - * @param seconds elapsed seconds since Unix epoch - * @return the UTC date based on the \p seconds - * @todo check if we need to change the epoch to the recommended one from the standard, 1 - * January 1958 - */ + * Convert elapsed seconds since Unix epoch to UTC date. + * + * This is a reimplemented gmtime() of <ctime> library in an embedded systems way + * + * @note + * This function can convert elapsed seconds since Unix epoch to UTC dates after 1 January 2019 + * + * @param seconds elapsed seconds since Unix epoch + * @return the UTC date based on the \p seconds + * @todo check if we need to change the epoch to the recommended one from the standard, 1 + * January 1958 + */ static TimeAndDate secondsToUTC(uint32_t seconds); /** @@ -76,10 +76,10 @@ public: * @param TimeInfo is the data provided from RTC (UTC) * @return TimeFormat the CDS time format. More specific, 48 bits are used for the T-field * (16 for the `DAY` and 32 for the `ms of day`) - * @todo time security for critical time operations - * @todo declare the implicit P-field + * @todo time security for critical time operations + * @todo declare the implicit P-field */ - static uint64_t generateCDStimeFormat(struct TimeAndDate &TimeInfo); + static uint64_t generateCDStimeFormat(struct TimeAndDate& TimeInfo); /** * Parse the CDS time format (3.3 in CCSDS 301.0-B-4 standard) @@ -88,8 +88,7 @@ public: * fixed size of 48 bits * @return the UTC date */ - static TimeAndDate parseCDStimeFormat(const uint8_t *data); + static TimeAndDate parseCDStimeFormat(const uint8_t* data); }; - -#endif //ECSS_SERVICES_TIMEHELPER_HPP +#endif // ECSS_SERVICES_TIMEHELPER_HPP diff --git a/inc/Message.hpp b/inc/Message.hpp index ac1509f9ea39dc2c8d330e0ebd4bcc34978c382a..011f994a5d313a6200fc721e700883c41ca9b480 100644 --- a/inc/Message.hpp +++ b/inc/Message.hpp @@ -1,10 +1,6 @@ #ifndef ECSS_SERVICES_PACKET_H #define ECSS_SERVICES_PACKET_H - -// Forward declaration of the Message class, needed for the ErrorHandler -class Message; - #include "ECSS_Definitions.hpp" #include <cstdint> #include <etl/String.hpp> @@ -29,9 +25,9 @@ public: * @param msg2 Second message for comparison * @return A boolean value indicating whether the messages are of the same type */ - static bool isSameType(const Message &msg1, const Message &msg2) { - return (msg1.packetType == msg2.packetType) && - (msg1.messageType == msg2.messageType) && (msg1.serviceType == msg2.serviceType); + static bool isSameType(const Message& msg1, const Message& msg2) { + return (msg1.packetType == msg2.packetType) && (msg1.messageType == msg2.messageType) && + (msg1.serviceType == msg2.serviceType); } /** @@ -42,19 +38,19 @@ public: * fixed size * @return The result of comparison */ - bool operator==(const Message &msg) const { + bool operator==(const Message& msg) const { // todo: Enable the following check when the message data field has a fixed size padded // with zeros. At the moment the data array is not padded with zeros to fulfil the // maximum set number of a TC request message. - //if (this->dataSize != msg.dataSize) return false; + // if (this->dataSize != msg.dataSize) return false; for (uint16_t i = 0; i < ECSS_MAX_MESSAGE_SIZE; i++) { if (this->data[i] != msg.data[i]) { return false; } } - return (this->packetType == msg.packetType) && - (this->messageType == msg.messageType) && (this->serviceType == msg.serviceType); + return (this->packetType == msg.packetType) && (this->messageType == msg.messageType) && + (this->serviceType == msg.serviceType); } enum PacketType { @@ -91,7 +87,7 @@ public: // TODO: Is it a good idea to not initialise this to 0? uint8_t data[ECSS_MAX_MESSAGE_SIZE] = {'\0'}; -//private: + // private: uint8_t currentBit = 0; // Next byte to read for read...() functions @@ -141,8 +137,8 @@ public: * * @param string The string to insert */ - template<const size_t SIZE> - void appendString(const String<SIZE> &string); + template <const size_t SIZE> + void appendString(const String<SIZE>& string); /** * Reads the next \p numBits bits from the the message in a big-endian format @@ -172,20 +168,19 @@ public: * NOTE: We assume that \p string is already allocated, and its size is at least * ECSS_MAX_STRING_SIZE. This function does placs a \0 at the end of the created string. */ - void readString(char *string, uint8_t size); + void readString(char* string, uint8_t size); /** - * Reads the next \p size bytes from the message, and stores them into the allocated \p string - * - * NOTE: We assume that \p string is already allocated, and its size is at least - * ECSS_MAX_STRING_SIZE. This function does placs a \0 at the end of the created string - * @todo Is uint16_t size too much or not enough? It has to be defined - */ - void readString(uint8_t *string, uint16_t size); + * Reads the next \p size bytes from the message, and stores them into the allocated \p string + * + * NOTE: We assume that \p string is already allocated, and its size is at least + * ECSS_MAX_STRING_SIZE. This function does placs a \0 at the end of the created string + * @todo Is uint16_t size too much or not enough? It has to be defined + */ + void readString(uint8_t* string, uint16_t size); public: - Message(uint8_t serviceType, uint8_t messageType, PacketType packetType, - uint16_t applicationId); + Message(uint8_t serviceType, uint8_t messageType, PacketType packetType, uint16_t applicationId); /** * Adds a single-byte boolean value to the end of the message @@ -268,8 +263,8 @@ public: * PTC = 3, PFC = 16 */ void appendUint64(uint64_t value) { - appendWord(static_cast<uint32_t >(value >> 32)); - appendWord(static_cast<uint32_t >(value)); + appendWord(static_cast<uint32_t>(value >> 32)); + appendWord(static_cast<uint32_t>(value)); } /** @@ -278,7 +273,7 @@ public: * PTC = 4, PFC = 4 */ void appendSint8(int8_t value) { - return appendByte(reinterpret_cast<uint8_t &>(value)); + return appendByte(reinterpret_cast<uint8_t&>(value)); } /** @@ -287,7 +282,7 @@ public: * PTC = 4, PFC = 8 */ void appendSint16(int16_t value) { - return appendHalfword(reinterpret_cast<uint16_t &>(value)); + return appendHalfword(reinterpret_cast<uint16_t&>(value)); } /** @@ -296,7 +291,7 @@ public: * PTC = 4, PFC = 14 */ void appendSint32(int32_t value) { - return appendWord(reinterpret_cast<uint32_t &>(value)); + return appendWord(reinterpret_cast<uint32_t&>(value)); } /** @@ -305,10 +300,9 @@ public: * PTC = 5, PFC = 1 */ void appendFloat(float value) { - static_assert(sizeof(uint32_t) == sizeof(value), - "Floating point numbers must be 32 bits long"); + static_assert(sizeof(uint32_t) == sizeof(value), "Floating point numbers must be 32 bits long"); - return appendWord(reinterpret_cast<uint32_t &>(value)); + return appendWord(reinterpret_cast<uint32_t&>(value)); } /** @@ -317,11 +311,10 @@ public: * * PTC = 7, PFC = 0 */ - template<const size_t SIZE> - void appendOctetString(const String<SIZE> &string) { + template <const size_t SIZE> + void appendOctetString(const String<SIZE>& string) { // Make sure that the string is large enough to count - ASSERT_INTERNAL(string.size() <= (std::numeric_limits<uint16_t>::max)(), - ErrorHandler::StringTooLarge); + ASSERT_INTERNAL(string.size() <= (std::numeric_limits<uint16_t>::max)(), ErrorHandler::StringTooLarge); appendUint16(string.size()); appendString(string); @@ -408,7 +401,7 @@ public: * PTC = 3, PFC = 16 */ uint64_t readUint64() { - return (static_cast<uint64_t >(readWord()) << 32) | static_cast<uint64_t >(readWord()); + return (static_cast<uint64_t>(readWord()) << 32) | static_cast<uint64_t>(readWord()); } /** @@ -418,7 +411,7 @@ public: */ int8_t readSint8() { uint8_t value = readByte(); - return reinterpret_cast<int8_t &>(value); + return reinterpret_cast<int8_t&>(value); } /** @@ -428,7 +421,7 @@ public: */ int16_t readSint16() { uint16_t value = readHalfword(); - return reinterpret_cast<int16_t &>(value); + return reinterpret_cast<int16_t&>(value); } /** @@ -438,7 +431,7 @@ public: */ int32_t readSint32() { uint32_t value = readWord(); - return reinterpret_cast<int32_t &>(value); + return reinterpret_cast<int32_t&>(value); } /** @@ -450,11 +443,10 @@ public: * PTC = 5, PFC = 1 */ float readFloat() { - static_assert(sizeof(uint32_t) == sizeof(float), - "Floating point numbers must be 32 bits long"); + static_assert(sizeof(uint32_t) == sizeof(float), "Floating point numbers must be 32 bits long"); uint32_t value = readWord(); - return reinterpret_cast<float &>(value); + return reinterpret_cast<float&>(value); } /** @@ -466,7 +458,7 @@ public: * * PTC = 7, PFC = 0 */ - uint16_t readOctetString(uint8_t *byteString) { + uint16_t readOctetString(uint8_t* byteString) { uint16_t size = readUint16(); // Get the data length from the message readString(byteString, size); // Read the string data @@ -494,15 +486,16 @@ public: * * @return True if the message is of correct type, false if not */ - bool assertType(Message::PacketType expectedPacketType, uint8_t expectedServiceType, - uint8_t expectedMessageType) { - if (packetType != expectedPacketType || serviceType != expectedServiceType || - messageType != expectedMessageType) { + bool assertType(Message::PacketType expectedPacketType, uint8_t expectedServiceType, uint8_t expectedMessageType) { + bool status = true; + + if ((packetType != expectedPacketType) || (serviceType != expectedServiceType) || + (messageType != expectedMessageType)) { ErrorHandler::reportInternalError(ErrorHandler::OtherMessageType); - return false; + status = false; } - return true; + return status; } /** @@ -522,8 +515,8 @@ public: } }; -template<const size_t SIZE> -inline void Message::appendString(const String<SIZE> &string) { +template <const size_t SIZE> +inline void Message::appendString(const String<SIZE>& string) { ASSERT_INTERNAL(dataSize + string.size() < ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge); // TODO: Do we need to keep this check? How does etl::string handle it? ASSERT_INTERNAL(string.size() < string.capacity(), ErrorHandler::StringTooLarge); @@ -533,4 +526,4 @@ inline void Message::appendString(const String<SIZE> &string) { dataSize += string.size(); } -#endif //ECSS_SERVICES_PACKET_H +#endif // ECSS_SERVICES_PACKET_H diff --git a/inc/MessageParser.hpp b/inc/MessageParser.hpp index 8afce35feeae7a703aaee8adf031f22dbb494bb6..b3b1f0ded171bdcab16489dbcbc06282a9f7a655 100644 --- a/inc/MessageParser.hpp +++ b/inc/MessageParser.hpp @@ -11,7 +11,6 @@ class MessageParser { public: - /** * This function takes as input TC packets and and calls the proper services' functions that have been * implemented to handle TC packets. @@ -31,7 +30,7 @@ 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 @@ -70,7 +69,7 @@ private: * @param length The size of the header * @param message The Message to modify based on the header */ - void parseTC(const uint8_t *data, uint16_t length, Message &message); + void parseTC(const uint8_t* data, uint16_t length, Message& message); /** * Parse the ECSS Telemetry packet secondary header @@ -81,8 +80,7 @@ private: * @param length The size of the header * @param message The Message to modify based on the header */ - void parseTM(const uint8_t *data, uint16_t length, Message &message); + void parseTM(const uint8_t* data, uint16_t length, Message& message); }; - -#endif //ECSS_SERVICES_MESSAGEPARSER_HPP +#endif // ECSS_SERVICES_MESSAGEPARSER_HPP diff --git a/inc/Platform/STM32F7/MemoryAddressLimits.hpp b/inc/Platform/STM32F7/MemoryAddressLimits.hpp index e30651f9373d45912404ca7f33ceceed060b2002..5afe31a625e6b819b03d1740c4b0be12b0fd2683 100644 --- a/inc/Platform/STM32F7/MemoryAddressLimits.hpp +++ b/inc/Platform/STM32F7/MemoryAddressLimits.hpp @@ -15,4 +15,4 @@ #define FLASH_LOWER_LIM 0x08000000UL #define FLASH_UPPER_LIM 0x08200000UL -#endif //ECSS_SERVICES_MEMORYADDRESSLIMITS_STM32F7_HPP +#endif // ECSS_SERVICES_MEMORYADDRESSLIMITS_STM32F7_HPP diff --git a/inc/Platform/x86/TimeGetter.hpp b/inc/Platform/x86/TimeGetter.hpp index 7dcf22ed020dd6163ef5c1adede6e1f3dbf26d22..7cb15d7389c5b3a7e3c9f69de719ca2ac0332c3e 100644 --- a/inc/Platform/x86/TimeGetter.hpp +++ b/inc/Platform/x86/TimeGetter.hpp @@ -5,20 +5,18 @@ #include <cstdint> #include <ctime> - /** * @brief Get the current time */ class TimeGetter { public: - /** * @brief Gets the current time in UNIX epoch * @return Current UNIX epoch time, in elapsed seconds */ static inline uint32_t getSeconds() { - return static_cast<uint32_t >(time(nullptr)); + return static_cast<uint32_t>(time(nullptr)); } }; -#endif //ECSS_SERVICES_TIMEGETTER_HPP +#endif // ECSS_SERVICES_TIMEGETTER_HPP diff --git a/inc/Service.hpp b/inc/Service.hpp index 7fc71104b2ea09aa0b99ce0a80b0f9c64f40bf44..32e77e19387cd0b74236c082ffc271f3557535b7 100644 --- a/inc/Service.hpp +++ b/inc/Service.hpp @@ -18,6 +18,7 @@ class ServicePool; class Service { private: uint16_t messageTypeCounter = 0; + protected: /** * The service type of this Service. For example, ST[12]'s serviceType is `12`. @@ -44,7 +45,7 @@ protected: * Note: For now, since we don't have any mechanisms to queue messages and send them later, * we just print the message to the screen */ - void storeMessage(Message &message); + void storeMessage(Message& message); /** * This function declared only to remind us that every service must have a function like @@ -63,14 +64,14 @@ public: * * Does not allow Services should be copied. There should be only one instance for each Service. */ - Service(Service const &) = delete; + Service(Service const&) = delete; /** * Unimplemented assignment operation * * Does not allow changing the instances of Services, as Services are singletons. */ - void operator=(Service const &) = delete; + void operator=(Service const&) = delete; /** * Default destructor @@ -80,13 +81,12 @@ public: /** * Default move constructor */ - Service(Service &&service) noexcept = default; + Service(Service&& service) noexcept = default; /** * Default move assignment operator */ - Service &operator=(Service &&service) noexcept = default; + Service& operator=(Service&& service) noexcept = default; }; - -#endif //ECSS_SERVICES_SERVICE_HPP +#endif // ECSS_SERVICES_SERVICE_HPP diff --git a/inc/ServicePool.hpp b/inc/ServicePool.hpp index 32c74849bc62bae21149118c1d4a02e4563672ea..97fbed7ff13ef836ad9de9da68f9c5d544050e7d 100644 --- a/inc/ServicePool.hpp +++ b/inc/ServicePool.hpp @@ -51,5 +51,4 @@ public: */ extern ServicePool Services; - -#endif //ECSS_SERVICES_SERVICEPOOL_HPP +#endif // ECSS_SERVICES_SERVICEPOOL_HPP diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp index 43dffb29e9802831a24c3b64f87ea556fc8d56e4..c8052e0e29df10312356c7595a53b2547ef56afa 100644 --- a/inc/Services/EventActionService.hpp +++ b/inc/Services/EventActionService.hpp @@ -1,7 +1,6 @@ #ifndef ECSS_SERVICES_EVENTACTIONSERVICE_HPP #define ECSS_SERVICES_EVENTACTIONSERVICE_HPP - #define ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE 256 #include "Service.hpp" @@ -24,10 +23,9 @@ */ class EventActionService : public Service { private: - /** - * Event-action function status - */ + * Event-action function status + */ bool eventActionFunctionStatus; /** @@ -115,7 +113,7 @@ public: * Getter for event-action function status * @return eventActionFunctionStatus */ - bool getEventActionFunctionStatus(){ + bool getEventActionFunctionStatus() { return eventActionFunctionStatus; } @@ -129,4 +127,4 @@ public: void execute(const Message& message); }; -#endif //ECSS_SERVICES_EVENTACTIONSERVICE_HPP +#endif // ECSS_SERVICES_EVENTACTIONSERVICE_HPP diff --git a/inc/Services/EventReportService.hpp b/inc/Services/EventReportService.hpp index 3ed47d86a1577189f8ce9e1f2c0e619f740e0055..6aea19a538b69373f5a15e5322efa86188b55d9e 100644 --- a/inc/Services/EventReportService.hpp +++ b/inc/Services/EventReportService.hpp @@ -19,6 +19,7 @@ class EventReportService : public Service { private: static const uint16_t numberOfEvents = 7; etl::bitset<numberOfEvents> stateOfEvents; + public: // Variables that count the event reports per severity level uint16_t lowSeverityReportCount; @@ -61,35 +62,35 @@ public: /** * An unknown event occured */ - InformativeUnknownEvent = 0, + InformativeUnknownEvent = 0, /** * Watchdogs have reset */ - WWDGReset = 1, + WWDGReset = 1, /** * Assertion has failed */ - AssertionFail = 2, + AssertionFail = 2, /** * Microcontroller has started */ - MCUStart = 3, + MCUStart = 3, /** * An unknown anomaly of low severity anomalyhas occurred */ - LowSeverityUnknownEvent = 4, + LowSeverityUnknownEvent = 4, /** * An unknown anomaly of medium severity has occurred */ - MediumSeverityUnknownEvent = 5, + MediumSeverityUnknownEvent = 5, /** * An unknown anomaly of high severity has occurred */ - HighSeverityUnknownEvent = 6, + HighSeverityUnknownEvent = 6, /** * When an execution of a notification/event fails to start */ - FailedStartOfExecution = 7 + FailedStartOfExecution = 7 }; /** @@ -102,7 +103,7 @@ public: * @param data the data of the report * @param length the length of the data */ - void informativeEventReport(Event eventID, const String<64> & data); + void informativeEventReport(Event eventID, const String<64>& data); /** * TM[5,2] low severiity anomaly report @@ -114,7 +115,7 @@ public: * @param data the data of the report * @param length the length of the data */ - void lowSeverityAnomalyReport(Event eventID, const String<64> & data); + void lowSeverityAnomalyReport(Event eventID, const String<64>& data); /** * TM[5,3] medium severity anomaly report @@ -126,7 +127,7 @@ public: * @param data the data of the report * @param length the length of the data */ - void mediumSeverityAnomalyReport(Event eventID, const String<64> & data); + void mediumSeverityAnomalyReport(Event eventID, const String<64>& data); /** * TM[5,4] high severity anomaly report @@ -138,7 +139,7 @@ public: * @param data the data of the report * @param length the length of the data */ - void highSeverityAnomalyReport(Event eventID, const String<64> & data); + void highSeverityAnomalyReport(Event eventID, const String<64>& data); /** * TC[5,5] request to enable report generation @@ -185,4 +186,4 @@ public: void execute(const Message& message); }; -#endif //ECSS_SERVICES_EVENTREPORTSERVICE_HPP +#endif // ECSS_SERVICES_EVENTREPORTSERVICE_HPP diff --git a/inc/Services/FunctionManagementService.hpp b/inc/Services/FunctionManagementService.hpp index 7b11f4177d65d29b383ba5b7136229b7800c694e..266e65468bbbfaabf3356cea4ddadb92018b8871 100644 --- a/inc/Services/FunctionManagementService.hpp +++ b/inc/Services/FunctionManagementService.hpp @@ -7,9 +7,9 @@ #include "Service.hpp" #include "ErrorHandler.hpp" -#define FUNC_MAP_SIZE 5 // size of the function map (number of elements) -#define FUNC_NAME_LENGTH 32 // max length of the function name -#define MAX_ARG_LENGTH 32 // maximum argument byte string length +#define FUNC_MAP_SIZE 5 // size of the function map (number of elements) +#define FUNC_NAME_LENGTH 32 // max length of the function name +#define MAX_ARG_LENGTH 32 // maximum argument byte string length /** * Implementation of the ST[08] function management service @@ -28,7 +28,7 @@ * @author Grigoris Pavlakis <grigpavl@ece.auth.gr> */ - /** +/** * Usage of the include() function: * * @code @@ -52,8 +52,7 @@ */ typedef String<FUNC_NAME_LENGTH> functionName; -typedef etl::map<functionName, void(*)(String<MAX_ARG_LENGTH>), FUNC_MAP_SIZE> -FunctionMap; +typedef etl::map<functionName, void (*)(String<MAX_ARG_LENGTH>), FUNC_MAP_SIZE> FunctionMap; class FunctionManagementService : public Service { /** @@ -61,7 +60,6 @@ class FunctionManagementService : public Service { */ FunctionMap funcPtrIndex; - public: /** * Constructs the function pointer index with all the necessary functions at initialization time @@ -87,9 +85,11 @@ public: * @param ptr pointer to a function of void return type and a MAX_ARG_LENGTH-lengthed byte * string as argument (which contains the actual arguments of the function) */ - void include(String<FUNC_NAME_LENGTH> funcName, void(*ptr)(String<MAX_ARG_LENGTH>)); + void include(String<FUNC_NAME_LENGTH> funcName, void (*ptr)(String<MAX_ARG_LENGTH>)); - int getMapSize() { return funcPtrIndex.size(); } + int getMapSize() { + return funcPtrIndex.size(); + } /** * It is responsible to call the suitable function that executes a telecommand packet. The source of that packet @@ -101,4 +101,4 @@ public: void execute(Message& param); }; -#endif //ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP +#endif // ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP diff --git a/inc/Services/LargePacketTransferService.hpp b/inc/Services/LargePacketTransferService.hpp index 7ed7d997ebcea0009193ebeb52d823001c38cab2..0e8746eb732deca05d855fc297f929cbd2a766a6 100644 --- a/inc/Services/LargePacketTransferService.hpp +++ b/inc/Services/LargePacketTransferService.hpp @@ -14,7 +14,6 @@ class LargePacketTransferService : public Service { public: - /** * Default constructor since only functions will be used. */ @@ -28,9 +27,8 @@ public: * @param partSequenceNumber The identifier of the part of the large packet * @param string The data contained in this part of the large packet */ - void firstDownlinkPartReport(uint16_t - largeMessageTransactionIdentifier, uint16_t partSequenceNumber, - const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> &string); + void firstDownlinkPartReport(uint16_t largeMessageTransactionIdentifier, uint16_t partSequenceNumber, + const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>& string); /** * Function that handles the n-2 parts of tbe n-part download report @@ -38,10 +36,8 @@ public: * @param partSequenceNumber The identifier of the part of the large packet * @param string The data contained in this part of the large packet */ - void intermediateDownlinkPartReport(uint16_t - largeMessageTransactionIdentifier, - uint16_t partSequenceNumber, - const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> &string); + void intermediateDownlinkPartReport(uint16_t largeMessageTransactionIdentifier, uint16_t partSequenceNumber, + const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>& string); /** * Function that handles the last part of the download report @@ -49,10 +45,8 @@ public: * @param partSequenceNumber The identifier of the part of the large packet * @param string The data contained in this part of the large packet */ - void lastDownlinkPartReport(uint16_t - largeMessageTransactionIdentifier, uint16_t partSequenceNumber, - const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> &string); - + void lastDownlinkPartReport(uint16_t largeMessageTransactionIdentifier, uint16_t partSequenceNumber, + const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>& string); // The three uplink functions should handle a TC request to "upload" data. Since there is not // a createTC function ready, I just return the given string. @@ -61,22 +55,20 @@ public: * Function that handles the first part of the uplink request * @param string This will change when these function will be modified */ - String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> - firstUplinkPart(const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> &string); + String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> firstUplinkPart(const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>& string); /** * Function that handles the n-2 parts of tbe n-part uplink request * @param string This will change when these function will be modified */ String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> - intermediateUplinkPart(const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> &string); + intermediateUplinkPart(const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>& string); /** * Function that handles the last part of the uplink request * @param string This will change when these function will be modified */ - String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> - lastUplinkPart(const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> &string); + String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> lastUplinkPart(const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>& string); }; #endif // ECSS_SERVICES_LARGEPACKETTRANSFERSERVICE_HPP diff --git a/inc/Services/MemoryManagementService.hpp b/inc/Services/MemoryManagementService.hpp index 2995924cad2de34b006959dafc5095899ea842e0..82b6454c0553cd57a384f3ec5d2eb62c3d825ad6 100644 --- a/inc/Services/MemoryManagementService.hpp +++ b/inc/Services/MemoryManagementService.hpp @@ -8,7 +8,6 @@ #include "ErrorHandler.hpp" #include "Platform/STM32F7/MemoryAddressLimits.hpp" - class MemoryManagementService : public Service { public: // Memory type ID's @@ -19,7 +18,7 @@ public: RAM_D3, ITCMRAM, FLASH, - EXTERNAL + EXTERNAL, }; MemoryManagementService(); @@ -33,10 +32,10 @@ public: */ class RawDataMemoryManagement { private: - MemoryManagementService &mainService; // Used to access main class's members + MemoryManagementService& mainService; // Used to access main class's members public: - explicit RawDataMemoryManagement(MemoryManagementService &parent); + explicit RawDataMemoryManagement(MemoryManagementService& parent); /** * TC[6,2] load raw values to memory @@ -46,7 +45,7 @@ public: * @param request Provide the received message as a parameter * @todo Only allow aligned memory address to be start addresses */ - void loadRawData(Message &request); + void loadRawData(Message& request); /** * TC[6,5] read raw memory values @@ -58,7 +57,7 @@ public: * different memory types * @todo Only allow aligned memory address to be start addresses */ - void dumpRawData(Message &request); + void dumpRawData(Message& request); /** * TC[6,9] check raw memory data @@ -84,11 +83,11 @@ public: private: /** - * Check whether the provided address is valid or not, based on the defined limit values - * - * @param memId The ID of the memory to check is passed - * @param address Takes the address to be checked for validity - */ + * Check whether the provided address is valid or not, based on the defined limit values + * + * @param memId The ID of the memory to check is passed + * @param address Takes the address to be checked for validity + */ bool addressValidator(MemoryManagementService::MemoryID memId, uint64_t address); /** @@ -102,7 +101,7 @@ private: * Validate the data according to checksum calculation * */ - bool dataValidator(const uint8_t *data, uint16_t checksum, uint16_t length); + bool dataValidator(const uint8_t* data, uint16_t checksum, uint16_t length); }; -#endif //ECSS_SERVICES_MEMMANGSERVICE_HPP +#endif // ECSS_SERVICES_MEMMANGSERVICE_HPP diff --git a/inc/Services/ParameterService.hpp b/inc/Services/ParameterService.hpp index 687fd32d07f48a1df09c668b4feaf63a236c2f8b..7387933211af5f776d56e09c995bc07f1e008a80 100644 --- a/inc/Services/ParameterService.hpp +++ b/inc/Services/ParameterService.hpp @@ -21,10 +21,10 @@ * ECSS-E-ST-70-41C, chapter 7.3 */ -typedef uint16_t ParamId; // parameter IDs are given sequentially +typedef uint16_t ParamId; // parameter IDs are given sequentially struct Parameter { - uint8_t ptc; // Packet field type code (PTC) - uint8_t pfc; // Packet field format code (PFC) + uint8_t ptc; // Packet field type code (PTC) + uint8_t pfc; // Packet field format code (PFC) uint32_t settingData; // Actual data defining the operation of a peripheral or subsystem. @@ -41,11 +41,10 @@ struct Parameter { * corresponding Parameter structs containing the PTC, PFC and the parameter's value. */ - class ParameterService : public Service { private: etl::map<ParamId, Parameter, MAX_PARAMS> paramsList; - uint16_t numOfValidIds(Message idMsg); //count the valid ids in a given TC[20, 1] + uint16_t numOfValidIds(Message idMsg); // count the valid ids in a given TC[20, 1] public: /** @@ -95,7 +94,6 @@ public: * @param param Contains the necessary parameters to call the suitable subservice */ void execute(Message& message); - }; -#endif //ECSS_SERVICES_PARAMETERSERVICE_HPP +#endif // ECSS_SERVICES_PARAMETERSERVICE_HPP diff --git a/inc/Services/RequestVerificationService.hpp b/inc/Services/RequestVerificationService.hpp index 571fb63a8a0ac9c5a38512d6d5d84c4f33e89bcc..ced3e8aed7f94171e7759ab1e708d15272d21d3b 100644 --- a/inc/Services/RequestVerificationService.hpp +++ b/inc/Services/RequestVerificationService.hpp @@ -29,7 +29,7 @@ public: * The data is actually some data members of Message that contain the basic info * of the telecommand packet that accepted successfully */ - void successAcceptanceVerification(const Message &request); + void successAcceptanceVerification(const Message& request); /** * TM[1,2] failed acceptance verification report @@ -39,8 +39,7 @@ public: * info of the telecommand packet that failed to be accepted * @param errorCode The cause of creating this type of report */ - void failAcceptanceVerification(const Message &request, ErrorHandler::AcceptanceErrorType - errorCode); + void failAcceptanceVerification(const Message& request, ErrorHandler::AcceptanceErrorType errorCode); /** * TM[1,3] successful start of execution verification report @@ -49,7 +48,7 @@ public: * The data is actually some data members of Message that contain the basic info * of the telecommand packet that its start of execution is successful */ - void successStartExecutionVerification(const Message &request); + void successStartExecutionVerification(const Message& request); /** * TM[1,4] failed start of execution verification report @@ -59,9 +58,7 @@ public: * of the telecommand packet that its start of execution has failed * @param errorCode The cause of creating this type of report */ - void failStartExecutionVerification(const Message &request, - ErrorHandler::ExecutionStartErrorType - errorCode); + void failStartExecutionVerification(const Message& request, ErrorHandler::ExecutionStartErrorType errorCode); /** * TM[1,5] successful progress of execution verification report @@ -69,12 +66,12 @@ public: * @param request Contains the necessary data to send the report. * The data is actually some data members of Message that contain the basic info * of the telecommand packet that its progress of execution is successful - * @param stepID If the execution of a request is a long process, then we can divide + * @param stepID If the execution of a request is a long process, then we can divide * the process into steps. Each step goes with its own definition, the stepID. * @todo Each value,that the stepID is assigned, should be documented. * @todo error handling for undocumented assigned values to stepID */ - void successProgressExecutionVerification(const Message &request, uint8_t stepID); + void successProgressExecutionVerification(const Message& request, uint8_t stepID); /** * TM[1,6] failed progress of execution verification report @@ -88,17 +85,17 @@ public: * @todo Each value,that the stepID is assigned, should be documented. * @todo error handling for undocumented assigned values to stepID */ - void failProgressExecutionVerification(const Message &request, - ErrorHandler::ExecutionProgressErrorType errorCode, uint8_t stepID); + void failProgressExecutionVerification(const Message& request, ErrorHandler::ExecutionProgressErrorType errorCode, + uint8_t stepID); /** - * TM[1,7] successful completion of execution verification report + * TM[1,7] successful completion of execution verification report * * @param request Contains the necessary data to send the report. * The data is actually data members of Message that contain the basic info of the * telecommand packet that executed completely and successfully - */ - void successCompletionExecutionVerification(const Message &request); + */ + void successCompletionExecutionVerification(const Message& request); /** * TM[1,8] failed completion of execution verification report @@ -108,8 +105,8 @@ public: * telecommand packet that failed to be executed completely * @param errorCode The cause of creating this type of report */ - void failCompletionExecutionVerification(const Message &request, - ErrorHandler::ExecutionCompletionErrorType errorCode); + void failCompletionExecutionVerification(const Message& request, + ErrorHandler::ExecutionCompletionErrorType errorCode); /** * TM[1,10] failed routing verification report @@ -118,9 +115,9 @@ public: * The data is actually some data members of Message that contain the basic info of the * telecommand packet that failed the routing * @param errorCode The cause of creating this type of report +<<<<<<< HEAD */ void failRoutingVerification(const Message &request, ErrorHandler::RoutingErrorType errorCode); }; - -#endif //ECSS_SERVICES_REQUESTVERIFICATIONSERVICE_HPP +#endif // ECSS_SERVICES_REQUESTVERIFICATIONSERVICE_HPP diff --git a/inc/Services/TestService.hpp b/inc/Services/TestService.hpp index cb8afc67dd97511083e9fc744073261731336ec8..8ed5d917e9a0868901ee1fbcde7b0ec4936f6b95 100644 --- a/inc/Services/TestService.hpp +++ b/inc/Services/TestService.hpp @@ -15,14 +15,14 @@ public: /** * TC[17,1] perform an are-you-alive connection test */ - void areYouAlive(Message &request); + void areYouAlive(Message& request); /** * TC[17,3] perform an on-board connection test * * @todo Only respond if we have the correct APID */ - void onBoardConnection(Message &request); + void onBoardConnection(Message& request); /** * It is responsible to call the suitable function that execute the proper subservice. The @@ -34,5 +34,4 @@ public: void execute(Message& message); }; - -#endif //ECSS_SERVICES_TESTSERVICE_HPP +#endif // ECSS_SERVICES_TESTSERVICE_HPP diff --git a/inc/Services/TimeBasedSchedulingService.hpp b/inc/Services/TimeBasedSchedulingService.hpp index ff8589b3c15f51c8d8c3d18639d1f349065e7b15..14581131ef478aa517555425ed22398197da4b50 100644 --- a/inc/Services/TimeBasedSchedulingService.hpp +++ b/inc/Services/TimeBasedSchedulingService.hpp @@ -21,17 +21,17 @@ * @def GROUPS_ENABLED * @brief Indicates whether scheduling groups are enabled */ -#define GROUPS_ENABLED 0 -#define SUB_SCHEDULES_ENABLED 0 - +#define GROUPS_ENABLED 0 +#define SUB_SCHEDULES_ENABLED 0 /** * @brief Namespace to access private members during test * * @details Define a namespace for the access of the private members to avoid conflicts */ -namespace unit_test { - struct Tester; +namespace unit_test +{ +struct Tester; } // namespace unit_test /** @@ -68,9 +68,9 @@ private: uint16_t sequenceCount = 0; uint8_t sourceID = 0; - bool operator!=(const RequestID &rightSide) const { - return (sequenceCount != rightSide.sequenceCount) or - (applicationID != rightSide.applicationID) or (sourceID != rightSide.sourceID); + bool operator!=(const RequestID& rightSide) const { + return (sequenceCount != rightSide.sequenceCount) or (applicationID != rightSide.applicationID) or + (sourceID != rightSide.sourceID); } }; @@ -99,17 +99,18 @@ private: */ etl::list<ScheduledActivity, ECSS_MAX_NUMBER_OF_TIME_SCHED_ACTIVITIES> scheduledActivities; - /** * @brief Sort the activities by their release time * * @details The ECSS standard requires that the activities are sorted in the TM message * response. Also it is better to have the activities sorted. */ - inline void sortActivitiesReleaseTime(etl::list<ScheduledActivity, - ECSS_MAX_NUMBER_OF_TIME_SCHED_ACTIVITIES> &schedActivities) { - schedActivities.sort([](ScheduledActivity const &leftSide, ScheduledActivity const - &rightSide) { return leftSide.requestReleaseTime < rightSide.requestReleaseTime; }); + inline void + sortActivitiesReleaseTime(etl::list<ScheduledActivity, ECSS_MAX_NUMBER_OF_TIME_SCHED_ACTIVITIES>& schedActivities) { + schedActivities.sort([](ScheduledActivity const& leftSide, ScheduledActivity const& rightSide) { + // cppcheck-suppress + return leftSide.requestReleaseTime < rightSide.requestReleaseTime; + }); } /** @@ -121,7 +122,6 @@ private: */ friend struct ::unit_test::Tester; - public: /** * @brief Class constructor @@ -135,7 +135,7 @@ public: * @details Enables the time-based command execution scheduling * @param request Provide the received message as a parameter */ - void enableScheduleExecution(Message &request); + void enableScheduleExecution(Message& request); /** * @breif TC[11,2] disable the time-based schedule execution function @@ -143,7 +143,7 @@ public: * @details Disables the time-based command execution scheduling * @param request Provide the received message as a parameter */ - void disableScheduleExecution(Message &request); + void disableScheduleExecution(Message& request); /** * @brief TC[11,3] reset the time-based schedule @@ -152,7 +152,7 @@ public: * activities. * @param request Provide the received message as a parameter */ - void resetSchedule(Message &request); + void resetSchedule(Message& request); /** * @brief TC[11,4] insert activities into the time based schedule @@ -169,7 +169,7 @@ public: * request is less than a set time margin, defined in @ref ECSS_TIME_MARGIN_FOR_ACTIVATION, * from the current time a @ref ErrorHandler::ExecutionStartErrorType is also issued. */ - void insertActivities(Message &request); + void insertActivities(Message& request); /** * @brief TC[11,15] time-shift all scheduled activities @@ -182,7 +182,7 @@ public: * set time margin, defined in @ref ECSS_TIME_MARGIN_FOR_ACTIVATION, from the current time an * @ref ErrorHandler::ExecutionStartErrorType report is issued for that instruction. */ - void timeShiftAllActivities(Message &request); + void timeShiftAllActivities(Message& request); /** * @brief TC[11,16] detail-report all activities @@ -192,7 +192,7 @@ public: * @param request Provide the received message as a parameter * @todo Replace the time parsing with the time parser */ - void detailReportAllActivities(Message &request); + void detailReportAllActivities(Message& request); /** * @brief TC[11,9] detail-report activities identified by request identifier @@ -206,7 +206,7 @@ public: * request identifier is not found in the schedule issue an @ref * ErrorHandler::ExecutionStartErrorType for that instruction. */ - void detailReportActivitiesByID(Message &request); + void detailReportActivitiesByID(Message& request); /** * @brief TC[11,12] summary-report activities identified by request identifier @@ -219,7 +219,7 @@ public: * request identifier is not found in the schedule issue an @ref * ErrorHandler::ExecutionStartErrorType for that instruction. */ - void summaryReportActivitiesByID(Message &request); + void summaryReportActivitiesByID(Message& request); /** * @brief TC[11,5] delete time-based scheduled activities identified by a request identifier @@ -230,7 +230,7 @@ public: * request identifier is not found in the schedule issue an @ref * ErrorHandler::ExecutionStartErrorType for that instruction. */ - void deleteActivitiesByID(Message &request); + void deleteActivitiesByID(Message& request); /** * @brief TC[11,7] time-shift scheduled activities identified by a request identifier @@ -256,4 +256,4 @@ public: void execute(Message& message); }; -#endif //ECSS_SERVICES_TIMEBASEDSCHEDULINGSERVICE_HPP +#endif // ECSS_SERVICES_TIMEBASEDSCHEDULINGSERVICE_HPP diff --git a/inc/Services/TimeManagementService.hpp b/inc/Services/TimeManagementService.hpp index 5812de3763c76234d27725e114376296468c90f9..4b6663c172208f52dc8201f7187e7da510a159da 100644 --- a/inc/Services/TimeManagementService.hpp +++ b/inc/Services/TimeManagementService.hpp @@ -1,7 +1,6 @@ #ifndef ECSS_SERVICES_TIMEMANAGEMENTSERVICE_HPP #define ECSS_SERVICES_TIMEMANAGEMENTSERVICE_HPP - #include <Service.hpp> #include "Helpers/TimeHelper.hpp" @@ -48,7 +47,7 @@ public: * or should ignore the standard? */ - void cdsTimeReport(TimeAndDate &TimeInfo); + void cdsTimeReport(TimeAndDate& TimeInfo); /** * TC[9,128] CDS time request. @@ -73,5 +72,4 @@ public: void execute(Message& message); }; - -#endif //ECSS_SERVICES_TIMEMANAGEMENTSERVICE_HPP +#endif // ECSS_SERVICES_TIMEMANAGEMENTSERVICE_HPP diff --git a/inc/etl/String.hpp b/inc/etl/String.hpp index f9198df199888453fa690067020528ce9c2d1a36..11c04b6747c6c12e211fb5bdd30ba498169c07f6 100644 --- a/inc/etl/String.hpp +++ b/inc/etl/String.hpp @@ -32,9 +32,8 @@ public: * * @param data The array of uint8_t data */ - String(const uint8_t * data) // NOLINTNEXTLINE(google-explicit-constructor) - : etl::string<MAX_SIZE>(reinterpret_cast<const char*>(data), MAX_SIZE) { - } + String(const uint8_t* data) // NOLINTNEXTLINE(google-explicit-constructor) + : etl::string<MAX_SIZE>(reinterpret_cast<const char*>(data), MAX_SIZE) {} /** * String constructor from a uint8_t array @@ -44,9 +43,7 @@ public: * @param data The array of uint8_t data * @param count The number of bytes to include */ - String(const uint8_t * data, size_t count) - : etl::string<MAX_SIZE>(reinterpret_cast<const char*>(data), count) { - } + String(const uint8_t* data, size_t count) : etl::string<MAX_SIZE>(reinterpret_cast<const char*>(data), count) {} /** * Declaration of the constructor from const char*s that calls the parent constructor @@ -58,10 +55,7 @@ public: * */ String(const char* text) // NOLINTNEXTLINE(google-explicit-constructor) - : etl::string<MAX_SIZE>(text) - { - } + : etl::string<MAX_SIZE>(text) {} }; - -#endif //ECSS_SERVICES_ETL_STRING_HPP +#endif // ECSS_SERVICES_ETL_STRING_HPP diff --git a/inc/etl_profile.h b/inc/etl_profile.h index 1b6ad5c151a4b1b7357796ca01fc75a2a1fc2a87..14e6e6b8ff6105ce7d593d65e404171340b27107 100644 --- a/inc/etl_profile.h +++ b/inc/etl_profile.h @@ -12,4 +12,4 @@ // Only GCC is used as a compiler #include "etl/profiles/gcc_linux_x86.h" -#endif //ECSS_SERVICES_ETL_PROFILE_H +#endif // ECSS_SERVICES_ETL_PROFILE_H diff --git a/inc/macros.hpp b/inc/macros.hpp index f5205be237b3768b4791b0e7f47ff256b968970d..12cce6c0072f87f7b2a1d9c368dcca2f10aa8da5 100644 --- a/inc/macros.hpp +++ b/inc/macros.hpp @@ -15,4 +15,4 @@ */ #define ASSERT_REQUEST(cond, error) (ErrorHandler::assertRequest((cond), *this, (error))) -#endif //ECSS_SERVICES_MACROS_HPP +#endif // ECSS_SERVICES_MACROS_HPP diff --git a/src/ErrorHandler.cpp b/src/ErrorHandler.cpp index a2f20e7703087577a6b9c1818d75e7618cced2cf..1cba15ca835dca1022adb68c032bb6912592dd8f 100644 --- a/src/ErrorHandler.cpp +++ b/src/ErrorHandler.cpp @@ -4,37 +4,35 @@ #include <ServicePool.hpp> #include "Services/RequestVerificationService.hpp" - -template<> -void ErrorHandler::reportError(const Message &message, AcceptanceErrorType errorCode) { +template <> +void ErrorHandler::reportError(const Message& message, AcceptanceErrorType errorCode) { Services.requestVerification.failAcceptanceVerification(message, errorCode); logError(message, errorCode); } -template<> -void ErrorHandler::reportError(const Message &message, ExecutionStartErrorType errorCode) { +template <> +void ErrorHandler::reportError(const Message& message, ExecutionStartErrorType errorCode) { Services.requestVerification.failStartExecutionVerification(message, errorCode); logError(message, errorCode); } -void ErrorHandler::reportProgressError(const Message &message, ExecutionProgressErrorType -errorCode, uint8_t stepID) { +void ErrorHandler::reportProgressError(const Message& message, ExecutionProgressErrorType errorCode, uint8_t stepID) { Services.requestVerification.failProgressExecutionVerification(message, errorCode, stepID); logError(message, errorCode); } -template<> -void ErrorHandler::reportError(const Message &message, ExecutionCompletionErrorType errorCode) { +template <> +void ErrorHandler::reportError(const Message& message, ExecutionCompletionErrorType errorCode) { Services.requestVerification.failCompletionExecutionVerification(message, errorCode); logError(message, errorCode); } -template<> -void ErrorHandler::reportError(const Message &message, RoutingErrorType errorCode) { +template <> +void ErrorHandler::reportError(const Message& message, RoutingErrorType errorCode) { Services.requestVerification.failRoutingVerification(message, errorCode); logError(message, errorCode); diff --git a/src/Helpers/CRCHelper.cpp b/src/Helpers/CRCHelper.cpp index 8361455071673204dcaa88ab4c3f136615127fdf..dda87aa34d4a7be7c539ab5642ee48cc81fc6f71 100644 --- a/src/Helpers/CRCHelper.cpp +++ b/src/Helpers/CRCHelper.cpp @@ -15,11 +15,10 @@ uint16_t CRCHelper::calculateCRC(const uint8_t* message, uint32_t length) { for (int j = 0; j < 8; j++) { // if the MSB is set, the bitwise AND gives 1 - if ((shiftReg & 0x8000u) != 0) { + if ((shiftReg & 0x8000u) != 0u) { // toss out of the register the MSB and divide (XOR) its content with the generator shiftReg = ((shiftReg << 1u) ^ polynomial); - } - else { + } else { // just toss out the MSB and make room for a new bit shiftReg <<= 1u; } @@ -28,7 +27,7 @@ uint16_t CRCHelper::calculateCRC(const uint8_t* message, uint32_t length) { return shiftReg; } -uint16_t CRCHelper::validateCRC(const uint8_t *message, uint32_t length) { +uint16_t CRCHelper::validateCRC(const uint8_t* message, uint32_t length) { return calculateCRC(message, length); // CRC result of a correct msg w/checksum appended is 0 } diff --git a/src/Helpers/TimeAndDate.cpp b/src/Helpers/TimeAndDate.cpp index 38280ecb745925f3ce989ad3547b9379bb888f67..b531d2274ce3917f79e865fd63d20c7e5d85c602 100644 --- a/src/Helpers/TimeAndDate.cpp +++ b/src/Helpers/TimeAndDate.cpp @@ -1,6 +1,5 @@ #include "Helpers/TimeHelper.hpp" - TimeAndDate::TimeAndDate() { // Unix epoch 1/1/1970 year = 1970; @@ -11,15 +10,14 @@ TimeAndDate::TimeAndDate() { second = 0; } -TimeAndDate::TimeAndDate(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, - uint8_t second) { +TimeAndDate::TimeAndDate(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) { // check if the parameters make sense ASSERT_INTERNAL(2019 <= year, ErrorHandler::InternalErrorType::InvalidDate); - ASSERT_INTERNAL(1 <= month && month <= 12, ErrorHandler::InternalErrorType::InvalidDate); - ASSERT_INTERNAL(1 <= day && day <= 31, ErrorHandler::InternalErrorType::InvalidDate); - ASSERT_INTERNAL(0 <= hour && hour <= 24, ErrorHandler::InternalErrorType::InvalidDate); - ASSERT_INTERNAL(0 <= minute && minute <= 60, ErrorHandler::InternalErrorType::InvalidDate); - ASSERT_INTERNAL(0 <= second && second <= 60, ErrorHandler::InternalErrorType::InvalidDate); + ASSERT_INTERNAL((1 <= month) && (month <= 12), ErrorHandler::InternalErrorType::InvalidDate); + ASSERT_INTERNAL((1 <= day) && (day <= 31), ErrorHandler::InternalErrorType::InvalidDate); + ASSERT_INTERNAL(hour <= 24, ErrorHandler::InternalErrorType::InvalidDate); + ASSERT_INTERNAL(minute <= 60, ErrorHandler::InternalErrorType::InvalidDate); + ASSERT_INTERNAL(second <= 60, ErrorHandler::InternalErrorType::InvalidDate); this->year = year; this->month = month; @@ -29,7 +27,7 @@ TimeAndDate::TimeAndDate(uint16_t year, uint8_t month, uint8_t day, uint8_t hour this->second = second; } -bool TimeAndDate::operator<(const TimeAndDate &Date) { +bool TimeAndDate::operator<(const TimeAndDate& Date) { // compare years if (this->year < Date.year) { return true; @@ -78,7 +76,7 @@ bool TimeAndDate::operator<(const TimeAndDate &Date) { return false; } -bool TimeAndDate::operator>(const TimeAndDate &Date) { +bool TimeAndDate::operator>(const TimeAndDate& Date) { // compare years if (this->year > Date.year) { return true; @@ -127,7 +125,7 @@ bool TimeAndDate::operator>(const TimeAndDate &Date) { return false; } -bool TimeAndDate::operator==(const TimeAndDate &Date) { +bool TimeAndDate::operator==(const TimeAndDate& Date) { // compare years if (this->year != Date.year) { return false; @@ -161,11 +159,10 @@ bool TimeAndDate::operator==(const TimeAndDate &Date) { return true; } - -bool TimeAndDate::operator<=(const TimeAndDate &Date) { - return (*this < Date || *this == Date); +bool TimeAndDate::operator<=(const TimeAndDate& Date) { + return ((*this < Date) || (*this == Date)); } -bool TimeAndDate::operator>=(const TimeAndDate &Date) { - return (*this > Date || *this == Date); +bool TimeAndDate::operator>=(const TimeAndDate& Date) { + return ((*this > Date) || (*this == Date)); } diff --git a/src/Helpers/TimeHelper.cpp b/src/Helpers/TimeHelper.cpp index 4b6885dc9b842ade6bb33fd0c5a09270b4df11e4..a42349001cf6cd005bc79f5769b9c539cc98f2f3 100644 --- a/src/Helpers/TimeHelper.cpp +++ b/src/Helpers/TimeHelper.cpp @@ -1,37 +1,32 @@ #include "Helpers/TimeHelper.hpp" bool TimeHelper::IsLeapYear(uint16_t year) { - if (year % 4 != 0) { + if ((year % 4) != 0) { return false; } - if (year % 100 != 0) { + if ((year % 100) != 0) { return true; } return (year % 400) == 0; } -uint32_t TimeHelper::utcToSeconds(TimeAndDate &TimeInfo) { +uint32_t TimeHelper::utcToSeconds(TimeAndDate& TimeInfo) { // the date, that \p TimeInfo represents, should be greater than or equal to 1/1/2019 and the // date should be valid according to Gregorian calendar ASSERT_INTERNAL(TimeInfo.year >= 2019, ErrorHandler::InternalErrorType::InvalidDate); - ASSERT_INTERNAL(1 <= TimeInfo.month && TimeInfo.month <= 12, - ErrorHandler::InternalErrorType::InvalidDate); - ASSERT_INTERNAL(1 <= TimeInfo.day && TimeInfo.day <= 31, - ErrorHandler::InternalErrorType::InvalidDate); - ASSERT_INTERNAL(0 <= TimeInfo.hour && TimeInfo.hour <= 24, - ErrorHandler::InternalErrorType::InvalidDate); - ASSERT_INTERNAL(0 <= TimeInfo.minute && TimeInfo.minute <= 60, - ErrorHandler::InternalErrorType::InvalidDate); - ASSERT_INTERNAL(0 <= TimeInfo.second && TimeInfo.second <= 60, - ErrorHandler::InternalErrorType::InvalidDate); + ASSERT_INTERNAL((1 <= TimeInfo.month) && (TimeInfo.month <= 12), ErrorHandler::InternalErrorType::InvalidDate); + ASSERT_INTERNAL((1 <= TimeInfo.day) && (TimeInfo.day <= 31), ErrorHandler::InternalErrorType::InvalidDate); + ASSERT_INTERNAL(TimeInfo.hour <= 24, ErrorHandler::InternalErrorType::InvalidDate); + ASSERT_INTERNAL(TimeInfo.minute <= 60, ErrorHandler::InternalErrorType::InvalidDate); + ASSERT_INTERNAL(TimeInfo.second <= 60, ErrorHandler::InternalErrorType::InvalidDate); uint32_t secs = 1546300800; // elapsed seconds from Unix epoch until 1/1/2019 00:00:00 (UTC) for (uint16_t y = 2019; y < TimeInfo.year; ++y) { secs += (IsLeapYear(y) ? 366 : 365) * SECONDS_PER_DAY; } for (uint16_t m = 1; m < TimeInfo.month; ++m) { - secs += DaysOfMonth[m - 1] * SECONDS_PER_DAY; - if (m == 2 && IsLeapYear(TimeInfo.year)) { + secs += DaysOfMonth[m - 1u] * SECONDS_PER_DAY; + if ((m == 2u) && IsLeapYear(TimeInfo.year)) { secs += SECONDS_PER_DAY; } } @@ -67,7 +62,7 @@ struct TimeAndDate TimeHelper::secondsToUTC(uint32_t seconds) { TimeInfo.month++; seconds -= (DaysOfMonth[i] * SECONDS_PER_DAY); i++; - if (i == 1 && IsLeapYear(TimeInfo.year)) { + if ((i == 1u) && IsLeapYear(TimeInfo.year)) { if (seconds <= (28 * SECONDS_PER_DAY)) { break; } @@ -96,7 +91,7 @@ struct TimeAndDate TimeHelper::secondsToUTC(uint32_t seconds) { return TimeInfo; } -uint64_t TimeHelper::generateCDStimeFormat(TimeAndDate &TimeInfo) { +uint64_t TimeHelper::generateCDStimeFormat(TimeAndDate& TimeInfo) { /** * Define the T-field. The total number of octets for the implementation of T-field is 6(2 for * the `DAY` and 4 for the `ms of day` @@ -114,22 +109,19 @@ uint64_t TimeHelper::generateCDStimeFormat(TimeAndDate &TimeInfo) { * The `ms of day` segment, 32 bits as defined in standard. The `ms of the day` and DAY` * should give the time passed since Unix epoch */ - auto msOfDay = static_cast<uint32_t >((seconds % SECONDS_PER_DAY) * 1000); + auto msOfDay = static_cast<uint32_t>((seconds % SECONDS_PER_DAY) * 1000); - uint64_t timeFormat = (static_cast<uint64_t>(elapsedDays) << 32 | msOfDay); + uint64_t timeFormat = (static_cast<uint64_t>(elapsedDays) << 32) | msOfDay; return timeFormat; } -TimeAndDate TimeHelper::parseCDStimeFormat(const uint8_t *data) { - uint16_t elapsedDays = (static_cast<uint16_t >(data[0])) << 8 | static_cast<uint16_t > - (data[1]); - uint32_t msOfDay = (static_cast<uint32_t >(data[2])) << 24 | - (static_cast<uint32_t >(data[3])) << 16 | - (static_cast<uint32_t >(data[4])) << 8 | - static_cast<uint32_t >(data[5]); +TimeAndDate TimeHelper::parseCDStimeFormat(const uint8_t* data) { + uint16_t elapsedDays = ((static_cast<uint16_t>(data[0])) << 8) | (static_cast<uint16_t>(data[1])); + uint32_t msOfDay = ((static_cast<uint32_t>(data[2])) << 24) | ((static_cast<uint32_t>(data[3]))) << 16 | + ((static_cast<uint32_t>(data[4]))) << 8 | (static_cast<uint32_t>(data[5])); - uint32_t seconds = elapsedDays * SECONDS_PER_DAY + msOfDay / 1000; + uint32_t seconds = (elapsedDays * SECONDS_PER_DAY) + (msOfDay / 1000u); return secondsToUTC(seconds); } diff --git a/src/Message.cpp b/src/Message.cpp index 0127ecf679d0bdf93600413653eea9878f20690e..a969e6ff432d6063787fc83211c5109d72688fc9 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -3,10 +3,8 @@ #include <cstring> #include <ErrorHandler.hpp> - -Message::Message(uint8_t serviceType, uint8_t messageType, Message::PacketType packetType, - uint16_t applicationId) : serviceType(serviceType), messageType(messageType), - packetType(packetType), applicationId(applicationId) {} +Message::Message(uint8_t serviceType, uint8_t messageType, Message::PacketType packetType, uint16_t applicationId) + : serviceType(serviceType), messageType(messageType), packetType(packetType), applicationId(applicationId) {} void Message::appendBits(uint8_t numBits, uint16_t data) { // TODO: Add assertion that data does not contain 1s outside of numBits bits @@ -15,7 +13,7 @@ void Message::appendBits(uint8_t numBits, uint16_t data) { while (numBits > 0) { // For every sequence of 8 bits... ASSERT_INTERNAL(dataSize < ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge); - if (currentBit + numBits >= 8) { + if ((currentBit + numBits) >= 8) { // Will have to shift the bits and insert the next ones later auto bitsToAddNow = static_cast<uint8_t>(8 - currentBit); @@ -54,7 +52,7 @@ void Message::appendByte(uint8_t value) { } void Message::appendHalfword(uint16_t value) { - ASSERT_INTERNAL(dataSize + 2 <= ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge); + ASSERT_INTERNAL((dataSize + 2) <= ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge); ASSERT_INTERNAL(currentBit == 0, ErrorHandler::ByteBetweenBits); data[dataSize] = static_cast<uint8_t>((value >> 8) & 0xFF); @@ -64,7 +62,7 @@ void Message::appendHalfword(uint16_t value) { } void Message::appendWord(uint32_t value) { - ASSERT_INTERNAL(dataSize + 4 <= ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge); + ASSERT_INTERNAL((dataSize + 4) <= ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge); ASSERT_INTERNAL(currentBit == 0, ErrorHandler::ByteBetweenBits); data[dataSize] = static_cast<uint8_t>((value >> 24) & 0xFF); @@ -83,10 +81,11 @@ uint16_t Message::readBits(uint8_t numBits) { while (numBits > 0) { ASSERT_REQUEST(readPosition < ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooShort); - if (currentBit + numBits >= 8) { + if ((currentBit + numBits) >= 8) { auto bitsToAddNow = static_cast<uint8_t>(8 - currentBit); - auto maskedData = static_cast<uint8_t>(data[readPosition] & ((1 << bitsToAddNow) - 1)); + uint8_t mask = ((1u << bitsToAddNow) - 1u); + uint8_t maskedData = data[readPosition] & mask; value |= maskedData << (numBits - bitsToAddNow); numBits -= bitsToAddNow; @@ -112,7 +111,7 @@ uint8_t Message::readByte() { } uint16_t Message::readHalfword() { - ASSERT_REQUEST(readPosition + 2 <= ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooShort); + ASSERT_REQUEST((readPosition + 2) <= ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooShort); uint16_t value = (data[readPosition] << 8) | data[readPosition + 1]; readPosition += 2; @@ -121,17 +120,17 @@ uint16_t Message::readHalfword() { } uint32_t Message::readWord() { - ASSERT_REQUEST(readPosition + 4 <= ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooShort); + ASSERT_REQUEST((readPosition + 4) <= ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooShort); - uint32_t value = (data[readPosition] << 24) | (data[readPosition + 1] << 16) | - (data[readPosition + 2] << 8) | data[readPosition + 3]; + uint32_t value = (data[readPosition] << 24) | (data[readPosition + 1] << 16) | (data[readPosition + 2] << 8) | + data[readPosition + 3]; readPosition += 4; return value; } -void Message::readString(char *string, uint8_t size) { - ASSERT_REQUEST(readPosition + size <= ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooShort); +void Message::readString(char* string, uint8_t size) { + ASSERT_REQUEST((readPosition + size) <= ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooShort); ASSERT_REQUEST(size < ECSS_MAX_STRING_SIZE, ErrorHandler::StringTooShort); memcpy(string, data + readPosition, size); @@ -140,8 +139,8 @@ void Message::readString(char *string, uint8_t size) { readPosition += size; } -void Message::readString(uint8_t *string, uint16_t size) { - ASSERT_REQUEST(readPosition + size <= ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooShort); +void Message::readString(uint8_t* string, uint16_t size) { + ASSERT_REQUEST((readPosition + size) <= ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooShort); ASSERT_REQUEST(size < ECSS_MAX_STRING_SIZE, ErrorHandler::StringTooShort); memcpy(string, data + readPosition, size); diff --git a/src/MessageParser.cpp b/src/MessageParser.cpp index 7f173c068b61d6b21d0b57958a9ba483397f7f46..f0cbe00f9f804a762c6eda04f9fcf25b5f32ebdf 100644 --- a/src/MessageParser.cpp +++ b/src/MessageParser.cpp @@ -37,7 +37,7 @@ void MessageParser::execute(Message& message) { } } -Message MessageParser::parse(uint8_t *data, uint32_t length) { +Message MessageParser::parse(uint8_t* data, uint32_t length) { ASSERT_INTERNAL(length >= 6, ErrorHandler::UnacceptablePacket); uint16_t packetHeaderIdentification = (data[0] << 8) | data[1]; @@ -52,10 +52,10 @@ Message MessageParser::parse(uint8_t *data, uint32_t length) { auto sequenceFlags = static_cast<uint8_t>(packetSequenceControl >> 14); // Returning an internal error, since the Message is not available yet - ASSERT_INTERNAL(versionNumber == 0, ErrorHandler::UnacceptablePacket); - ASSERT_INTERNAL(secondaryHeaderFlag == 1, ErrorHandler::UnacceptablePacket); - ASSERT_INTERNAL(sequenceFlags == 0x3, ErrorHandler::UnacceptablePacket); - ASSERT_INTERNAL(packetDataLength == length - 6, ErrorHandler::UnacceptablePacket); + ASSERT_INTERNAL(versionNumber == 0u, ErrorHandler::UnacceptablePacket); + ASSERT_INTERNAL(secondaryHeaderFlag == 1u, ErrorHandler::UnacceptablePacket); + ASSERT_INTERNAL(sequenceFlags == 0x3u, ErrorHandler::UnacceptablePacket); + ASSERT_INTERNAL(packetDataLength == (length - 6u), ErrorHandler::UnacceptablePacket); Message message(0, 0, packetType, APID); @@ -68,7 +68,7 @@ Message MessageParser::parse(uint8_t *data, uint32_t length) { return message; } -void MessageParser::parseTC(const uint8_t *data, uint16_t length, Message &message) { +void MessageParser::parseTC(const uint8_t* data, uint16_t length, Message& message) { ErrorHandler::assertRequest(length >= 5, message, ErrorHandler::UnacceptableMessage); // Individual fields of the TC header @@ -78,7 +78,7 @@ void MessageParser::parseTC(const uint8_t *data, uint16_t length, Message &messa // todo: Fix this parsing function, because it assumes PUS header in data, which is not true // with the current implementation - ErrorHandler::assertRequest(pusVersion == 2, message, ErrorHandler::UnacceptableMessage); + ErrorHandler::assertRequest(pusVersion == 2u, message, ErrorHandler::UnacceptableMessage); // Remove the length of the header length -= 5; @@ -93,7 +93,7 @@ void MessageParser::parseTC(const uint8_t *data, uint16_t length, Message &messa Message MessageParser::parseRequestTC(String<ECSS_TC_REQUEST_STRING_SIZE> data) { Message message; - auto *dataInt = reinterpret_cast<uint8_t *>(data.data()); + auto* dataInt = reinterpret_cast<uint8_t*>(data.data()); message.packetType = Message::TC; parseTC(dataInt, ECSS_TC_REQUEST_STRING_SIZE, message); return message; @@ -106,7 +106,7 @@ Message MessageParser::parseRequestTC(uint8_t* data) { return message; } -String<ECSS_TC_REQUEST_STRING_SIZE> MessageParser::convertTCToStr(Message &message) { +String<ECSS_TC_REQUEST_STRING_SIZE> MessageParser::convertTCToStr(Message& message) { uint8_t tempString[ECSS_TC_REQUEST_STRING_SIZE] = {0}; tempString[0] = ECSS_PUS_VERSION << 4; // Assign the pusVersion = 2 @@ -118,7 +118,7 @@ String<ECSS_TC_REQUEST_STRING_SIZE> MessageParser::convertTCToStr(Message &messa return dataString; } -void MessageParser::parseTM(const uint8_t *data, uint16_t length, Message &message) { +void MessageParser::parseTM(const uint8_t* data, uint16_t length, Message& message) { ErrorHandler::assertRequest(length >= 5, message, ErrorHandler::UnacceptableMessage); // Individual fields of the TM header @@ -126,7 +126,7 @@ void MessageParser::parseTM(const uint8_t *data, uint16_t length, Message &messa uint8_t serviceType = data[1]; uint8_t messageType = data[2]; - ErrorHandler::assertRequest(pusVersion == 2, message, ErrorHandler::UnacceptableMessage); + ErrorHandler::assertRequest(pusVersion == 2u, message, ErrorHandler::UnacceptableMessage); // Remove the length of the header length -= 5; diff --git a/src/Platform/x86/ErrorHandler.cpp b/src/Platform/x86/ErrorHandler.cpp index 6119440cc09527624c64a4adc517e7d6c551e7ee..a59e36514ddf1a7047ab4e2e2a47f05dfd4cfd89 100644 --- a/src/Platform/x86/ErrorHandler.cpp +++ b/src/Platform/x86/ErrorHandler.cpp @@ -9,32 +9,32 @@ #include <Message.hpp> // TODO: Find a way to reduce the number of copies of this chunk -template void ErrorHandler::logError(const Message &, ErrorHandler::AcceptanceErrorType); -template void ErrorHandler::logError(const Message &, ErrorHandler::ExecutionStartErrorType); -template void ErrorHandler::logError(const Message &, ErrorHandler::ExecutionProgressErrorType); -template void ErrorHandler::logError(const Message &, ErrorHandler::ExecutionCompletionErrorType); -template void ErrorHandler::logError(const Message &, ErrorHandler::RoutingErrorType); +template void ErrorHandler::logError(const Message&, ErrorHandler::AcceptanceErrorType); +template void ErrorHandler::logError(const Message&, ErrorHandler::ExecutionStartErrorType); +template void ErrorHandler::logError(const Message&, ErrorHandler::ExecutionProgressErrorType); +template void ErrorHandler::logError(const Message&, ErrorHandler::ExecutionCompletionErrorType); +template void ErrorHandler::logError(const Message&, ErrorHandler::RoutingErrorType); template void ErrorHandler::logError(ErrorHandler::InternalErrorType); -template<typename ErrorType> -void ErrorHandler::logError(const Message &message, ErrorType errorType) { +template <typename ErrorType> +void ErrorHandler::logError(const Message& message, ErrorType errorType) { std::cerr - /* - * Gets the error class name from the template - * Note: This is g++-dependent code and should only be used for debugging. - */ - << abi::__cxa_demangle(typeid(ErrorType).name(), nullptr, nullptr, nullptr) - << " Error " << "[" << static_cast<uint16_t>(message.serviceType) << "," << - static_cast<uint16_t>(message.messageType) << "]: " << errorType << std::endl; + /* + * Gets the error class name from the template + * Note: This is g++-dependent code and should only be used for debugging. + */ + << abi::__cxa_demangle(typeid(ErrorType).name(), nullptr, nullptr, nullptr) << " Error " + << "[" << static_cast<uint16_t>(message.serviceType) << "," << static_cast<uint16_t>(message.messageType) + << "]: " << errorType << std::endl; } -template<typename ErrorType> +template <typename ErrorType> void ErrorHandler::logError(ErrorType errorType) { std::cerr - /* - * Gets the error class name from the template - * Note: This is g++-dependent code and should only be used for debugging. - */ - << abi::__cxa_demangle(typeid(ErrorType).name(), nullptr, nullptr, nullptr) - << " Error: " << errorType << std::endl; + /* + * Gets the error class name from the template + * Note: This is g++-dependent code and should only be used for debugging. + */ + << abi::__cxa_demangle(typeid(ErrorType).name(), nullptr, nullptr, nullptr) << " Error: " << errorType + << std::endl; } diff --git a/src/Platform/x86/Service.cpp b/src/Platform/x86/Service.cpp index 6a251f27d1d3a70713833baa949bdcc5a787ec0d..7c20d2f90bea925cd43754c62a231c25bc2c5648 100644 --- a/src/Platform/x86/Service.cpp +++ b/src/Platform/x86/Service.cpp @@ -2,7 +2,7 @@ #include <iomanip> #include "Service.hpp" -void Service::storeMessage(Message &message) { +void Service::storeMessage(Message& message) { // appends the remaining bits to complete a byte message.finalize(); @@ -10,9 +10,9 @@ void Service::storeMessage(Message &message) { std::cout << "New " << ((message.packetType == Message::TM) ? "TM" : "TC") << "[" << std::hex // << std::dec - << static_cast<int>(message.serviceType) << "," - << static_cast<int>(message.messageType) << "] message!\n"; - //std::cout << std::hex << std::setfill('0') << std::setw(2); + << static_cast<int>(message.serviceType) << "," << static_cast<int>(message.messageType) + << "] message!\n"; + // std::cout << std::hex << std::setfill('0') << std::setw(2); for (int i = 0; i < message.dataSize; i++) { std::cout << static_cast<int>(message.data[i]); std::cout << " "; diff --git a/src/Service.cpp b/src/Service.cpp index 66fdd045bb9f777cea939f8c32fb344a995263a5..559315bd7ed54f3840139c3303b3b65eccb71e25 100644 --- a/src/Service.cpp +++ b/src/Service.cpp @@ -1 +1,3 @@ #include "Service.hpp" + +// Nothing exists here yet diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index 450003a26f4af60b00ea0e49405e6a0b3645f227..8844e69581f3f4a59513723d6f98a6d9fb7ccc16 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -15,14 +15,14 @@ void EventActionService::addEventActionDefinitions(Message message) { uint16_t eventDefinitionID = message.readEnum16(); bool accepted = true; for (index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { - if (eventActionDefinitionArray[index].applicationId == applicationID && - eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID && + if ((eventActionDefinitionArray[index].applicationId == applicationID) && + (eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) && eventActionDefinitionArray[index].enabled) { // @todo: throw a failed start of execution error accepted = false; } } - if (accepted){ + 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) { @@ -34,13 +34,12 @@ void EventActionService::addEventActionDefinitions(Message message) { eventActionDefinitionArray[index].enabled = true; eventActionDefinitionArray[index].applicationId = applicationID; eventActionDefinitionArray[index].eventDefinitionID = eventDefinitionID; - if (message.dataSize - 4 > ECSS_TC_REQUEST_STRING_SIZE) { + if ((message.dataSize - 4) > ECSS_TC_REQUEST_STRING_SIZE) { ErrorHandler::reportInternalError(ErrorHandler::InternalErrorType::MessageTooLarge); } else { char data[ECSS_TC_REQUEST_STRING_SIZE]; message.readString(data, message.dataSize - 4); - eventActionDefinitionArray[index].request = String<ECSS_TC_REQUEST_STRING_SIZE>( - data); + eventActionDefinitionArray[index].request = String<ECSS_TC_REQUEST_STRING_SIZE>(data); } } } @@ -54,8 +53,8 @@ void EventActionService::deleteEventActionDefinitions(Message message) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { - if (eventActionDefinitionArray[index].applicationId == applicationID && - eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID && + if ((eventActionDefinitionArray[index].applicationId == applicationID) && + (eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) && eventActionDefinitionArray[index].enabled) { eventActionDefinitionArray[index].empty = true; eventActionDefinitionArray[index].eventDefinitionID = 65535; @@ -88,20 +87,20 @@ void EventActionService::enableEventActionDefinitions(Message message) { message.assertTC(19, 4); uint16_t numberOfEventActionDefinitions = message.readUint16(); - if (numberOfEventActionDefinitions != 0){ + if (numberOfEventActionDefinitions != 0u) { for (uint16_t i = 0; i < numberOfEventActionDefinitions; i++) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { - if (eventActionDefinitionArray[index].applicationId == applicationID && - eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) { + if ((eventActionDefinitionArray[index].applicationId == applicationID) && + (eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID)) { eventActionDefinitionArray[index].enabled = true; } } } } else { for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { - if (not eventActionDefinitionArray[index].empty){ + if (not eventActionDefinitionArray[index].empty) { eventActionDefinitionArray[index].enabled = true; } } @@ -113,20 +112,20 @@ void EventActionService::disableEventActionDefinitions(Message message) { message.assertTC(19, 5); uint16_t numberOfEventActionDefinitions = message.readUint16(); - if (numberOfEventActionDefinitions != 0){ + if (numberOfEventActionDefinitions != 0u) { for (uint16_t i = 0; i < numberOfEventActionDefinitions; i++) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { - if (eventActionDefinitionArray[index].applicationId == applicationID && - eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) { + if ((eventActionDefinitionArray[index].applicationId == applicationID) && + (eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID)) { eventActionDefinitionArray[index].enabled = false; } } } } else { for (uint16_t index = 0; index < ECSS_EVENT_ACTION_STRUCT_ARRAY_SIZE; index++) { - if (not eventActionDefinitionArray[index].empty){ + if (not eventActionDefinitionArray[index].empty) { eventActionDefinitionArray[index].enabled = false; } } @@ -150,7 +149,7 @@ void EventActionService::eventActionStatusReport() { } } report.appendUint8(count); - for (const auto &definition : eventActionDefinitionArray) { + for (const auto& definition : eventActionDefinitionArray) { if (not definition.empty) { report.appendEnum16(definition.applicationId); report.appendEnum16(definition.eventDefinitionID); @@ -178,9 +177,8 @@ void EventActionService::disableEventActionFunction(Message message) { void EventActionService::executeAction(uint16_t eventID) { // Custom function if (eventActionFunctionStatus) { - for (const auto &definition : eventActionDefinitionArray) { - if (not definition.empty && - definition.enabled) { + for (const auto& definition : eventActionDefinitionArray) { + if (not definition.empty && definition.enabled) { if (definition.eventDefinitionID == eventID) { MessageParser messageParser; Message message = messageParser.parseRequestTC( diff --git a/src/Services/EventReportService.cpp b/src/Services/EventReportService.cpp index ae2888e2587a5654207e90b0bffe960451d54696..3e3a24fee74cee32028ab21391c53cbb63d5391e 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, const String<64> & data) { +void EventReportService::informativeEventReport(Event eventID, const String<64>& data) { // TM[5,1] - if (stateOfEvents[static_cast<uint16_t> (eventID)]) { + if (stateOfEvents[static_cast<uint16_t>(eventID)]) { Message report = createTM(1); report.appendEnum16(eventID); report.appendString(data); @@ -19,16 +19,15 @@ void EventReportService::informativeEventReport(Event eventID, const String<64> } } -void -EventReportService::lowSeverityAnomalyReport(Event eventID, const String<64> & data) { +void EventReportService::lowSeverityAnomalyReport(Event eventID, const String<64>& data) { lowSeverityEventCount++; // TM[5,2] - if (stateOfEvents[static_cast<uint16_t> (eventID)]) { + if (stateOfEvents[static_cast<uint16_t>(eventID)]) { lowSeverityReportCount++; Message report = createTM(2); report.appendEnum16(eventID); report.appendString(data); - lastLowSeverityReportID = static_cast<uint16_t >(eventID); + lastLowSeverityReportID = static_cast<uint16_t>(eventID); storeMessage(report); EventActionService eventActionService; @@ -36,15 +35,15 @@ EventReportService::lowSeverityAnomalyReport(Event eventID, const String<64> & d } } -void EventReportService::mediumSeverityAnomalyReport(Event eventID, const String<64> & data) { +void EventReportService::mediumSeverityAnomalyReport(Event eventID, const String<64>& data) { mediumSeverityEventCount++; // TM[5,3] - if (stateOfEvents[static_cast<uint16_t> (eventID)]) { + if (stateOfEvents[static_cast<uint16_t>(eventID)]) { mediumSeverityReportCount++; Message report = createTM(3); report.appendEnum16(eventID); report.appendString(data); - lastMediumSeverityReportID = static_cast<uint16_t >(eventID); + lastMediumSeverityReportID = static_cast<uint16_t>(eventID); storeMessage(report); EventActionService eventActionService; @@ -52,16 +51,15 @@ void EventReportService::mediumSeverityAnomalyReport(Event eventID, const String } } -void -EventReportService::highSeverityAnomalyReport(Event eventID, const String<64> & data) { +void EventReportService::highSeverityAnomalyReport(Event eventID, const String<64>& data) { highSeverityEventCount++; // TM[5,4] - if (stateOfEvents[static_cast<uint16_t> (eventID)]) { + if (stateOfEvents[static_cast<uint16_t>(eventID)]) { highSeverityReportCount++; Message report = createTM(4); report.appendEnum16(eventID); report.appendString(data); - lastHighSeverityReportID = static_cast<uint16_t >(eventID); + lastHighSeverityReportID = static_cast<uint16_t>(eventID); storeMessage(report); EventActionService eventActionService; @@ -74,16 +72,16 @@ void EventReportService::enableReportGeneration(Message message) { message.assertTC(5, 5); /** - * @todo: Report an error if length > numberOfEvents - */ + * @todo: Report an error if length > numberOfEvents + */ uint16_t length = message.readUint16(); Event eventID[length]; for (uint16_t i = 0; i < length; i++) { - eventID[i] = static_cast<Event >(message.readEnum16()); + eventID[i] = static_cast<Event>(message.readEnum16()); } if (length <= numberOfEvents) { for (uint16_t i = 0; i < length; i++) { - stateOfEvents[static_cast<uint16_t> (eventID[i])] = true; + stateOfEvents[static_cast<uint16_t>(eventID[i])] = true; } } disabledEventsCount = stateOfEvents.size() - stateOfEvents.count(); @@ -94,16 +92,16 @@ void EventReportService::disableReportGeneration(Message message) { message.assertTC(5, 6); /** - * @todo: Report an error if length > numberOfEvents - */ + * @todo: Report an error if length > numberOfEvents + */ uint16_t length = message.readUint16(); Event eventID[length]; for (uint16_t i = 0; i < length; i++) { - eventID[i] = static_cast<Event >(message.readEnum16()); + eventID[i] = static_cast<Event>(message.readEnum16()); } if (length <= numberOfEvents) { for (uint16_t i = 0; i < length; i++) { - stateOfEvents[static_cast<uint16_t> (eventID[i])] = false; + stateOfEvents[static_cast<uint16_t>(eventID[i])] = false; } } disabledEventsCount = stateOfEvents.size() - stateOfEvents.count(); diff --git a/src/Services/FunctionManagementService.cpp b/src/Services/FunctionManagementService.cpp index 7b41c862e0eb5c524b742c3822ce8aaac2723b09..96f7a2a8e250053f56ce1c8e456d53a836e34e76 100644 --- a/src/Services/FunctionManagementService.cpp +++ b/src/Services/FunctionManagementService.cpp @@ -4,22 +4,20 @@ void FunctionManagementService::call(Message& msg) { msg.resetRead(); ErrorHandler::assertRequest(msg.packetType == Message::TC, msg, ErrorHandler::AcceptanceErrorType::UnacceptableMessage); - ErrorHandler::assertRequest(msg.messageType == 1, msg, - ErrorHandler::AcceptanceErrorType::UnacceptableMessage); - ErrorHandler::assertRequest(msg.serviceType == 8, msg, - ErrorHandler::AcceptanceErrorType::UnacceptableMessage); + ErrorHandler::assertRequest(msg.messageType == 1, msg, ErrorHandler::AcceptanceErrorType::UnacceptableMessage); + ErrorHandler::assertRequest(msg.serviceType == 8, msg, ErrorHandler::AcceptanceErrorType::UnacceptableMessage); - uint8_t funcName[FUNC_NAME_LENGTH]; // the function's name - uint8_t funcArgs[MAX_ARG_LENGTH]; // arguments for the function + uint8_t funcName[FUNC_NAME_LENGTH]; // the function's name + uint8_t funcArgs[MAX_ARG_LENGTH]; // arguments for the function msg.readString(funcName, FUNC_NAME_LENGTH); msg.readString(funcArgs, MAX_ARG_LENGTH); - if (msg.dataSize > FUNC_NAME_LENGTH + MAX_ARG_LENGTH) { + if (msg.dataSize > (FUNC_NAME_LENGTH + MAX_ARG_LENGTH)) { ErrorHandler::reportError(msg, - ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError); // report failed - // start of execution as requested by the standard - return; + ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError); // report failed + // start of execution as requested by the standard + return; } // locate the appropriate function pointer @@ -30,8 +28,7 @@ void FunctionManagementService::call(Message& msg) { if (iter != funcPtrIndex.end()) { selected = *iter->second; } else { - ErrorHandler::reportError(msg, - ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError); + ErrorHandler::reportError(msg, ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError); return; } @@ -39,10 +36,8 @@ void FunctionManagementService::call(Message& msg) { selected(funcArgs); } -void FunctionManagementService::include(String<FUNC_NAME_LENGTH> funcName, void(*ptr) - (String<MAX_ARG_LENGTH>)) { - - if (not funcPtrIndex.full()) { // CAUTION: etl::map won't check by itself if it's full +void FunctionManagementService::include(String<FUNC_NAME_LENGTH> funcName, void (*ptr)(String<MAX_ARG_LENGTH>)) { + if (not funcPtrIndex.full()) { // CAUTION: etl::map won't check by itself if it's full // before attempting to insert a key-value pair, causing segmentation faults. Check first! funcName.append(FUNC_NAME_LENGTH - funcName.length(), '\0'); funcPtrIndex.insert(std::make_pair(funcName, ptr)); diff --git a/src/Services/LargePacketTransferService.cpp b/src/Services/LargePacketTransferService.cpp index fedfec8f97b65dd9264502c8ef45c8e801e4e084..06fdad2604656bcd34feba03808e5c644b05c584 100644 --- a/src/Services/LargePacketTransferService.cpp +++ b/src/Services/LargePacketTransferService.cpp @@ -2,10 +2,9 @@ #include "Message.hpp" #include <etl/String.hpp> -void LargePacketTransferService::firstDownlinkPartReport(uint16_t - largeMessageTransactionIdentifier, - uint16_t partSequenceNumber, - const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> &string) { +void LargePacketTransferService::firstDownlinkPartReport(uint16_t largeMessageTransactionIdentifier, + uint16_t partSequenceNumber, + const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>& string) { // TM[13,1] Message report = createTM(1); @@ -15,9 +14,9 @@ void LargePacketTransferService::firstDownlinkPartReport(uint16_t storeMessage(report); } -void LargePacketTransferService::intermediateDownlinkPartReport(uint16_t - largeMessageTransactionIdentifier, uint16_t partSequenceNumber, const - String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> &string) { +void LargePacketTransferService::intermediateDownlinkPartReport( + uint16_t largeMessageTransactionIdentifier, uint16_t partSequenceNumber, + const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>& string) { // TM[13,2] Message report = createTM(2); report.appendUint16(largeMessageTransactionIdentifier); // large message transaction identifier @@ -27,7 +26,8 @@ void LargePacketTransferService::intermediateDownlinkPartReport(uint16_t } void LargePacketTransferService::lastDownlinkPartReport(uint16_t largeMessageTransactionIdentifier, - uint16_t partSequenceNumber, const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> &string) { + uint16_t partSequenceNumber, + const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>& string) { // TM[13,3] Message report = createTM(3); report.appendUint16(largeMessageTransactionIdentifier); // large message transaction identifier @@ -36,20 +36,20 @@ void LargePacketTransferService::lastDownlinkPartReport(uint16_t largeMessageTra storeMessage(report); } -String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> LargePacketTransferService::firstUplinkPart( - const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> &string) { +String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> +LargePacketTransferService::firstUplinkPart(const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>& string) { // TC[13,9] return string; } -String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> LargePacketTransferService::intermediateUplinkPart( - const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> &string) { +String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> +LargePacketTransferService::intermediateUplinkPart(const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>& string) { // TC[13,10] return string; } String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> -LargePacketTransferService::lastUplinkPart(const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> &string) { +LargePacketTransferService::lastUplinkPart(const String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>& string) { // TC[13, 11] return string; } diff --git a/src/Services/MemoryManagementService.cpp b/src/Services/MemoryManagementService.cpp index a963c3e4a3e4c345ce9845765ccb05659a35250b..4afae414952f178986328df2fbf857bf2d0400f7 100644 --- a/src/Services/MemoryManagementService.cpp +++ b/src/Services/MemoryManagementService.cpp @@ -8,12 +8,11 @@ MemoryManagementService::MemoryManagementService() : rawDataMemorySubservice(*th serviceType = 6; } -MemoryManagementService::RawDataMemoryManagement::RawDataMemoryManagement( - MemoryManagementService &parent) : mainService(parent) {} - +MemoryManagementService::RawDataMemoryManagement::RawDataMemoryManagement(MemoryManagementService& parent) + : mainService(parent) {} // Function declarations for the raw data memory management subservice -void MemoryManagementService::RawDataMemoryManagement::loadRawData(Message &request) { +void MemoryManagementService::RawDataMemoryManagement::loadRawData(Message& request) { /** * Bear in mind that there is currently no error checking for invalid parameters. * A future version will include error checking and the corresponding error report/notification, @@ -47,12 +46,12 @@ void MemoryManagementService::RawDataMemoryManagement::loadRawData(Message &requ if (mainService.addressValidator(memoryID, startAddress) && mainService.addressValidator(memoryID, startAddress + dataLength)) { for (std::size_t i = 0; i < dataLength; i++) { - *(reinterpret_cast<uint8_t *>(startAddress) + i) = readData[i]; + *(reinterpret_cast<uint8_t*>(startAddress) + i) = readData[i]; } // Read the loaded data for checksum validation and perform a check for (std::size_t i = 0; i < dataLength; i++) { - readData[i] = *(reinterpret_cast<uint8_t *>(startAddress) + i); + readData[i] = *(reinterpret_cast<uint8_t*>(startAddress) + i); } if (checksum != CRCHelper::calculateCRC(readData, dataLength)) { ErrorHandler::reportError(request, ErrorHandler::ChecksumFailed); @@ -71,7 +70,7 @@ void MemoryManagementService::RawDataMemoryManagement::loadRawData(Message &requ } } -void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &request) { +void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message& request) { // Check if we have the correct packet request.assertTC(6, 5); @@ -95,12 +94,10 @@ void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &requ uint16_t readLength = request.readUint16(); // Start address for the memory read // Read memory data, an octet at a time, checking for a valid address first - if (mainService.addressValidator(MemoryManagementService::MemoryID(memoryID), - startAddress) && - mainService.addressValidator(MemoryManagementService::MemoryID(memoryID), - startAddress + readLength)) { + if (mainService.addressValidator(MemoryManagementService::MemoryID(memoryID), startAddress) && + mainService.addressValidator(MemoryManagementService::MemoryID(memoryID), startAddress + readLength)) { for (std::size_t i = 0; i < readLength; i++) { - readData[i] = *(reinterpret_cast<uint8_t *>(startAddress) + i); + readData[i] = *(reinterpret_cast<uint8_t*>(startAddress) + i); } // This part is repeated N-times (N = iteration count) @@ -120,7 +117,7 @@ void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &requ } } -void MemoryManagementService::RawDataMemoryManagement::checkRawData(Message &request) { +void MemoryManagementService::RawDataMemoryManagement::checkRawData(Message& request) { // Check if we have the correct packet request.assertTC(6, 9); @@ -143,13 +140,11 @@ void MemoryManagementService::RawDataMemoryManagement::checkRawData(Message &req uint16_t readLength = request.readUint16(); // Start address for the memory read // Check whether the first and the last addresses are within the limits - if (mainService.addressValidator(MemoryManagementService::MemoryID(memoryID), - startAddress) && - mainService.addressValidator(MemoryManagementService::MemoryID(memoryID), - startAddress + readLength)) { + if (mainService.addressValidator(MemoryManagementService::MemoryID(memoryID), startAddress) && + mainService.addressValidator(MemoryManagementService::MemoryID(memoryID), startAddress + readLength)) { // Read memory data and save them for checksum calculation for (std::size_t i = 0; i < readLength; i++) { - readData[i] = *(reinterpret_cast<uint8_t *>(startAddress) + i); + readData[i] = *(reinterpret_cast<uint8_t*>(startAddress) + i); } // This part is repeated N-times (N = iteration count) @@ -161,7 +156,6 @@ void MemoryManagementService::RawDataMemoryManagement::checkRawData(Message &req } } - mainService.storeMessage(report); // Save the report message request.resetRead(); // Reset the reading count } else { @@ -169,40 +163,38 @@ void MemoryManagementService::RawDataMemoryManagement::checkRawData(Message &req } } - // Private function declaration section -bool MemoryManagementService::addressValidator( - MemoryManagementService::MemoryID memId, uint64_t address) { +bool MemoryManagementService::addressValidator(MemoryManagementService::MemoryID memId, uint64_t address) { bool validIndicator = false; switch (memId) { case MemoryManagementService::MemoryID::DTCMRAM: - if (address >= DTCMRAM_LOWER_LIM && address <= DTCMRAM_UPPER_LIM) { + if ((address >= DTCMRAM_LOWER_LIM) && (address <= DTCMRAM_UPPER_LIM)) { validIndicator = true; } break; case MemoryManagementService::MemoryID::ITCMRAM: - if (address >= ITCMRAM_LOWER_LIM && address <= ITCMRAM_UPPER_LIM) { + if ((address >= ITCMRAM_LOWER_LIM) && (address <= ITCMRAM_UPPER_LIM)) { validIndicator = true; } break; case MemoryManagementService::MemoryID::RAM_D1: - if (address >= RAM_D1_LOWER_LIM && address <= RAM_D1_UPPER_LIM) { + if ((address >= RAM_D1_LOWER_LIM) && (address <= RAM_D1_UPPER_LIM)) { validIndicator = true; } break; case MemoryManagementService::MemoryID::RAM_D2: - if (address >= RAM_D2_LOWER_LIM && address <= RAM_D2_UPPER_LIM) { + if ((address >= RAM_D2_LOWER_LIM) && (address <= RAM_D2_UPPER_LIM)) { validIndicator = true; } break; case MemoryManagementService::MemoryID::RAM_D3: - if (address >= RAM_D3_LOWER_LIM && address <= RAM_D3_UPPER_LIM) { + if ((address >= RAM_D3_LOWER_LIM) && (address <= RAM_D3_UPPER_LIM)) { validIndicator = true; } break; case MemoryManagementService::MemoryID::FLASH: - if (address >= FLASH_LOWER_LIM && address <= FLASH_UPPER_LIM) { + if ((address >= FLASH_LOWER_LIM) && (address <= FLASH_UPPER_LIM)) { validIndicator = true; } break; @@ -215,8 +207,7 @@ bool MemoryManagementService::addressValidator( return validIndicator; } -inline bool MemoryManagementService::memoryIdValidator( - MemoryManagementService::MemoryID memId) { +inline bool MemoryManagementService::memoryIdValidator(MemoryManagementService::MemoryID memId) { return (memId == MemoryManagementService::MemoryID::RAM_D1) || (memId == MemoryManagementService::MemoryID::RAM_D2) || (memId == MemoryManagementService::MemoryID::RAM_D3) || @@ -226,8 +217,7 @@ inline bool MemoryManagementService::memoryIdValidator( (memId == MemoryManagementService::MemoryID::EXTERNAL); } -inline bool MemoryManagementService::dataValidator(const uint8_t *data, uint16_t checksum, - uint16_t length) { +inline bool MemoryManagementService::dataValidator(const uint8_t* data, uint16_t checksum, uint16_t length) { return (checksum == CRCHelper::calculateCRC(data, length)); } diff --git a/src/Services/ParameterService.cpp b/src/Services/ParameterService.cpp index e82623086b0d2d357fc3dcb2a1f39e320b0d40fa..44d766820f6eac6e67de2e502a52db608c7b5eac 100644 --- a/src/Services/ParameterService.cpp +++ b/src/Services/ParameterService.cpp @@ -10,17 +10,17 @@ ParameterService::ParameterService() { // Test code, setting up some of the parameter fields time_t currTime = time(nullptr); - struct tm *today = localtime(&currTime); + struct tm* today = localtime(&currTime); Parameter test1, test2; - test1.settingData = today->tm_hour; // the current hour - test1.ptc = 3; // unsigned int - test1.pfc = 14; // 32 bits + test1.settingData = today->tm_hour; // the current hour + test1.ptc = 3; // unsigned int + test1.pfc = 14; // 32 bits - test2.settingData = today->tm_min; // the current minute - test2.ptc = 3; // unsigned int - test2.pfc = 14; // 32 bits + test2.settingData = today->tm_min; // the current minute + test2.ptc = 3; // unsigned int + test2.pfc = 14; // 32 bits // MAKE SURE THE IDS ARE UNIQUE WHEN INSERTING! /** @@ -36,9 +36,9 @@ ParameterService::ParameterService() { void ParameterService::reportParameterIds(Message& paramIds) { paramIds.assertTC(20, 1); - Message reqParam(20, 2, Message::TM, 1); // empty TM[20, 2] parameter report message + Message reqParam(20, 2, Message::TM, 1); // empty TM[20, 2] parameter report message - paramIds.resetRead(); // since we're passing a reference, the reading position shall be reset + paramIds.resetRead(); // since we're passing a reference, the reading position shall be reset // to its default before any read operations (to ensure the correct data is being read) // assertion: correct message, packet and service type (at failure throws an @@ -51,18 +51,17 @@ void ParameterService::reportParameterIds(Message& paramIds) { ErrorHandler::AcceptanceErrorType::UnacceptableMessage); uint16_t ids = paramIds.readUint16(); - reqParam.appendUint16(numOfValidIds(paramIds)); // include the number of valid IDs + reqParam.appendUint16(numOfValidIds(paramIds)); // include the number of valid IDs - for (int i = 0; i < ids; i++) { - uint16_t currId = paramIds.readUint16(); // current ID to be appended + for (uint16_t i = 0; i < ids; i++) { + uint16_t currId = paramIds.readUint16(); // current ID to be appended if (paramsList.find(currId) != paramsList.end()) { reqParam.appendUint16(currId); reqParam.appendUint32(paramsList[currId].settingData); } else { - ErrorHandler::reportError(paramIds, - ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError); - continue; // generate failed start of execution notification & ignore + ErrorHandler::reportError(paramIds, ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError); + continue; // generate failed start of execution notification & ignore } } @@ -76,23 +75,23 @@ void ParameterService::setParameterIds(Message& newParamValues) { // InternalError::UnacceptablePacket which gets logged) ErrorHandler::assertRequest(newParamValues.packetType == Message::TC, newParamValues, - ErrorHandler::AcceptanceErrorType::UnacceptableMessage); + ErrorHandler::AcceptanceErrorType::UnacceptableMessage); ErrorHandler::assertRequest(newParamValues.messageType == 3, newParamValues, - ErrorHandler::AcceptanceErrorType::UnacceptableMessage); + ErrorHandler::AcceptanceErrorType::UnacceptableMessage); ErrorHandler::assertRequest(newParamValues.serviceType == 20, newParamValues, - ErrorHandler::AcceptanceErrorType::UnacceptableMessage); + ErrorHandler::AcceptanceErrorType::UnacceptableMessage); - uint16_t ids = newParamValues.readUint16(); //get number of ID's + uint16_t ids = newParamValues.readUint16(); // get number of ID's - for (int i = 0; i < ids; i++) { + for (uint16_t i = 0; i < ids; i++) { uint16_t currId = newParamValues.readUint16(); if (paramsList.find(currId) != paramsList.end()) { paramsList[currId].settingData = newParamValues.readUint32(); } else { ErrorHandler::reportError(newParamValues, - ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError); - continue; // generate failed start of execution notification & ignore + ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError); + continue; // generate failed start of execution notification & ignore } } } @@ -102,14 +101,14 @@ uint16_t ParameterService::numOfValidIds(Message idMsg) { // start reading from the beginning of the idMsg object // (original obj. will not be influenced if this is called by value) - uint16_t ids = idMsg.readUint16(); // first 16bits of the packet are # of IDs + uint16_t ids = idMsg.readUint16(); // first 16bits of the packet are # of IDs uint16_t validIds = 0; - for (int i = 0; i < ids; i++) { + for (uint16_t i = 0; i < ids; i++) { uint16_t currId = idMsg.readUint16(); if (idMsg.messageType == 3) { - idMsg.readUint32(); //skip the 32bit settings blocks, we need only the IDs + idMsg.readUint32(); // skip the 32bit settings blocks, we need only the IDs } if (paramsList.find(currId) != paramsList.end()) { diff --git a/src/Services/RequestVerificationService.cpp b/src/Services/RequestVerificationService.cpp index 733dd0babd3dcceeda6e62a805ede5b2d68f3e0d..fdab0b0cc3f85a808ef84cc1db546b7c17ff5537 100644 --- a/src/Services/RequestVerificationService.cpp +++ b/src/Services/RequestVerificationService.cpp @@ -1,7 +1,6 @@ #include "Services/RequestVerificationService.hpp" - -void RequestVerificationService::successAcceptanceVerification(const Message &request) { +void RequestVerificationService::successAcceptanceVerification(const Message& request) { // TM[1,1] successful acceptance verification report Message report = createTM(1); @@ -16,9 +15,8 @@ void RequestVerificationService::successAcceptanceVerification(const Message &re storeMessage(report); } -void -RequestVerificationService::failAcceptanceVerification(const Message &request, - ErrorHandler::AcceptanceErrorType errorCode) { +void RequestVerificationService::failAcceptanceVerification(const Message& request, + ErrorHandler::AcceptanceErrorType errorCode) { // TM[1,2] failed acceptance verification report Message report = createTM(2); @@ -34,7 +32,7 @@ RequestVerificationService::failAcceptanceVerification(const Message &request, storeMessage(report); } -void RequestVerificationService::successStartExecutionVerification(const Message &request) { +void RequestVerificationService::successStartExecutionVerification(const Message& request) { // TM[1,3] successful start of execution verification report Message report = createTM(3); @@ -49,8 +47,8 @@ void RequestVerificationService::successStartExecutionVerification(const Message storeMessage(report); } -void RequestVerificationService::failStartExecutionVerification(const Message &request, - ErrorHandler::ExecutionStartErrorType errorCode) { +void RequestVerificationService::failStartExecutionVerification(const Message& request, + ErrorHandler::ExecutionStartErrorType errorCode) { // TM[1,4] failed start of execution verification report Message report = createTM(4); @@ -66,8 +64,7 @@ void RequestVerificationService::failStartExecutionVerification(const Message &r storeMessage(report); } -void RequestVerificationService::successProgressExecutionVerification(const Message &request, - uint8_t stepID) { +void RequestVerificationService::successProgressExecutionVerification(const Message& request, uint8_t stepID) { // TM[1,5] successful progress of execution verification report Message report = createTM(5); @@ -83,8 +80,9 @@ void RequestVerificationService::successProgressExecutionVerification(const Mess storeMessage(report); } -void RequestVerificationService::failProgressExecutionVerification(const Message &request, - ErrorHandler::ExecutionProgressErrorType errorCode, uint8_t stepID) { +void RequestVerificationService::failProgressExecutionVerification(const Message& request, + ErrorHandler::ExecutionProgressErrorType errorCode, + uint8_t stepID) { // TM[1,6] failed progress of execution verification report Message report = createTM(6); @@ -101,7 +99,7 @@ void RequestVerificationService::failProgressExecutionVerification(const Message storeMessage(report); } -void RequestVerificationService::successCompletionExecutionVerification(const Message &request) { +void RequestVerificationService::successCompletionExecutionVerification(const Message& request) { // TM[1,7] successful completion of execution verification report Message report = createTM(7); @@ -116,9 +114,8 @@ void RequestVerificationService::successCompletionExecutionVerification(const Me storeMessage(report); } -void -RequestVerificationService::failCompletionExecutionVerification(const Message &request, - ErrorHandler::ExecutionCompletionErrorType errorCode) { +void RequestVerificationService::failCompletionExecutionVerification( + const Message& request, ErrorHandler::ExecutionCompletionErrorType errorCode) { // TM[1,8] failed completion of execution verification report Message report = createTM(8); @@ -134,9 +131,8 @@ RequestVerificationService::failCompletionExecutionVerification(const Message &r storeMessage(report); } -void -RequestVerificationService::failRoutingVerification(const Message &request, - ErrorHandler::RoutingErrorType errorCode) { +void RequestVerificationService::failRoutingVerification(const Message& request, + ErrorHandler::RoutingErrorType errorCode) { // TM[1,10] failed routing verification report Message report = createTM(10); diff --git a/src/Services/TestService.cpp b/src/Services/TestService.cpp index 5dab3a0a4c4a7faf800dbbc7e8b671388012218e..001726da6eee06412b6fff685f9114610c05aaa8 100644 --- a/src/Services/TestService.cpp +++ b/src/Services/TestService.cpp @@ -1,6 +1,6 @@ #include "Services/TestService.hpp" -void TestService::areYouAlive(Message &request) { +void TestService::areYouAlive(Message& request) { request.assertTC(17, 1); // TM[17,2] are-you-alive connection test report Message report = createTM(2); @@ -8,7 +8,7 @@ void TestService::areYouAlive(Message &request) { storeMessage(report); } -void TestService::onBoardConnection(Message &request) { +void TestService::onBoardConnection(Message& request) { request.assertTC(17, 3); // TM[17,4] on-board connection test report Message report = createTM(4); diff --git a/src/Services/TimeBasedSchedulingService.cpp b/src/Services/TimeBasedSchedulingService.cpp index 58f532ae60e92f7949d92364479b28c4bb47e0e2..170f9c93f6141ea06d15a6ad6b3e4339896756b2 100644 --- a/src/Services/TimeBasedSchedulingService.cpp +++ b/src/Services/TimeBasedSchedulingService.cpp @@ -1,12 +1,10 @@ #include "Services/TimeBasedSchedulingService.hpp" - TimeBasedSchedulingService::TimeBasedSchedulingService() { serviceType = 11; } -void TimeBasedSchedulingService::enableScheduleExecution(Message &request) { - +void TimeBasedSchedulingService::enableScheduleExecution(Message& request) { // Check if the correct packet is being processed assert(request.serviceType == 11); assert(request.messageType == 1); @@ -14,8 +12,7 @@ void TimeBasedSchedulingService::enableScheduleExecution(Message &request) { executionFunctionStatus = true; // Enable the service } -void TimeBasedSchedulingService::disableScheduleExecution(Message &request) { - +void TimeBasedSchedulingService::disableScheduleExecution(Message& request) { // Check if the correct packet is being processed assert(request.serviceType == 11); assert(request.messageType == 2); @@ -23,8 +20,7 @@ void TimeBasedSchedulingService::disableScheduleExecution(Message &request) { executionFunctionStatus = false; // Disable the service } -void TimeBasedSchedulingService::resetSchedule(Message &request) { - +void TimeBasedSchedulingService::resetSchedule(Message& request) { // Check if the correct packet is being processed assert(request.serviceType == 11); assert(request.messageType == 3); @@ -34,21 +30,19 @@ void TimeBasedSchedulingService::resetSchedule(Message &request) { // todo: Add resetting for sub-schedules and groups, if defined } -void TimeBasedSchedulingService::insertActivities(Message &request) { - +void TimeBasedSchedulingService::insertActivities(Message& request) { // Check if the correct packet is being processed assert(request.serviceType == 11); assert(request.messageType == 4); // todo: Get the sub-schedule ID if they are implemented uint16_t iterationCount = request.readUint16(); // Get the iteration count, (N) - while (iterationCount--) { + while (iterationCount-- != 0) { // todo: Get the group ID first, if groups are used uint32_t currentTime = TimeGetter::getSeconds(); // Get the current system time uint32_t releaseTime = request.readUint32(); // Get the specified release time - if ((not scheduledActivities.available()) || - (releaseTime < (currentTime + ECSS_TIME_MARGIN_FOR_ACTIVATION))) { + if ((scheduledActivities.available() == 0) || (releaseTime < (currentTime + ECSS_TIME_MARGIN_FOR_ACTIVATION))) { ErrorHandler::reportError(request, ErrorHandler::InstructionExecutionStartError); request.skipBytes(ECSS_TC_REQUEST_STRING_SIZE); } else { @@ -72,8 +66,7 @@ void TimeBasedSchedulingService::insertActivities(Message &request) { sortActivitiesReleaseTime(scheduledActivities); // Sort activities by their release time } -void TimeBasedSchedulingService::timeShiftAllActivities(Message &request) { - +void TimeBasedSchedulingService::timeShiftAllActivities(Message& request) { // Check if the correct packet is being processed assert(request.serviceType == 11); assert(request.messageType == 15); @@ -81,29 +74,24 @@ void TimeBasedSchedulingService::timeShiftAllActivities(Message &request) { uint32_t current_time = TimeGetter::getSeconds(); // Get the current system time // Find the earliest release time. It will be the first element of the iterator pair - const auto releaseTimes = etl::minmax_element(scheduledActivities.begin(), - scheduledActivities.end(), - [](ScheduledActivity const &leftSide, - ScheduledActivity const & - rightSide) { - return leftSide.requestReleaseTime < - rightSide.requestReleaseTime; - }); + const auto releaseTimes = + etl::minmax_element(scheduledActivities.begin(), scheduledActivities.end(), + [](ScheduledActivity const& leftSide, ScheduledActivity const& rightSide) { + return leftSide.requestReleaseTime < rightSide.requestReleaseTime; + }); // todo: Define what the time format is going to be int32_t relativeOffset = request.readSint32(); // Get the relative offset - if ((releaseTimes.first->requestReleaseTime + relativeOffset) < - (current_time + ECSS_TIME_MARGIN_FOR_ACTIVATION)) { + if ((releaseTimes.first->requestReleaseTime + relativeOffset) < (current_time + ECSS_TIME_MARGIN_FOR_ACTIVATION)) { // Report the error ErrorHandler::reportError(request, ErrorHandler::SubServiceExecutionStartError); } else { - for (auto &activity : scheduledActivities) { + for (auto& activity : scheduledActivities) { activity.requestReleaseTime += relativeOffset; // Time shift each activity } } } -void TimeBasedSchedulingService::timeShiftActivitiesByID(Message &request) { - +void TimeBasedSchedulingService::timeShiftActivitiesByID(Message& request) { // Check if the correct packet is being processed assert(request.serviceType == 11); assert(request.messageType == 7); @@ -112,7 +100,7 @@ void TimeBasedSchedulingService::timeShiftActivitiesByID(Message &request) { int32_t relativeOffset = request.readSint32(); // Get the offset first uint16_t iterationCount = request.readUint16(); // Get the iteration count, (N) - while (iterationCount--) { + while (iterationCount-- != 0) { // Parse the request ID RequestID receivedRequestID; // Save the received request ID receivedRequestID.sourceID = request.readUint8(); // Get the source ID @@ -120,12 +108,9 @@ void TimeBasedSchedulingService::timeShiftActivitiesByID(Message &request) { receivedRequestID.sequenceCount = request.readUint16(); // Get the sequence count // Try to find the activity with the requested request ID - auto requestIDMatch = etl::find_if_not(scheduledActivities.begin(), - scheduledActivities.end(), - [&receivedRequestID] - (ScheduledActivity const ¤tElement) { - return receivedRequestID != - currentElement.requestID; + auto requestIDMatch = etl::find_if_not(scheduledActivities.begin(), scheduledActivities.end(), + [&receivedRequestID](ScheduledActivity const& currentElement) { + return receivedRequestID != currentElement.requestID; }); if (requestIDMatch != scheduledActivities.end()) { @@ -143,14 +128,13 @@ void TimeBasedSchedulingService::timeShiftActivitiesByID(Message &request) { sortActivitiesReleaseTime(scheduledActivities); // Sort activities by their release time } -void TimeBasedSchedulingService::deleteActivitiesByID(Message &request) { - +void TimeBasedSchedulingService::deleteActivitiesByID(Message& request) { // Check if the correct packet is being processed assert(request.serviceType == 11); assert(request.messageType == 5); uint16_t iterationCount = request.readUint16(); // Get the iteration count, (N) - while (iterationCount--) { + while (iterationCount-- != 0) { // Parse the request ID RequestID receivedRequestID; // Save the received request ID receivedRequestID.sourceID = request.readUint8(); // Get the source ID @@ -158,12 +142,10 @@ void TimeBasedSchedulingService::deleteActivitiesByID(Message &request) { receivedRequestID.sequenceCount = request.readUint16(); // Get the sequence count // Try to find the activity with the requested request ID - const auto requestIDMatch = etl::find_if_not(scheduledActivities.begin(), - scheduledActivities.end(), [&receivedRequestID] - (ScheduledActivity const ¤tElement) { - return receivedRequestID != currentElement - .requestID; - }); + const auto requestIDMatch = etl::find_if_not(scheduledActivities.begin(), scheduledActivities.end(), + [&receivedRequestID](ScheduledActivity const& currentElement) { + return receivedRequestID != currentElement.requestID; + }); if (requestIDMatch != scheduledActivities.end()) { scheduledActivities.erase(requestIDMatch); // Delete activity from the schedule @@ -173,17 +155,16 @@ void TimeBasedSchedulingService::deleteActivitiesByID(Message &request) { } } -void TimeBasedSchedulingService::detailReportAllActivities(Message &request) { - +void TimeBasedSchedulingService::detailReportAllActivities(Message& request) { // Check if the correct packet is being processed assert(request.serviceType == 11); assert(request.messageType == 16); // Create the report message object of telemetry message subtype 10 for each activity Message report = createTM(10); - report.appendUint16(static_cast<uint16_t >(scheduledActivities.size())); + report.appendUint16(static_cast<uint16_t>(scheduledActivities.size())); - for (auto &activity : scheduledActivities) { + for (auto& activity : scheduledActivities) { // todo: append sub-schedule and group ID if they are defined report.appendUint32(activity.requestReleaseTime); @@ -192,8 +173,7 @@ void TimeBasedSchedulingService::detailReportAllActivities(Message &request) { storeMessage(report); // Save the report } -void TimeBasedSchedulingService::detailReportActivitiesByID(Message &request) { - +void TimeBasedSchedulingService::detailReportActivitiesByID(Message& request) { // Check if the correct packet is being processed assert(request.serviceType == 11); assert(request.messageType == 9); @@ -203,7 +183,7 @@ void TimeBasedSchedulingService::detailReportActivitiesByID(Message &request) { etl::list<ScheduledActivity, ECSS_MAX_NUMBER_OF_TIME_SCHED_ACTIVITIES> matchedActivities; uint16_t iterationCount = request.readUint16(); // Get the iteration count, (N) - while (iterationCount--) { + while (iterationCount-- != 0) { // Parse the request ID RequestID receivedRequestID; // Save the received request ID receivedRequestID.sourceID = request.readUint8(); // Get the source ID @@ -211,12 +191,10 @@ void TimeBasedSchedulingService::detailReportActivitiesByID(Message &request) { receivedRequestID.sequenceCount = request.readUint16(); // Get the sequence count // Try to find the activity with the requested request ID - const auto requestIDMatch = etl::find_if_not(scheduledActivities.begin(), - scheduledActivities.end(), [&receivedRequestID] - (ScheduledActivity const ¤tElement) { - return receivedRequestID != currentElement - .requestID; - }); + const auto requestIDMatch = etl::find_if_not(scheduledActivities.begin(), scheduledActivities.end(), + [&receivedRequestID](ScheduledActivity const& currentElement) { + return receivedRequestID != currentElement.requestID; + }); if (requestIDMatch != scheduledActivities.end()) { matchedActivities.push_back(*requestIDMatch); // Save the matched activity @@ -225,19 +203,18 @@ void TimeBasedSchedulingService::detailReportActivitiesByID(Message &request) { } } - sortActivitiesReleaseTime(matchedActivities); // Sort activities by their release time + sortActivitiesReleaseTime(matchedActivities); // Sort activities by their release time // todo: append sub-schedule and group ID if they are defined - report.appendUint16(static_cast<uint16_t >(matchedActivities.size())); - for (auto &match : matchedActivities) { + report.appendUint16(static_cast<uint16_t>(matchedActivities.size())); + for (auto& match : matchedActivities) { report.appendUint32(match.requestReleaseTime); // todo: Replace with the time parser report.appendString(msgParser.convertTCToStr(match.request)); } storeMessage(report); // Save the report } -void TimeBasedSchedulingService::summaryReportActivitiesByID(Message &request) { - +void TimeBasedSchedulingService::summaryReportActivitiesByID(Message& request) { // Check if the correct packet is being processed assert(request.serviceType == 11); assert(request.messageType == 12); @@ -247,7 +224,7 @@ void TimeBasedSchedulingService::summaryReportActivitiesByID(Message &request) { etl::list<ScheduledActivity, ECSS_MAX_NUMBER_OF_TIME_SCHED_ACTIVITIES> matchedActivities; uint16_t iterationCount = request.readUint16(); // Get the iteration count, (N) - while (iterationCount--) { + while (iterationCount-- != 0) { // Parse the request ID RequestID receivedRequestID; // Save the received request ID receivedRequestID.sourceID = request.readUint8(); // Get the source ID @@ -255,12 +232,10 @@ void TimeBasedSchedulingService::summaryReportActivitiesByID(Message &request) { receivedRequestID.sequenceCount = request.readUint16(); // Get the sequence count // Try to find the activity with the requested request ID - auto requestIDMatch = etl::find_if_not(scheduledActivities.begin(), - scheduledActivities.end(), [&receivedRequestID] - (ScheduledActivity const ¤tElement) { - return receivedRequestID != currentElement - .requestID; - }); + auto requestIDMatch = etl::find_if_not(scheduledActivities.begin(), scheduledActivities.end(), + [&receivedRequestID](ScheduledActivity const& currentElement) { + return receivedRequestID != currentElement.requestID; + }); if (requestIDMatch != scheduledActivities.end()) { matchedActivities.push_back(*requestIDMatch); @@ -271,8 +246,8 @@ void TimeBasedSchedulingService::summaryReportActivitiesByID(Message &request) { sortActivitiesReleaseTime(matchedActivities); // Sort activities by their release time // todo: append sub-schedule and group ID if they are defined - report.appendUint16(static_cast<uint16_t >(matchedActivities.size())); - for (auto &match : matchedActivities) { + report.appendUint16(static_cast<uint16_t>(matchedActivities.size())); + for (auto& match : matchedActivities) { // todo: append sub-schedule and group ID if they are defined report.appendUint32(match.requestReleaseTime); report.appendUint8(match.requestID.sourceID); diff --git a/src/Services/TimeManagementService.cpp b/src/Services/TimeManagementService.cpp index 93c224bbbd28ba8aa06ccc3d0257ac8e75a82e2c..832cc31f30eca2e6d52efd710b591dc605eaeaa7 100644 --- a/src/Services/TimeManagementService.cpp +++ b/src/Services/TimeManagementService.cpp @@ -1,25 +1,24 @@ #include "Services/TimeManagementService.hpp" -void TimeManagementService::cdsTimeReport(TimeAndDate &TimeInfo) { +void TimeManagementService::cdsTimeReport(TimeAndDate& TimeInfo) { // TM[9,3] CDS time report Message timeReport = createTM(3); uint64_t timeFormat = TimeHelper::generateCDStimeFormat(TimeInfo); - timeReport.appendHalfword(static_cast<uint16_t >(timeFormat >> 32)); - timeReport.appendWord(static_cast<uint32_t >(timeFormat)); + timeReport.appendHalfword(static_cast<uint16_t>(timeFormat >> 32)); + timeReport.appendWord(static_cast<uint32_t>(timeFormat)); storeMessage(timeReport); } -TimeAndDate TimeManagementService::cdsTimeRequest(Message &message) { +TimeAndDate TimeManagementService::cdsTimeRequest(Message& message) { // TC[9,128] CDS time request message.assertTC(9, 128); // check if we have the correct size of the data. The size should be 6 (48 bits) - ErrorHandler::assertRequest(message.dataSize == 6, message, - ErrorHandler::AcceptanceErrorType::UnacceptableMessage); + ErrorHandler::assertRequest(message.dataSize == 6, message, ErrorHandler::AcceptanceErrorType::UnacceptableMessage); TimeAndDate timeInfo = TimeHelper::parseCDStimeFormat(message.data); diff --git a/src/main.cpp b/src/main.cpp index 50a1540d1b7a31aa46cbf0ad2ca43ee53bed2438..35728108032224e530d26e6465f6774598921e34 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,6 @@ #include "ErrorHandler.hpp" #include "etl/String.hpp" - int main() { Message packet = Message(0, 0, Message::TC, 1); @@ -34,36 +33,34 @@ int main() { char string[6]; packet.readString(string, 5); - std::cout << "Word: " << string << " " << packet.readBits(15) << packet.readBits(1) - << std::endl; + std::cout << "Word: " << string << " " << packet.readBits(15) << packet.readBits(1) << std::endl; std::cout << packet.readFloat() << " " << std::dec << packet.readSint32() << std::endl; // ST[17] test - TestService & testService = Services.testService; + TestService& testService = Services.testService; Message receivedPacket = Message(17, 1, Message::TC, 1); testService.areYouAlive(receivedPacket); receivedPacket = Message(17, 3, Message::TC, 1); receivedPacket.appendUint16(7); testService.onBoardConnection(receivedPacket); - // ST[20] test - ParameterService & paramService = Services.parameterManagement; + ParameterService& paramService = Services.parameterManagement; // Test code for reportParameter - Message sentPacket = Message(20, 1, Message::TC, 1); //application id is a dummy number (1) - sentPacket.appendUint16(2); //number of contained IDs - sentPacket.appendUint16(0); //first ID - sentPacket.appendUint16(1); //second ID + Message sentPacket = Message(20, 1, Message::TC, 1); // application id is a dummy number (1) + sentPacket.appendUint16(2); // number of contained IDs + sentPacket.appendUint16(0); // first ID + sentPacket.appendUint16(1); // second ID paramService.reportParameterIds(sentPacket); // Test code for setParameter - Message sentPacket2 = Message(20, 3, Message::TC, 1); //application id is a dummy number (1) - sentPacket2.appendUint16(2); //number of contained IDs - sentPacket2.appendUint16(0); //first parameter ID - sentPacket2.appendUint32(63238); //settings for first parameter - sentPacket2.appendUint16(1); //2nd parameter ID - sentPacket2.appendUint32(45823); //settings for 2nd parameter + Message sentPacket2 = Message(20, 3, Message::TC, 1); // application id is a dummy number (1) + sentPacket2.appendUint16(2); // number of contained IDs + sentPacket2.appendUint16(0); // first parameter ID + sentPacket2.appendUint32(63238); // settings for first parameter + sentPacket2.appendUint16(1); // 2nd parameter ID + sentPacket2.appendUint32(45823); // settings for 2nd parameter paramService.setParameterIds(sentPacket2); paramService.reportParameterIds(sentPacket); @@ -76,17 +73,17 @@ int main() { *(pStr + 1) = 'G'; *(pStr + 2) = '\0'; - MemoryManagementService & memMangService = Services.memoryManagement; + MemoryManagementService& memMangService = Services.memoryManagement; Message rcvPack = Message(6, 5, Message::TC, 1); rcvPack.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID rcvPack.appendUint16(3); // Iteration count - rcvPack.appendUint64(reinterpret_cast<uint64_t >(string)); // Start address + rcvPack.appendUint64(reinterpret_cast<uint64_t>(string)); // Start address rcvPack.appendUint16(sizeof(string) / sizeof(string[0])); // Data read length - rcvPack.appendUint64(reinterpret_cast<uint64_t >(anotherStr)); + rcvPack.appendUint64(reinterpret_cast<uint64_t>(anotherStr)); rcvPack.appendUint16(sizeof(anotherStr) / sizeof(anotherStr[0])); - rcvPack.appendUint64(reinterpret_cast<uint64_t >(yetAnotherStr)); + rcvPack.appendUint64(reinterpret_cast<uint64_t>(yetAnotherStr)); rcvPack.appendUint16(sizeof(yetAnotherStr) / sizeof(yetAnotherStr[0])); memMangService.rawDataMemorySubservice.dumpRawData(rcvPack); @@ -95,10 +92,10 @@ int main() { uint8_t data[2] = {'h', 'R'}; rcvPack.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID rcvPack.appendUint16(2); // Iteration count - rcvPack.appendUint64(reinterpret_cast<uint64_t >(pStr)); // Start address + rcvPack.appendUint64(reinterpret_cast<uint64_t>(pStr)); // Start address rcvPack.appendOctetString(String<2>(data, 2)); rcvPack.appendBits(16, CRCHelper::calculateCRC(data, 2)); // Append the CRC value - rcvPack.appendUint64(reinterpret_cast<uint64_t >(pStr + 1)); // Start address + rcvPack.appendUint64(reinterpret_cast<uint64_t>(pStr + 1)); // Start address rcvPack.appendOctetString(String<1>(data, 1)); rcvPack.appendBits(16, CRCHelper::calculateCRC(data, 1)); // Append the CRC value memMangService.rawDataMemorySubservice.loadRawData(rcvPack); @@ -107,16 +104,15 @@ int main() { rcvPack.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID rcvPack.appendUint16(2); // Iteration count - rcvPack.appendUint64(reinterpret_cast<uint64_t >(data)); // Start address + rcvPack.appendUint64(reinterpret_cast<uint64_t>(data)); // Start address rcvPack.appendUint16(2); - rcvPack.appendUint64(reinterpret_cast<uint64_t >(data + 1)); // Start address + rcvPack.appendUint64(reinterpret_cast<uint64_t>(data + 1)); // Start address rcvPack.appendUint16(1); memMangService.rawDataMemorySubservice.checkRawData(rcvPack); - // ST[01] test - RequestVerificationService & reqVerifService = Services.requestVerification; + RequestVerificationService& reqVerifService = Services.requestVerification; Message receivedMessage = Message(1, 1, Message::TC, 3); reqVerifService.successAcceptanceVerification(receivedMessage); @@ -128,22 +124,19 @@ int main() { reqVerifService.successStartExecutionVerification(receivedMessage); receivedMessage = Message(1, 4, Message::TC, 3); - reqVerifService.failStartExecutionVerification(receivedMessage, - ErrorHandler::UnknownExecutionStartError); + reqVerifService.failStartExecutionVerification(receivedMessage, ErrorHandler::UnknownExecutionStartError); receivedMessage = Message(1, 5, Message::TC, 3); reqVerifService.successProgressExecutionVerification(receivedMessage, 0); receivedMessage = Message(1, 6, Message::TC, 3); - reqVerifService.failProgressExecutionVerification(receivedMessage, - ErrorHandler::UnknownExecutionProgressError, 0); + reqVerifService.failProgressExecutionVerification(receivedMessage, ErrorHandler::UnknownExecutionProgressError, 0); receivedMessage = Message(1, 7, Message::TC, 3); reqVerifService.successCompletionExecutionVerification(receivedMessage); receivedMessage = Message(1, 8, Message::TC, 3); - reqVerifService.failCompletionExecutionVerification(receivedMessage, - ErrorHandler::UnknownExecutionCompletionError); + reqVerifService.failCompletionExecutionVerification(receivedMessage, ErrorHandler::UnknownExecutionCompletionError); receivedMessage = Message(1, 10, Message::TC, 3); reqVerifService.failRoutingVerification(receivedMessage, ErrorHandler::UnknownRoutingError); @@ -151,14 +144,10 @@ int main() { // ST[05] (5,1 to 5,4) test [works] const char eventReportData[12] = "Hello World"; EventReportService eventReportService; - eventReportService.informativeEventReport(EventReportService::InformativeUnknownEvent, - eventReportData); - eventReportService.lowSeverityAnomalyReport(EventReportService::LowSeverityUnknownEvent, - eventReportData); - eventReportService.mediumSeverityAnomalyReport(EventReportService::MediumSeverityUnknownEvent, - eventReportData); - eventReportService.highSeverityAnomalyReport(EventReportService::HighSeverityUnknownEvent, - eventReportData); + eventReportService.informativeEventReport(EventReportService::InformativeUnknownEvent, eventReportData); + eventReportService.lowSeverityAnomalyReport(EventReportService::LowSeverityUnknownEvent, eventReportData); + eventReportService.mediumSeverityAnomalyReport(EventReportService::MediumSeverityUnknownEvent, eventReportData); + eventReportService.highSeverityAnomalyReport(EventReportService::HighSeverityUnknownEvent, eventReportData); Message trivialMessage = Message(); MessageParser::execute(trivialMessage); @@ -173,7 +162,7 @@ int main() { errorMessage.appendByte(15); // ST[09] test - TimeManagementService & timeReport = Services.timeManagement; + TimeManagementService& timeReport = Services.timeManagement; TimeAndDate timeInfo; // 10/04/1998 10:15:00 timeInfo.year = 1998; @@ -205,7 +194,7 @@ int main() { // ST[19] test - EventActionService & eventActionService = Services.eventAction; + EventActionService& eventActionService = Services.eventAction; Message eventActionDefinition(19, 1, Message::TC, 1); eventActionDefinition.appendEnum16(0); eventActionDefinition.appendEnum16(2); @@ -234,10 +223,9 @@ int main() { eventActionDefinition3.appendUint16(4); eventActionService.disableEventActionDefinitions(eventActionDefinition3); - std::cout << "Status of position 0,1,2 should be 000:" << eventActionService - .eventActionDefinitionArray[0].enabled << eventActionService - .eventActionDefinitionArray[1].enabled << - eventActionService.eventActionDefinitionArray[2].enabled; + std::cout << "Status of position 0,1,2 should be 000:" << eventActionService.eventActionDefinitionArray[0].enabled + << eventActionService.eventActionDefinitionArray[1].enabled + << eventActionService.eventActionDefinitionArray[2].enabled; Message eventActionDefinition5(19, 4, Message::TC, 1); eventActionDefinition5.appendUint16(2); @@ -246,10 +234,9 @@ int main() { eventActionDefinition5.appendUint16(0); eventActionDefinition5.appendUint16(3); eventActionService.enableEventActionDefinitions(eventActionDefinition5); - std::cout << "\nStatus of position 0,1,2 should be 110:" << eventActionService - .eventActionDefinitionArray[0].enabled << eventActionService - .eventActionDefinitionArray[1].enabled << - eventActionService.eventActionDefinitionArray[2].enabled; + std::cout << "\nStatus of position 0,1,2 should be 110:" << eventActionService.eventActionDefinitionArray[0].enabled + << eventActionService.eventActionDefinitionArray[1].enabled + << eventActionService.eventActionDefinitionArray[2].enabled; Message eventActionDefinition4(19, 2, Message::TC, 1); eventActionDefinition4.appendUint16(2); @@ -259,15 +246,14 @@ int main() { eventActionDefinition4.appendUint16(3); eventActionService.deleteEventActionDefinitions(eventActionDefinition4); - std::cout << "\nPositions 0,1 empty should be 11:" << static_cast<uint16_t>(eventActionService - .eventActionDefinitionArray[0].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:" << static_cast<uint16_t>(eventActionService - .eventActionDefinitionArray[0].empty); - + std::cout << "\nPositions 0,1 empty should be 1:" + << static_cast<uint16_t>(eventActionService.eventActionDefinitionArray[0].empty); // ST13 test @@ -275,11 +261,10 @@ int main() { String<256> dataToTransfer = "12345678"; largePacketTransferService.firstDownlinkPartReport(1, 1, dataToTransfer); - // ST[11] test TimeBasedSchedulingService timeBasedSchedulingService; MessageParser msgParser; - auto currentTime = static_cast<uint32_t >(time(nullptr)); // Get the current system time + auto currentTime = static_cast<uint32_t>(time(nullptr)); // Get the current system time std::cout << "\n\nST[11] service is running"; std::cout << "\nCurrent time in seconds (UNIX epoch): " << currentTime << std::endl; @@ -294,10 +279,10 @@ int main() { receivedMsg = Message(11, 4, Message::TC, 1); receivedMsg.appendUint16(2); // Total number of requests - receivedMsg.appendUint32(currentTime + 1556435); + receivedMsg.appendUint32(currentTime + 1556435u); receivedMsg.appendString(msgParser.convertTCToStr(testMessage1)); - receivedMsg.appendUint32(currentTime + 1957232); + receivedMsg.appendUint32(currentTime + 1957232u); receivedMsg.appendString(msgParser.convertTCToStr(testMessage2)); timeBasedSchedulingService.insertActivities(receivedMsg); diff --git a/test/ErrorHandler.cpp b/test/ErrorHandler.cpp index eb8be383e89a8ce91686eb0ceddf57c7cd383933..0e8a14b616dce2b5f5e44ebeb9f06d0d7c9d8d82 100644 --- a/test/ErrorHandler.cpp +++ b/test/ErrorHandler.cpp @@ -48,8 +48,7 @@ TEST_CASE("Error: Failed Execution Start", "[errors]") { TEST_CASE("Error: Failed Execution Progress", "[errors]") { Message failedMessage(38, 32, Message::TC, 56); - ErrorHandler::reportProgressError(failedMessage, ErrorHandler::UnknownExecutionProgressError, - 0); + ErrorHandler::reportProgressError(failedMessage, ErrorHandler::UnknownExecutionProgressError, 0); REQUIRE(ServiceTests::hasOneMessage()); Message report = ServiceTests::get(0); diff --git a/test/Helpers/CRCHelper.cpp b/test/Helpers/CRCHelper.cpp index eba63019bf29f99c108dae56a5fa1db2b26e8a97..5988eb3ee1be035397b87530493ef7d9e7b8526a 100644 --- a/test/Helpers/CRCHelper.cpp +++ b/test/Helpers/CRCHelper.cpp @@ -2,10 +2,10 @@ #include "Helpers/CRCHelper.hpp" TEST_CASE("CRC calculation - Basic String tests") { - CHECK(CRCHelper::calculateCRC((uint8_t*) "Raccoon Squad!", 14) == 0x08FC); - CHECK(CRCHelper::calculateCRC((uint8_t*) "ASAT", 4) == 0xBFFA); - CHECK(CRCHelper::calculateCRC((uint8_t*) "All your space are belong to us", 31) == 0x545F); - CHECK(CRCHelper::calculateCRC((uint8_t*) "SPAAAAAAAAACE!", 14) == 0xB441); + CHECK(CRCHelper::calculateCRC((uint8_t*)"Raccoon Squad!", 14) == 0x08FC); + CHECK(CRCHelper::calculateCRC((uint8_t*)"ASAT", 4) == 0xBFFA); + CHECK(CRCHelper::calculateCRC((uint8_t*)"All your space are belong to us", 31) == 0x545F); + CHECK(CRCHelper::calculateCRC((uint8_t*)"SPAAAAAAAAACE!", 14) == 0xB441); } TEST_CASE("CRC calculation - Basic byte tests") { @@ -40,8 +40,7 @@ TEST_CASE("CRC validation - Basic tests") { uint8_t data4[6] = {'A', 0x43, 0x52, 0xDF, 0xBF, 0xFA}; // ASAT, but "corrupted" with the last 2 bytes the original checksum of the 'ASAT' string - uint8_t data5[9] = {'C', 'U', 'B', 'E', 'S', 'A', 'T', 0x53, 0x15}; //corrupted CRC checksum - + uint8_t data5[9] = {'C', 'U', 'B', 'E', 'S', 'A', 'T', 0x53, 0x15}; // corrupted CRC checksum CHECK(CRCHelper::validateCRC(data1, 7) == 0x0); CHECK(CRCHelper::validateCRC(data2, 6) == 0x0); diff --git a/test/Helpers/TimeAndDate.cpp b/test/Helpers/TimeAndDate.cpp index 44d1c43938ee20b9e2de6f3d040b3dba2b7a07a2..f5bc35fe51a660fe403847e65eda1b1c21d4b9b3 100644 --- a/test/Helpers/TimeAndDate.cpp +++ b/test/Helpers/TimeAndDate.cpp @@ -1,9 +1,7 @@ #include "catch2/catch.hpp" #include "Helpers/TimeAndDate.hpp" - TEST_CASE("Date comparison", "[operands]") { - SECTION("Invalid date") { TimeAndDate InvalidDate0(1900, 2, 2, 4, 5, 6); // error in year TimeAndDate InvalidDate1(2030, 70, 2, 4, 5, 6); // error in month @@ -46,7 +44,6 @@ TEST_CASE("Date comparison", "[operands]") { } SECTION("Different month") { - TimeAndDate Now; // 10/05/2020 10:15:00 Now.year = 2020; diff --git a/test/Helpers/TimeHelper.cpp b/test/Helpers/TimeHelper.cpp index 31fb012da5fff869c06e1305fa6e194b7cf9be0b..ea9431d644725b9953871be6bc69f008e5e65868 100644 --- a/test/Helpers/TimeHelper.cpp +++ b/test/Helpers/TimeHelper.cpp @@ -2,7 +2,6 @@ #include "Helpers/TimeHelper.hpp" TEST_CASE("Time format implementation", "[CUC]") { - SECTION("Invalid date") { TimeAndDate TimeInfo; diff --git a/test/Message.cpp b/test/Message.cpp index 01df6ce0f149d21a9d2c9c381e372fb7ab904e0b..1caa5a2624377bc123c9dd7192e27104cd053afe 100644 --- a/test/Message.cpp +++ b/test/Message.cpp @@ -43,9 +43,7 @@ TEST_CASE("Bit manipulations", "[message]") { } TEST_CASE("Requirement 5.3.1", "[message][ecss]") { - SECTION("5.3.1a") { - - } + SECTION("5.3.1a") {} SECTION("5.3.1b") { REQUIRE(sizeof(Message::serviceType) == 1); diff --git a/test/MessageParser.cpp b/test/MessageParser.cpp index 4639d76b875354bf4c7237006d46dc2718ebf5f4..d11d42ab54e4bfd796f1d726855bda45489458aa 100644 --- a/test/MessageParser.cpp +++ b/test/MessageParser.cpp @@ -7,11 +7,10 @@ #include "Services/ServiceTests.hpp" #include "ServicePool.hpp" + TEST_CASE("TC message parsing", "[MessageParser]") { MessageParser messageParser; - - uint8_t packet[] = {0x18, 0x07, 0xc0, 0x4d, 0x00, 0x0a, 0x20, 0x81, 0x1f, 0x00, 0x00, 0x68, - 0x65, 0x6c, 0x6c, 0x6f}; + uint8_t packet[] = {0x18, 0x07, 0xc0, 0x4d, 0x00, 0x0a, 0x20, 0x81, 0x1f, 0x00, 0x00, 0x68, 0x65, 0x6c, 0x6c, 0x6f}; Message message = messageParser.parse(packet, 16); CHECK(message.packetType == Message::TC); @@ -22,15 +21,13 @@ TEST_CASE("TC message parsing", "[MessageParser]") { CHECK(memcmp(message.data, "hello", 5) == 0); } -TEST_CASE("TC data parsing into a message", "[MessageParser]") { - -} +TEST_CASE("TC data parsing into a message", "[MessageParser]") {} TEST_CASE("TM message parsing", "[MessageParser]") { MessageParser messageParser; - uint8_t packet[] = {0x08, 0x02, 0xc0, 0x4d, 0x00, 0x0c, 0x20, 0x16, 0x11, 0x00, 0x00, 0x68, - 0x65, 0x6c, 0x6c, 0x6f, - 0x68, 0x69}; + uint8_t packet[] = {0x08, 0x02, 0xc0, 0x4d, 0x00, 0x0c, 0x20, 0x16, 0x11, + 0x00, 0x00, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x68, 0x69}; + Message message = messageParser.parse(packet, 18); CHECK(message.packetType == Message::TM); CHECK(message.applicationId == 2); diff --git a/test/Services/EventActionService.cpp b/test/Services/EventActionService.cpp index 0e34be07b4d3497a289ec0abb0e9091ff8dbeab6..5b1d53511597309289b1480e8362b1ca18abedcf 100644 --- a/test/Services/EventActionService.cpp +++ b/test/Services/EventActionService.cpp @@ -7,7 +7,7 @@ #include <iostream> #include <ServicePool.hpp> -EventActionService & eventActionService = Services.eventAction; +EventActionService& eventActionService = Services.eventAction; TEST_CASE("Add event-action definitions TC[19,1]", "[service][st19]") { @@ -114,7 +114,6 @@ TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st19]") { CHECK(eventActionService.eventActionDefinitionArray[4].eventDefinitionID == 65535); CHECK(eventActionService.eventActionDefinitionArray[4].request.compare("") == 0); CHECK(eventActionService.eventActionDefinitionArray[4].enabled == 0); - } TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { @@ -152,7 +151,7 @@ TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { Message message(19, 3, Message::TC, 0); eventActionService.deleteAllEventActionDefinitions(message); - for (int i = 0; i < 256; i++){ + for (int i = 0; i < 256; i++) { CHECK(eventActionService.eventActionDefinitionArray[i].empty == 1); CHECK(eventActionService.eventActionDefinitionArray[i].applicationId == 0); CHECK(eventActionService.eventActionDefinitionArray[i].eventDefinitionID == 65535); @@ -182,7 +181,6 @@ TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st19]") { MessageParser::execute(message2); CHECK(eventActionService.eventActionDefinitionArray[0].enabled == 1); CHECK(eventActionService.eventActionDefinitionArray[1].enabled == 1); - } TEST_CASE("Disable event-action definitions TC[19,5]", "[service][st19]") { @@ -259,6 +257,4 @@ TEST_CASE("Disable event-action function TC[19,9]", "[service][st19]") { CHECK(eventActionService.getEventActionFunctionStatus() == false); } -TEST_CASE("Execute a TC request", "[service][st19]"){ - -} +TEST_CASE("Execute a TC request", "[service][st09]") {} diff --git a/test/Services/EventReportService.cpp b/test/Services/EventReportService.cpp index d2892cd9482d517595c4881fc2b055a72e810150..e87f7e4098713f9ea507ad5fb0a223a8c9a3b994 100644 --- a/test/Services/EventReportService.cpp +++ b/test/Services/EventReportService.cpp @@ -4,13 +4,12 @@ #include "ServiceTests.hpp" #include <cstring> -EventReportService & eventReportService = Services.eventReport; +EventReportService& eventReportService = Services.eventReport; TEST_CASE("Informative Event Report TM[5,1]", "[service][st05]") { const char eventReportData[] = "HelloWorld"; char checkString[255]; - eventReportService.informativeEventReport(EventReportService::InformativeUnknownEvent, - eventReportData); + eventReportService.informativeEventReport(EventReportService::InformativeUnknownEvent, eventReportData); REQUIRE(ServiceTests::hasOneMessage()); Message report = ServiceTests::get(0); @@ -28,8 +27,7 @@ TEST_CASE("Informative Event Report TM[5,1]", "[service][st05]") { TEST_CASE("Low Severity Anomaly Report TM[5,2]", "[service][st05]") { const char eventReportData[] = "HelloWorld"; char checkString[255]; - eventReportService.lowSeverityAnomalyReport(EventReportService::LowSeverityUnknownEvent, - eventReportData); + eventReportService.lowSeverityAnomalyReport(EventReportService::LowSeverityUnknownEvent, eventReportData); REQUIRE(ServiceTests::hasOneMessage()); Message report = ServiceTests::get(0); @@ -47,8 +45,7 @@ TEST_CASE("Low Severity Anomaly Report TM[5,2]", "[service][st05]") { TEST_CASE("Medium Severity Anomaly Report TM[5,3]", "[service][st05]") { const char eventReportData[] = "HelloWorld"; char checkString[255]; - eventReportService.mediumSeverityAnomalyReport - (EventReportService::MediumSeverityUnknownEvent, eventReportData); + eventReportService.mediumSeverityAnomalyReport(EventReportService::MediumSeverityUnknownEvent, eventReportData); REQUIRE(ServiceTests::hasOneMessage()); Message report = ServiceTests::get(0); @@ -66,8 +63,7 @@ TEST_CASE("Medium Severity Anomaly Report TM[5,3]", "[service][st05]") { TEST_CASE("High Severity Anomaly Report TM[5,4]", "[service][st05]") { const char eventReportData[] = "HelloWorld"; char checkString[255]; - eventReportService.highSeverityAnomalyReport(EventReportService::HighSeverityUnknownEvent, - eventReportData); + eventReportService.highSeverityAnomalyReport(EventReportService::HighSeverityUnknownEvent, eventReportData); REQUIRE(ServiceTests::hasOneMessage()); Message report = ServiceTests::get(0); @@ -107,8 +103,7 @@ TEST_CASE("Disable Report Generation TC[5,6]", "[service][st05]") { CHECK(eventReportService.getStateOfEvents()[5] == 0); const String<64> eventReportData = "HelloWorld"; - eventReportService.highSeverityAnomalyReport(EventReportService::InformativeUnknownEvent, - eventReportData); + eventReportService.highSeverityAnomalyReport(EventReportService::InformativeUnknownEvent, eventReportData); CHECK(ServiceTests::hasOneMessage() == false); } @@ -123,8 +118,7 @@ TEST_CASE("Request list of disabled events TC[5,7]", "[service][st05]") { } TEST_CASE("List of Disabled Events Report TM[5,8]", "[service][st05]") { - EventReportService::Event eventID[] = {EventReportService::MCUStart, - EventReportService::HighSeverityUnknownEvent}; + EventReportService::Event eventID[] = {EventReportService::MCUStart, EventReportService::HighSeverityUnknownEvent}; Message message(5, 6, Message::TC, 1); message.appendUint16(2); message.appendEnum16(eventID[0]); @@ -155,10 +149,8 @@ TEST_CASE("List of observables 6.5.6", "[service][st05]") { const String<64> eventReportData = "HelloWorld"; - eventReportService.highSeverityAnomalyReport(EventReportService::HighSeverityUnknownEvent, - eventReportData); - eventReportService.mediumSeverityAnomalyReport(EventReportService::MediumSeverityUnknownEvent, - eventReportData); + eventReportService.highSeverityAnomalyReport(EventReportService::HighSeverityUnknownEvent, eventReportData); + eventReportService.mediumSeverityAnomalyReport(EventReportService::MediumSeverityUnknownEvent, eventReportData); CHECK(eventReportService.lowSeverityReportCount == 0); CHECK(eventReportService.mediumSeverityReportCount == 1); CHECK(eventReportService.highSeverityReportCount == 0); diff --git a/test/Services/FunctionManagementService.cpp b/test/Services/FunctionManagementService.cpp index 235e1198ba9e3246491c13b52875d40bafae7299..cb7e7e31accac7bf328e9cd5b00f81c07d033ff6 100644 --- a/test/Services/FunctionManagementService.cpp +++ b/test/Services/FunctionManagementService.cpp @@ -4,14 +4,13 @@ #include "ServiceTests.hpp" #include <iostream> -FunctionManagementService & fms = Services.functionManagement; +FunctionManagementService& fms = Services.functionManagement; void test(String<MAX_ARG_LENGTH> a) { std::cout << a.c_str() << std::endl; } TEST_CASE("ST[08] - Call Tests") { - SECTION("Malformed name") { ServiceTests::reset(); fms.include(String<FUNC_NAME_LENGTH>("test"), &test); @@ -35,13 +34,11 @@ TEST_CASE("ST[08] - Call Tests") { } } - TEST_CASE("ST[08] - Insert Tests") { - SECTION("Insertion to full pointer map") { // make sure the pointer map is full to the brim ServiceTests::reset(); - std::string name = "test"; // FOR TESTING ONLY! + std::string name = "test"; // FOR TESTING ONLY! for (int i = 0; i < FUNC_MAP_SIZE + 1; i++) { name += std::to_string(i); // different names to fill up the map diff --git a/test/Services/LargePacketTransferService.cpp b/test/Services/LargePacketTransferService.cpp index e7109ee763d620047241ac94cc0ab19a6aa73662..1171f2f302ca19a16b1e52f7009e3cd1ac2fb622 100644 --- a/test/Services/LargePacketTransferService.cpp +++ b/test/Services/LargePacketTransferService.cpp @@ -5,11 +5,10 @@ #include <cstring> #include <etl/String.hpp> -LargePacketTransferService &lPT = Services.largePacketTransferService; +LargePacketTransferService& lPT = Services.largePacketTransferService; TEST_CASE("First Downlink Part Report TM[13,1]", "[service][st13]") { - String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> string = String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> - ("12345678"); + String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> string = String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>("12345678"); lPT.firstDownlinkPartReport(1, 1, string); REQUIRE(ServiceTests::hasOneMessage()); Message report = ServiceTests::get(0); @@ -24,8 +23,7 @@ TEST_CASE("First Downlink Part Report TM[13,1]", "[service][st13]") { } TEST_CASE("Intermediate Downlink Part Report TM[13,2]", "[service][st13]") { - String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> string = String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>( - "12345678"); + String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> string = String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>("12345678"); lPT.intermediateDownlinkPartReport(1, 1, string); REQUIRE(ServiceTests::hasOneMessage()); Message report = ServiceTests::get(0); @@ -40,8 +38,7 @@ TEST_CASE("Intermediate Downlink Part Report TM[13,2]", "[service][st13]") { } TEST_CASE("Last Downlink Part Report TM[13,3]", "[service][st13]") { - String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> string = String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>( - "12345678"); + String<ECSS_MAX_FIXED_OCTET_STRING_SIZE> string = String<ECSS_MAX_FIXED_OCTET_STRING_SIZE>("12345678"); lPT.lastDownlinkPartReport(1, 1, string); REQUIRE(ServiceTests::hasOneMessage()); Message report = ServiceTests::get(0); diff --git a/test/Services/MemoryManagementService.cpp b/test/Services/MemoryManagementService.cpp index 4861c6a7c2f379ae16a7d3373dc027ab7f0ef46b..0d07c04e0a9dbfb720314244c55757bb6d2a44a7 100644 --- a/test/Services/MemoryManagementService.cpp +++ b/test/Services/MemoryManagementService.cpp @@ -4,11 +4,11 @@ #include "ServiceTests.hpp" #include "Helpers/CRCHelper.hpp" -MemoryManagementService & memMangService = Services.memoryManagement; +MemoryManagementService& memMangService = Services.memoryManagement; TEST_CASE("TC[6,2]", "[service][st06]") { // Required test variables - char *pStr = static_cast<char *>(malloc(4)); + char* pStr = static_cast<char*>(malloc(4)); *pStr = 'T'; *(pStr + 1) = 'G'; *(pStr + 2) = '\0'; @@ -17,10 +17,10 @@ TEST_CASE("TC[6,2]", "[service][st06]") { Message receivedPacket = Message(6, 2, Message::TC, 1); receivedPacket.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID receivedPacket.appendUint16(2); // Iteration count - receivedPacket.appendUint64(reinterpret_cast<uint64_t >(pStr)); // Start address + receivedPacket.appendUint64(reinterpret_cast<uint64_t>(pStr)); // Start address receivedPacket.appendOctetString(String<2>(data)); receivedPacket.appendBits(16, CRCHelper::calculateCRC(data, 2)); // Append CRC - receivedPacket.appendUint64(reinterpret_cast<uint64_t >(pStr + 2)); // Start address + receivedPacket.appendUint64(reinterpret_cast<uint64_t>(pStr + 2)); // Start address receivedPacket.appendOctetString(String<1>(data)); // Append CRC receivedPacket.appendBits(16, CRCHelper::calculateCRC(data, 1)); MessageParser::execute(receivedPacket); @@ -38,17 +38,16 @@ TEST_CASE("TC[6,5]", "[service][st06]") { uint8_t checkString[ECSS_MAX_STRING_SIZE]; uint16_t readSize = 0, checksum = 0; - MemoryManagementService memMangService; Message receivedPacket = Message(6, 5, Message::TC, 1); receivedPacket.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID receivedPacket.appendUint16(3); // Iteration count (Equal to 3 test strings) - receivedPacket.appendUint64(reinterpret_cast<uint64_t >(testString_1)); // Start address + receivedPacket.appendUint64(reinterpret_cast<uint64_t>(testString_1)); // Start address receivedPacket.appendUint16(sizeof(testString_1) / sizeof(testString_1[0])); // Data read length - receivedPacket.appendUint64(reinterpret_cast<uint64_t >(testString_2)); + receivedPacket.appendUint64(reinterpret_cast<uint64_t>(testString_2)); receivedPacket.appendUint16(sizeof(testString_2) / sizeof(testString_2[0])); - receivedPacket.appendUint64(reinterpret_cast<uint64_t >(testString_3)); + receivedPacket.appendUint64(reinterpret_cast<uint64_t>(testString_3)); receivedPacket.appendUint16(sizeof(testString_3) / sizeof(testString_3[0])); MessageParser::execute(receivedPacket); REQUIRE(ServiceTests::hasOneMessage()); @@ -60,7 +59,7 @@ TEST_CASE("TC[6,5]", "[service][st06]") { CHECK(response.readEnum8() == MemoryManagementService::MemoryID::EXTERNAL); CHECK(response.readUint16() == 3); - CHECK(response.readUint64() == reinterpret_cast<uint64_t >(testString_1)); + CHECK(response.readUint64() == reinterpret_cast<uint64_t>(testString_1)); readSize = response.readOctetString(checkString); checksum = response.readBits(16); CHECK(readSize == sizeof(testString_1) / sizeof(testString_1[0])); @@ -72,7 +71,7 @@ TEST_CASE("TC[6,5]", "[service][st06]") { CHECK(checkString[5] == '\0'); CHECK(checksum == CRCHelper::calculateCRC(checkString, readSize)); - CHECK(response.readUint64() == reinterpret_cast<uint64_t >(testString_2)); + CHECK(response.readUint64() == reinterpret_cast<uint64_t>(testString_2)); readSize = response.readOctetString(checkString); checksum = response.readBits(16); CHECK(readSize == sizeof(testString_2) / sizeof(testString_2[0])); @@ -86,7 +85,7 @@ TEST_CASE("TC[6,5]", "[service][st06]") { CHECK(checkString[7] == '\0'); CHECK(checksum == CRCHelper::calculateCRC(checkString, readSize)); - CHECK(response.readUint64() == reinterpret_cast<uint64_t >(testString_3)); + CHECK(response.readUint64() == reinterpret_cast<uint64_t>(testString_3)); readSize = response.readOctetString(checkString); checksum = response.readBits(16); CHECK(readSize == sizeof(testString_3) / sizeof(testString_3[0])); @@ -100,14 +99,13 @@ TEST_CASE("TC[6,9]", "[service][st06]") { uint8_t testString_2[8] = "SecStrT"; uint16_t readSize = 0, checksum = 0; - MemoryManagementService memMangService; Message receivedPacket = Message(6, 9, Message::TC, 1); receivedPacket.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID receivedPacket.appendUint16(2); // Iteration count - receivedPacket.appendUint64(reinterpret_cast<uint64_t >(testString_1)); // Start address + receivedPacket.appendUint64(reinterpret_cast<uint64_t>(testString_1)); // Start address receivedPacket.appendUint16(sizeof(testString_1) / sizeof(testString_1[0])); // Data read length - receivedPacket.appendUint64(reinterpret_cast<uint64_t >(testString_2)); + receivedPacket.appendUint64(reinterpret_cast<uint64_t>(testString_2)); receivedPacket.appendUint16(sizeof(testString_2) / sizeof(testString_2[0])); MessageParser::execute(receivedPacket); REQUIRE(ServiceTests::hasOneMessage()); @@ -119,13 +117,13 @@ TEST_CASE("TC[6,9]", "[service][st06]") { CHECK(response.readEnum8() == MemoryManagementService::MemoryID::EXTERNAL); CHECK(response.readUint16() == 2); - CHECK(response.readUint64() == reinterpret_cast<uint64_t >(testString_1)); + CHECK(response.readUint64() == reinterpret_cast<uint64_t>(testString_1)); readSize = response.readUint16(); checksum = response.readBits(16); CHECK(readSize == sizeof(testString_1) / sizeof(testString_1[0])); CHECK(checksum == CRCHelper::calculateCRC(testString_1, readSize)); - CHECK(response.readUint64() == reinterpret_cast<uint64_t >(testString_2)); + CHECK(response.readUint64() == reinterpret_cast<uint64_t>(testString_2)); readSize = response.readUint16(); checksum = response.readBits(16); CHECK(readSize == sizeof(testString_2) / sizeof(testString_2[0])); diff --git a/test/Services/ParameterService.cpp b/test/Services/ParameterService.cpp index 5ea20d5246b09e4efd5fae6784554ac82ae49521..d21f32bd200f27e3334d9d40de88f945468a7edf 100644 --- a/test/Services/ParameterService.cpp +++ b/test/Services/ParameterService.cpp @@ -3,16 +3,16 @@ #include "Message.hpp" #include "ServiceTests.hpp" -ParameterService & pserv = Services.parameterManagement; +ParameterService& pserv = Services.parameterManagement; TEST_CASE("Parameter Report Subservice") { SECTION("Faulty Instruction Handling Test") { Message request(20, 1, Message::TC, 1); Message report(20, 2, Message::TM, 1); - request.appendUint16(2); // number of requested IDs - request.appendUint16(34672); // faulty ID in this context - request.appendUint16(1); // valid + request.appendUint16(2); // number of requested IDs + request.appendUint16(34672); // faulty ID in this context + request.appendUint16(1); // valid MessageParser::execute(request); report = ServiceTests::get(0); @@ -22,8 +22,8 @@ TEST_CASE("Parameter Report Subservice") { request.readUint16(); while (report.readPosition <= report.dataSize) { - CHECK_FALSE(report.readUint16() == 34672); //fail if faulty ID is present in report - report.readUint32(); //ignore the carried settings + CHECK_FALSE(report.readUint16() == 34672); // fail if faulty ID is present in report + report.readUint32(); // ignore the carried settings } } @@ -31,7 +31,7 @@ TEST_CASE("Parameter Report Subservice") { // TODO: Update this test (and all tests in general) to use the error handler's output when // checking for assertions. SECTION("Wrong Message Type Handling Test") { - Message falseRequest(15, 3, Message::TM, 1); // a totally wrong message + Message falseRequest(15, 3, Message::TM, 1); // a totally wrong message MessageParser::execute(falseRequest); Message errorNotif = ServiceTests::get(0); @@ -43,7 +43,7 @@ TEST_CASE("Parameter Report Subservice") { CHECK(response.messageType == 2); CHECK(response.serviceType == 20); CHECK(response.packetType == Message::TM); - CHECK(response.readPosition == 0); // if empty, this should't change from 0 + CHECK(response.readPosition == 0); // if empty, this should't change from 0 } } @@ -52,19 +52,18 @@ TEST_CASE("Parameter Setting Subservice") { Message setRequest(20, 3, Message::TC, 1); Message reportRequest(20, 1, Message::TC, 1); - setRequest.appendUint16(2); // total number of IDs - setRequest.appendUint16(1); // correct ID in this context - setRequest.appendUint32(3735928559); // 0xDEADBEEF in hex (new setting) - setRequest.appendUint16(16742); // faulty ID in this context - setRequest.appendUint32(3131746989); // 0xBAAAAAAD (this shouldn't be found in the report) + setRequest.appendUint16(2); // total number of IDs + setRequest.appendUint16(1); // correct ID in this context + setRequest.appendUint32(3735928559); // 0xDEADBEEF in hex (new setting) + setRequest.appendUint16(16742); // faulty ID in this context + setRequest.appendUint32(3131746989); // 0xBAAAAAAD (this shouldn't be found in the report) reportRequest.appendUint16(2); reportRequest.appendUint16(16742); - reportRequest.appendUint16(1); // used to be 3, which pointed the bug with + reportRequest.appendUint16(1); // used to be 3, which pointed the bug with // numOfValidIds out, now is 1 in order to be a valid ID (a separate test for // numOfValidIds shall be introduced) - // Since every reporting and setting is called with the same (sometimes faulty) parameters, // and there are errors generated (as should be) it is important to catch and check for // them in order to preserve the integrity of the test. @@ -88,11 +87,11 @@ TEST_CASE("Parameter Setting Subservice") { Message after = ServiceTests::get(4); before.readUint16(); - after.readUint16(); // skip the number of IDs + after.readUint16(); // skip the number of IDs while (after.readPosition <= after.dataSize) { - CHECK(before.readUint16() == after.readUint16()); // check if all IDs are present - CHECK_FALSE(after.readUint32() == 0xBAAAAAAD); // fail if any settings are BAAAAAAD :P + CHECK(before.readUint16() == after.readUint16()); // check if all IDs are present + CHECK_FALSE(after.readUint32() == 0xBAAAAAAD); // fail if any settings are BAAAAAAD :P } } } diff --git a/test/Services/RequestVerificationService.cpp b/test/Services/RequestVerificationService.cpp index 8464dc5b8eb48cb1dfc1de38c0f4bcd3dfc59a20..6576bdbaa5b2183432e747a1a76b25788f646fda 100644 --- a/test/Services/RequestVerificationService.cpp +++ b/test/Services/RequestVerificationService.cpp @@ -3,7 +3,7 @@ #include <Message.hpp> #include "ServiceTests.hpp" -RequestVerificationService & reqVerifService = Services.requestVerification; +RequestVerificationService& reqVerifService = Services.requestVerification; TEST_CASE("TM[1,1]", "[service][st01]") { Message receivedMessage = Message(1, 1, Message::TC, 3); @@ -28,8 +28,7 @@ TEST_CASE("TM[1,1]", "[service][st01]") { TEST_CASE("TM[1,2]", "[service][st01]") { Message receivedMessage = Message(1, 2, Message::TC, 3); - reqVerifService.failAcceptanceVerification(receivedMessage, - ErrorHandler::UnknownAcceptanceError); + reqVerifService.failAcceptanceVerification(receivedMessage, ErrorHandler::UnknownAcceptanceError); REQUIRE(ServiceTests::hasOneMessage()); Message response = ServiceTests::get(0); @@ -72,8 +71,7 @@ TEST_CASE("TM[1,3]", "[service][st01]") { TEST_CASE("TM[1,4]", "[service][st01]") { Message receivedMessage = Message(1, 2, Message::TC, 3); - reqVerifService.failStartExecutionVerification(receivedMessage, - ErrorHandler::UnknownExecutionStartError); + reqVerifService.failStartExecutionVerification(receivedMessage, ErrorHandler::UnknownExecutionStartError); REQUIRE(ServiceTests::hasOneMessage()); Message response = ServiceTests::get(0); @@ -117,9 +115,7 @@ TEST_CASE("TM[1,5]", "[service][st01]") { TEST_CASE("TM[1,6]", "[service][st01]") { Message receivedMessage = Message(1, 5, Message::TC, 3); - reqVerifService.failProgressExecutionVerification(receivedMessage, - ErrorHandler::UnknownExecutionProgressError, - 0); + reqVerifService.failProgressExecutionVerification(receivedMessage, ErrorHandler::UnknownExecutionProgressError, 0); REQUIRE(ServiceTests::hasOneMessage()); Message response = ServiceTests::get(0); @@ -163,8 +159,7 @@ TEST_CASE("TM[1,7]", "[service][st01]") { TEST_CASE("TM[1,8]", "[service][st01]") { Message receivedMessage = Message(1, 8, Message::TC, 3); - reqVerifService.failCompletionExecutionVerification(receivedMessage, - ErrorHandler::UnknownExecutionCompletionError); + reqVerifService.failCompletionExecutionVerification(receivedMessage, ErrorHandler::UnknownExecutionCompletionError); REQUIRE(ServiceTests::hasOneMessage()); Message response = ServiceTests::get(0); diff --git a/test/Services/ServiceTests.hpp b/test/Services/ServiceTests.hpp index 09957305df164f3c7042ddd058aa19a4081b7054..df769167d28843854d9d6919a7730c5015d5b2f7 100644 --- a/test/Services/ServiceTests.hpp +++ b/test/Services/ServiceTests.hpp @@ -45,14 +45,14 @@ public: * Get a message from the list of queued messages to send * @param number The number of the message, starting from 0 in chronological order */ - static Message &get(uint64_t number) { + static Message& get(uint64_t number) { return queuedMessages.at(number); } /** * Add a message to the queue of messages having been sent */ - static void queue(const Message &message) { + static void queue(const Message& message) { queuedMessages.push_back(message); } @@ -95,7 +95,7 @@ public: Services.reset(); } -/** + /** * Return whether an error assertion function was called, which means that we are expecting this * request to contain errors * @return @@ -128,7 +128,7 @@ public: * @param errorType The error code of the Error, corresponding to the correct type as * specified in ErrorHandler */ - template<typename ErrorType> + template <typename ErrorType> static bool thrownError(ErrorType errorType) { ErrorHandler::ErrorSource errorSource = ErrorHandler::findErrorSource(errorType); @@ -138,4 +138,4 @@ public: } }; -#endif //ECSS_SERVICES_TESTS_SERVICES_SERVICETESTS_HPP +#endif // ECSS_SERVICES_TESTS_SERVICES_SERVICETESTS_HPP diff --git a/test/Services/TestService.cpp b/test/Services/TestService.cpp index b2a3ce689de532ee16b5ddd55d25e91f593fa061..b58e5b902ce0a9677deeb49004f66cbb9aafeefb 100644 --- a/test/Services/TestService.cpp +++ b/test/Services/TestService.cpp @@ -3,7 +3,7 @@ #include <Message.hpp> #include "ServiceTests.hpp" -TestService & testService = Services.testService; +TestService& testService = Services.testService; TEST_CASE("TM[17,1]", "[service][st17]") { Message receivedPacket = Message(17, 1, Message::TC, 1); diff --git a/test/Services/TimeBasedSchedulingService.cpp b/test/Services/TimeBasedSchedulingService.cpp index e6f5ec565012a24be66957b4d8a4d59b3e05d154..56a7267df7c9b2859a9d813bcd4ed780f01430e2 100644 --- a/test/Services/TimeBasedSchedulingService.cpp +++ b/test/Services/TimeBasedSchedulingService.cpp @@ -91,6 +91,7 @@ auto activityInsertion(TimeBasedSchedulingService& timeService) { return unit_test::Tester::scheduledActivities(timeService); // Return the activities vector } + TimeBasedSchedulingService & timeBasedService = Services.timeBasedScheduling; TEST_CASE("TC[11,1] Enable Schedule Execution", "[service][st11]") { diff --git a/test/Services/TimeManagementService.cpp b/test/Services/TimeManagementService.cpp index 7055523b6cd128c447b5ef6d30dbf737ed5e39a9..f196f8ebc4b5968f87a101bb3f9eea9cabeabc21 100644 --- a/test/Services/TimeManagementService.cpp +++ b/test/Services/TimeManagementService.cpp @@ -2,7 +2,7 @@ #include <Services/TimeManagementService.hpp> #include "ServiceTests.hpp" -TimeManagementService & timeService = Services.timeManagement; +TimeManagementService& timeService = Services.timeManagement; TEST_CASE("TM[9,3]", "[service][st09]") { TimeAndDate TimeInfo; @@ -17,7 +17,7 @@ TEST_CASE("TM[9,3]", "[service][st09]") { uint32_t currTime = TimeHelper::utcToSeconds(TimeInfo); - uint16_t elapsedDays = currTime/86400; + uint16_t elapsedDays = currTime / 86400; uint32_t msOfDay = currTime % 86400 * 1000; uint64_t timeFormat = (static_cast<uint64_t>(elapsedDays) << 32 | msOfDay); @@ -27,11 +27,11 @@ TEST_CASE("TM[9,3]", "[service][st09]") { CHECK(response.messageType == 3); CHECK(response.packetType == Message::TM); CHECK(response.readHalfword() == static_cast<uint16_t>(timeFormat >> 32)); - CHECK(response.readWord() == static_cast<uint32_t >(timeFormat)); + CHECK(response.readWord() == static_cast<uint32_t>(timeFormat)); Message message = Message(9, 128, Message::TC, 3); - message.appendHalfword(static_cast<uint16_t >(timeFormat >> 32)); - message.appendWord(static_cast<uint32_t >(timeFormat)); + message.appendHalfword(static_cast<uint16_t>(timeFormat >> 32)); + message.appendWord(static_cast<uint32_t>(timeFormat)); MessageParser::execute(message); TimeInfo = timeService.cdsTimeRequest(message); @@ -42,7 +42,6 @@ TEST_CASE("TM[9,3]", "[service][st09]") { CHECK(TimeInfo.minute == 15); CHECK(TimeInfo.second == 0); - // 1/1/2019 00:00:00 TimeInfo.year = 2019; TimeInfo.month = 1; @@ -53,7 +52,7 @@ TEST_CASE("TM[9,3]", "[service][st09]") { currTime = TimeHelper::utcToSeconds(TimeInfo); - elapsedDays = currTime/86400; + elapsedDays = currTime / 86400; msOfDay = currTime % 86400 * 1000; timeFormat = (static_cast<uint64_t>(elapsedDays) << 32 | msOfDay); @@ -63,11 +62,11 @@ TEST_CASE("TM[9,3]", "[service][st09]") { CHECK(response.messageType == 3); CHECK(response.packetType == Message::TM); CHECK(response.readHalfword() == static_cast<uint16_t>(timeFormat >> 32)); - CHECK(response.readWord() == static_cast<uint32_t >(timeFormat)); + CHECK(response.readWord() == static_cast<uint32_t>(timeFormat)); message = Message(9, 128, Message::TC, 3); - message.appendHalfword(static_cast<uint16_t >(timeFormat >> 32)); - message.appendWord(static_cast<uint32_t >(timeFormat)); + message.appendHalfword(static_cast<uint16_t>(timeFormat >> 32)); + message.appendWord(static_cast<uint32_t>(timeFormat)); TimeInfo = timeService.cdsTimeRequest(message); CHECK(TimeInfo.year == 2019); diff --git a/test/TestPlatform.cpp b/test/TestPlatform.cpp index f6297918c4bd8f09fe7e93a7902bf8ac9833963e..a4cbee4d07452934aec010d06061b4479cb2d775 100644 --- a/test/TestPlatform.cpp +++ b/test/TestPlatform.cpp @@ -6,30 +6,30 @@ #include "Services/ServiceTests.hpp" // Explicit template specializations for the logError() function -template void ErrorHandler::logError(const Message &, ErrorHandler::AcceptanceErrorType); -template void ErrorHandler::logError(const Message &, ErrorHandler::ExecutionStartErrorType); -template void ErrorHandler::logError(const Message &, ErrorHandler::ExecutionProgressErrorType); -template void ErrorHandler::logError(const Message &, ErrorHandler::ExecutionCompletionErrorType); -template void ErrorHandler::logError(const Message &, ErrorHandler::RoutingErrorType); +template void ErrorHandler::logError(const Message&, ErrorHandler::AcceptanceErrorType); +template void ErrorHandler::logError(const Message&, ErrorHandler::ExecutionStartErrorType); +template void ErrorHandler::logError(const Message&, ErrorHandler::ExecutionProgressErrorType); +template void ErrorHandler::logError(const Message&, ErrorHandler::ExecutionCompletionErrorType); +template void ErrorHandler::logError(const Message&, ErrorHandler::RoutingErrorType); template void ErrorHandler::logError(ErrorHandler::InternalErrorType); // Initialisation of ServiceTests properties std::vector<Message> ServiceTests::queuedMessages = std::vector<Message>(); std::multimap<std::pair<ErrorHandler::ErrorSource, uint16_t>, bool> ServiceTests::thrownErrors = - std::multimap<std::pair<ErrorHandler::ErrorSource, uint16_t>, bool>(); + std::multimap<std::pair<ErrorHandler::ErrorSource, uint16_t>, bool>(); bool ServiceTests::expectingErrors = false; -void Service::storeMessage(Message &message) { +void Service::storeMessage(Message& message) { // Just add the message to the queue ServiceTests::queue(message); } -template<typename ErrorType> -void ErrorHandler::logError(const Message &message, ErrorType errorType) { +template <typename ErrorType> +void ErrorHandler::logError(const Message& message, ErrorType errorType) { logError(errorType); } -template<typename ErrorType> +template <typename ErrorType> void ErrorHandler::logError(ErrorType errorType) { ServiceTests::addError(ErrorHandler::findErrorSource(errorType), errorType); } @@ -37,18 +37,18 @@ void ErrorHandler::logError(ErrorType errorType) { struct ServiceTestsListener : Catch::TestEventListenerBase { using TestEventListenerBase::TestEventListenerBase; // inherit constructor - void sectionEnded(Catch::SectionStats const §ionStats) override { + void sectionEnded(Catch::SectionStats const& sectionStats) override { // Make sure we don't have any errors if (not ServiceTests::isExpectingErrors()) { // An Error was thrown with this Message. If you expected this to happen, please call a // corresponding assertion function from ServiceTests to silence this message. - //TODO: Uncomment the following line as soon as Issue #19 is closed + // TODO: Uncomment the following line as soon as Issue #19 is closed // CHECK(ServiceTests::hasNoErrors()); } } - void testCaseEnded(Catch::TestCaseStats const &testCaseStats) override { + void testCaseEnded(Catch::TestCaseStats const& testCaseStats) override { // Tear-down after a test case is run ServiceTests::reset(); }