syslog
This commit is contained in:
parent
0b443f7bd5
commit
8b37d39f14
@ -2,6 +2,10 @@
|
||||
#include <usart.h>
|
||||
#include <show.h>
|
||||
#include <PontCoopScheduler.h>
|
||||
#include <logger.h>
|
||||
#include <ringbuffer.h>
|
||||
#include <wizHelper.h>
|
||||
#include <socket.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@ -10,15 +14,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include <logger.h>
|
||||
#include <ringbuffer.h>
|
||||
|
||||
#define LOGBUFFER_SIZE 1024
|
||||
#define MSGBUFFER_SIZE 128
|
||||
|
||||
|
||||
extern const uint8_t SYSLOG_SOCK;
|
||||
|
||||
const uint8_t syslogAddr[] = { 172, 16, 11, 15 };
|
||||
|
||||
uint8_t singleOctetTXBuffer;
|
||||
|
||||
@ -40,6 +42,21 @@ void debugTxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
}
|
||||
}
|
||||
|
||||
void syslog(char *msg) {
|
||||
static uint8_t state = 0;
|
||||
int8_t res8 = 0;
|
||||
switch (state) {
|
||||
case 0:
|
||||
res8 = socket(SYSLOG_SOCK, Sn_MR_UDP, 514, SF_IO_NONBLOCK);
|
||||
if (res8 == SYSLOG_SOCK) {
|
||||
state = 1;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
sendto(SYSLOG_SOCK, (uint8_t*)msg, strlen(msg), syslogAddr, 514);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void flashGreenLed(void *handle) {
|
||||
show(LED_GREEN, TOGGLE);
|
||||
@ -66,7 +83,6 @@ static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const
|
||||
strcat(msgBuffer, post);
|
||||
}
|
||||
|
||||
|
||||
HAL_NVIC_DisableIRQ(UART4_IRQn);
|
||||
res = ringbufferPut(&logBuffer, (uint8_t*) msgBuffer, strlen(msgBuffer));
|
||||
HAL_NVIC_EnableIRQ(UART4_IRQn);
|
||||
@ -77,6 +93,10 @@ static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const
|
||||
schAdd(flashGreenLed, NULL, 100, 0);
|
||||
}
|
||||
debugTxCpltCallback(NULL);
|
||||
|
||||
if (true) {
|
||||
syslog(msgBuffer);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user