mirror of
https://github.com/adrigongv23/G26---Telemetry-Software.git
synced 2026-05-25 12:31:27 +02:00
Compare commits
No commits in common. "d190db3d3cce443138b8c43d84f880b675700b8b" and "2cbffe21e2755f422bf6e75b16b67a482d283df1" have entirely different histories.
d190db3d3c
...
2cbffe21e2
5 changed files with 124 additions and 144 deletions
|
|
@ -1,11 +1,10 @@
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include "SdFat.h"
|
#include "SdFat.h"
|
||||||
|
|
||||||
#include "include/can.hpp"
|
#include "include/can.hpp"
|
||||||
#include "include/data_processor.hpp"
|
#include "include/data_processor.hpp"
|
||||||
|
|
||||||
|
|
||||||
// --- CONFIGURACIÓN SD (VSPI) ---
|
// --- CONFIGURACIÓN SD (VSPI) ---
|
||||||
#define SD_CS_PIN 5
|
#define SD_CS_PIN 5
|
||||||
#define SPI_CLOCK SD_SCK_MHZ(20)
|
#define SPI_CLOCK SD_SCK_MHZ(20)
|
||||||
|
|
@ -25,19 +24,14 @@ void setup() {
|
||||||
if (!sd.begin(SD_CS_PIN, SPI_CLOCK)) {
|
if (!sd.begin(SD_CS_PIN, SPI_CLOCK)) {
|
||||||
Serial.println("[FALLO] SD no detectada. El sistema continuará sin Datalogging.");
|
Serial.println("[FALLO] SD no detectada. El sistema continuará sin Datalogging.");
|
||||||
} else {
|
} else {
|
||||||
if (logFile.open("G26.csv", O_RDWR | O_CREAT | O_APPEND)) {
|
Serial.println("[OK] SD Montada.");
|
||||||
|
if (!logFile.exists("G26.csv")) {
|
||||||
// Si el archivo es nuevo (tamaño 0), escribimos la cabecera
|
if (logFile.open("G26.csv", O_RDWR | O_CREAT | O_AT_END)) {
|
||||||
if (logFile.size() == 0) {
|
// SOLO Cabeceras de lo que vamos a grabar ahora
|
||||||
logFile.println("Time,ECT");
|
logFile.println("Time,ECT");
|
||||||
|
logFile.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// El archivo se queda abierto y listo.
|
|
||||||
Serial.println("[OK] Archivo abierto");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Serial.println("[ERROR] No se pudo abrir el archivo G26.csv");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. VINCULACIÓN
|
// 2. VINCULACIÓN
|
||||||
|
|
@ -55,4 +49,4 @@ void setup() {
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
@ -2,13 +2,9 @@
|
||||||
#define COMMON_LIBRARIES_HPP
|
#define COMMON_LIBRARIES_HPP
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <SPI.h>
|
|
||||||
#include "SdFat.h"
|
#include "SdFat.h"
|
||||||
|
#include "time.h"
|
||||||
|
#include <ArduinoJson.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "time.h"
|
#endif
|
||||||
#include <ArduinoJson.h>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -6,4 +6,4 @@ enum class TelemetryStatus {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1,17 +1,14 @@
|
||||||
#ifndef DATAPROCESSOR_HPP
|
#ifndef DATAPROCESSOR_HPP
|
||||||
#define DATAPROCESSOR_HPP
|
#define DATAPROCESSOR_HPP
|
||||||
|
|
||||||
#include "common/common_libraries.hpp"
|
#include <Arduino.h>
|
||||||
|
#include "SdFat.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class DataProcessor {
|
class DataProcessor {
|
||||||
public:
|
public:
|
||||||
DataProcessor() = default;
|
DataProcessor() = default;
|
||||||
|
|
||||||
// Estructura de datos
|
|
||||||
struct CarState {
|
|
||||||
int ect = 0; // Temperatura (IMPORTANTE POR AHORA). Luego habría que añadir aquí todas las variables que se vallan a guardar.
|
|
||||||
};
|
|
||||||
|
|
||||||
// Configuración SD
|
// Configuración SD
|
||||||
void setLogSystem(SdFat* sd_inst, SdFile* file_inst) {
|
void setLogSystem(SdFat* sd_inst, SdFile* file_inst) {
|
||||||
_sd = sd_inst;
|
_sd = sd_inst;
|
||||||
|
|
@ -33,4 +30,4 @@ private:
|
||||||
void flushToSD(); // Guardado físico
|
void flushToSD(); // Guardado físico
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -3,13 +3,9 @@
|
||||||
|
|
||||||
//RPM + TPS + vBatt + ECT
|
//RPM + TPS + vBatt + ECT
|
||||||
void DataProcessor::send_serial_frame_0(int rpmh, int rpml, int tpsh, int tpsl, int vbatth, int vbattl, int ect){
|
void DataProcessor::send_serial_frame_0(int rpmh, int rpml, int tpsh, int tpsl, int vbatth, int vbattl, int ect){
|
||||||
|
int rpm = (rpmh * 256) + rpml;
|
||||||
car.ect = ect; // GUARDAR LA VARIABLE DEL FRAME EN LA ESTRUCTURA
|
int tps = (tpsh * 256) + tpsl;
|
||||||
|
double vbatt = ((vbatth * 256) + vbattl) / 100.0;
|
||||||
// El resto de variables no son relevantes ahora, se quedan comentadas para ahorrar memoria
|
|
||||||
// int rpm = (rpmh * 256) + rpml;
|
|
||||||
// int tps = (tpsh * 256) + tpsl;
|
|
||||||
// double vbatt = ((vbatth * 256) + vbattl) / 100.0;
|
|
||||||
|
|
||||||
// 2. Escribimos en la SD
|
// 2. Escribimos en la SD
|
||||||
flushToSD();
|
flushToSD();
|
||||||
|
|
@ -20,145 +16,142 @@ void DataProcessor::send_serial_frame_0(int rpmh, int rpml, int tpsh, int tpsl,
|
||||||
//LAMB + LAMBTRG + FUEL + GEAR
|
//LAMB + LAMBTRG + FUEL + GEAR
|
||||||
void DataProcessor::send_serial_frame_1(int lmbh, int lmbl, int lmbth, int lmbtl, int fuelh, int fuell, int gear){
|
void DataProcessor::send_serial_frame_1(int lmbh, int lmbl, int lmbth, int lmbtl, int fuelh, int fuell, int gear){
|
||||||
|
|
||||||
|
int lmb = (lmbh * 256) + lmbl;
|
||||||
// int lmb = (lmbh * 256) + lmbl;
|
int lmbtrg = (lmbth * 256) + lmbtl;
|
||||||
// int lmbtrg = (lmbth * 256) + lmbtl;
|
int fuel = (fuelh * 256) + fuell;
|
||||||
// int fuel = (fuelh * 256) + fuell;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DataProcessor::send_serial_frame_2(int shut, int fan, int lmbch, int lmbcl, int brakeh, int brakel, int aux1){
|
void DataProcessor::send_serial_frame_2(int shut, int fan, int lmbch, int lmbcl, int brakeh, int brakel, int aux1){
|
||||||
// int lmbcorrect = (lmbch * 256) + lmbcl;
|
int lmbcorrect = (lmbch * 256) + lmbcl;
|
||||||
// int brake = (brakeh * 256) + brakel;
|
int brake = (brakeh * 256) + brakel;
|
||||||
|
|
||||||
// char shut_str[10];
|
char shut_str[10];
|
||||||
// char fan_str[10];
|
char fan_str[10];
|
||||||
// char aux1_str[10];
|
char aux1_str[10];
|
||||||
}
|
}
|
||||||
void DataProcessor::send_serial_frame_3(int aux3, int aux4, int aux5, int aux6, int aux7, int aux8, int dig1){
|
void DataProcessor::send_serial_frame_3(int aux3, int aux4, int aux5, int aux6, int aux7, int aux8, int dig1){
|
||||||
|
|
||||||
// char aux3_str[10];
|
char aux3_str[10];
|
||||||
// char aux4_str[10];
|
char aux4_str[10];
|
||||||
// char aux5_str[10];
|
char aux5_str[10];
|
||||||
// char aux6_str[10];
|
char aux6_str[10];
|
||||||
// char aux7_str[10];
|
char aux7_str[10];
|
||||||
// char aux8_str[10];
|
char aux8_str[10];
|
||||||
// char dig1_str[10];
|
char dig1_str[10];
|
||||||
|
|
||||||
// if (aux3 == 1){
|
if (aux3 == 1){
|
||||||
// strcpy(aux3_str, "ON");
|
strcpy(aux3_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(aux3_str, "OFF");
|
strcpy(aux3_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (aux4 == 1){
|
if (aux4 == 1){
|
||||||
|
|
||||||
// strcpy(aux4_str, "ON");
|
strcpy(aux4_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(aux4_str, "OFF");
|
strcpy(aux4_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (aux5 == 1){
|
if (aux5 == 1){
|
||||||
// strcpy(aux5_str, "ON");
|
strcpy(aux5_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(aux5_str, "OFF");
|
strcpy(aux5_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (aux6 == 1){
|
if (aux6 == 1){
|
||||||
// strcpy(aux6_str, "ON");
|
strcpy(aux6_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(aux6_str, "OFF");
|
strcpy(aux6_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (aux7 == 1){
|
if (aux7 == 1){
|
||||||
// strcpy(aux7_str, "ON");
|
strcpy(aux7_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(aux7_str, "OFF");
|
strcpy(aux7_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (aux8 == 1){
|
if (aux8 == 1){
|
||||||
// strcpy(aux8_str, "ON");
|
strcpy(aux8_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(aux8_str, "OFF");
|
strcpy(aux8_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (dig1 == 1){
|
if (dig1 == 1){
|
||||||
// strcpy(dig1_str, "ON");
|
strcpy(dig1_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(dig1_str, "OFF");
|
strcpy(dig1_str, "OFF");
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataProcessor::send_serial_frame_4(int dig3, int dig4, int dig5, int dig6, int dig7, int dig8, int dig9){
|
void DataProcessor::send_serial_frame_4(int dig3, int dig4, int dig5, int dig6, int dig7, int dig8, int dig9){
|
||||||
|
|
||||||
// char dig3_str[10];
|
char dig3_str[10];
|
||||||
// char dig4_str[10];
|
char dig4_str[10];
|
||||||
// char dig5_str[10];
|
char dig5_str[10];
|
||||||
// char dig6_str[10];
|
char dig6_str[10];
|
||||||
// char dig7_str[10];
|
char dig7_str[10];
|
||||||
// char dig8_str[10];
|
char dig8_str[10];
|
||||||
// char dig9_str[10];
|
char dig9_str[10];
|
||||||
|
|
||||||
// if (dig3 == 1){
|
if (dig3 == 1){
|
||||||
// strcpy(dig3_str, "ON");
|
strcpy(dig3_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(dig3_str, "OFF");
|
strcpy(dig3_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (dig4 == 1){
|
if (dig4 == 1){
|
||||||
// strcpy(dig4_str, "ON");
|
strcpy(dig4_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(dig4_str, "OFF");
|
strcpy(dig4_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (dig5 == 1){
|
if (dig5 == 1){
|
||||||
// strcpy(dig5_str, "ON");
|
strcpy(dig5_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(dig5_str, "OFF");
|
strcpy(dig5_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (dig6 == 1){
|
if (dig6 == 1){
|
||||||
// strcpy(dig6_str, "ON");
|
strcpy(dig6_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(dig6_str, "OFF");
|
strcpy(dig6_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (dig7 == 1){
|
if (dig7 == 1){
|
||||||
// strcpy(dig7_str, "ON");
|
strcpy(dig7_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(dig7_str, "OFF");
|
strcpy(dig7_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (dig8 == 1){
|
if (dig8 == 1){
|
||||||
// strcpy(dig8_str, "ON");
|
strcpy(dig8_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(dig8_str, "OFF");
|
strcpy(dig8_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (dig9 == 1){
|
if (dig9 == 1){
|
||||||
// strcpy(dig9_str, "ON");
|
strcpy(dig9_str, "ON");
|
||||||
// } else {
|
} else {
|
||||||
// strcpy(dig9_str, "OFF");
|
strcpy(dig9_str, "OFF");
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ESCRITURA EN SD
|
// ESCRITURA EN SD
|
||||||
|
|
||||||
void DataProcessor::flushToSD() {
|
void DataProcessor::flushToSD() {
|
||||||
// Verificamos que los punteros existan Y que el archivo esté abierto
|
// Solo escribe si la tarjeta está lista
|
||||||
if (_sd && _logFile && _logFile->isOpen()) {
|
if (_sd && _logFile && _sd->card()) {
|
||||||
|
|
||||||
// 1. Escribimos los datos
|
|
||||||
_logFile->print(millis());
|
|
||||||
_logFile->print(",");
|
|
||||||
_logFile->println(car.ect);
|
|
||||||
|
|
||||||
// 2. SYNC
|
|
||||||
// Esto fuerza a la SD a guardar físicamente los datos AHORA MISMO,
|
|
||||||
// pero mantiene el archivo abierto para la siguiente vuelta.
|
|
||||||
_logFile->sync();
|
|
||||||
|
|
||||||
|
// Modo APPEND
|
||||||
|
if (_logFile->open("G26.csv", O_RDWR | O_CREAT | O_AT_END)) {
|
||||||
|
|
||||||
|
_logFile->print(millis());
|
||||||
|
_logFile->print(",");
|
||||||
|
_logFile->println(ect);
|
||||||
|
|
||||||
|
_logFile->close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue