From 7178e0376ef0a74a1c2c34254719bdb4182f3e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Fri, 12 Sep 2025 22:19:44 +0300 Subject: [PATCH 1/5] Reduce CAN messages used by Kia PHEV --- .../battery/KIA-HYUNDAI-HYBRID-BATTERY.cpp | 16 ++++++++---- .../src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h | 25 ++++--------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.cpp b/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.cpp index 38c32872..d17b4aca 100644 --- a/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.cpp +++ b/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.cpp @@ -201,15 +201,21 @@ void KiaHyundaiHybridBattery::transmit_can(unsigned long currentMillis) { } poll_data_pid++; if (poll_data_pid == 1) { - transmit_can_frame(&KIA_7E4_id1); + KIA_7E4.data.u8[2] = 0x01; + KIA_7E4.data.u8[3] = 0x00; + transmit_can_frame(&KIA_7E4); } else if (poll_data_pid == 2) { - transmit_can_frame(&KIA_7E4_id2); + KIA_7E4.data.u8[2] = 0x02; + transmit_can_frame(&KIA_7E4); } else if (poll_data_pid == 3) { - transmit_can_frame(&KIA_7E4_id3); + KIA_7E4.data.u8[2] = 0x03; + transmit_can_frame(&KIA_7E4); } else if (poll_data_pid == 4) { - + //Group 4 not polled } else if (poll_data_pid == 5) { - transmit_can_frame(&KIA_7E4_id5); + KIA_7E4.data.u8[2] = 0x05; + KIA_7E4.data.u8[3] = 0x04; + transmit_can_frame(&KIA_7E4); } } } diff --git a/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h b/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h index 3bd9f499..e1b5366a 100644 --- a/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h +++ b/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h @@ -34,26 +34,11 @@ class KiaHyundaiHybridBattery : public CanBattery { uint16_t min_cell_voltage_mv = 3700; uint16_t max_cell_voltage_mv = 3700; - CAN_frame KIA_7E4_id1 = {.FD = false, - .ext_ID = false, - .DLC = 8, - .ID = 0x7E4, - .data = {0x02, 0x21, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}}; - CAN_frame KIA_7E4_id2 = {.FD = false, - .ext_ID = false, - .DLC = 8, - .ID = 0x7E4, - .data = {0x02, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}}; - CAN_frame KIA_7E4_id3 = {.FD = false, - .ext_ID = false, - .DLC = 8, - .ID = 0x7E4, - .data = {0x02, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}}; - CAN_frame KIA_7E4_id5 = {.FD = false, - .ext_ID = false, - .DLC = 8, - .ID = 0x7E4, - .data = {0x02, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00}}; + CAN_frame KIA_7E4 = {.FD = false, + .ext_ID = false, + .DLC = 8, + .ID = 0x7E4, + .data = {0x02, 0x21, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}}; CAN_frame KIA_7E4_ack = {.FD = false, .ext_ID = false, .DLC = 8, From 2546b6da21ac11709d7627d1a6de94e7cff847b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Fri, 12 Sep 2025 22:32:03 +0300 Subject: [PATCH 2/5] Reduce CAN templates in BYD-CAN --- Software/src/inverter/BYD-CAN.cpp | 12 ++++++++---- Software/src/inverter/BYD-CAN.h | 25 +++++-------------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/Software/src/inverter/BYD-CAN.cpp b/Software/src/inverter/BYD-CAN.cpp index a779a270..10c4a3a0 100644 --- a/Software/src/inverter/BYD-CAN.cpp +++ b/Software/src/inverter/BYD-CAN.cpp @@ -166,8 +166,12 @@ void BydCanInverter::send_initial_data() { transmit_can_frame(&BYD_250); transmit_can_frame(&BYD_290); transmit_can_frame(&BYD_2D0); - transmit_can_frame(&BYD_3D0_0); - transmit_can_frame(&BYD_3D0_1); - transmit_can_frame(&BYD_3D0_2); - transmit_can_frame(&BYD_3D0_3); + BYD_3D0.data = {0x00, 0x42, 0x61, 0x74, 0x74, 0x65, 0x72, 0x79}; //Battery + transmit_can_frame(&BYD_3D0); + BYD_3D0.data = {0x01, 0x2D, 0x42, 0x6F, 0x78, 0x20, 0x50, 0x72}; //-Box Pr + transmit_can_frame(&BYD_3D0); + BYD_3D0.data = {0x02, 0x65, 0x6D, 0x69, 0x75, 0x6D, 0x20, 0x48}; //emium H + transmit_can_frame(&BYD_3D0); + BYD_3D0.data = {0x03, 0x56, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00}; //VS + transmit_can_frame(&BYD_3D0); } diff --git a/Software/src/inverter/BYD-CAN.h b/Software/src/inverter/BYD-CAN.h index 4eb63918..e7af38c5 100644 --- a/Software/src/inverter/BYD-CAN.h +++ b/Software/src/inverter/BYD-CAN.h @@ -40,26 +40,11 @@ class BydCanInverter : public CanInverterProtocol { .DLC = 8, .ID = 0x2D0, .data = {0x00, 0x42, 0x59, 0x44, 0x00, 0x00, 0x00, 0x00}}; //BYD - CAN_frame BYD_3D0_0 = {.FD = false, - .ext_ID = false, - .DLC = 8, - .ID = 0x3D0, - .data = {0x00, 0x42, 0x61, 0x74, 0x74, 0x65, 0x72, 0x79}}; //Battery - CAN_frame BYD_3D0_1 = {.FD = false, - .ext_ID = false, - .DLC = 8, - .ID = 0x3D0, - .data = {0x01, 0x2D, 0x42, 0x6F, 0x78, 0x20, 0x50, 0x72}}; //-Box Pr - CAN_frame BYD_3D0_2 = {.FD = false, - .ext_ID = false, - .DLC = 8, - .ID = 0x3D0, - .data = {0x02, 0x65, 0x6D, 0x69, 0x75, 0x6D, 0x20, 0x48}}; //emium H - CAN_frame BYD_3D0_3 = {.FD = false, - .ext_ID = false, - .DLC = 8, - .ID = 0x3D0, - .data = {0x03, 0x56, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00}}; //VS + CAN_frame BYD_3D0 = {.FD = false, + .ext_ID = false, + .DLC = 8, + .ID = 0x3D0, + .data = {0x00, 0x42, 0x61, 0x74, 0x74, 0x65, 0x72, 0x79}}; //Battery //Actual content messages CAN_frame BYD_110 = {.FD = false, .ext_ID = false, From fdc1fb61ba162b53d5b72537ceca5c7e12454f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Fri, 12 Sep 2025 22:39:01 +0300 Subject: [PATCH 3/5] Improve Afore writing of name --- Software/src/inverter/AFORE-CAN.cpp | 9 ++++----- Software/src/inverter/AFORE-CAN.h | 5 ----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Software/src/inverter/AFORE-CAN.cpp b/Software/src/inverter/AFORE-CAN.cpp index a195e4ab..ade4756b 100644 --- a/Software/src/inverter/AFORE-CAN.cpp +++ b/Software/src/inverter/AFORE-CAN.cpp @@ -139,11 +139,10 @@ void AforeCanInverter::map_can_frame_to_variable(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x305: // Every 1s from inverter datalayer.system.status.CAN_inverter_still_alive = CAN_STILL_ALIVE; - char0 = rx_frame.data.u8[0]; // A - char1 = rx_frame.data.u8[0]; // F - char2 = rx_frame.data.u8[0]; // O - char3 = rx_frame.data.u8[0]; // R - char4 = rx_frame.data.u8[0]; // E + for (uint8_t i = 0; i < 5; i++) { + datalayer.system.info.inverter_brand[i] = rx_frame.data.u8[i]; + } + datalayer.system.info.inverter_brand[7] = '\0'; inverter_status = rx_frame.data.u8[7]; time_to_send_info = true; break; diff --git a/Software/src/inverter/AFORE-CAN.h b/Software/src/inverter/AFORE-CAN.h index 96e59ec6..09f9eb09 100644 --- a/Software/src/inverter/AFORE-CAN.h +++ b/Software/src/inverter/AFORE-CAN.h @@ -16,11 +16,6 @@ class AforeCanInverter : public CanInverterProtocol { uint8_t inverter_status = 0; //0 = init, 1 = standby, 2 = starting, 3 = grid connected, 4 off-grid, 5 diesel generator, 6 grid connected, but disconnected, 7off grid and disconnected, 8 = power failure processing, 9 = power off, 10 = Failure bool time_to_send_info = false; - uint8_t char0 = 0; - uint8_t char1 = 0; - uint8_t char2 = 0; - uint8_t char3 = 0; - uint8_t char4 = 0; //Actual content messages CAN_frame AFORE_350 = {.FD = false, // Operation information .ext_ID = false, From bf14553d777621d1f20fde0746181681600be463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Sat, 13 Sep 2025 10:53:11 +0300 Subject: [PATCH 4/5] Add notes on BYD messages --- Software/src/inverter/BYD-CAN.cpp | 14 +++++++++----- Software/src/inverter/BYD-CAN.h | 10 +++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Software/src/inverter/BYD-CAN.cpp b/Software/src/inverter/BYD-CAN.cpp index 10c4a3a0..e57b2c6c 100644 --- a/Software/src/inverter/BYD-CAN.cpp +++ b/Software/src/inverter/BYD-CAN.cpp @@ -69,6 +69,10 @@ void BydCanInverter:: BYD_150.data.u8[6] = (fully_charged_capacity_ah >> 8); BYD_150.data.u8[7] = (fully_charged_capacity_ah & 0x00FF); + //Alarms + //TODO: BYD Alarms are not implemented yet. Investigation needed on the bits in this message + //BYD_190.data.u8[0] = + //Voltage (ex 370.0) BYD_1D0.data.u8[0] = (datalayer.battery.status.voltage_dV >> 8); BYD_1D0.data.u8[1] = (datalayer.battery.status.voltage_dV & 0x00FF); @@ -144,21 +148,21 @@ void BydCanInverter::transmit_can(unsigned long currentMillis) { if (currentMillis - previousMillis2s >= INTERVAL_2_S) { previousMillis2s = currentMillis; - transmit_can_frame(&BYD_110); + transmit_can_frame(&BYD_110); //Send Limits } // Send 10s CAN Message if (currentMillis - previousMillis10s >= INTERVAL_10_S) { previousMillis10s = currentMillis; - transmit_can_frame(&BYD_150); - transmit_can_frame(&BYD_1D0); - transmit_can_frame(&BYD_210); + transmit_can_frame(&BYD_150); //Send States + transmit_can_frame(&BYD_1D0); //Send Battery Info + transmit_can_frame(&BYD_210); //Send Cell Info } //Send 60s message if (currentMillis - previousMillis60s >= INTERVAL_60_S) { previousMillis60s = currentMillis; - transmit_can_frame(&BYD_190); + transmit_can_frame(&BYD_190); //Send Alarm } } diff --git a/Software/src/inverter/BYD-CAN.h b/Software/src/inverter/BYD-CAN.h index e7af38c5..09538ad3 100644 --- a/Software/src/inverter/BYD-CAN.h +++ b/Software/src/inverter/BYD-CAN.h @@ -46,27 +46,27 @@ class BydCanInverter : public CanInverterProtocol { .ID = 0x3D0, .data = {0x00, 0x42, 0x61, 0x74, 0x74, 0x65, 0x72, 0x79}}; //Battery //Actual content messages - CAN_frame BYD_110 = {.FD = false, + CAN_frame BYD_110 = {.FD = false, //Limits .ext_ID = false, .DLC = 8, .ID = 0x110, .data = {0x01, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; - CAN_frame BYD_150 = {.FD = false, + CAN_frame BYD_150 = {.FD = false, //States .ext_ID = false, .DLC = 8, .ID = 0x150, .data = {0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00}}; - CAN_frame BYD_190 = {.FD = false, + CAN_frame BYD_190 = {.FD = false, //Alarm .ext_ID = false, .DLC = 8, .ID = 0x190, .data = {0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}}; - CAN_frame BYD_1D0 = {.FD = false, + CAN_frame BYD_1D0 = {.FD = false, //Battery Info .ext_ID = false, .DLC = 8, .ID = 0x1D0, .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x08}}; - CAN_frame BYD_210 = {.FD = false, + CAN_frame BYD_210 = {.FD = false, //Cell info .ext_ID = false, .DLC = 8, .ID = 0x210, From 79964a0601a009a20f1c785d74e3384bfe71139b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Tue, 16 Sep 2025 14:44:30 +0300 Subject: [PATCH 5/5] Remove old method to disable webserver to save flash --- Software/Software.cpp | 16 +++++----------- Software/src/devboard/webserver/webserver.cpp | 3 --- Software/src/devboard/webserver/webserver.h | 2 -- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Software/Software.cpp b/Software/Software.cpp index 5c65c717..63f2026b 100644 --- a/Software/Software.cpp +++ b/Software/Software.cpp @@ -86,9 +86,7 @@ void connectivity_loop(void*) { // Init wifi init_WiFi(); - if (webserver_enabled) { - init_webserver(); - } + init_webserver(); if (mdns_enabled) { init_mDNS(); @@ -98,9 +96,7 @@ void connectivity_loop(void*) { START_TIME_MEASUREMENT(wifi); wifi_monitor(); - if (webserver_enabled) { - ota_monitor(); - } + ota_monitor(); END_TIME_MEASUREMENT_MAX(wifi, datalayer.system.status.wifi_task_10s_max_us); @@ -388,11 +384,9 @@ void core_loop(void*) { END_TIME_MEASUREMENT_MAX(comm, datalayer.system.status.time_comm_us); - if (webserver_enabled) { - START_TIME_MEASUREMENT(ota); - ElegantOTA.loop(); - END_TIME_MEASUREMENT_MAX(ota, datalayer.system.status.time_ota_us); - } + START_TIME_MEASUREMENT(ota); + ElegantOTA.loop(); + END_TIME_MEASUREMENT_MAX(ota, datalayer.system.status.time_ota_us); // Process currentMillis = millis(); diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 5a58b66a..70647e95 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -23,9 +23,6 @@ extern std::string http_username; extern std::string http_password; -bool webserver_enabled = - true; // Global flag to enable or disable the webserver //Old method to disable was with #ifdef WEBSERVER - bool webserver_auth = false; // Create AsyncWebServer object on port 80 diff --git a/Software/src/devboard/webserver/webserver.h b/Software/src/devboard/webserver/webserver.h index 6f3f5c45..6cbb956f 100644 --- a/Software/src/devboard/webserver/webserver.h +++ b/Software/src/devboard/webserver/webserver.h @@ -7,8 +7,6 @@ #include "../../lib/ayushsharma82-ElegantOTA/src/ElegantOTA.h" #include "../../lib/mathieucarbou-AsyncTCPSock/src/AsyncTCP.h" -extern bool webserver_enabled; - extern const char* version_number; // The current software version, shown on webserver // Common charger parameters