This commit is contained in:
Wolfgang Hottgenroth 2020-11-17 10:50:23 +01:00
parent 0b443f7bd5
commit 8b37d39f14
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F

View File

@ -2,6 +2,10 @@
#include <usart.h> #include <usart.h>
#include <show.h> #include <show.h>
#include <PontCoopScheduler.h> #include <PontCoopScheduler.h>
#include <logger.h>
#include <ringbuffer.h>
#include <wizHelper.h>
#include <socket.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@ -10,15 +14,13 @@
#include <stdio.h> #include <stdio.h>
#include <logger.h>
#include <ringbuffer.h>
#define LOGBUFFER_SIZE 1024 #define LOGBUFFER_SIZE 1024
#define MSGBUFFER_SIZE 128 #define MSGBUFFER_SIZE 128
extern const uint8_t SYSLOG_SOCK; extern const uint8_t SYSLOG_SOCK;
const uint8_t syslogAddr[] = { 172, 16, 11, 15 };
uint8_t singleOctetTXBuffer; 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) { static void flashGreenLed(void *handle) {
show(LED_GREEN, TOGGLE); show(LED_GREEN, TOGGLE);
@ -66,7 +83,6 @@ static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const
strcat(msgBuffer, post); strcat(msgBuffer, post);
} }
HAL_NVIC_DisableIRQ(UART4_IRQn); HAL_NVIC_DisableIRQ(UART4_IRQn);
res = ringbufferPut(&logBuffer, (uint8_t*) msgBuffer, strlen(msgBuffer)); res = ringbufferPut(&logBuffer, (uint8_t*) msgBuffer, strlen(msgBuffer));
HAL_NVIC_EnableIRQ(UART4_IRQn); 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); schAdd(flashGreenLed, NULL, 100, 0);
} }
debugTxCpltCallback(NULL); debugTxCpltCallback(NULL);
if (true) {
syslog(msgBuffer);
}
} }
return res; return res;
} }