Skip to content

Commit

Permalink
kostal: more debug output to get better understanding of temporal beh…
Browse files Browse the repository at this point in the history
…aviour

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
```
  • Loading branch information
lewurm committed Nov 27, 2024
1 parent 4232da8 commit 0e4ec96
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 10 deletions.
13 changes: 13 additions & 0 deletions Software/Software.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -841,20 +850,23 @@ void handle_contactors() {
set(PRECHARGE_PIN, ON);
prechargeStartTime = currentTime;
contactorStatus = NEGATIVE;
debug_contactors("PRECHARGE");
break;

case NEGATIVE:
if (currentTime - prechargeStartTime >= PRECHARGE_TIME_MS) {
set(NEGATIVE_CONTACTOR_PIN, ON, PWM_ON_DUTY);
negativeStartTime = currentTime;
contactorStatus = POSITIVE;
debug_contactors("NEGATIVE");
}
break;

case POSITIVE:
if (currentTime - negativeStartTime >= NEGATIVE_CONTACTOR_TIME_MS) {
set(POSITIVE_CONTACTOR_PIN, ON, PWM_ON_DUTY);
contactorStatus = PRECHARGE_OFF;
debug_contactors("POSITIVE");
}
break;

Expand All @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion Software/src/battery/BMW-I3-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
46 changes: 37 additions & 9 deletions Software/src/inverter/KOSTAL-RS485.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -255,32 +278,34 @@ 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
}
}

if (B1_delay) {
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();
if (RX_allow) {
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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
12 changes: 12 additions & 0 deletions Software/src/inverter/KOSTAL-RS485.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0e4ec96

Please sign in to comment.