40 lines
680 B
C++
40 lines
680 B
C++
|
#include "logging.h"
|
||
|
|
||
|
void logEvent(uint8_t eventCode, const char *data, size_t num)
|
||
|
{
|
||
|
struct logData event;
|
||
|
|
||
|
noInterrupts();
|
||
|
|
||
|
event.unixTime = time(nullptr);
|
||
|
event.eventCode = eventCode;
|
||
|
|
||
|
memset(event.data, 0, LOG_DATA_LENGTH);
|
||
|
for (uint8_t i = 0; i < LOG_DATA_LENGTH; i++) {
|
||
|
if (i >= num) break;
|
||
|
event.data[i] = data[i];
|
||
|
}
|
||
|
|
||
|
if (logPosition < LOG_SIZE) {
|
||
|
eventLog[logPosition++] = event;
|
||
|
}
|
||
|
|
||
|
interrupts();
|
||
|
}
|
||
|
|
||
|
void removeLogRecords(uint8_t num)
|
||
|
{
|
||
|
// shift records down by num because they've been sent
|
||
|
|
||
|
if (num > logPosition) return;
|
||
|
|
||
|
noInterrupts();
|
||
|
|
||
|
for (int i = 0; i < num; i++) {
|
||
|
eventLog[i] = eventLog[i + num];
|
||
|
}
|
||
|
logPosition -= num;
|
||
|
|
||
|
interrupts();
|
||
|
}
|