Обновление
This commit is contained in:
parent
62b73298e3
commit
60f80e3c34
|
|
@ -8,16 +8,29 @@
|
|||
#include "SerialPort.h"
|
||||
#include "LoggerInterface.h"
|
||||
#include "RtcIO.h"
|
||||
#include <cmsis_os.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
tSerialPortIO *serialPortIo;
|
||||
tSerialPortIO *serialPortIo_IN_VIRT;
|
||||
tSerialPortIO *serialPortIo_OUT_VIRT;
|
||||
tSerialPortIO *serialPortIo_PHYSIC;
|
||||
tRtcIO *rtc;
|
||||
uint32_t timeout;
|
||||
uint32_t timeoutTransmittedLog;
|
||||
uint8_t authorLimit;
|
||||
bool open;
|
||||
tLoggerInterface logger;
|
||||
uint16_t flags;
|
||||
int32_t greenwichOffset;
|
||||
|
||||
struct {
|
||||
osThreadId_t id;
|
||||
uint32_t stack[512];
|
||||
StaticTask_t controlBlock;
|
||||
osThreadAttr_t attr;
|
||||
} thread;
|
||||
|
||||
} tLoggerToSerialPort;
|
||||
|
||||
#define SERIAL_LOGGER_SHOW_AUTHOR 0b1 << 0
|
||||
|
|
@ -28,13 +41,18 @@ typedef struct {
|
|||
void LoggerToSerialPort_Init(
|
||||
tLoggerToSerialPort *env,
|
||||
int32_t greenwichOffset,
|
||||
tSerialPortIO *serialPortIo,
|
||||
tSerialPortIO *serialPortIo_IN_VIRT,
|
||||
tSerialPortIO *serialPortIo_OUT_VIRT,
|
||||
tSerialPortIO *serialPortIo_PHYSIC,
|
||||
tRtcIO *rtc,
|
||||
uint16_t flags
|
||||
uint16_t flags,
|
||||
uint32_t timeoutTransmittedLog
|
||||
// bool showDate,
|
||||
// bool showTime,
|
||||
// bool showLoglevel,
|
||||
// bool showAuthor
|
||||
);
|
||||
|
||||
void LogTransmitter_StartThread(tLoggerToSerialPort *env);
|
||||
|
||||
#endif //UVEOS_ON_NATION_LOGGERTOSERIALPORT_H
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "AsciiStringAssmeblingUtils.h"
|
||||
#include "Rtc.h"
|
||||
#include <time.h>
|
||||
#include "CmsisRtosThreadUtils.h"
|
||||
#include CMSIS_device_header
|
||||
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ static void LoggerToSerialPort_TimeToString(time_t timestamp, char *strbuf) {
|
|||
|
||||
static void LoggerToSerialPort_PrintLegend(
|
||||
tLoggerToSerialPort *env,
|
||||
const char *authorStatic,
|
||||
char *authorStatic,
|
||||
const uint8_t authorLen,
|
||||
eLoggerLevel loglevel
|
||||
) {
|
||||
|
|
@ -70,14 +71,14 @@ static void LoggerToSerialPort_PrintLegend(
|
|||
if (env->flags)
|
||||
vAsciiStringAdd(str, &strLen, ": ", 2);
|
||||
|
||||
SerialPortTransmit(env->serialPortIo, (uint8_t *) str, strLen, env->timeout);
|
||||
SerialPortTransmit(env->serialPortIo_IN_VIRT, (uint8_t *) str, strLen, env->timeout);
|
||||
|
||||
env->open = true;
|
||||
}
|
||||
|
||||
static void LoggerToSerialPort_Logging(
|
||||
tLoggerToSerialPort *env,
|
||||
const char *authorStatic,
|
||||
char *authorStatic,
|
||||
const uint8_t authorLen,
|
||||
eLoggerLevel loglevel,
|
||||
char *msg,
|
||||
|
|
@ -85,9 +86,9 @@ static void LoggerToSerialPort_Logging(
|
|||
bool complete
|
||||
) {
|
||||
|
||||
uint32_t adr = *(uint32_t *)(env->serialPortIo->env);
|
||||
// uint32_t adr = *(uint32_t *)(env->serialPortIo->env);
|
||||
|
||||
uint32_t timeoutLocal = env->timeout;
|
||||
// uint32_t timeoutLocal = env->timeout;
|
||||
// Если это UART (виртуальный)
|
||||
// if (adr < PERIPH_BASE) {
|
||||
// env->timeout = 0;
|
||||
|
|
@ -98,37 +99,69 @@ static void LoggerToSerialPort_Logging(
|
|||
}
|
||||
|
||||
//выводим сообщение
|
||||
SerialPortTransmit(env->serialPortIo, (uint8_t *) msg, msgLen, env->timeout);
|
||||
SerialPortTransmit(env->serialPortIo_IN_VIRT, (uint8_t *) msg, msgLen, env->timeout);
|
||||
|
||||
if (complete) {
|
||||
//переводим строку
|
||||
SerialPortTransmit(env->serialPortIo, (uint8_t *) "\r\n", 2, env->timeout);
|
||||
SerialPortTransmit(env->serialPortIo_IN_VIRT, (uint8_t *) "\r\n", 2, env->timeout);
|
||||
env->open = false;
|
||||
} else {
|
||||
env->open = true;
|
||||
}
|
||||
|
||||
env->timeout = timeoutLocal;
|
||||
// env->timeout = timeoutLocal;
|
||||
}
|
||||
|
||||
|
||||
void LoggerToSerialPort_Init(
|
||||
tLoggerToSerialPort *env,
|
||||
int32_t greenwichOffset,
|
||||
tSerialPortIO *serialPortIo,
|
||||
tSerialPortIO *serialPortIo_IN_VIRT,
|
||||
tSerialPortIO *serialPortIo_OUT_VIRT,
|
||||
tSerialPortIO *serialPortIo_PHYSIC,
|
||||
tRtcIO *rtc,
|
||||
uint16_t flags
|
||||
uint16_t flags,
|
||||
uint32_t timeoutTransmittedLog
|
||||
) {
|
||||
env->serialPortIo = serialPortIo;
|
||||
env->serialPortIo_IN_VIRT = serialPortIo_IN_VIRT;
|
||||
env->serialPortIo_OUT_VIRT = serialPortIo_OUT_VIRT;
|
||||
env->serialPortIo_PHYSIC = serialPortIo_PHYSIC;
|
||||
env->open = false;
|
||||
env->timeout = 200;// не ждем на каждой операции так как если порт исправен то все должно отрабатывать моментально
|
||||
env->timeout = 0;// не ждем на каждой операции так как если порт исправен то все должно отрабатывать моментально
|
||||
env->logger.env = env;
|
||||
env->greenwichOffset = greenwichOffset;
|
||||
env->logger.logging = (LoggerGenericMethod) LoggerToSerialPort_Logging;
|
||||
env->rtc = rtc;
|
||||
env->flags = flags;
|
||||
env->timeoutTransmittedLog = timeoutTransmittedLog;
|
||||
// env->showDate = showDate;
|
||||
// env->showTime = showTime;
|
||||
// env->showLoglevel = showLoglevel;
|
||||
// env->showAuthor = showAuthor;
|
||||
|
||||
InitThreadAtrStatic(&env->thread.attr, "LogTransmitter", env->thread.controlBlock, env->thread.stack,
|
||||
osPriorityNormal);
|
||||
|
||||
LogTransmitter_StartThread(env);
|
||||
}
|
||||
|
||||
extern uint8_t buf_USART2_TRANSMITTED[512];
|
||||
|
||||
static _Noreturn void LogTransmitter_Thread(tLoggerToSerialPort *env) {
|
||||
for (;;) {
|
||||
uint16_t len = env->serialPortIo_OUT_VIRT->receive(env->serialPortIo_OUT_VIRT->env, buf_USART2_TRANSMITTED,
|
||||
sizeof(buf_USART2_TRANSMITTED), env->timeoutTransmittedLog);
|
||||
|
||||
if (len > 0) {
|
||||
len = env->serialPortIo_PHYSIC->transmit(env->serialPortIo_PHYSIC->env, buf_USART2_TRANSMITTED,
|
||||
len, env->timeoutTransmittedLog);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LogTransmitter_StartThread(tLoggerToSerialPort *env) {
|
||||
if (!env->thread.id) {
|
||||
env->thread.id = osThreadNew((osThreadFunc_t) (LogTransmitter_Thread), (void *) (env), &env->thread.attr);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue