mirror of
https://github.com/adrigongv23/G26---Telemetry-Software.git
synced 2026-05-25 04:21:27 +02:00
Compare commits
No commits in common. "72dc48807d4710f64ede63378080f5785eb3b343" and "9993acaba6ec982f44704b34b66e5cff0b5b805f" have entirely different histories.
72dc48807d
...
9993acaba6
3 changed files with 11 additions and 16 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,3 +0,0 @@
|
|||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/settings.json
|
||||
|
|
@ -17,7 +17,7 @@ CAN can_interface;
|
|||
DataProcessor processor;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(2000000);
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.println("\n--- G26 TELEMETRY: INICIO DE SISTEMA ---");
|
||||
|
||||
|
|
@ -28,9 +28,8 @@ void setup() {
|
|||
if (logFile.open("G26.csv", O_RDWR | O_CREAT | O_APPEND)) {
|
||||
|
||||
// Si el archivo es nuevo (tamaño 0), escribimos la cabecera
|
||||
if (logFile.fileSize() == 0) {
|
||||
if (logFile.size() == 0) {
|
||||
logFile.println("Time,ECT");
|
||||
logFile.sync();
|
||||
}
|
||||
|
||||
// El archivo se queda abierto y listo.
|
||||
|
|
|
|||
|
|
@ -150,19 +150,18 @@ void DataProcessor::flushToSD() {
|
|||
// Verificamos que los punteros existan Y que el archivo esté abierto
|
||||
if (_sd && _logFile && _logFile->isOpen()) {
|
||||
|
||||
// 1. ESTRUCTURACIÓN EN RAM (El método snprintf)
|
||||
// Reservamos 128 bytes de memoria temporal.
|
||||
char buffer[128];
|
||||
|
||||
// Ensamblamos la cadena en la RAM. snprintf devuelve la longitud real de la cadena.
|
||||
int len = snprintf(buffer, sizeof(buffer), "%lu,%d\n", millis(), car.ect);
|
||||
|
||||
_logFile->write(buffer, len);
|
||||
// 1. Escribimos al BUFFER (RAM) - Esto es instantáneo (microsegundos)
|
||||
_logFile->print(millis());
|
||||
_logFile->print(",");
|
||||
_logFile->println(car.ect);
|
||||
|
||||
// 2. SYNC CONTROLADO
|
||||
// Solo obligamos a la tarjeta a "escribir de verdad" si ha pasado X tiempo.
|
||||
// Esto evita detener el CAN cada 10ms.
|
||||
if (millis() - _last_sync_time > _sync_interval_ms) {
|
||||
_logFile->sync();
|
||||
_logFile->sync(); // Aquí sí gastamos tiempo, pero solo 1 vez por segundo
|
||||
_last_sync_time = millis();
|
||||
// Serial.println("[SD] Sync realizado"); // Descomentar solo para debug
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue