From 0e4ec962d1acbffcfb858ae19b4db71dc629cc08 Mon Sep 17 00:00:00 2001 From: Bernhard Urban-Forster Date: Wed, 27 Nov 2024 20:38:21 +0100 Subject: [PATCH] kostal: more debug output to get better understanding of temporal behaviour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Example: ``` FAKE Values going to inverter SOH%: 99% , SOC%: 52% , Voltage: 370V , Max discharge power: 5000W , Max charge power: 5000W , Max temp: 6°C , Min temp: 5°C , Max cell voltage: 3596mV , Min cell voltage: 3500mV [28357 ms] RX (dropped): 07 63 FF 02 FF 29 5E 02 16 00 FAKE Values going to inverter SOH%: 99% , SOC%: 52% , Voltage: 370V , Max discharge power: 5000W , Max charge power: 5000W , Max temp: 6°C , Min temp: 5°C , Max cell voltage: 3596mV , Min cell voltage: 3500mV [29177 ms] RX (dropped): 07 63 FF 02 FF 29 5E 02 16 00 [29997 ms] RX (dropped): 07 63 FF 02 FF 29 5E 02 16 00 FAKE Values going to inverter SOH%: 99% , SOC%: 52% , Voltage: 370V , Max discharge power: 5000W , Max charge power: 5000W , Max temp: 6°C , Min temp: 5°C , Max cell voltage: 3596mV , Min cell voltage: 3500mV [30817 ms] RX (dropped): 07 63 FF 02 FF 29 5E 02 16 00 FAKE Values going to inverter SOH%: 99% , SOC%: 52% , Voltage: 370V , Max discharge power: 5000W , Max charge power: 5000W , Max temp: 6°C , Min temp: 5°C , Max cell voltage: 3596mV , Min cell voltage: 3500mV [31637 ms] RX (dropped): 07 63 FF 02 FF 29 5E 02 16 00 FAKE Values going to inverter SOH%: 99% , SOC%: 52% , Voltage: 370V , Max discharge power: 5000W , Max charge power: 5000W , Max temp: 6°C , Min temp: 5°C , Max cell voltage: 3596mV , Min cell voltage: 3500mV [32458 ms] RX (dropped): 07 63 FF 02 FF 29 5E 02 16 00 FAKE Values going to inverter SOH%: 99% , SOC%: 52% , Voltage: 370V , Max discharge power: 5000W , Max charge power: 5000W , Max temp: 6°C , Min temp: 5°C , Max cell voltage: 3596mV , Min cell voltage: 3500mV [33278 ms] RX (dropped): 07 63 FF 02 FF 29 5E 02 16 00 FAKE Values going to inverter SOH%: 99% , SOC%: 52% , Voltage: 370V , Max discharge power: 5000W , Max charge power: 5000W , Max temp: 6°C , Min temp: 5°C , Max cell voltage: 3596mV , Min cell voltage: 3500mV [34100 ms] RX: 09 62 FF 02 FF 29 4A 08 23 00 [34100 ms] TX: 06 E2 FF 02 FF 29 01 08 A2 43 E4 70 8A 5C B5 02 D3 01 01 05 C8 41 C2 18 01 03 59 42 01 01 01 02 05 02 A0 01 01 02 2B 00 ``` --- Software/Software.ino | 13 +++++++ Software/src/battery/BMW-I3-BATTERY.cpp | 7 +++- Software/src/inverter/KOSTAL-RS485.cpp | 46 ++++++++++++++++++++----- Software/src/inverter/KOSTAL-RS485.h | 12 +++++++ 4 files changed, 68 insertions(+), 10 deletions(-) diff --git a/Software/Software.ino b/Software/Software.ino index 721eabde..b7c1363e 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -781,6 +781,15 @@ void check_interconnect_available() { } #endif //DOUBLE_BATTERY +static void debug_contactors(const char* state) { +#ifdef DEBUG_VIA_USB + Serial.print("["); + Serial.print(millis()); + Serial.print(" ms] contactors: "); + Serial.println(state); +#endif +} + void handle_contactors() { #ifdef BYD_SMA datalayer.system.status.inverter_allows_contactor_closing = digitalRead(INVERTER_CONTACTOR_ENABLE_PIN); @@ -841,6 +850,7 @@ void handle_contactors() { set(PRECHARGE_PIN, ON); prechargeStartTime = currentTime; contactorStatus = NEGATIVE; + debug_contactors("PRECHARGE"); break; case NEGATIVE: @@ -848,6 +858,7 @@ void handle_contactors() { set(NEGATIVE_CONTACTOR_PIN, ON, PWM_ON_DUTY); negativeStartTime = currentTime; contactorStatus = POSITIVE; + debug_contactors("NEGATIVE"); } break; @@ -855,6 +866,7 @@ void handle_contactors() { if (currentTime - negativeStartTime >= NEGATIVE_CONTACTOR_TIME_MS) { set(POSITIVE_CONTACTOR_PIN, ON, PWM_ON_DUTY); contactorStatus = PRECHARGE_OFF; + debug_contactors("POSITIVE"); } break; @@ -865,6 +877,7 @@ void handle_contactors() { set(POSITIVE_CONTACTOR_PIN, ON, PWM_HOLD_DUTY); contactorStatus = COMPLETED; datalayer.system.status.contactors_engaged = true; + debug_contactors("PRECHARGE_OFF"); } break; default: diff --git a/Software/src/battery/BMW-I3-BATTERY.cpp b/Software/src/battery/BMW-I3-BATTERY.cpp index e43eaa5a..d9093898 100644 --- a/Software/src/battery/BMW-I3-BATTERY.cpp +++ b/Software/src/battery/BMW-I3-BATTERY.cpp @@ -872,7 +872,12 @@ void send_can_battery() { if (startup_counter_contactor < 160) { startup_counter_contactor++; - } else { //After 160 messages, turn on the request + } else { //After 160 messages, turn on the request +#ifdef DEBUG_VIA_USB + Serial.print("["); + Serial.print(millis()); + Serial.println("] BMW i3: close contactors"); +#endif BMW_10B.data.u8[1] = 0x10; // Close contactors } diff --git a/Software/src/inverter/KOSTAL-RS485.cpp b/Software/src/inverter/KOSTAL-RS485.cpp index 7df23ff1..6361ee30 100644 --- a/Software/src/inverter/KOSTAL-RS485.cpp +++ b/Software/src/inverter/KOSTAL-RS485.cpp @@ -119,7 +119,9 @@ void float2frameMSB(byte* arr, float value, byte framepointer) { void send_kostal(byte* arr, int alen) { #ifdef DEBUG_KOSTAL_RS485_DATA - Serial.print("TX: "); + Serial.print("["); + Serial.print(millis()); + Serial.print(" ms] TX: "); for (int i = 0; i < alen; i++) { if (arr[i] < 0x10) { Serial.print("0"); @@ -236,6 +238,24 @@ void update_RS485_registers_inverter() { } } +static void dump_rs485_data_rx(const char* prefix) { +#ifdef DEBUG_KOSTAL_RS485_DATA + Serial.print("["); + Serial.print(millis()); + Serial.print(" ms] RX"); + Serial.print(prefix); + Serial.print(": "); + for (uint8_t i = 0; i < 10; i++) { + if (RS485_RXFRAME[i] < 0x10) { + Serial.print("0"); + } + Serial.print(RS485_RXFRAME[i], HEX); + Serial.print(" "); + } + Serial.println(""); +#endif +} + static uint8_t rx_index = 0; void receive_RS485() // Runs as fast as possible to handle the serial stream @@ -246,6 +266,9 @@ void receive_RS485() // Runs as fast as possible to handle the serial stream contactorMillis = currentMillis; } if (currentMillis - contactorMillis >= INTERVAL_2_S & !RX_allow) { +#ifdef DEBUG_KOSTAL_RS485_DATA + Serial.println("RX_allow -> true"); +#endif RX_allow = true; } @@ -255,10 +278,16 @@ void receive_RS485() // Runs as fast as possible to handle the serial stream // Disconnect allowed only, when curren zero if (datalayer.battery.status.current_dA == 0) { datalayer.system.status.inverter_allows_contactor_closing = false; +#ifdef DEBUG_KOSTAL_RS485_DATA + Serial.println("inverter_allows_contactor_closing -> false"); +#endif } } else if (((currentMillis - startupMillis) >= 7000) & datalayer.system.status.inverter_allows_contactor_closing == false) { datalayer.system.status.inverter_allows_contactor_closing = true; +#ifdef DEBUG_KOSTAL_RS485_DATA + Serial.println("inverter_allows_contactor_closing -> true"); +#endif } } @@ -266,6 +295,9 @@ void receive_RS485() // Runs as fast as possible to handle the serial stream if ((currentMillis - B1_last_millis) > INTERVAL_1_S) { send_kostal(frameB1b, 8); B1_delay = false; +#ifdef DEBUG_KOSTAL_RS485_DATA + Serial.println("B1_delay -> false"); +#endif } } else if (Serial2.available()) { RS485_RXFRAME[rx_index] = Serial2.read(); @@ -273,14 +305,7 @@ void receive_RS485() // Runs as fast as possible to handle the serial stream rx_index++; if (RS485_RXFRAME[rx_index - 1] == 0x00) { if ((rx_index == 10) && (RS485_RXFRAME[0] == 0x09) && register_content_ok) { -#ifdef DEBUG_KOSTAL_RS485_DATA - Serial.print("RX: "); - for (uint8_t i = 0; i < 10; i++) { - Serial.print(RS485_RXFRAME[i], HEX); - Serial.print(" "); - } - Serial.println(""); -#endif + dump_rs485_data_rx(""); rx_index = 0; if (check_kostal_frame_crc()) { incoming_message_counter = RS485_HEALTHY; @@ -334,11 +359,14 @@ void receive_RS485() // Runs as fast as possible to handle the serial stream send_kostal(frame3, 9); } } + } else { + dump_rs485_data_rx(" (dropped)"); } rx_index = 0; } } if (rx_index >= 10) { + dump_rs485_data_rx(" (!RX_allow)"); rx_index = 0; } } diff --git a/Software/src/inverter/KOSTAL-RS485.h b/Software/src/inverter/KOSTAL-RS485.h index 3de0697d..2aaaa053 100644 --- a/Software/src/inverter/KOSTAL-RS485.h +++ b/Software/src/inverter/KOSTAL-RS485.h @@ -6,4 +6,16 @@ #define RS485_INVERTER_SELECTED //#define DEBUG_KOSTAL_RS485_DATA // Enable this line to get TX / RX printed out via serial +#ifdef DEBUG_KOSTAL_RS485_DATA +#ifndef DEBUG_VIA_USB +#define DEBUG_VIA_USB +#endif +#endif + +#ifdef DEBUG_VIA_USB +#ifndef DEBUG_KOSTAL_RS485_DATA +#define DEBUG_KOSTAL_RS485_DATA +#endif +#endif + #endif