diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7f4cb416c083d265558da75d457237d671..ddbb1a0de8b0c80ce8e40c9cc0cfb6a7952199c1 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,9 @@ <project version="4"> <component name="VcsDirectoryMappings"> <mapping directory="$PROJECT_DIR$" vcs="Git" /> + <mapping directory="$PROJECT_DIR$/Lib/ecss-services" vcs="Git" /> + <mapping directory="$PROJECT_DIR$/Lib/ecss-services/ci/page_style/doxygen_dark_theme" vcs="Git" /> + <mapping directory="$PROJECT_DIR$/Lib/ecss-services/lib/Catch2" vcs="Git" /> + <mapping directory="$PROJECT_DIR$/Lib/ecss-services/lib/etl" vcs="Git" /> </component> </project> \ No newline at end of file diff --git a/Lib/ecss-services b/Lib/ecss-services index 49f6188a6128ab6da80fb0589eddbafc1eebf635..5e8c791d34a23f504946d8d38c565591e4308be0 160000 --- a/Lib/ecss-services +++ b/Lib/ecss-services @@ -1 +1 @@ -Subproject commit 49f6188a6128ab6da80fb0589eddbafc1eebf635 +Subproject commit 5e8c791d34a23f504946d8d38c565591e4308be0 diff --git a/Src/Platform/ErrorHandler.cpp b/Src/Platform/ErrorHandler.cpp index 1e35cfff26be5a2016ebe62c45fc3ab9ccaacd24..775da7d74bd0d4c38e337b48cf1fc6b18d413737 100644 --- a/Src/Platform/ErrorHandler.cpp +++ b/Src/Platform/ErrorHandler.cpp @@ -8,6 +8,7 @@ #include <cxxabi.h> #include <ErrorHandler.hpp> #include <Message.hpp> +#include <inc/Logger.hpp> template void ErrorHandler::logError(const Message&, ErrorHandler::AcceptanceErrorType); template void ErrorHandler::logError(const Message&, ErrorHandler::ExecutionStartErrorType); @@ -18,14 +19,11 @@ template void ErrorHandler::logError(ErrorHandler::InternalErrorType); template <typename ErrorType> void ErrorHandler::logError(const Message& message, ErrorType errorType) { - char string [90]; - snprintf(string, 90, "ERROR %s on [%2d,%2d]\r\n", abi::__cxa_demangle(typeid(ErrorType).name(), nullptr, nullptr, nullptr), message.serviceType, message.messageType); - sendUARTString(string); + LOG_ERROR << abi::__cxa_demangle(typeid(ErrorType).name(), nullptr, nullptr, nullptr) + << " on " << "[" << message.serviceType << "," << message.messageType << "]"; } template <typename ErrorType> void ErrorHandler::logError(ErrorType errorType) { - char string [90]; - snprintf(string, 90, "ERROR %s\r\n", abi::__cxa_demangle(typeid(ErrorType).name(), nullptr, nullptr, nullptr)); - sendUARTString(string); + LOG_ERROR << abi::__cxa_demangle(typeid(ErrorType).name(), nullptr, nullptr, nullptr); } diff --git a/Src/Platform/Logger.cpp b/Src/Platform/Logger.cpp new file mode 100644 index 0000000000000000000000000000000000000000..290c712afa2a3d9087bf97693b02077eded51bd3 --- /dev/null +++ b/Src/Platform/Logger.cpp @@ -0,0 +1,26 @@ +#include <inc/Logger.hpp> +#include "main.h" + +void Logger::log(Logger::LogLevel level, String<LOGGER_MAX_MESSAGE_SIZE> & message) { + char uartMessage[256]; + char name[10]; + + if (level <= Logger::trace) { + strcpy(name, "trace"); + } else if (level <= Logger::debug) { + strcpy(name, "debug"); + } else if (level <= Logger::info) { + strcpy(name, "info"); + } else if (level <= Logger::notice) { + strcpy(name, "notice"); + } else if (level <= Logger::warning) { + strcpy(name, "warning"); + } else if (level <= Logger::error) { + strcpy(name, "error"); + } else { + strcpy(name, "emergency"); + } + + snprintf(uartMessage, 256, "%-7lu [%-7s] %s\r\n", HAL_GetTick(), name, message.c_str()); + sendUARTString(uartMessage); +} \ No newline at end of file diff --git a/Src/Platform/Service.cpp b/Src/Platform/Service.cpp index eeed00a0192a778e32a79c17bd63a7dd5687d57e..9ca0c349cdf1776e482cc9a8e344ec6309cae0bc 100644 --- a/Src/Platform/Service.cpp +++ b/Src/Platform/Service.cpp @@ -1,15 +1,14 @@ #include "main.h" #include <iostream> #include <iomanip> +#include <inc/Logger.hpp> #include "Service.hpp" void Service::storeMessage(Message& message) { // appends the remaining bits to complete a byte message.finalize(); - // Generate a report and send it away via UART - char string[90]; - snprintf(string, 90, "New %s [%2d,%2d]\r\n", (message.packetType == Message::TM) ? "TM" : "TC", message.serviceType, message.messageType); - - sendUARTString(string); + // Generate a report and log it away + LOG_DEBUG << "New " << ((message.packetType == Message::TM) ? "TM" : "TC") + << " [" << message.serviceType << "," << message.messageType << "]"; } diff --git a/Src/main.c b/Src/main.c index 67d9137353b63d386f162b6a0558ed4caecad874..edd0aee60d7e8bf7113c8af38fb152f2cd11a1a2 100644 --- a/Src/main.c +++ b/Src/main.c @@ -105,12 +105,8 @@ int main(void) #pragma clang diagnostic ignored "-Wmissing-noreturn" while (1) { - const char string[90]; - snprintf(string, 90, "A? %d\r\n", HAL_GetTick()); - main_cpp(); - HAL_UART_Transmit(&huart2, string, strlen(string), 10000); HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_2); HAL_Delay(100); /* USER CODE END WHILE */ diff --git a/Src/mockup.cpp b/Src/mockup.cpp index f87b41c124fdb036868a84a4b6679941ff5fee8d..48c748f14ab203fbed666b993b8ebb7fb7bfe131 100644 --- a/Src/mockup.cpp +++ b/Src/mockup.cpp @@ -1,6 +1,7 @@ #include <cstdio> #include <inc/ServicePool.hpp> #include <inc/Message.hpp> +#include <inc/Logger.hpp> extern "C" { #include "main.h" @@ -40,8 +41,6 @@ extern "C" { ErrorHandler::reportError(msg, ErrorHandler::UnknownAcceptanceError); // Print the temperature - char temperature[50]; - snprintf(temperature, 50, "Temperature is %.1f\r\n", getTemperature(), getTemperature()); - sendUARTString(temperature); + LOG_INFO << "Temperature is " << getTemperature(); } } \ No newline at end of file