removed some unused variables and contactor closing allowed after 7.th battery status message

This commit is contained in:
rha 2025-07-27 12:52:45 +03:00
parent ca360feaca
commit 038f7089dc
2 changed files with 14 additions and 11 deletions

View file

@ -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, 18); // Last current
float2frame(CYCLIC_DATA, (float)datalayer.battery.status.current_dA / 10, 22); // Should be Avg current(1s) 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,. // On startup, byte 56 seems to be always 0x00 couple of frames,.
if (f2_startup_count < 9) { if (f2_startup_count < 9) {
CYCLIC_DATA[56] = 0x00; 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)) { if (check_kostal_frame_crc(rx_index)) {
incoming_message_counter = RS485_HEALTHY; incoming_message_counter = RS485_HEALTHY;
if (RS485_RXFRAME[1] == 'c') { if (RS485_RXFRAME[1] == 'c' && info_sent) {
if (RS485_RXFRAME[6] == 0x47) { if (RS485_RXFRAME[6] == 0x47) {
// Set time function - Do nothing. // Set time function - Do nothing.
send_kostal(ACK_FRAME, 8); // ACK 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) { if (RS485_RXFRAME[6] == 0x5E) {
// Set State function // Set State function
if (RS485_RXFRAME[7] == 0x00) { 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 send_kostal(ACK_FRAME, 8); // ACK
} else if (RS485_RXFRAME[7] == 0x04) { } 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 { } else {
// Battery deep sleep? // Battery deep sleep?
send_kostal(ACK_FRAME, 8); // ACK 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 //Reverse polarity, do nothing
} else { } else {
int code = RS485_RXFRAME[6] + RS485_RXFRAME[7] * 0x100; int code = RS485_RXFRAME[6] + RS485_RXFRAME[7] * 0x100;
if (code == 0x44a) { if (code == 0x44a && info_sent) {
//Send cyclic data //Send cyclic data
// TODO: Probably not a good idea to use the battery object here like this. // TODO: Probably not a good idea to use the battery object here like this.
if (battery) { if (battery) {
@ -274,13 +279,12 @@ void KostalInverterProtocol::receive() // Runs as fast as possible to handle th
tmpframe[38] = calculate_kostal_crc(tmpframe, 38); tmpframe[38] = calculate_kostal_crc(tmpframe, 38);
null_stuffer(tmpframe, 40); null_stuffer(tmpframe, 40);
send_kostal(tmpframe, 40); send_kostal(tmpframe, 40);
datalayer.system.status.inverter_allows_contactor_closing = true; info_sent = true;
dbg_message("inverter_allows_contactor_closing (battery_info) -> true");
if (!startupMillis) { if (!startupMillis) {
startupMillis = currentMillis; startupMillis = currentMillis;
} }
} }
if (code == 0x353) { if (code == 0x353 && info_sent) {
//Send battery error/status //Send battery error/status
byte tmpframe[9]; //copy values to prevent data manipulation during rewrite/crc calculation byte tmpframe[9]; //copy values to prevent data manipulation during rewrite/crc calculation
memcpy(tmpframe, STATUS_FRAME, 9); memcpy(tmpframe, STATUS_FRAME, 9);

View file

@ -40,8 +40,7 @@ class KostalInverterProtocol : public Rs485InverterProtocol {
uint8_t incoming_message_counter = RS485_HEALTHY; uint8_t incoming_message_counter = RS485_HEALTHY;
int8_t f2_startup_count = 0; int8_t f2_startup_count = 0;
boolean B1_delay = false; boolean info_sent = false;
unsigned long B1_last_millis = 0;
unsigned long currentMillis; unsigned long currentMillis;
unsigned long startupMillis = 0; unsigned long startupMillis = 0;
unsigned long contactorMillis = 0; unsigned long contactorMillis = 0;