commit b57010d3e8ba65fbd3593224af0512892ab5b8bc Author: cfif Date: Tue Sep 30 15:52:33 2025 +0300 Добавлены интерфейсы и драйверы diff --git a/Inc/LoggerToSerialPort.h b/Inc/LoggerToSerialPort.h new file mode 100644 index 0000000..fff8a4a --- /dev/null +++ b/Inc/LoggerToSerialPort.h @@ -0,0 +1,40 @@ +// +// Created by xemon on 13.11.22. +// + +#ifndef UVEOS_ON_NATION_LOGGERTOSERIALPORT_H +#define UVEOS_ON_NATION_LOGGERTOSERIALPORT_H + +#include "SerialPort.h" +#include "LoggerInterface.h" +#include "RtcIO.h" + +typedef struct { + tSerialPortIO *serialPortIo; + tRtcIO *rtc; + uint32_t timeout; + uint8_t authorLimit; + bool open; + tLoggerInterface logger; + uint16_t flags; + int32_t greenwichOffset; +} tLoggerToSerialPort; + +#define SERIAL_LOGGER_SHOW_AUTHOR 0b1 << 0 +#define SERIAL_LOGGER_SHOW_LOG_LEVEL 0b1 << 1 +#define SERIAL_LOGGER_SHOW_TIME 0b1 << 2 +#define SERIAL_LOGGER_SHOW_DATE 0b1 << 3 + +void LoggerToSerialPort_Init( + tLoggerToSerialPort *env, + int32_t greenwichOffset, + tSerialPortIO *serialPortIo, + tRtcIO *rtc, + uint16_t flags +// bool showDate, +// bool showTime, +// bool showLoglevel, +// bool showAuthor +); + +#endif //UVEOS_ON_NATION_LOGGERTOSERIALPORT_H diff --git a/Src/LoggerToSerialPort.c b/Src/LoggerToSerialPort.c new file mode 100644 index 0000000..033cbac --- /dev/null +++ b/Src/LoggerToSerialPort.c @@ -0,0 +1,134 @@ +// +// Created by xemon on 13.11.22. +// +#include +#include "LoggerToSerialPort.h" +#include "SystemDelayInterface.h" +#include "AsciiStringAssmeblingUtils.h" +#include "Rtc.h" +#include +#include CMSIS_device_header + + +static void LoggerToSerialPort_TimeToString(time_t timestamp, char *strbuf) { + struct tm timestampTM; + localtime_r(×tamp, ×tampTM); + asctime_r(×tampTM, strbuf); +} + +static void LoggerToSerialPort_PrintLegend( + tLoggerToSerialPort *env, + const char *authorStatic, + const uint8_t authorLen, + eLoggerLevel loglevel +) { + char str[128]; + size_t strLen = 0; + + time_t timestamp; + + char timeString[24]; + + if (env->flags & (SERIAL_LOGGER_SHOW_DATE | SERIAL_LOGGER_SHOW_TIME)) { + if (env->rtc) { + RtcGet(env->rtc, ×tamp); + timestamp += env->greenwichOffset * 3600; + } else { + uint32_t msFromDeviceStart = SystemGetMs() / 1000; + timestamp = 1672531200 + msFromDeviceStart; + } + + LoggerToSerialPort_TimeToString(timestamp, timeString); + + if (env->flags & SERIAL_LOGGER_SHOW_DATE) { + vAsciiStringAdd(str, &strLen, &timeString[20], 4); + vAsciiStringAdd(str, &strLen, &timeString[3], 7); + vAsciiStringAdd(str, &strLen, " ", 1); + } + + if (env->flags & SERIAL_LOGGER_SHOW_TIME) { + vAsciiStringAdd(str, &strLen, &timeString[11], 8); + vAsciiStringAdd(str, &strLen, " ", 1); + } + } + + if (env->flags & SERIAL_LOGGER_SHOW_AUTHOR) { + //выводим автора сообщения + vAsciiStringAdd(str, &strLen, authorStatic, authorLen); + } + + if (env->flags & SERIAL_LOGGER_SHOW_LOG_LEVEL) { + tStringStatic levelName = LOGGER_LEVEL_NAMES[loglevel]; + //выводим уровень сообщения + vAsciiStringAddChar(str, &strLen, '['); + vAsciiStringAdd(str, &strLen, levelName.data, levelName.length); + vAsciiStringAddChar(str, &strLen, ']'); + } + + + //разделитель + if (env->flags) + vAsciiStringAdd(str, &strLen, ": ", 2); + + SerialPortTransmit(env->serialPortIo, (uint8_t *) str, strLen, env->timeout); + + env->open = true; +} + +static void LoggerToSerialPort_Logging( + tLoggerToSerialPort *env, + const char *authorStatic, + const uint8_t authorLen, + eLoggerLevel loglevel, + char *msg, + uint16_t msgLen, + bool complete +) { + + uint32_t adr = *(uint32_t *)(env->serialPortIo->env); + + uint32_t timeoutLocal = env->timeout; + // Если это UART (виртуальный) +// if (adr < PERIPH_BASE) { +// env->timeout = 0; +// } + + if (!env->open) { + LoggerToSerialPort_PrintLegend(env, authorStatic, authorLen, loglevel); + } + + //выводим сообщение + SerialPortTransmit(env->serialPortIo, (uint8_t *) msg, msgLen, env->timeout); + + if (complete) { + //переводим строку + SerialPortTransmit(env->serialPortIo, (uint8_t *) "\r\n", 2, env->timeout); + env->open = false; + } else { + env->open = true; + } + + env->timeout = timeoutLocal; +} + + +void LoggerToSerialPort_Init( + tLoggerToSerialPort *env, + int32_t greenwichOffset, + tSerialPortIO *serialPortIo, + tRtcIO *rtc, + uint16_t flags +) { + env->serialPortIo = serialPortIo; + env->open = false; + env->timeout = 200;// не ждем на каждой операции так как если порт исправен то все должно отрабатывать моментально + env->logger.env = env; + env->greenwichOffset = greenwichOffset; + env->logger.logging = (LoggerGenericMethod) LoggerToSerialPort_Logging; + env->rtc = rtc; + env->flags = flags; +// env->showDate = showDate; +// env->showTime = showTime; +// env->showLoglevel = showLoglevel; +// env->showAuthor = showAuthor; +} diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..dd169ba --- /dev/null +++ b/modular.json @@ -0,0 +1,37 @@ +{ + "dep": [ + { + "type": "git", + "provider": "HVAC_M7", + "repo": "RtcInterface" + }, + { + "type": "git", + "provider": "HVAC_M7", + "repo": "Rtc" + }, + { + "type": "git", + "provider": "HVAC_M7", + "repo": "SerialPort" + }, + { + "type": "git", + "provider": "HVAC_M7", + "repo": "LoggerInterface" + }, + { + "type": "git", + "provider": "HVAC_M7", + "repo": "AsciiStringAssemblingUtils" + } + ], + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file