diff --git a/Inc/LoggerToSerialPort.h b/Inc/LoggerToSerialPort.h index ba77554..e2162f6 100644 --- a/Inc/LoggerToSerialPort.h +++ b/Inc/LoggerToSerialPort.h @@ -10,7 +10,6 @@ #include "RtcIO.h" #include - typedef struct { tSerialPortIO *serialPortIo_VIRT; tSerialPortIO *serialPortIo_PHYSIC; @@ -25,6 +24,14 @@ typedef struct { uint8_t buf_LOG[256]; + uint8_t bufPrintfLogger[MAX_COUNT_BUF_LOG][MAX_LEN_BUF_LOG]; + uint8_t bufPrintfNames[MAX_COUNT_BUF_LOG][MAX_LEN_BUF_NAME_LOG]; + uint8_t countBufPrintfNames; + + uint8_t bufLogger[MAX_COUNT_BUF_LOG][MAX_LEN_BUF_LOG]; + uint8_t bufLoggerNames[MAX_COUNT_BUF_LOG][MAX_LEN_BUF_NAME_LOG]; + uint8_t countBufLoggerNames; + struct { osThreadId_t id; uint32_t stack[384]; diff --git a/Src/LoggerToSerialPort.c b/Src/LoggerToSerialPort.c index 968d1a1..1e47002 100644 --- a/Src/LoggerToSerialPort.c +++ b/Src/LoggerToSerialPort.c @@ -8,9 +8,52 @@ #include "Rtc.h" #include #include "CmsisRtosThreadUtils.h" +#include "memory.h" #include CMSIS_device_header +static uint8_t *getMemPrintfBufLog(tLoggerToSerialPort *env, char *authorStatic, const uint8_t authorLen) { + + for (uint8_t i = 0; i < env->countBufPrintfNames; ++i) { + if (memcmp(env->bufPrintfNames[i], authorStatic, authorLen) == 0) { + return env->bufPrintfLogger[i]; + } + } + + configASSERT(env->countBufPrintfNames < MAX_COUNT_BUF_LOG); + + uint8_t len = authorLen; + if (authorLen > MAX_LEN_BUF_NAME_LOG) { + len = MAX_LEN_BUF_NAME_LOG; + } + + memcpy(env->bufPrintfNames[env->countBufPrintfNames], authorStatic, len); + ++env->countBufPrintfNames; + + return env->bufPrintfLogger[env->countBufPrintfNames - 1]; +} + +static uint8_t *getMemLoggerBufLog(tLoggerToSerialPort *env, char *authorStatic, const uint8_t authorLen) { + + for (uint8_t i = 0; i < env->countBufLoggerNames; ++i) { + if (memcmp(env->bufLoggerNames[i], authorStatic, authorLen) == 0) { + return env->bufLogger[i]; + } + } + + configASSERT(env->countBufLoggerNames < MAX_COUNT_BUF_LOG); + + uint8_t len = authorLen; + if (authorLen > MAX_LEN_BUF_NAME_LOG) { + len = MAX_LEN_BUF_NAME_LOG; + } + + memcpy(env->bufLoggerNames[env->countBufLoggerNames], authorStatic, len); + ++env->countBufLoggerNames; + + return env->bufLogger[env->countBufLoggerNames - 1]; +} + static void LoggerToSerialPort_TimeToString(time_t timestamp, char *strbuf) { struct tm timestampTM; localtime_r(×tamp, ×tampTM); @@ -23,14 +66,15 @@ static void LoggerToSerialPort_PrintLegend( const uint8_t authorLen, eLoggerLevel loglevel ) { - char str[128]; + //char str[128]; + char *str = (char *) getMemLoggerBufLog(env, authorStatic, authorLen); size_t strLen = 0; - time_t timestamp; - - char timeString[24]; - if (env->flags & (SERIAL_LOGGER_SHOW_DATE | SERIAL_LOGGER_SHOW_TIME)) { + + time_t timestamp; + char timeString[24]; + if (env->rtc) { RtcGet(env->rtc, ×tamp); timestamp += env->greenwichOffset * 3600; @@ -129,6 +173,7 @@ void LoggerToSerialPort_Init( env->logger.env = env; env->greenwichOffset = greenwichOffset; env->logger.logging = (LoggerGenericMethod) LoggerToSerialPort_Logging; + env->logger.getMemPrintfBufLog = (getMemPrintfBufLogMethod) getMemPrintfBufLog; env->rtc = rtc; env->flags = flags; env->timeoutTransmittedLog = timeoutTransmittedLog; @@ -144,7 +189,6 @@ void LoggerToSerialPort_Init( } - static _Noreturn void LogTransmitter_Thread(tLoggerToSerialPort *env) { for (;;) { uint16_t len = env->serialPortIo_VIRT->receive(env->serialPortIo_VIRT->env, env->buf_LOG,