diff --git a/CMakeLists.txt b/CMakeLists.txt index ab4a0c23da21cba1f8099c647336622dfdc369ae..1be913a658697eb33f7285d291d8cea22ac23714 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,8 @@ add_executable(ecss_services $<TARGET_OBJECTS:common> ${x86_main_SRC} ) +set_target_properties(ecss_services + PROPERTIES COMPILE_DEFINITIONS LOGLEVEL_TRACE) IF (EXISTS "${PROJECT_SOURCE_DIR}/lib/Catch2/CMakeLists.txt") # Gather all the .cpp files corresponding to tests diff --git a/inc/Logger.hpp b/inc/Logger.hpp index 894461eae37bee691170f052531e0be55a4956dc..48a3ab1923fd9d1958da424efe66291a042a9231 100644 --- a/inc/Logger.hpp +++ b/inc/Logger.hpp @@ -169,5 +169,6 @@ Logger::LogEntry& operator<<(Logger::LogEntry& entry, const T value) { return entry; } +Logger::LogEntry& operator<<(Logger::LogEntry& entry, const std::string & value); #endif //ECSS_SERVICES_LOGGER_HPP diff --git a/src/Logger.cpp b/src/Logger.cpp index 990c49df940068955576993dfcd6ff4bde0c1f79..bb3e40d83f6a77a10de0c5ff546c605b59a1a779 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -1,10 +1,16 @@ #include <Logger.hpp> +// Reimplementation of the function for variable C strings +template <> +Logger::LogEntry& operator<<(Logger::LogEntry& entry, char* value) { + entry.message.append(value); + return entry; +} + // Reimplementation of the function for C strings template <> Logger::LogEntry& operator<<(Logger::LogEntry& entry, const char* value) { entry.message.append(value); - return entry; } diff --git a/src/Platform/x86/ErrorHandler.cpp b/src/Platform/x86/ErrorHandler.cpp index a59e36514ddf1a7047ab4e2e2a47f05dfd4cfd89..ffddffd2d0501e688779674251ae1da83aa035d7 100644 --- a/src/Platform/x86/ErrorHandler.cpp +++ b/src/Platform/x86/ErrorHandler.cpp @@ -7,6 +7,7 @@ #include <cxxabi.h> #include <ErrorHandler.hpp> #include <Message.hpp> +#include <Logger.hpp> // TODO: Find a way to reduce the number of copies of this chunk template void ErrorHandler::logError(const Message&, ErrorHandler::AcceptanceErrorType); @@ -18,23 +19,22 @@ template void ErrorHandler::logError(ErrorHandler::InternalErrorType); template <typename ErrorType> void ErrorHandler::logError(const Message& message, ErrorType errorType) { - std::cerr + LOG_ERROR /* * 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; + << "]: " << errorType; } template <typename ErrorType> void ErrorHandler::logError(ErrorType errorType) { - std::cerr + LOG_ERROR /* * 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; + << abi::__cxa_demangle(typeid(ErrorType).name(), nullptr, nullptr, nullptr) << " Error: " << errorType; } diff --git a/src/Platform/x86/Logger.cpp b/src/Platform/x86/Logger.cpp index 9ee1b8b0fe236cab3d72400f323df9930b4bdcef..ed4fe3a079c6328d63ce7e8f215d3e9587e8991a 100644 --- a/src/Platform/x86/Logger.cpp +++ b/src/Platform/x86/Logger.cpp @@ -24,7 +24,6 @@ void Logger::log(Logger::LogLevel level, String<LOGGER_MAX_MESSAGE_SIZE> & messa } else if (level <= Logger::debug) { name = "debug"; colour = "90"; // bright black - keepColour = true; } else if (level <= Logger::info) { name = "info"; colour = "32"; // green @@ -59,3 +58,11 @@ void Logger::log(Logger::LogLevel level, String<LOGGER_MAX_MESSAGE_SIZE> & messa ss << "\n"; std::cerr << ss.str(); } + +// Reimplementation of the log function for C++ strings +// This is kept in the Platform files, since we don't want to mess with std::strings in the microcontroller +Logger::LogEntry& operator<<(Logger::LogEntry& entry, const std::string & value) { + entry.message.append(value.c_str()); + + return entry; +} diff --git a/src/Platform/x86/Service.cpp b/src/Platform/x86/Service.cpp index 7c20d2f90bea925cd43754c62a231c25bc2c5648..c44acb96e53b0d2f96ddc4022c19b4934e375660 100644 --- a/src/Platform/x86/Service.cpp +++ b/src/Platform/x86/Service.cpp @@ -1,21 +1,24 @@ #include <iostream> #include <iomanip> +#include <Logger.hpp> #include "Service.hpp" void Service::storeMessage(Message& message) { // appends the remaining bits to complete a byte message.finalize(); + // Create a new stream to display the packet + std::ostringstream ss; + // Just print it to the screen - 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); - for (int i = 0; i < message.dataSize; i++) { - std::cout << static_cast<int>(message.data[i]); - std::cout << " "; + ss << "New " << ((message.packetType == Message::TM) ? "TM" : "TC") << "[" + << std::hex + << static_cast<int>(message.serviceType) << "," << static_cast<int>(message.messageType) + << "] message! "; + + for (unsigned int i = 0; i < message.dataSize; i++) { + ss << static_cast<int>(message.data[i]) << " "; // Ignore-MISRA } - std::cout << std::endl; + + LOG_DEBUG << ss.str(); } diff --git a/src/Platform/x86/main.cpp b/src/Platform/x86/main.cpp index f53c4ae357477df24e0d3a3eb343f5e98c16a87e..2e15a3afd40df45d1dbfda53d9b624ddfab7542e 100644 --- a/src/Platform/x86/main.cpp +++ b/src/Platform/x86/main.cpp @@ -1,5 +1,3 @@ -#define LOGLEVEL_TRACE - #include <iostream> #include <ServicePool.hpp> #include <Logger.hpp>