STA모드 추가

This commit is contained in:
2026-02-18 15:49:30 +00:00
parent 9bb14219af
commit 0baac2bf90
9 changed files with 794 additions and 150 deletions

View File

@@ -2,7 +2,7 @@
#include "serial_task.h"
#include <time.h>
static SPIClass hspi(HSPI);
static SPIClass vspi(VSPI);
volatile bool sdLoggingActive = false;
char currentLogFileName[64] = "";
static File logFile;
@@ -12,9 +12,9 @@ static SemaphoreHandle_t sdMutex = NULL;
void sdTaskInit() {
sdMutex = xSemaphoreCreateMutex();
hspi.begin(SD_HSPI_CLK, SD_HSPI_MISO, SD_HSPI_MOSI, SD_HSPI_CS);
vspi.begin(SD_VSPI_SCLK, SD_VSPI_MISO, SD_VSPI_MOSI, SD_VSPI_CS);
if (!SD.begin(SD_HSPI_CS, hspi, 4000000)) {
if (!SD.begin(SD_VSPI_CS, vspi, 4000000)) {
Serial.println("[SD] Card mount FAILED!");
sdReady = false;
} else {
@@ -26,14 +26,15 @@ void sdTaskInit() {
sdReady = true;
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("[SD] Card mounted. Type: %d, Size: %lluMB\n", cardType, cardSize);
hspi.setFrequency(20000000);
vspi.setFrequency(20000000);
if (!SD.exists(LOG_DIR)) {
SD.mkdir(LOG_DIR);
Serial.println("[SD] Created /logs directory");
}
sdCreateNewLogFile();
sdLoggingActive = true;
// Don't auto-start logging - user starts manually via web UI
sdLoggingActive = false;
Serial.println("[SD] Ready (logging OFF - start via web UI)");
}
}
@@ -88,11 +89,12 @@ void sdLoggingTask(void *param) {
"\"%s\",\"%c\",\"", entry->timestamp,
entry->direction == 'T' ? 'T' : 'R');
// Write data as plain string (no hex encoding)
for (int i = 0; i < entry->dataLen && len < (int)sizeof(csvLine) - 4; i++) {
char c = entry->data[i];
if (c == '"') { csvLine[len++] = '"'; csvLine[len++] = '"'; }
else if (c >= 0x20 && c < 0x7F) { csvLine[len++] = c; }
else { len += snprintf(csvLine + len, sizeof(csvLine) - len, "\\x%02X", (uint8_t)c); }
else if (c >= 0x20) { csvLine[len++] = c; }
// Skip control chars (0x00~0x1F) silently
}
len += snprintf(csvLine + len, sizeof(csvLine) - len, "\"\r\n");
logFile.write((uint8_t*)csvLine, len);