syslog
This commit is contained in:
parent
eb5267771f
commit
0b443f7bd5
@ -1,9 +1,7 @@
|
||||
#ifndef TEST
|
||||
#include <main.h>
|
||||
#include <usart.h>
|
||||
#include <show.h>
|
||||
#include <PontCoopScheduler.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@ -15,16 +13,13 @@
|
||||
#include <logger.h>
|
||||
#include <ringbuffer.h>
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
#define LOGBUFFER_SIZE 32
|
||||
#define MSGBUFFER_SIZE 16
|
||||
#else
|
||||
#define LOGBUFFER_SIZE 1024
|
||||
#define MSGBUFFER_SIZE 128
|
||||
#endif // TEST
|
||||
|
||||
|
||||
extern const uint8_t SYSLOG_SOCK;
|
||||
|
||||
|
||||
uint8_t singleOctetTXBuffer;
|
||||
|
||||
static ringbuffer_t logBuffer;
|
||||
@ -46,21 +41,23 @@ void debugTxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
}
|
||||
|
||||
|
||||
#ifndef TEST
|
||||
static void flashGreenLed(void *handle) {
|
||||
show(LED_GREEN, TOGGLE);
|
||||
}
|
||||
#endif // TEST
|
||||
|
||||
static int innerLogMsg(const char *pre, const char *post, const char *format, va_list vl) {
|
||||
static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const char *format, va_list vl) {
|
||||
const static char SYSLOG_HEADER[] = "<133>1 ";
|
||||
int res = -1;
|
||||
int offset = 0;
|
||||
char msgBuffer[MSGBUFFER_SIZE+20];
|
||||
memset(msgBuffer, 0, MSGBUFFER_SIZE+20);
|
||||
|
||||
|
||||
strcpy(msgBuffer, SYSLOG_HEADER);
|
||||
offset += strlen(SYSLOG_HEADER);
|
||||
if (pre) {
|
||||
strcpy(msgBuffer, pre);
|
||||
offset = strlen(pre);
|
||||
strcpy(msgBuffer+offset, pre);
|
||||
offset += strlen(pre);
|
||||
}
|
||||
int vcnt = vsnprintf(msgBuffer+offset, MSGBUFFER_SIZE, format, vl);
|
||||
|
||||
@ -75,13 +72,9 @@ static int innerLogMsg(const char *pre, const char *post, const char *format, va
|
||||
HAL_NVIC_EnableIRQ(UART4_IRQn);
|
||||
|
||||
if (-1 == res) {
|
||||
#ifndef TEST
|
||||
// blink the green light or so
|
||||
flashGreenLed(NULL);
|
||||
schAdd(flashGreenLed, NULL, 100, 0);
|
||||
#else
|
||||
printf("\n*** green blink ***\n");
|
||||
#endif // TEST
|
||||
}
|
||||
debugTxCpltCallback(NULL);
|
||||
}
|
||||
@ -91,7 +84,7 @@ static int innerLogMsg(const char *pre, const char *post, const char *format, va
|
||||
int logMsg(const char *format, ...) {
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
int res = innerLogMsg(NULL, "\r\n", format, vl);
|
||||
int res = innerLogMsg(NULL, "\r\n", false, format, vl);
|
||||
va_end(vl);
|
||||
return res;
|
||||
}
|
||||
@ -99,7 +92,7 @@ int logMsg(const char *format, ...) {
|
||||
int errMsg(const char *format, ...) {
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
int res = innerLogMsg("\x1b[31;1m", "\x1b[0m\r\n", format, vl);
|
||||
int res = innerLogMsg("\x1b[31;1m", "\x1b[0m\r\n", true, format, vl);
|
||||
va_end(vl);
|
||||
return res;
|
||||
}
|
||||
@ -131,7 +124,7 @@ int coloredMsg(const t_logColor color, const char *format, ...) {
|
||||
}
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
int res = innerLogMsg(pre, POST, format, vl);
|
||||
int res = innerLogMsg(pre, POST, false, format, vl);
|
||||
va_end(vl);
|
||||
return res;
|
||||
}
|
||||
|
@ -210,7 +210,6 @@ void my_loop() {
|
||||
}
|
||||
|
||||
void SYSTICK_Callback() {
|
||||
// Pont Scheduler
|
||||
schUpdate();
|
||||
}
|
||||
|
||||
|
@ -7,3 +7,4 @@
|
||||
const uint8_t DHCP_SOCK = 0;
|
||||
const uint8_t MQTT_SOCK = 1;
|
||||
const uint8_t CMD_SOCK = 2;
|
||||
const uint8_t SYSLOG_SOCK = 3;
|
||||
|
Loading…
x
Reference in New Issue
Block a user