How dalathegreat/battery-emulator works
Project Type and Purpose
• This is an embedded IoT/firmware project running on an ESP32‐based devboard (LilyGo T-CAN485).
• Its purpose is to read CAN-bus signals from a large EV battery pack, translate them into a solar-inverter-compatible protocol (Modbus over RS485), and manage associated hardware (contactors, pre-charge circuits), plus provide local web/UI, logging, safety and OTA.
High-Level File-Structure Analysis
• Top-level: PlatformIO/CMake build files, .ino entry point, global settings (USER_SETTINGS.h, system_settings.h).
• Software/src/… is subdivided into:
• battery (per-battery-type implementations inheriting a common interface)
• charger (charger abstractions)
• inverter (per-inverter protocol modules)
• communication (drivers/interfaces for CAN, RS485/Modbus, contactor control, NVM, pre-charge control, stop button)
• datalayer (unified in-memory model bridging vehicle data to emulator logic)
• devboard (HAL and board-specific services: GPIO, SD card, Wi-Fi, MQTT, webserver, safety, timers, logging)
• Software/src/lib holds third-party libraries (ArduinoJson, AsyncTCP/WebServer, eModbus, CAN drivers, etc.).
• test/… contains unit tests.
Key Architectural Insights from README
• EV‐battery CAN ↔ ESP32 (CommCAN) → DataLayer → ProtocolTranslator (Inverter emulator) → RS485 Modbus (CommRS485) ↔ Solar inverter.
• HAL abstracts hardware (GPIO, timers, interrupts, SD card).
• Webserver + Wi-Fi + MQTT provide configuration & telemetry.
• Safety & contactor control modules manage high‐voltage circuitry.