diff --git a/G26-Telemetria.ino b/G26-Telemetria.ino index 23bde5a..4ddb9ae 100644 --- a/G26-Telemetria.ino +++ b/G26-Telemetria.ino @@ -6,9 +6,15 @@ #include "include/data_processor.hpp" -// --- CONFIGURACIÓN SD (VSPI) --- -#define SD_CS_PIN 5 -#define SPI_CLOCK SD_SCK_MHZ(20) +// --- CONFIGURACIÓN SD (HSPI, pines de la PCB validados por esquemático) --- +#define SD_CS 25 +#define SD_MOSI 26 +#define SD_SCK 27 +#define SD_MISO 14 + +SPIClass spiSD(HSPI); +#define SD_CONFIG SdSpiConfig(SD_CS, DEDICATED_SPI, SD_SCK_MHZ(1), &spiSD) + SdFat sd; SdFile logFile; @@ -22,38 +28,44 @@ void setup() { Serial.println("\n--- G26 TELEMETRY: INICIO DE SISTEMA ---"); // 1. INICIALIZACIÓN SD - if (!sd.begin(SD_CS_PIN, SPI_CLOCK)) { + spiSD.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS); + + if (!sd.begin(SD_CONFIG)) { Serial.println("[FALLO] SD no detectada. El sistema continuará sin Datalogging."); } else { - if (logFile.open("G26.csv", O_RDWR | O_CREAT | O_APPEND)) { + char filename[24]; + int session = 1; + bool opened = false; - // Si el archivo es nuevo (tamaño 0), escribimos la cabecera - if (logFile.fileSize() == 0) { - logFile.println("Time,ECT"); - logFile.sync(); + while (!opened && session < 100000) { + snprintf(filename, sizeof(filename), "G26-%d.csv", session); + if (logFile.open(filename, O_RDWR | O_CREAT | O_EXCL)) { + opened = true; + Serial.printf("[OK] Nueva sesion: %s\n", filename); + } else { + session++; + } } - // El archivo se queda abierto y listo. - Serial.println("[OK] Archivo abierto"); - - } else { - Serial.println("[ERROR] No se pudo abrir el archivo G26.csv"); - } + if (opened) { + logFile.println("Time,ECT,RPM,TPS,VBATT"); + logFile.sync(); + } else { + Serial.println("[ERROR] No se pudo abrir archivo de sesion"); + } } // 2. VINCULACIÓN - // Le damos al procesador acceso a la SD para que guarde cuando lleguen datos processor.setLogSystem(&sd, &logFile); can_interface.set_data_proccessor(&processor); // 3. INICIO CAN can_interface.start(); - can_interface.start_listening_task(); // Escucha en Core 1 (Background) - + can_interface.start_listening_task(); + Serial.println("[OK] Sistema ONLINE."); } void loop() { - - delay(100); -} + delay(100); +} \ No newline at end of file diff --git a/include/can.hpp b/include/can.hpp index 7a03905..94467b2 100644 --- a/include/can.hpp +++ b/include/can.hpp @@ -1,8 +1,8 @@ #ifndef CAN_HPP #define CAN_HPP -#define RX_PIN 13 -#define TX_PIN 38 +#define RX_PIN 23 +#define TX_PIN 22 #define POLLING_RATE_MS 1000 #define TRANSMIT_RATE_MS 1000 diff --git a/include/data_processor.hpp b/include/data_processor.hpp index 33b4992..f5c05d3 100644 --- a/include/data_processor.hpp +++ b/include/data_processor.hpp @@ -9,7 +9,11 @@ public: // 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. + int ect = 0; + int rpm = 0; + int tps = 0; + double vbatt = 0; + }; // Configuración SD diff --git a/index.html b/index.html deleted file mode 100644 index 886c04d..0000000 --- a/index.html +++ /dev/null @@ -1,254 +0,0 @@ - - - - - Telemetría IoT - Sesiones - - - - -
-

🔬 Telemetría IoT

-
❌ Sesión Inactiva
-
--- kg
-
Socket: desconocido
- -
-
Ventanas recibidas
0
-
Muestras totales
0
-
Última actualización
---
-
- -
- - - -
- -
-
- - - - - - - diff --git a/src/can.cpp b/src/can.cpp index f4ef323..bb076e1 100644 --- a/src/can.cpp +++ b/src/can.cpp @@ -11,7 +11,7 @@ static bool driver_installed = false; void CAN::start() { Serial.println("Starting CAN Controller..."); twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)TX_PIN, (gpio_num_t)RX_PIN, TWAI_MODE_NORMAL); - twai_timing_config_t t_config = TWAI_TIMING_CONFIG_125KBITS(); + twai_timing_config_t t_config = TWAI_TIMING_CONFIG_500KBITS(); twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); esp_err_t install_status = twai_driver_install(&g_config, &t_config, &f_config); diff --git a/src/data_processor.cpp b/src/data_processor.cpp index bfc23b1..7305ef1 100644 --- a/src/data_processor.cpp +++ b/src/data_processor.cpp @@ -6,10 +6,14 @@ void DataProcessor::send_serial_frame_0(int rpmh, int rpml, int tpsh, int tpsl, car.ect = ect; // GUARDAR LA VARIABLE DEL FRAME EN LA ESTRUCTURA - // 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; + int rpm = (rpmh * 256) + rpml; + car.rpm = rpm; + + int tps = (tpsh * 256) + tpsl; + car.tps = tps; + + double vbatt = ((vbatth * 256) + vbattl) / 100.0; + car.vbatt = vbatt; // 2. Escribimos en la SD flushToSD();