After various memory exercises, then back to GPS to get UBlox working. UBlox is working. TODO: start libraries, downplay SD Card as we can use memory for interim logging
This commit is contained in:
parent
c7646e169e
commit
41c1fe6819
16 changed files with 2016 additions and 71 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <U8g2lib.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifndef NODE_LABEL
|
||||
#define NODE_LABEL "RAM"
|
||||
|
|
@ -21,10 +22,11 @@
|
|||
|
||||
static U8G2_SH1106_128X64_NONAME_F_HW_I2C g_oled(U8G2_R0, U8X8_PIN_NONE);
|
||||
|
||||
static const char *kTmpPath = "/tmp/volatile.txt";
|
||||
static const size_t kTmpFileCapacity = 4096;
|
||||
static const char *kTmpPath = "/tmp/AMY_output.log";
|
||||
static const size_t kTmpFileCapacity = 32768;
|
||||
static char g_tmpFileBuffer[kTmpFileCapacity];
|
||||
static size_t g_tmpFileSize = 0;
|
||||
static unsigned g_tmpLineNumber = 0;
|
||||
|
||||
static void oledShowLines(const char *l1,
|
||||
const char *l2 = nullptr,
|
||||
|
|
@ -47,6 +49,51 @@ static size_t getAvailableRamBytes()
|
|||
return ESP.getFreeHeap();
|
||||
}
|
||||
|
||||
static void getTimestamp(char *out, size_t outSize)
|
||||
{
|
||||
const time_t now = time(nullptr);
|
||||
if (now > 1700000000) {
|
||||
struct tm tmNow;
|
||||
localtime_r(&now, &tmNow);
|
||||
snprintf(out, outSize, "%04d-%02d-%02d %02d:%02d:%02d",
|
||||
tmNow.tm_year + 1900,
|
||||
tmNow.tm_mon + 1,
|
||||
tmNow.tm_mday,
|
||||
tmNow.tm_hour,
|
||||
tmNow.tm_min,
|
||||
tmNow.tm_sec);
|
||||
return;
|
||||
}
|
||||
|
||||
const uint32_t sec = millis() / 1000;
|
||||
const uint32_t hh = sec / 3600;
|
||||
const uint32_t mm = (sec % 3600) / 60;
|
||||
const uint32_t ss = sec % 60;
|
||||
snprintf(out, outSize, "uptime %02u:%02u:%02u", (unsigned)hh, (unsigned)mm, (unsigned)ss);
|
||||
}
|
||||
|
||||
static void appendTimestampLine()
|
||||
{
|
||||
char timestamp[32];
|
||||
getTimestamp(timestamp, sizeof(timestamp));
|
||||
|
||||
char line[96];
|
||||
const int written = snprintf(line, sizeof(line), "%u, %s\r\n", g_tmpLineNumber + 1, timestamp);
|
||||
if (written <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t lineLen = (size_t)written;
|
||||
if (g_tmpFileSize + lineLen > kTmpFileCapacity - 1) {
|
||||
Serial.println("Warning: /tmp log full, stopping writes");
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(g_tmpFileBuffer + g_tmpFileSize, line, lineLen);
|
||||
g_tmpFileSize += lineLen;
|
||||
g_tmpLineNumber++;
|
||||
}
|
||||
|
||||
static void printRamStatus()
|
||||
{
|
||||
const size_t freeBytes = getAvailableRamBytes();
|
||||
|
|
@ -65,7 +112,7 @@ static void printRamStatus()
|
|||
char line4[32];
|
||||
snprintf(line4, sizeof(line4), "Total: %u KB", (unsigned)(totalBytes / 1024U));
|
||||
char line5[32];
|
||||
snprintf(line5, sizeof(line5), "Max alloc: %u KB", (unsigned)(maxAlloc / 1024U));
|
||||
snprintf(line5, sizeof(line5), "Lines: %u", (unsigned)g_tmpLineNumber);
|
||||
|
||||
oledShowLines(line1, line2, line3, line4, line5);
|
||||
}
|
||||
|
|
@ -85,6 +132,7 @@ static void printTmpFileStat()
|
|||
{
|
||||
Serial.printf("Path: %s\r\n", kTmpPath);
|
||||
Serial.printf("Size: %u bytes\r\n", (unsigned)g_tmpFileSize);
|
||||
Serial.printf("Lines: %u\r\n", (unsigned)g_tmpLineNumber);
|
||||
Serial.printf("Capacity: %u bytes\r\n", (unsigned)kTmpFileCapacity);
|
||||
}
|
||||
|
||||
|
|
@ -219,5 +267,6 @@ void loop()
|
|||
}
|
||||
lastMs = now;
|
||||
|
||||
appendTimestampLine();
|
||||
printRamStatus();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue