logger, implementation and test

This commit is contained in:
2020-10-29 14:30:55 +01:00
parent 08c4907526
commit e5a77ccc00
6 changed files with 224 additions and 45 deletions

View File

@ -1,17 +1,65 @@
#ifndef TEST
#include <main.h>
#include <usart.h>
#include <logger.h>
#endif
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
void log(char *msg) {
uint16_t len = strlen(msg);
#ifdef TEST
#include <stdio.h>
#endif
if (HAL_UART_Transmit_IT(&debugUart, msg, len) != HAL_OK) {
if(RingBuffer_Write(&txBuf, msg, len) != RING_BUFFER_OK)
return 0;
}
return 1;
#include <logger.h>
#include <ringbuffer.h>
#ifdef TEST
#define LOGBUFFER_SIZE 32
#else
#define LOGBUFFER_SIZE 1024
#endif // TEST
static ringbuffer_t logBuffer;
void logInit() {
ringbufferInit(&logBuffer, LOGBUFFER_SIZE);
}
void logFree() {
ringbufferFree(&logBuffer);
}
int logExecute() {
int c = -1;
#ifndef TEST
if (false) { // is the TX channel free
#endif // TEST
c = ringbufferGetOne(&logBuffer);
if (c > 0) {
#ifndef TEST
// transfer to TX channel
#endif // TEST
}
#ifndef TEST
}
#endif // TEST
return c;
}
int logMsg(char *msg) {
int res = -1;
if (-1 == (res = ringbufferPut(&logBuffer, msg, strlen(msg)))) {
#ifndef TEST
// blink the red light or so
#else
printf("\n*** red blink ***\n");
#endif // TEST
}
return res;
}