Добавлены интерфейсы и драйверы

This commit is contained in:
cfif 2025-09-30 15:52:33 +03:00
commit b57010d3e8
3 changed files with 211 additions and 0 deletions

40
Inc/LoggerToSerialPort.h Normal file
View File

@ -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

134
Src/LoggerToSerialPort.c Normal file
View File

@ -0,0 +1,134 @@
//
// Created by xemon on 13.11.22.
//
#include <stdbool.h>
#include "LoggerToSerialPort.h"
#include "SystemDelayInterface.h"
#include "AsciiStringAssmeblingUtils.h"
#include "Rtc.h"
#include <time.h>
#include CMSIS_device_header
static void LoggerToSerialPort_TimeToString(time_t timestamp, char *strbuf) {
struct tm timestampTM;
localtime_r(&timestamp, &timestampTM);
asctime_r(&timestampTM, 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, &timestamp);
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;
}

37
modular.json Normal file
View File

@ -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"
]
}
}