diff --git a/defaultcfg/fsfwconfig/FSFWConfig.h b/defaultcfg/fsfwconfig/FSFWConfig.h index d94f6cc7..261e3d6d 100644 --- a/defaultcfg/fsfwconfig/FSFWConfig.h +++ b/defaultcfg/fsfwconfig/FSFWConfig.h @@ -9,25 +9,26 @@ //! the C stdio functions can be used alternatively #define FSFW_CPP_OSTREAM_ENABLED 1 -//! Reduced printout to further decrease code size +//! More FSFW related printouts. //! Be careful, this also turns off most diagnostic prinouts! #define FSFW_ENHANCED_PRINTOUT 0 //! Can be used to completely disable printouts, even the C stdio ones. -#if FSFW_CPP_OSTREAM_ENABLED == 1 +#if FSFW_CPP_OSTREAM_ENABLED == 0 && FSFW_ENHANCED_PRINTOUT == 0 #define FSFW_DISABLE_PRINTOUT 0 #endif //! Can be used to enable additional debugging printouts for developing the FSFW #define FSFW_PRINT_VERBOSITY_LEVEL 0 +//! Can be used to disable the ANSI color sequences for C stdio. +#define FSFW_COLORED_OUTPUT 1 + //! If FSFW_OBJ_EVENT_TRANSLATION is set to one, //! additional output which requires the translation files translateObjects //! and translateEvents (and their compiled source files) #define FSFW_OBJ_EVENT_TRANSLATION 0 -#define FSFW_COLORED_OUTPUT 1 - #if FSFW_OBJ_EVENT_TRANSLATION == 1 //! Specify whether info events are printed too. #define FSFW_DEBUG_INFO 1 diff --git a/serviceinterface/ServiceInterfaceBuffer.cpp b/serviceinterface/ServiceInterfaceBuffer.cpp index 68fc4dec..eb940cfa 100644 --- a/serviceinterface/ServiceInterfaceBuffer.cpp +++ b/serviceinterface/ServiceInterfaceBuffer.cpp @@ -1,5 +1,7 @@ #include "../timemanager/Clock.h" #include "ServiceInterfaceBuffer.h" +#include "serviceInterfaceDefintions.h" +#include #include #include @@ -17,6 +19,21 @@ ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string setMessage, // Set pointers if the stream is buffered. setp( buf, buf + BUF_SIZE ); } + +#if FSFW_COLORED_OUTPUT == 1 + if(setMessage.find("DEBUG")) { + colorPrefix = fsfw::ANSI_COLOR_MAGENTA; + } + else if(setMessage.find("INFO")) { + colorPrefix = fsfw::ANSI_COLOR_GREEN; + } + else if(setMessage.find("WARNING")) { + colorPrefix = fsfw::ANSI_COLOR_YELLOW; + } + else if(setMessage.find("ERROR")) { + colorPrefix = fsfw::ANSI_COLOR_RED; + } +#endif preamble.reserve(MAX_PREAMBLE_SIZE); preamble.resize(MAX_PREAMBLE_SIZE); } @@ -102,6 +119,12 @@ std::string* ServiceInterfaceBuffer::getPreamble(size_t * preambleSize) { currentSize += 1; parsePosition += 1; } + +#if FSFW_COLORED_OUTPUT == 1 + currentSize += sprintf(parsePosition, "%s", colorPrefix.c_str()); + parsePosition += colorPrefix.size(); +#endif + int32_t charCount = sprintf(parsePosition, "%s: | %02" SCNu32 ":%02" SCNu32 ":%02" SCNu32 ".%03" SCNu32 " | ", this->logMessage.c_str(), loggerTime.hour, diff --git a/serviceinterface/ServiceInterfaceBuffer.h b/serviceinterface/ServiceInterfaceBuffer.h index c953846d..8f2a601c 100644 --- a/serviceinterface/ServiceInterfaceBuffer.h +++ b/serviceinterface/ServiceInterfaceBuffer.h @@ -42,6 +42,11 @@ private: //! For additional message information std::string logMessage; std::string preamble; + +#if FSFW_COLORED_OUTPUT == 1 + std::string colorPrefix; +#endif + // For EOF detection typedef std::char_traits Traits; diff --git a/serviceinterface/ServiceInterfacePrinter.cpp b/serviceinterface/ServiceInterfacePrinter.cpp index 04430d61..177d7c4a 100644 --- a/serviceinterface/ServiceInterfacePrinter.cpp +++ b/serviceinterface/ServiceInterfacePrinter.cpp @@ -1,8 +1,10 @@ #include "ServiceInterfacePrinter.h" +#include "serviceInterfaceDefintions.h" #include "../timemanager/Clock.h" #include + #include #include @@ -25,7 +27,7 @@ void fsfwPrint(fsfw::PrintLevel printType, const char* fmt, va_list arg) { len += sprintf((char *)printBuffer, fsfw::ANSI_COLOR_GREEN); } else if(printType == fsfw::PrintLevel::DEBUG) { - len += sprintf((char *)printBuffer, fsfw::ANSI_COLOR_BLUE); + len += sprintf((char *)printBuffer, fsfw::ANSI_COLOR_MAGENTA); } else if(printType == fsfw::PrintLevel::WARNING) { len += sprintf((char *)printBuffer, fsfw::ANSI_COLOR_YELLOW); diff --git a/serviceinterface/ServiceInterfacePrinter.h b/serviceinterface/ServiceInterfacePrinter.h index a2ba483d..1991f412 100644 --- a/serviceinterface/ServiceInterfacePrinter.h +++ b/serviceinterface/ServiceInterfacePrinter.h @@ -11,15 +11,6 @@ enum class PrintLevel { DEBUG = 4 }; - -static const char* const ANSI_COLOR_RED = "\x1b[31m"; -static const char* const ANSI_COLOR_GREEN = "\x1b[32m"; -static const char* const ANSI_COLOR_YELLOW = "\x1b[33m"; -static const char* const ANSI_COLOR_BLUE = "\x1b[34m"; -static const char* const ANSI_COLOR_MAGENTA = "\x1b[35m"; -static const char* const ANSI_COLOR_CYAN = "\x1b[36m"; -static const char* const ANSI_COLOR_RESET = "\x1b[0m"; - void setPrintLevel(PrintLevel printLevel); PrintLevel getPrintLevel(); diff --git a/serviceinterface/ServiceInterfaceStream.cpp b/serviceinterface/ServiceInterfaceStream.cpp index 5b7b9f00..05643460 100644 --- a/serviceinterface/ServiceInterfaceStream.cpp +++ b/serviceinterface/ServiceInterfaceStream.cpp @@ -13,20 +13,3 @@ std::string* ServiceInterfaceStream::getPreamble() { return streambuf.getPreamble(); } -void ServiceInterfaceStream::print(std::string error, - bool withPreamble, bool withNewline, bool flush) { - if(not streambuf.isBuffered() and withPreamble) { - *this << getPreamble() << error; - } - else { - *this << error; - } - - if(withNewline) { - *this << "\n"; - } - // if mode is non-buffered, no need to flush. - if(flush and streambuf.isBuffered()) { - this->flush(); - } -} diff --git a/serviceinterface/ServiceInterfaceStream.h b/serviceinterface/ServiceInterfaceStream.h index 76fa1bf2..cd2adf85 100644 --- a/serviceinterface/ServiceInterfaceStream.h +++ b/serviceinterface/ServiceInterfaceStream.h @@ -35,13 +35,6 @@ public: */ std::string* getPreamble(); - /** - * This prints an error with a preamble. Useful if using the unbuffered - * mode. Flushes in default mode (prints immediately). - */ - void print(std::string error, bool withPreamble = true, - bool withNewline = true, bool flush = true); - protected: ServiceInterfaceBuffer streambuf; }; diff --git a/serviceinterface/serviceInterfaceDefintions.h b/serviceinterface/serviceInterfaceDefintions.h new file mode 100644 index 00000000..684c7366 --- /dev/null +++ b/serviceinterface/serviceInterfaceDefintions.h @@ -0,0 +1,16 @@ +#ifndef FSFW_SERVICEINTERFACE_SERVICEINTERFACEDEFINTIONS_H_ +#define FSFW_SERVICEINTERFACE_SERVICEINTERFACEDEFINTIONS_H_ + +namespace fsfw { + +static const char* const ANSI_COLOR_RED = "\x1b[31m"; +static const char* const ANSI_COLOR_GREEN = "\x1b[32m"; +static const char* const ANSI_COLOR_YELLOW = "\x1b[33m"; +static const char* const ANSI_COLOR_BLUE = "\x1b[34m"; +static const char* const ANSI_COLOR_MAGENTA = "\x1b[35m"; +static const char* const ANSI_COLOR_CYAN = "\x1b[36m"; +static const char* const ANSI_COLOR_RESET = "\x1b[0m"; + +} + +#endif /* FSFW_SERVICEINTERFACE_SERVICEINTERFACEDEFINTIONS_H_ */