Обновление

This commit is contained in:
cfif 2026-03-11 11:08:21 +03:00
parent b84f837913
commit 8edf3e2514
2 changed files with 58 additions and 7 deletions

View File

@ -10,7 +10,6 @@
#include "RtcIO.h"
#include <cmsis_os.h>
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];

View File

@ -8,9 +8,52 @@
#include "Rtc.h"
#include <time.h>
#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(&timestamp, &timestampTM);
@ -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;
if (env->flags & (SERIAL_LOGGER_SHOW_DATE | SERIAL_LOGGER_SHOW_TIME)) {
time_t timestamp;
char timeString[24];
if (env->flags & (SERIAL_LOGGER_SHOW_DATE | SERIAL_LOGGER_SHOW_TIME)) {
if (env->rtc) {
RtcGet(env->rtc, &timestamp);
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,