From 024446862459f81d928a14d0fe9d9c1a4e36d3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Wed, 17 Sep 2025 23:06:30 +0300 Subject: [PATCH 1/4] Make contactor opening take 9s instead of 60s --- Software/src/battery/TESLA-BATTERY.cpp | 30 +++++++++++++------------- Software/src/battery/TESLA-BATTERY.h | 6 +++++- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Software/src/battery/TESLA-BATTERY.cpp b/Software/src/battery/TESLA-BATTERY.cpp index 42226c9f..ff4208be 100644 --- a/Software/src/battery/TESLA-BATTERY.cpp +++ b/Software/src/battery/TESLA-BATTERY.cpp @@ -976,22 +976,22 @@ void TeslaBattery:: if ((datalayer.system.status.inverter_allows_contactor_closing == true) && (datalayer.battery.status.bms_status != FAULT) && (!datalayer.system.settings.equipment_stop_active)) { // Carry on: 0x221 DRIVE state & reset power down timer - vehicleState = 1; - powerDownTimer = 180; //0x221 50ms cyclic, 20 calls/second + vehicleState = CAR_DRIVE; + powerDownSeconds = 9; } else { // Faulted state, or inverter blocks contactor closing // Shut down: 0x221 ACCESSORY state for 3 seconds, followed by GOING_DOWN, then OFF - if (powerDownTimer <= 180 && powerDownTimer > 120) { - vehicleState = 2; //ACCESSORY - powerDownTimer--; + if (powerDownSeconds <= 9 && powerDownSeconds > 6) { + vehicleState = ACCESSORY; + powerDownSeconds--; } - if (powerDownTimer <= 120 && powerDownTimer > 60) { - vehicleState = 3; //GOING_DOWN - powerDownTimer--; + if (powerDownSeconds <= 6 && powerDownSeconds > 3) { + vehicleState = GOING_DOWN; + powerDownSeconds--; } - if (powerDownTimer <= 60 && powerDownTimer > 0) { - vehicleState = 0; //OFF - powerDownTimer--; + if (powerDownSeconds <= 3 && powerDownSeconds > 0) { + vehicleState = CAR_OFF; + powerDownSeconds--; } } @@ -2059,7 +2059,7 @@ void TeslaBattery::transmit_can(unsigned long currentMillis) { previousMillis50 = currentMillis; //0x221 VCFRONT_LVPowerState - if (vehicleState == 1) { // Drive + if (vehicleState == CAR_DRIVE) { switch (muxNumber_TESLA_221) { case 0: generateMuxFrameCounterChecksum(TESLA_221_DRIVE_Mux0, frameCounter_TESLA_221, 52, 4, 56, 8); @@ -2077,7 +2077,7 @@ void TeslaBattery::transmit_can(unsigned long currentMillis) { //Generate next new frame frameCounter_TESLA_221 = (frameCounter_TESLA_221 + 1) % 16; } - if (vehicleState == 2) { // Accessory + if (vehicleState == ACCESSORY) { switch (muxNumber_TESLA_221) { case 0: generateMuxFrameCounterChecksum(TESLA_221_ACCESSORY_Mux0, frameCounter_TESLA_221, 52, 4, 56, 8); @@ -2095,7 +2095,7 @@ void TeslaBattery::transmit_can(unsigned long currentMillis) { //Generate next new frame frameCounter_TESLA_221 = (frameCounter_TESLA_221 + 1) % 16; } - if (vehicleState == 3) { // Going down + if (vehicleState == GOING_DOWN) { switch (muxNumber_TESLA_221) { case 0: generateMuxFrameCounterChecksum(TESLA_221_GOING_DOWN_Mux0, frameCounter_TESLA_221, 52, 4, 56, 8); @@ -2113,7 +2113,7 @@ void TeslaBattery::transmit_can(unsigned long currentMillis) { //Generate next new frame frameCounter_TESLA_221 = (frameCounter_TESLA_221 + 1) % 16; } - if (vehicleState == 0) { // Off + if (vehicleState == CAR_OFF) { switch (muxNumber_TESLA_221) { case 0: generateMuxFrameCounterChecksum(TESLA_221_OFF_Mux0, frameCounter_TESLA_221, 52, 4, 56, 8); diff --git a/Software/src/battery/TESLA-BATTERY.h b/Software/src/battery/TESLA-BATTERY.h index 0bf4037f..91311b52 100644 --- a/Software/src/battery/TESLA-BATTERY.h +++ b/Software/src/battery/TESLA-BATTERY.h @@ -78,7 +78,11 @@ class TeslaBattery : public CanBattery { uint8_t muxNumber_TESLA_221 = 0; uint8_t frameCounter_TESLA_221 = 15; // Start at 15 for Mux 0 uint8_t vehicleState = 1; // "OFF": 0, "DRIVE": 1, "ACCESSORY": 2, "GOING_DOWN": 3 - uint16_t powerDownTimer = 180; // Car power down (i.e. contactor open) tracking timer, 3 seconds per sendingState + static const uint8_t CAR_OFF = 0; + static const uint8_t CAR_DRIVE = 1; + static const uint8_t ACCESSORY = 2; + static const uint8_t GOING_DOWN = 3; + uint8_t powerDownSeconds = 9; // Car power down (i.e. contactor open) tracking timer, 3 seconds per sendingState //0x2E1 VCFRONT_status, 6 mux tracker uint8_t muxNumber_TESLA_2E1 = 0; //0x334 UI From 15143d1384c5f3bae853c35dab1a6b4e4b505e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Wed, 17 Sep 2025 23:23:55 +0300 Subject: [PATCH 2/4] Add configurable option for estimated SOC --- Software/src/battery/BATTERIES.cpp | 2 ++ Software/src/battery/BATTERIES.h | 2 +- Software/src/battery/KIA-E-GMP-BATTERY.cpp | 19 ++++++++++--------- Software/src/battery/KIA-E-GMP-BATTERY.h | 2 +- Software/src/communication/nvm/comm_nvm.cpp | 1 + .../src/devboard/webserver/settings_html.cpp | 14 ++++++++++++++ Software/src/devboard/webserver/webserver.cpp | 8 ++++---- 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/Software/src/battery/BATTERIES.cpp b/Software/src/battery/BATTERIES.cpp index a444ed1a..1c954d13 100644 --- a/Software/src/battery/BATTERIES.cpp +++ b/Software/src/battery/BATTERIES.cpp @@ -296,6 +296,8 @@ bool user_selected_tesla_GTW_rightHandDrive = true; uint16_t user_selected_tesla_GTW_mapRegion = 2; uint16_t user_selected_tesla_GTW_chassisType = 2; uint16_t user_selected_tesla_GTW_packEnergy = 1; +/* User-selected EGMP+others settings */ +bool user_selected_use_estimated_SOC = false; // Use 0V for user selected cell/pack voltage defaults (On boot will be replaced with saved values from NVM) uint16_t user_selected_max_pack_voltage_dV = 0; diff --git a/Software/src/battery/BATTERIES.h b/Software/src/battery/BATTERIES.h index 0324c189..cb24124e 100644 --- a/Software/src/battery/BATTERIES.h +++ b/Software/src/battery/BATTERIES.h @@ -62,7 +62,7 @@ extern uint16_t user_selected_max_pack_voltage_dV; extern uint16_t user_selected_min_pack_voltage_dV; extern uint16_t user_selected_max_cell_voltage_mV; extern uint16_t user_selected_min_cell_voltage_mV; - +extern bool user_selected_use_estimated_SOC; extern bool user_selected_LEAF_interlock_mandatory; extern bool user_selected_tesla_digital_HVIL; extern uint16_t user_selected_tesla_GTW_country; diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.cpp b/Software/src/battery/KIA-E-GMP-BATTERY.cpp index 20f3cd8e..664d4867 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.cpp +++ b/Software/src/battery/KIA-E-GMP-BATTERY.cpp @@ -114,16 +114,17 @@ uint8_t KiaEGmpBattery::calculateCRC(CAN_frame rx_frame, uint8_t length, uint8_t void KiaEGmpBattery::update_values() { -#ifdef ESTIMATE_SOC_FROM_CELLVOLTAGE - // Use the simplified pack-based SOC estimation with proper compensation - datalayer.battery.status.real_soc = estimateSOC(batteryVoltage, datalayer.battery.info.number_of_cells, batteryAmps); + if (user_selected_use_estimated_SOC) { + // Use the simplified pack-based SOC estimation with proper compensation + datalayer.battery.status.real_soc = + estimateSOC(batteryVoltage, datalayer.battery.info.number_of_cells, batteryAmps); - // For comparison or fallback, we can still calculate from min/max cell voltages - SOC_estimated_lowest = estimateSOCFromCell(CellVoltMin_mV); - SOC_estimated_highest = estimateSOCFromCell(CellVoltMax_mV); -#else - datalayer.battery.status.real_soc = (SOC_Display * 10); //increase SOC range from 0-100.0 -> 100.00 -#endif + // For comparison or fallback, we can still calculate from min/max cell voltages + SOC_estimated_lowest = estimateSOCFromCell(CellVoltMin_mV); + SOC_estimated_highest = estimateSOCFromCell(CellVoltMax_mV); + } else { + datalayer.battery.status.real_soc = (SOC_Display * 10); //increase SOC range from 0-100.0 -> 100.00 + } datalayer.battery.status.soh_pptt = (batterySOH * 10); //Increase decimals from 100.0% -> 100.00% diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.h b/Software/src/battery/KIA-E-GMP-BATTERY.h index dfd0237c..f28b8529 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.h +++ b/Software/src/battery/KIA-E-GMP-BATTERY.h @@ -3,7 +3,7 @@ #include "CanBattery.h" #include "KIA-E-GMP-HTML.h" -#define ESTIMATE_SOC_FROM_CELLVOLTAGE +extern bool user_selected_use_estimated_SOC; class KiaEGmpBattery : public CanBattery { public: diff --git a/Software/src/communication/nvm/comm_nvm.cpp b/Software/src/communication/nvm/comm_nvm.cpp index 58eba5c9..315c9fcc 100644 --- a/Software/src/communication/nvm/comm_nvm.cpp +++ b/Software/src/communication/nvm/comm_nvm.cpp @@ -104,6 +104,7 @@ void init_stored_settings() { user_selected_can_addon_crystal_frequency_mhz = settings.getUInt("CANFREQ", 8); user_selected_canfd_addon_crystal_frequency_mhz = settings.getUInt("CANFDFREQ", 40); user_selected_LEAF_interlock_mandatory = settings.getBool("INTERLOCKREQ", false); + user_selected_use_estimated_SOC = settings.getBool("SOCESTIMATED", false); user_selected_tesla_digital_HVIL = settings.getBool("DIGITALHVIL", false); user_selected_tesla_GTW_country = settings.getUInt("GTWCOUNTRY", 0); user_selected_tesla_GTW_rightHandDrive = settings.getBool("GTWRHD", false); diff --git a/Software/src/devboard/webserver/settings_html.cpp b/Software/src/devboard/webserver/settings_html.cpp index 6c91561c..8184bea4 100644 --- a/Software/src/devboard/webserver/settings_html.cpp +++ b/Software/src/devboard/webserver/settings_html.cpp @@ -251,6 +251,10 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti return settings.getBool("DBLBTR") ? "checked" : ""; } + if (var == "SOCESTIMATED") { + return settings.getBool("SOCESTIMATED") ? "checked" : ""; + } + if (var == "CNTCTRL") { return settings.getBool("CNTCTRL") ? "checked" : ""; } @@ -912,6 +916,11 @@ const char* getCANInterfaceName(CAN_Interface interface) { display: contents; } + form .if-socestimated { display: none; } /* Integrations where you can turn on SOC estimation */ + form[data-battery="16"] .if-socestimated { + display: contents; + } + form .if-dblbtr { display: none; } form[data-dblbtr="true"] .if-dblbtr { display: contents; @@ -1022,6 +1031,11 @@ const char* getCANInterfaceName(CAN_Interface interface) { +
+ + +
+