adjusted, but too few SPIs
This commit is contained in:
@ -4,8 +4,6 @@
|
||||
#include <PontCoopScheduler.h>
|
||||
#include <logger.h>
|
||||
#include <ringbuffer.h>
|
||||
#include <wizHelper.h>
|
||||
#include <socket.h>
|
||||
#include <config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
@ -29,9 +27,6 @@
|
||||
|
||||
static t_configBlock *config;
|
||||
|
||||
extern const uint8_t SYSLOG_SOCK;
|
||||
uint8_t syslogAddr[4];
|
||||
|
||||
uint8_t singleOctetTXBuffer;
|
||||
|
||||
static ringbuffer_t logBuffer;
|
||||
@ -70,41 +65,8 @@ int logExec() {
|
||||
}
|
||||
#endif //LOGGER_OUTPUT_BY_INTERRUPT
|
||||
|
||||
void syslog(char *msg) {
|
||||
static uint8_t state = 0;
|
||||
int8_t res8 = 0;
|
||||
int32_t res32 = 0;
|
||||
|
||||
if (isNetworkAvailable()) {
|
||||
switch (state) {
|
||||
case 0:
|
||||
res8 = socket(SYSLOG_SOCK, Sn_MR_UDP, 514, SF_IO_NONBLOCK);
|
||||
if (res8 != SYSLOG_SOCK) {
|
||||
break;
|
||||
}
|
||||
state = 1;
|
||||
// no break
|
||||
case 1:
|
||||
if (! wizDnsQuery(config->syslogServerName, syslogAddr)) {
|
||||
disconnect(SYSLOG_SOCK);
|
||||
state = 0;
|
||||
break;
|
||||
}
|
||||
state = 2;
|
||||
// no break
|
||||
case 2:
|
||||
res32 = sendto(SYSLOG_SOCK, (uint8_t*)msg, strlen(msg), syslogAddr, 514);
|
||||
if (res32 != strlen(msg)) {
|
||||
disconnect(SYSLOG_SOCK);
|
||||
state = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const char *format, va_list vl) {
|
||||
const static char SYSLOG_HEADER[] = "<133>1 ";
|
||||
static int innerLogMsg(const char *pre, const char *post, const char *format, va_list vl) {
|
||||
#define MAX_PREFIX_SIZE 20
|
||||
int res = -1;
|
||||
char msgBuffer[MSGBUFFER_SIZE+MAX_PREFIX_SIZE];
|
||||
@ -112,9 +74,8 @@ static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const
|
||||
|
||||
memset(msgBuffer, 0, MSGBUFFER_SIZE+MAX_PREFIX_SIZE);
|
||||
|
||||
uint16_t syslogHeaderSize = strlen(SYSLOG_HEADER);
|
||||
uint16_t preSize = (pre) ? strlen(pre) : 0;
|
||||
uint16_t prefixSize = (syslogHeaderSize > preSize) ? syslogHeaderSize : preSize;
|
||||
uint16_t prefixSize = preSize;
|
||||
if (prefixSize > MAX_PREFIX_SIZE) {
|
||||
return -1;
|
||||
}
|
||||
@ -122,11 +83,6 @@ static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const
|
||||
|
||||
int vcnt = vsnprintf(bufferStart, MSGBUFFER_SIZE, format, vl);
|
||||
if (vcnt < MSGBUFFER_SIZE) {
|
||||
if (syslogToo) {
|
||||
memcpy(bufferStart - syslogHeaderSize, SYSLOG_HEADER, syslogHeaderSize);
|
||||
syslog(bufferStart - syslogHeaderSize);
|
||||
}
|
||||
|
||||
if (pre) {
|
||||
memcpy(bufferStart - preSize, pre, preSize);
|
||||
}
|
||||
@ -154,12 +110,12 @@ static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const
|
||||
int logMsg(const char *format, ...) {
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
int res = innerLogMsg(NULL, "\r\n", false, format, vl);
|
||||
int res = innerLogMsg(NULL, "\r\n", format, vl);
|
||||
va_end(vl);
|
||||
return res;
|
||||
}
|
||||
|
||||
int coloredMsg(const t_logColor color, bool syslogToo, const char *format, ...) {
|
||||
int coloredMsg(const t_logColor color, const char *format, ...) {
|
||||
const static char POST[] = "\x1b[0m\r\n";
|
||||
const static char HIGH[] = "\x1b[1m";
|
||||
const static char RED[] = "\x1b[31;1m";
|
||||
@ -189,7 +145,7 @@ int coloredMsg(const t_logColor color, bool syslogToo, const char *format, ...)
|
||||
}
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
int res = innerLogMsg(pre, POST, syslogToo, format, vl);
|
||||
int res = innerLogMsg(pre, POST, format, vl);
|
||||
va_end(vl);
|
||||
return res;
|
||||
}
|
||||
|
Reference in New Issue
Block a user