mirror of
https://github.com/adrigongv23/G26---Telemetry-Software.git
synced 2026-08-25 19:43:16 +02:00
La SD usaba VSPI por defecto (SCK=18, MISO=19, MOSI=23, CS=5), y el pin MOSI (GPIO23) coincidía físicamente con el RX del CAN, por lo que ambos periféricos competían por el mismo pin y la SD no funcionaba de forma fiable. Se migra la SD a un bus SPI propio (HSPI) con los pines validados por esquemático de la PCB (CS=25, MOSI=26, SCK=27, MISO=14), que no colisionan con ningún pin usado por el CAN. Se baja además la velocidad de reloj SPI de 20 MHz a 1 MHz mediante SdSpiConfig, necesario por la integridad de señal del cableado/PCB actual. Se añade también la creación de un archivo de sesión nuevo en cada arranque (G26-1.csv, G26-2.csv, ...) usando O_EXCL para no sobrescribir nunca sesiones anteriores, evitando que distintas ejecuciones compartan el mismo archivo con timestamps solapados.
44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
#ifndef DATAPROCESSOR_HPP
|
|
#define DATAPROCESSOR_HPP
|
|
|
|
#include "common/common_libraries.hpp"
|
|
|
|
class DataProcessor {
|
|
public:
|
|
DataProcessor() = default;
|
|
|
|
// Estructura de datos
|
|
struct CarState {
|
|
int ect = 0;
|
|
int rpm = 0;
|
|
int tps = 0;
|
|
double vbatt = 0;
|
|
|
|
};
|
|
|
|
// Configuración SD
|
|
void setLogSystem(SdFat* sd_inst, SdFile* file_inst) {
|
|
_sd = sd_inst;
|
|
_logFile = file_inst;
|
|
}
|
|
|
|
void send_serial_frame_0(int rpmh, int rpml, int tpsh, int tpsl, int vbatth, int vbattl, int ect);
|
|
|
|
void send_serial_frame_1(int lmbh, int lmbl, int lmbth, int lmbtl, int fuelh, int fuell, int gear);
|
|
void send_serial_frame_2(int shut, int fan, int lmbch, int lmbcl, int brakeh, int brakel, int aux1);
|
|
void send_serial_frame_3(int aux3, int aux4, int aux5, int aux6, int aux7, int aux8, int dig1);
|
|
void send_serial_frame_4(int dig3, int dig4, int dig5, int dig6, int dig7, int dig8, int dig9);
|
|
|
|
private:
|
|
SdFat* _sd;
|
|
SdFile* _logFile;
|
|
CarState car;
|
|
|
|
uint32_t _last_sync_time = 0;
|
|
const uint32_t _sync_interval_ms = 1000; // Guardar físicamente cada 1 segundo (ajustable)
|
|
// Esto optimiza tiempos. Los datos se guardan a la velocidad del CAN en RAM y cada 1 segundo se vuelcan a la SD. Cosa mucho más optima ya que la SD es relativamente lenta comparada al CAN
|
|
|
|
void flushToSD(); // Guardado físico
|
|
};
|
|
|
|
#endif
|