diff --git a/Inc/LoggerToSerialPort.h b/Inc/LoggerToSerialPort.h index 378f8e7..3f460d1 100644 --- a/Inc/LoggerToSerialPort.h +++ b/Inc/LoggerToSerialPort.h @@ -35,6 +35,8 @@ typedef struct { uint8_t bufLoggerNames[MAX_COUNT_BUF_LOG][MAX_LEN_BUF_NAME_LOG]; uint8_t countBufLoggerNames; + osMutexId_t access; + struct { osThreadId_t id; uint32_t stack[384]; diff --git a/Src/LoggerToSerialPort.c b/Src/LoggerToSerialPort.c index e2de63d..696a648 100644 --- a/Src/LoggerToSerialPort.c +++ b/Src/LoggerToSerialPort.c @@ -57,8 +57,9 @@ static void LoggerToSerialPort_TimeToString(time_t timestamp, char *strbuf) { asctime_r(×tampTM, strbuf); } -static void LoggerToSerialPort_PrintLegend( +static uint32_t LoggerToSerialPort_PrintLegend( tLoggerToSerialPort *env, + char *outStr[], char *authorStatic, const uint8_t authorLen, eLoggerLevel loglevel @@ -113,9 +114,12 @@ static void LoggerToSerialPort_PrintLegend( if (env->flags) vAsciiStringAdd(str, &strLen, ": ", 2); - SerialPortTransmit(env->serialPortIo_VIRT, (uint8_t *) str, strLen, env->timeout); +// SerialPortTransmit(env->serialPortIo_VIRT, (uint8_t *) str, strLen, env->timeout); + *outStr = str; env->open = true; + + return strLen; } static void LoggerToSerialPort_Logging( @@ -136,19 +140,30 @@ static void LoggerToSerialPort_Logging( // env->timeout = 0; // } - if (!env->open) { - LoggerToSerialPort_PrintLegend(env, authorStatic, authorLen, loglevel); - } + char *outStr = NULL; + uint32_t lenStr; - //выводим сообщение - SerialPortTransmit(env->serialPortIo_VIRT, (uint8_t *) msg, msgLen, env->timeout); +// if (!env->open) { + lenStr = LoggerToSerialPort_PrintLegend(env, &outStr, authorStatic, authorLen, loglevel); +// } - if (complete) { - //переводим строку - SerialPortTransmit(env->serialPortIo_VIRT, (uint8_t *) "\r\n", 2, env->timeout); - env->open = false; - } else { - env->open = true; + if (osMutexAcquire(env->access, env->timeout) == osOK) { + + //выводим сообщение + if (outStr != NULL) { + SerialPortTransmit(env->serialPortIo_VIRT, (uint8_t *) outStr, lenStr, env->timeout); + } + + SerialPortTransmit(env->serialPortIo_VIRT, (uint8_t *) msg, msgLen, env->timeout); + + if (complete) { + //переводим строку + SerialPortTransmit(env->serialPortIo_VIRT, (uint8_t *) "\r\n", 2, env->timeout); + // env->open = false; + } else { + // env->open = true; + } + osMutexRelease(env->access); } // env->timeout = timeoutLocal; @@ -175,6 +190,9 @@ void LoggerToSerialPort_Init( env->rtc = rtc; env->flags = flags; env->timeoutTransmittedLog = timeoutTransmittedLog; + + env->access = osMutexNew(NULL); + // env->showDate = showDate; // env->showTime = showTime; // env->showLoglevel = showLoglevel;