2021-11-18 06:37:20 +00:00
|
|
|
//
|
|
|
|
// Created by jedi on 18.11.21.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
#include <espressif/esp_common.h>
|
|
|
|
|
|
|
|
constexpr unsigned syslog_buffer_size = 1024;
|
2022-09-22 19:48:36 +00:00
|
|
|
char syslog_buf[syslog_buffer_size + 1];
|
2021-11-18 06:37:20 +00:00
|
|
|
volatile unsigned head = 0;
|
|
|
|
volatile unsigned streams = 0;
|
|
|
|
|
|
|
|
extern "C" void syslog(const char *msg) {
|
2022-09-22 19:48:36 +00:00
|
|
|
//printf("syslog> %s", msg);
|
2021-11-18 06:37:20 +00:00
|
|
|
while (char c = *msg++) {
|
|
|
|
syslog_buf[head++ % syslog_buffer_size] = c;
|
|
|
|
}
|
|
|
|
syslog_buf[head] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned syslog_current_tail() {
|
|
|
|
if(head < syslog_buffer_size)
|
|
|
|
return 0;
|
|
|
|
return head + 1 - syslog_buffer_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned syslog_data_after(unsigned local_tail) {
|
|
|
|
if(local_tail > head)
|
|
|
|
return 0;
|
|
|
|
return (head % syslog_buffer_size) - (local_tail % syslog_buffer_size);
|
|
|
|
}
|
|
|
|
|
2022-09-13 03:29:26 +00:00
|
|
|
extern "C" int syslog_copy_out(char *out, unsigned len, unsigned local_tail) {
|
2021-11-18 06:37:20 +00:00
|
|
|
unsigned cnt = 0;
|
|
|
|
while (cnt < syslog_data_after(local_tail) && cnt < len) {
|
|
|
|
out[cnt] = syslog_buf[local_tail % syslog_buffer_size + cnt];
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void syslog_attach() {
|
|
|
|
streams++;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void syslog_detach() {
|
|
|
|
streams--;
|
|
|
|
}
|