diff --git a/DbgTracePort.cpp b/DbgTracePort.cpp index 61d0cd4..de5a19f 100644 --- a/DbgTracePort.cpp +++ b/DbgTracePort.cpp @@ -5,10 +5,10 @@ * Author: niklausd */ -#include "DbgTraceContext.h" -#include "DbgTraceOut.h" -#include "DbgTracePort.h" -#include "DbgCliCommand.h" +#include +#include +#include +#include #ifdef ARDUINO #include @@ -17,6 +17,7 @@ #endif #include #include +#include //----------------------------------------------------------------------------- // concrete command class DbgCli_Command_ChangeOut @@ -372,6 +373,16 @@ DbgTrace_Port::~DbgTrace_Port() } } +void DbgTrace_Port::printStrFormat(const char* format, ...) +{ + char stream[s_cTraceBufSize]; + va_list args; + va_start(args, format); + vsnprintf(stream, s_cTraceBufSize, format, args); + va_end(args); + printStr(stream); +} + void DbgTrace_Port::printStr(const char* str) { if(0 != m_out) diff --git a/DbgTracePort.h b/DbgTracePort.h index aa371d5..a005127 100644 --- a/DbgTracePort.h +++ b/DbgTracePort.h @@ -17,6 +17,7 @@ class DbgTrace_Context; class DbgTrace_Out; class DbgCli_Topic; +#define TR_PRINTF(PORT, LEVEL, args...) do { if ((PORT)->getLevel()>=(LEVEL)) (PORT)->printStrFormat(args); } while (0); #define TR_PRINT_STR(PORT, LEVEL, MSG) do { if (((PORT)->getLevel()>=(LEVEL))) (PORT)->printStr((MSG)); } while (0); #define TR_PRINT_LONG(PORT, LEVEL, MSG) do { if (((PORT)->getLevel()>=(LEVEL))) (PORT)->printLong((MSG)); } while (0); #define TR_PRINT_DBL(PORT, LEVEL, MSG) do { if (((PORT)->getLevel()>=(LEVEL))) (PORT)->printDbl((MSG)); } while (0); @@ -104,6 +105,13 @@ class DbgTrace_Port */ DbgTrace_Level::Level getLevel() { return m_level; } + /** + * @brief Helper method to print a formatted string. Don't call this function directly, use the defined macros. + * @param format Const char format string to be printed out. + * @param var_arg Variable list of paramters to be printed according to placeholders in the format string. + */ + void printStrFormat(const char* format, ...); + /** * @brief Helper method to print a string. Don't call this function directly, use the defined macros. * @param str Const char message to be printed out. @@ -148,7 +156,7 @@ class DbgTrace_Port static const unsigned int s_cMaxPortTagLength = 16; /*!< Max. number of characters for a tag name of a trace port. */ static const unsigned int s_cTestTimeStamp = 10; /*!< Max. number of characters for the printed time-stamp using the test environment. */ static const unsigned int s_cArduinoTimeStamp = 12; /*!< Max. number of characters for the printed time-stamp using arduino. */ - static const unsigned int s_cTraceBufSize = s_cMaxPortTagLength + s_cMaxPortTagLength + 40; /*!< Max. number of characters of the hole printed message. */ + static const unsigned int s_cTraceBufSize = s_cMaxPortTagLength + s_cMaxPortTagLength + 100; /*!< Max. number of characters of the hole printed message. */ private: