From 038f7089dc043a1ea9c7b827013f45abf1199b6a Mon Sep 17 00:00:00 2001 From: rha Date: Sun, 27 Jul 2025 12:52:45 +0300 Subject: [PATCH] removed some unused variables and contactor closing allowed after 7.th battery status message --- Software/src/inverter/KOSTAL-RS485.cpp | 22 +++++++++++++--------- Software/src/inverter/KOSTAL-RS485.h | 3 +-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Software/src/inverter/KOSTAL-RS485.cpp b/Software/src/inverter/KOSTAL-RS485.cpp index 518ba4cf..94283632 100644 --- a/Software/src/inverter/KOSTAL-RS485.cpp +++ b/Software/src/inverter/KOSTAL-RS485.cpp @@ -154,6 +154,12 @@ void KostalInverterProtocol::update_values() { float2frame(CYCLIC_DATA, (float)datalayer.battery.status.current_dA / 10, 18); // Last current float2frame(CYCLIC_DATA, (float)datalayer.battery.status.current_dA / 10, 22); // Should be Avg current(1s) + // Close contactors after 7 battery info frames requested + if (f2_startup_count > 7) { + datalayer.system.status.inverter_allows_contactor_closing = true; + dbg_message("inverter_allows_contactor_closing -> true"); + } + // On startup, byte 56 seems to be always 0x00 couple of frames,. if (f2_startup_count < 9) { CYCLIC_DATA[56] = 0x00; @@ -226,7 +232,7 @@ void KostalInverterProtocol::receive() // Runs as fast as possible to handle th if (check_kostal_frame_crc(rx_index)) { incoming_message_counter = RS485_HEALTHY; - if (RS485_RXFRAME[1] == 'c') { + if (RS485_RXFRAME[1] == 'c' && info_sent) { if (RS485_RXFRAME[6] == 0x47) { // Set time function - Do nothing. send_kostal(ACK_FRAME, 8); // ACK @@ -234,12 +240,11 @@ void KostalInverterProtocol::receive() // Runs as fast as possible to handle th if (RS485_RXFRAME[6] == 0x5E) { // Set State function if (RS485_RXFRAME[7] == 0x00) { - // Allow contactor closing - datalayer.system.status.inverter_allows_contactor_closing = true; - dbg_message("inverter_allows_contactor_closing -> true"); send_kostal(ACK_FRAME, 8); // ACK } else if (RS485_RXFRAME[7] == 0x04) { - // INVALID STATE, no ACK sent + send_kostal(ACK_FRAME, 8); // ACK + } else if (RS485_RXFRAME[7] == 0xFF) { + // no ACK sent } else { // Battery deep sleep? send_kostal(ACK_FRAME, 8); // ACK @@ -250,7 +255,7 @@ void KostalInverterProtocol::receive() // Runs as fast as possible to handle th //Reverse polarity, do nothing } else { int code = RS485_RXFRAME[6] + RS485_RXFRAME[7] * 0x100; - if (code == 0x44a) { + if (code == 0x44a && info_sent) { //Send cyclic data // TODO: Probably not a good idea to use the battery object here like this. if (battery) { @@ -274,13 +279,12 @@ void KostalInverterProtocol::receive() // Runs as fast as possible to handle th tmpframe[38] = calculate_kostal_crc(tmpframe, 38); null_stuffer(tmpframe, 40); send_kostal(tmpframe, 40); - datalayer.system.status.inverter_allows_contactor_closing = true; - dbg_message("inverter_allows_contactor_closing (battery_info) -> true"); + info_sent = true; if (!startupMillis) { startupMillis = currentMillis; } } - if (code == 0x353) { + if (code == 0x353 && info_sent) { //Send battery error/status byte tmpframe[9]; //copy values to prevent data manipulation during rewrite/crc calculation memcpy(tmpframe, STATUS_FRAME, 9); diff --git a/Software/src/inverter/KOSTAL-RS485.h b/Software/src/inverter/KOSTAL-RS485.h index 01a5cf35..d1b1767a 100644 --- a/Software/src/inverter/KOSTAL-RS485.h +++ b/Software/src/inverter/KOSTAL-RS485.h @@ -40,8 +40,7 @@ class KostalInverterProtocol : public Rs485InverterProtocol { uint8_t incoming_message_counter = RS485_HEALTHY; int8_t f2_startup_count = 0; - boolean B1_delay = false; - unsigned long B1_last_millis = 0; + boolean info_sent = false; unsigned long currentMillis; unsigned long startupMillis = 0; unsigned long contactorMillis = 0;