mirror of
https://github.com/adrigongv23/G26---Telemetry-Software.git
synced 2026-05-25 12:31:27 +02:00
Compare commits
4 commits
9993acaba6
...
72dc48807d
| Author | SHA1 | Date | |
|---|---|---|---|
| 72dc48807d | |||
| c446873682 | |||
| 9072c162df | |||
| 95c4c51c07 |
3 changed files with 16 additions and 11 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/settings.json
|
||||
|
|
@ -17,7 +17,7 @@ CAN can_interface;
|
|||
DataProcessor processor;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.begin(2000000);
|
||||
delay(1000);
|
||||
Serial.println("\n--- G26 TELEMETRY: INICIO DE SISTEMA ---");
|
||||
|
||||
|
|
@ -28,8 +28,9 @@ 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.size() == 0) {
|
||||
if (logFile.fileSize() == 0) {
|
||||
logFile.println("Time,ECT");
|
||||
logFile.sync();
|
||||
}
|
||||
|
||||
// El archivo se queda abierto y listo.
|
||||
|
|
|
|||
|
|
@ -150,18 +150,19 @@ void DataProcessor::flushToSD() {
|
|||
// Verificamos que los punteros existan Y que el archivo esté abierto
|
||||
if (_sd && _logFile && _logFile->isOpen()) {
|
||||
|
||||
// 1. Escribimos al BUFFER (RAM) - Esto es instantáneo (microsegundos)
|
||||
_logFile->print(millis());
|
||||
_logFile->print(",");
|
||||
_logFile->println(car.ect);
|
||||
// 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);
|
||||
|
||||
// 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(); // Aquí sí gastamos tiempo, pero solo 1 vez por segundo
|
||||
_logFile->sync();
|
||||
_last_sync_time = millis();
|
||||
// Serial.println("[SD] Sync realizado"); // Descomentar solo para debug
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue