Remove ifdef from logging

This commit is contained in:
Daniel Öster 2025-08-29 23:16:36 +03:00
parent 681b915faa
commit a1e5bc57d0
30 changed files with 14 additions and 545 deletions

View file

@ -307,9 +307,7 @@ void BmwIXBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
if ((rx_frame.data.u8[6] << 8 | rx_frame.data.u8[7]) == 10000 || if ((rx_frame.data.u8[6] << 8 | rx_frame.data.u8[7]) == 10000 ||
(rx_frame.data.u8[8] << 8 | rx_frame.data.u8[9]) == 10000) { //Qualifier Invalid Mode - Request Reboot (rx_frame.data.u8[8] << 8 | rx_frame.data.u8[9]) == 10000) { //Qualifier Invalid Mode - Request Reboot
#ifdef DEBUG_LOG
logging.println("Cell MinMax Qualifier Invalid - Requesting BMS Reset"); logging.println("Cell MinMax Qualifier Invalid - Requesting BMS Reset");
#endif // DEBUG_LOG
//set_event(EVENT_BATTERY_VALUE_UNAVAILABLE, (millis())); //Eventually need new Info level event type //set_event(EVENT_BATTERY_VALUE_UNAVAILABLE, (millis())); //Eventually need new Info level event type
transmit_can_frame(&BMWiX_6F4_REQUEST_HARD_RESET); transmit_can_frame(&BMWiX_6F4_REQUEST_HARD_RESET);
} else { //Only ingest values if they are not the 10V Error state } else { //Only ingest values if they are not the 10V Error state
@ -378,15 +376,11 @@ void BmwIXBattery::transmit_can(unsigned long currentMillis) {
// Detect edge // Detect edge
if (ContactorCloseRequest.previous == false && ContactorCloseRequest.present == true) { if (ContactorCloseRequest.previous == false && ContactorCloseRequest.present == true) {
// Rising edge detected // Rising edge detected
#ifdef DEBUG_LOG
logging.println("Rising edge detected. Resetting 10ms counter."); logging.println("Rising edge detected. Resetting 10ms counter.");
#endif // DEBUG_LOG
counter_10ms = 0; // reset counter counter_10ms = 0; // reset counter
} else if (ContactorCloseRequest.previous == true && ContactorCloseRequest.present == false) { } else if (ContactorCloseRequest.previous == true && ContactorCloseRequest.present == false) {
// Dropping edge detected // Dropping edge detected
#ifdef DEBUG_LOG
logging.println("Dropping edge detected. Resetting 10ms counter."); logging.println("Dropping edge detected. Resetting 10ms counter.");
#endif // DEBUG_LOG
counter_10ms = 0; // reset counter counter_10ms = 0; // reset counter
} }
ContactorCloseRequest.previous = ContactorCloseRequest.present; ContactorCloseRequest.previous = ContactorCloseRequest.present;
@ -465,12 +459,10 @@ void BmwIXBattery::setup(void) { // Performs one time setup at startup
void BmwIXBattery::HandleIncomingUserRequest(void) { void BmwIXBattery::HandleIncomingUserRequest(void) {
// Debug user request to open or close the contactors // Debug user request to open or close the contactors
#ifdef DEBUG_LOG
logging.print("User request: contactor close: "); logging.print("User request: contactor close: ");
logging.print(userRequestContactorClose); logging.print(userRequestContactorClose);
logging.print(" User request: contactor open: "); logging.print(" User request: contactor open: ");
logging.println(userRequestContactorOpen); logging.println(userRequestContactorOpen);
#endif // DEBUG_LOG
if ((userRequestContactorClose == false) && (userRequestContactorOpen == false)) { if ((userRequestContactorClose == false) && (userRequestContactorOpen == false)) {
// do nothing // do nothing
} else if ((userRequestContactorClose == true) && (userRequestContactorOpen == false)) { } else if ((userRequestContactorClose == true) && (userRequestContactorOpen == false)) {
@ -487,11 +479,9 @@ void BmwIXBattery::HandleIncomingUserRequest(void) {
// set user request to false // set user request to false
userRequestContactorClose = false; userRequestContactorClose = false;
userRequestContactorOpen = false; userRequestContactorOpen = false;
// print error, as both these flags shall not be true at the same time // print error, as both these flags shall not be true at the same time
#ifdef DEBUG_LOG
logging.println( logging.println(
"Error: user requested contactors to close and open at the same time. Contactors have been opened."); "Error: user requested contactors to close and open at the same time. Contactors have been opened.");
#endif // DEBUG_LOG
} }
} }
@ -499,16 +489,12 @@ void BmwIXBattery::HandleIncomingInverterRequest(void) {
InverterContactorCloseRequest.present = datalayer.system.status.inverter_allows_contactor_closing; InverterContactorCloseRequest.present = datalayer.system.status.inverter_allows_contactor_closing;
// Detect edge // Detect edge
if (InverterContactorCloseRequest.previous == false && InverterContactorCloseRequest.present == true) { if (InverterContactorCloseRequest.previous == false && InverterContactorCloseRequest.present == true) {
// Rising edge detected // Rising edge detected
#ifdef DEBUG_LOG
logging.println("Inverter requests to close contactors"); logging.println("Inverter requests to close contactors");
#endif // DEBUG_LOG
BmwIxCloseContactors(); BmwIxCloseContactors();
} else if (InverterContactorCloseRequest.previous == true && InverterContactorCloseRequest.present == false) { } else if (InverterContactorCloseRequest.previous == true && InverterContactorCloseRequest.present == false) {
// Falling edge detected // Falling edge detected
#ifdef DEBUG_LOG
logging.println("Inverter requests to open contactors"); logging.println("Inverter requests to open contactors");
#endif // DEBUG_LOG
BmwIxOpenContactors(); BmwIxOpenContactors();
} // else: do nothing } // else: do nothing
@ -517,16 +503,12 @@ void BmwIXBattery::HandleIncomingInverterRequest(void) {
} }
void BmwIXBattery::BmwIxCloseContactors(void) { void BmwIXBattery::BmwIxCloseContactors(void) {
#ifdef DEBUG_LOG
logging.println("Closing contactors"); logging.println("Closing contactors");
#endif // DEBUG_LOG
contactorCloseReq = true; contactorCloseReq = true;
} }
void BmwIXBattery::BmwIxOpenContactors(void) { void BmwIXBattery::BmwIxOpenContactors(void) {
#ifdef DEBUG_LOG
logging.println("Opening contactors"); logging.println("Opening contactors");
#endif // DEBUG_LOG
contactorCloseReq = false; contactorCloseReq = false;
counter_100ms = 0; // reset counter, such that keep contactors closed message sequence starts from the beginning counter_100ms = 0; // reset counter, such that keep contactors closed message sequence starts from the beginning
} }
@ -552,46 +534,34 @@ void BmwIXBattery::HandleBmwIxCloseContactorsRequest(uint16_t counter_10ms) {
if (counter_10ms == 0) { if (counter_10ms == 0) {
// @0 ms // @0 ms
transmit_can_frame(&BMWiX_510); transmit_can_frame(&BMWiX_510);
#ifdef DEBUG_LOG
logging.println("Transmitted 0x510 - 1/6"); logging.println("Transmitted 0x510 - 1/6");
#endif // DEBUG_LOG
} else if (counter_10ms == 5) { } else if (counter_10ms == 5) {
// @50 ms // @50 ms
transmit_can_frame(&BMWiX_276); transmit_can_frame(&BMWiX_276);
#ifdef DEBUG_LOG
logging.println("Transmitted 0x276 - 2/6"); logging.println("Transmitted 0x276 - 2/6");
#endif // DEBUG_LOG
} else if (counter_10ms == 10) { } else if (counter_10ms == 10) {
// @100 ms // @100 ms
BMWiX_510.data.u8[2] = 0x04; // TODO: check if needed BMWiX_510.data.u8[2] = 0x04; // TODO: check if needed
transmit_can_frame(&BMWiX_510); transmit_can_frame(&BMWiX_510);
#ifdef DEBUG_LOG
logging.println("Transmitted 0x510 - 3/6"); logging.println("Transmitted 0x510 - 3/6");
#endif // DEBUG_LOG
} else if (counter_10ms == 20) { } else if (counter_10ms == 20) {
// @200 ms // @200 ms
BMWiX_510.data.u8[2] = 0x10; // TODO: check if needed BMWiX_510.data.u8[2] = 0x10; // TODO: check if needed
BMWiX_510.data.u8[5] = 0x80; // needed to close contactors BMWiX_510.data.u8[5] = 0x80; // needed to close contactors
transmit_can_frame(&BMWiX_510); transmit_can_frame(&BMWiX_510);
#ifdef DEBUG_LOG
logging.println("Transmitted 0x510 - 4/6"); logging.println("Transmitted 0x510 - 4/6");
#endif // DEBUG_LOG
} else if (counter_10ms == 30) { } else if (counter_10ms == 30) {
// @300 ms // @300 ms
BMWiX_16E.data.u8[0] = 0x6A; BMWiX_16E.data.u8[0] = 0x6A;
BMWiX_16E.data.u8[1] = 0xAD; BMWiX_16E.data.u8[1] = 0xAD;
transmit_can_frame(&BMWiX_16E); transmit_can_frame(&BMWiX_16E);
#ifdef DEBUG_LOG
logging.println("Transmitted 0x16E - 5/6"); logging.println("Transmitted 0x16E - 5/6");
#endif // DEBUG_LOG
} else if (counter_10ms == 50) { } else if (counter_10ms == 50) {
// @500 ms // @500 ms
BMWiX_16E.data.u8[0] = 0x03; BMWiX_16E.data.u8[0] = 0x03;
BMWiX_16E.data.u8[1] = 0xA9; BMWiX_16E.data.u8[1] = 0xA9;
transmit_can_frame(&BMWiX_16E); transmit_can_frame(&BMWiX_16E);
#ifdef DEBUG_LOG
logging.println("Transmitted 0x16E - 6/6"); logging.println("Transmitted 0x16E - 6/6");
#endif // DEBUG_LOG
ContactorState.closed = true; ContactorState.closed = true;
ContactorState.open = false; ContactorState.open = false;
} }
@ -613,9 +583,7 @@ void BmwIXBattery::BmwIxKeepContactorsClosed(uint8_t counter_100ms) {
0xC9, 0x3A, 0xF7}; // Explicit declaration, to prevent modification by other functions 0xC9, 0x3A, 0xF7}; // Explicit declaration, to prevent modification by other functions
if (counter_100ms == 0) { if (counter_100ms == 0) {
#ifdef DEBUG_LOG
logging.println("Sending keep contactors closed messages started"); logging.println("Sending keep contactors closed messages started");
#endif // DEBUG_LOG
// @0 ms // @0 ms
transmit_can_frame(&BMWiX_510); transmit_can_frame(&BMWiX_510);
} else if (counter_100ms == 7) { } else if (counter_100ms == 7) {
@ -631,9 +599,7 @@ void BmwIXBattery::BmwIxKeepContactorsClosed(uint8_t counter_100ms) {
BMWiX_16E.data.u8[0] = 0x02; BMWiX_16E.data.u8[0] = 0x02;
BMWiX_16E.data.u8[1] = 0xA7; BMWiX_16E.data.u8[1] = 0xA7;
transmit_can_frame(&BMWiX_16E); transmit_can_frame(&BMWiX_16E);
#ifdef DEBUG_LOG
logging.println("Sending keep contactors closed messages finished"); logging.println("Sending keep contactors closed messages finished");
#endif // DEBUG_LOG
} else if (counter_100ms == 140) { } else if (counter_100ms == 140) {
// @14000 ms // @14000 ms
// reset counter (outside of this function) // reset counter (outside of this function)

View file

@ -122,9 +122,7 @@ bool BmwPhevBattery::storeUDSPayload(const uint8_t* payload, uint8_t length) {
if (gUDSContext.UDS_bytesReceived + length > sizeof(gUDSContext.UDS_buffer)) { if (gUDSContext.UDS_bytesReceived + length > sizeof(gUDSContext.UDS_buffer)) {
// Overflow => abort // Overflow => abort
gUDSContext.UDS_inProgress = false; gUDSContext.UDS_inProgress = false;
#ifdef DEBUG_LOG
logging.println("UDS Payload Overflow"); logging.println("UDS Payload Overflow");
#endif // DEBUG_LOG
return false; return false;
} }
memcpy(&gUDSContext.UDS_buffer[gUDSContext.UDS_bytesReceived], payload, length); memcpy(&gUDSContext.UDS_buffer[gUDSContext.UDS_bytesReceived], payload, length);
@ -134,9 +132,7 @@ bool BmwPhevBattery::storeUDSPayload(const uint8_t* payload, uint8_t length) {
// If weve reached or exceeded the expected length, mark complete // If weve reached or exceeded the expected length, mark complete
if (gUDSContext.UDS_bytesReceived >= gUDSContext.UDS_expectedLength) { if (gUDSContext.UDS_bytesReceived >= gUDSContext.UDS_expectedLength) {
gUDSContext.UDS_inProgress = false; gUDSContext.UDS_inProgress = false;
// #ifdef DEBUG_LOG
// logging.println("Recived all expected UDS bytes"); // logging.println("Recived all expected UDS bytes");
// #endif // DEBUG_LOG
} }
return true; return true;
} }
@ -196,9 +192,7 @@ void BmwPhevBattery::wake_battery_via_canbus() {
change_can_speed(original_speed); change_can_speed(original_speed);
#ifdef DEBUG_LOG
logging.println("Sent magic wakeup packet to SME at 100kbps..."); logging.println("Sent magic wakeup packet to SME at 100kbps...");
#endif
} }
void BmwPhevBattery::update_values() { //This function maps all the values fetched via CAN to the battery datalayer void BmwPhevBattery::update_values() { //This function maps all the values fetched via CAN to the battery datalayer
@ -246,9 +240,7 @@ void BmwPhevBattery::update_values() { //This function maps all the values fetc
datalayer.battery.status.cell_min_voltage_mV = 9999; //Stale values force stop datalayer.battery.status.cell_min_voltage_mV = 9999; //Stale values force stop
datalayer.battery.status.cell_max_voltage_mV = 9999; //Stale values force stop datalayer.battery.status.cell_max_voltage_mV = 9999; //Stale values force stop
set_event(EVENT_STALE_VALUE, 0); set_event(EVENT_STALE_VALUE, 0);
#ifdef DEBUG_LOG
logging.println("Stale Min/Max voltage values detected during charge/discharge sending - 9999mV..."); logging.println("Stale Min/Max voltage values detected during charge/discharge sending - 9999mV...");
#endif // DEBUG_LOG
} else { } else {
datalayer.battery.status.cell_min_voltage_mV = min_cell_voltage; //Value is alive datalayer.battery.status.cell_min_voltage_mV = min_cell_voltage; //Value is alive
@ -398,11 +390,7 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
rx_frame.data.u8[4] == rx_frame.data.u8[4] ==
0xAD) { //Balancing Status 01 Active 03 Not Active 7DLC F1 05 71 03 AD 6B 01 0xAD) { //Balancing Status 01 Active 03 Not Active 7DLC F1 05 71 03 AD 6B 01
balancing_status = (rx_frame.data.u8[6]); balancing_status = (rx_frame.data.u8[6]);
// #ifdef DEBUG_LOG //logging.println("Balancing Status received");
// logging.println("Balancing Status received");
// #endif // DEBUG_LOG
} }
break; break;
@ -525,7 +513,6 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
battery_current = ((int32_t)((gUDSContext.UDS_buffer[3] << 24) | (gUDSContext.UDS_buffer[4] << 16) | battery_current = ((int32_t)((gUDSContext.UDS_buffer[3] << 24) | (gUDSContext.UDS_buffer[4] << 16) |
(gUDSContext.UDS_buffer[5] << 8) | gUDSContext.UDS_buffer[6])) * (gUDSContext.UDS_buffer[5] << 8) | gUDSContext.UDS_buffer[6])) *
0.1; 0.1;
#ifdef DEBUG_LOG
logging.print("Received current/amps measurement data: "); logging.print("Received current/amps measurement data: ");
logging.print(battery_current); logging.print(battery_current);
logging.print(" - "); logging.print(" - ");
@ -538,7 +525,6 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
logging.print(" "); logging.print(" ");
} }
logging.println(); // new line at the end logging.println(); // new line at the end
#endif // DEBUG_LOG
} }
//Cell Min/Max //Cell Min/Max
@ -553,7 +539,6 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
min_cell_voltage = (gUDSContext.UDS_buffer[9] << 8 | gUDSContext.UDS_buffer[10]) / 10; min_cell_voltage = (gUDSContext.UDS_buffer[9] << 8 | gUDSContext.UDS_buffer[10]) / 10;
max_cell_voltage = (gUDSContext.UDS_buffer[11] << 8 | gUDSContext.UDS_buffer[12]) / 10; max_cell_voltage = (gUDSContext.UDS_buffer[11] << 8 | gUDSContext.UDS_buffer[12]) / 10;
} else { } else {
#ifdef DEBUG_LOG
logging.println("Cell Min Max Invalid 65535 or 0..."); logging.println("Cell Min Max Invalid 65535 or 0...");
logging.print("Received data: "); logging.print("Received data: ");
for (uint16_t i = 0; i < gUDSContext.UDS_bytesReceived; i++) { for (uint16_t i = 0; i < gUDSContext.UDS_bytesReceived; i++) {
@ -565,7 +550,6 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
logging.print(" "); logging.print(" ");
} }
logging.println(); // new line at the end logging.println(); // new line at the end
#endif // DEBUG_LOG
} }
} }
@ -618,16 +602,12 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
if (rx_frame.data.u8[6] > 0 && rx_frame.data.u8[6] < 255) { if (rx_frame.data.u8[6] > 0 && rx_frame.data.u8[6] < 255) {
battery_temperature_min = (rx_frame.data.u8[6] - 50); battery_temperature_min = (rx_frame.data.u8[6] - 50);
} else { } else {
#ifdef DEBUG_LOG
logging.println("Pre parsed Cell Temp Min is Invalid "); logging.println("Pre parsed Cell Temp Min is Invalid ");
#endif
} }
if (rx_frame.data.u8[7] > 0 && rx_frame.data.u8[7] < 255) { if (rx_frame.data.u8[7] > 0 && rx_frame.data.u8[7] < 255) {
battery_temperature_max = (rx_frame.data.u8[7] - 50); battery_temperature_max = (rx_frame.data.u8[7] - 50);
} else { } else {
#ifdef DEBUG_LOG
logging.println("Pre parsed Cell Temp Max is Invalid "); logging.println("Pre parsed Cell Temp Max is Invalid ");
#endif
} }
break; break;

View file

@ -116,7 +116,6 @@ void ChademoBattery::process_vehicle_charging_session(CAN_frame rx_frame) {
x102_chg_session.ChargingCurrentRequest = newChargingCurrentRequest; x102_chg_session.ChargingCurrentRequest = newChargingCurrentRequest;
x102_chg_session.TargetBatteryVoltage = newTargetBatteryVoltage; x102_chg_session.TargetBatteryVoltage = newTargetBatteryVoltage;
#ifdef DEBUG_LOG
//Note on p131 //Note on p131
uint8_t chargingrate = 0; uint8_t chargingrate = 0;
if (x100_chg_lim.ConstantOfChargingRateIndication > 0) { if (x100_chg_lim.ConstantOfChargingRateIndication > 0) {
@ -124,7 +123,6 @@ void ChademoBattery::process_vehicle_charging_session(CAN_frame rx_frame) {
logging.print("Charge Rate (kW): "); logging.print("Charge Rate (kW): ");
logging.println(chargingrate); logging.println(chargingrate);
} }
#endif
//Table A.26—Charge control termination command patterns -- should echo x108 handling //Table A.26—Charge control termination command patterns -- should echo x108 handling
@ -136,41 +134,31 @@ void ChademoBattery::process_vehicle_charging_session(CAN_frame rx_frame) {
*/ */
if ((CHADEMO_Status == CHADEMO_INIT && vehicle_permission) || if ((CHADEMO_Status == CHADEMO_INIT && vehicle_permission) ||
(x102_chg_session.s.status.StatusVehicleChargingEnabled && !vehicle_permission)) { (x102_chg_session.s.status.StatusVehicleChargingEnabled && !vehicle_permission)) {
#ifdef DEBUG_LOG
logging.println("Inconsistent charge/discharge state."); logging.println("Inconsistent charge/discharge state.");
#endif
CHADEMO_Status = CHADEMO_FAULT; CHADEMO_Status = CHADEMO_FAULT;
return; return;
} }
if (x102_chg_session.f.fault.FaultBatteryOverVoltage) { if (x102_chg_session.f.fault.FaultBatteryOverVoltage) {
#ifdef DEBUG_LOG
logging.println("Vehicle indicates fault, battery over voltage."); logging.println("Vehicle indicates fault, battery over voltage.");
#endif
CHADEMO_Status = CHADEMO_STOP; CHADEMO_Status = CHADEMO_STOP;
return; return;
} }
if (x102_chg_session.f.fault.FaultBatteryUnderVoltage) { if (x102_chg_session.f.fault.FaultBatteryUnderVoltage) {
#ifdef DEBUG_LOG
logging.println("Vehicle indicates fault, battery under voltage."); logging.println("Vehicle indicates fault, battery under voltage.");
#endif
CHADEMO_Status = CHADEMO_STOP; CHADEMO_Status = CHADEMO_STOP;
return; return;
} }
if (x102_chg_session.f.fault.FaultBatteryCurrentDeviation) { if (x102_chg_session.f.fault.FaultBatteryCurrentDeviation) {
#ifdef DEBUG_LOG
logging.println("Vehicle indicates fault, battery current deviation. Possible EVSE issue?"); logging.println("Vehicle indicates fault, battery current deviation. Possible EVSE issue?");
#endif
CHADEMO_Status = CHADEMO_STOP; CHADEMO_Status = CHADEMO_STOP;
return; return;
} }
if (x102_chg_session.f.fault.FaultBatteryVoltageDeviation) { if (x102_chg_session.f.fault.FaultBatteryVoltageDeviation) {
#ifdef DEBUG_LOG
logging.println("Vehicle indicates fault, battery voltage deviation. Possible EVSE issue?"); logging.println("Vehicle indicates fault, battery voltage deviation. Possible EVSE issue?");
#endif
CHADEMO_Status = CHADEMO_STOP; CHADEMO_Status = CHADEMO_STOP;
return; return;
} }
@ -183,18 +171,14 @@ void ChademoBattery::process_vehicle_charging_session(CAN_frame rx_frame) {
//FIXME condition nesting or more stanzas needed here for clear determination of cessation reason //FIXME condition nesting or more stanzas needed here for clear determination of cessation reason
if (CHADEMO_Status == CHADEMO_POWERFLOW && EVSE_mode == CHADEMO_CHARGE && !vehicle_permission) { if (CHADEMO_Status == CHADEMO_POWERFLOW && EVSE_mode == CHADEMO_CHARGE && !vehicle_permission) {
#ifdef DEBUG_LOG
logging.println("State of charge ceiling reached or charging interrupted, stop charging"); logging.println("State of charge ceiling reached or charging interrupted, stop charging");
#endif
CHADEMO_Status = CHADEMO_STOP; CHADEMO_Status = CHADEMO_STOP;
return; return;
} }
if (vehicle_permission && CHADEMO_Status == CHADEMO_NEGOTIATE) { if (vehicle_permission && CHADEMO_Status == CHADEMO_NEGOTIATE) {
CHADEMO_Status = CHADEMO_EV_ALLOWED; CHADEMO_Status = CHADEMO_EV_ALLOWED;
#ifdef DEBUG_LOG
logging.println("STATE shift to CHADEMO_EV_ALLOWED in process_vehicle_charging_session()"); logging.println("STATE shift to CHADEMO_EV_ALLOWED in process_vehicle_charging_session()");
#endif
return; return;
} }
@ -203,23 +187,17 @@ void ChademoBattery::process_vehicle_charging_session(CAN_frame rx_frame) {
// consider relocating // consider relocating
if (vehicle_permission && CHADEMO_Status == CHADEMO_EVSE_PREPARE && priorTargetBatteryVoltage == 0 && if (vehicle_permission && CHADEMO_Status == CHADEMO_EVSE_PREPARE && priorTargetBatteryVoltage == 0 &&
newTargetBatteryVoltage > 0 && x102_chg_session.s.status.StatusVehicleChargingEnabled) { newTargetBatteryVoltage > 0 && x102_chg_session.s.status.StatusVehicleChargingEnabled) {
#ifdef DEBUG_LOG
logging.println("STATE SHIFT to EVSE_START reached in process_vehicle_charging_session()"); logging.println("STATE SHIFT to EVSE_START reached in process_vehicle_charging_session()");
#endif
CHADEMO_Status = CHADEMO_EVSE_START; CHADEMO_Status = CHADEMO_EVSE_START;
return; return;
} }
if (vehicle_permission && evse_permission && CHADEMO_Status == CHADEMO_POWERFLOW) { if (vehicle_permission && evse_permission && CHADEMO_Status == CHADEMO_POWERFLOW) {
#ifdef DEBUG_LOG
logging.println("updating vehicle request in process_vehicle_charging_session()"); logging.println("updating vehicle request in process_vehicle_charging_session()");
#endif
return; return;
} }
#ifdef DEBUG_LOG
logging.println("UNHANDLED CHADEMO STATE, try unplugging chademo cable, reboot emulator, and retry!"); logging.println("UNHANDLED CHADEMO STATE, try unplugging chademo cable, reboot emulator, and retry!");
#endif
return; return;
} }
@ -231,8 +209,7 @@ void ChademoBattery::process_vehicle_charging_limits(CAN_frame rx_frame) {
x200_discharge_limits.MinimumBatteryDischargeLevel = rx_frame.data.u8[6]; x200_discharge_limits.MinimumBatteryDischargeLevel = rx_frame.data.u8[6];
x200_discharge_limits.MaxRemainingCapacityForCharging = rx_frame.data.u8[7]; x200_discharge_limits.MaxRemainingCapacityForCharging = rx_frame.data.u8[7];
#ifdef DEBUG_LOG /* unsigned long currentMillis = millis();
/* unsigned long currentMillis = millis();
if (currentMillis - previousMillis5000 >= INTERVAL_5_S) { if (currentMillis - previousMillis5000 >= INTERVAL_5_S) {
previousMillis5000 = currentMillis; previousMillis5000 = currentMillis;
logging.println("x200 Max remaining capacity for charging/discharging:"); logging.println("x200 Max remaining capacity for charging/discharging:");
@ -240,16 +217,13 @@ void ChademoBattery::process_vehicle_charging_limits(CAN_frame rx_frame) {
logging.println(0xFF - x200_discharge_limits.MaxRemainingCapacityForCharging); logging.println(0xFF - x200_discharge_limits.MaxRemainingCapacityForCharging);
} }
*/ */
#endif
if (get_measured_voltage() <= x200_discharge_limits.MinimumDischargeVoltage && CHADEMO_Status > CHADEMO_NEGOTIATE) { if (get_measured_voltage() <= x200_discharge_limits.MinimumDischargeVoltage && CHADEMO_Status > CHADEMO_NEGOTIATE) {
#ifdef DEBUG_LOG
logging.println("x200 minimum discharge voltage met or exceeded, stopping."); logging.println("x200 minimum discharge voltage met or exceeded, stopping.");
logging.print("Measured: "); logging.print("Measured: ");
logging.print(get_measured_voltage()); logging.print(get_measured_voltage());
logging.print("Minimum voltage: "); logging.print("Minimum voltage: ");
logging.print(x200_discharge_limits.MinimumDischargeVoltage); logging.print(x200_discharge_limits.MinimumDischargeVoltage);
#endif
CHADEMO_Status = CHADEMO_STOP; CHADEMO_Status = CHADEMO_STOP;
} }
} }
@ -264,7 +238,6 @@ void ChademoBattery::process_vehicle_discharge_estimate(CAN_frame rx_frame) {
x201_discharge_estimate.ApproxDischargeCompletionTime = ((rx_frame.data.u8[2] << 8) | rx_frame.data.u8[1]); x201_discharge_estimate.ApproxDischargeCompletionTime = ((rx_frame.data.u8[2] << 8) | rx_frame.data.u8[1]);
x201_discharge_estimate.AvailableVehicleEnergy = ((rx_frame.data.u8[4] << 8) | rx_frame.data.u8[3]); x201_discharge_estimate.AvailableVehicleEnergy = ((rx_frame.data.u8[4] << 8) | rx_frame.data.u8[3]);
#ifdef DEBUG_LOG
if (currentMillis - previousMillis5000 >= INTERVAL_5_S) { if (currentMillis - previousMillis5000 >= INTERVAL_5_S) {
previousMillis5000 = currentMillis; previousMillis5000 = currentMillis;
logging.print("x201 availabile vehicle energy, completion time: "); logging.print("x201 availabile vehicle energy, completion time: ");
@ -272,7 +245,6 @@ void ChademoBattery::process_vehicle_discharge_estimate(CAN_frame rx_frame) {
logging.print("x201 approx vehicle completion time: "); logging.print("x201 approx vehicle completion time: ");
logging.println(x201_discharge_estimate.ApproxDischargeCompletionTime); logging.println(x201_discharge_estimate.ApproxDischargeCompletionTime);
} }
#endif
} }
void ChademoBattery::process_vehicle_dynamic_control(CAN_frame rx_frame) { void ChademoBattery::process_vehicle_dynamic_control(CAN_frame rx_frame) {
@ -615,10 +587,8 @@ void ChademoBattery::transmit_can(unsigned long currentMillis) {
// TODO need an update_evse_dynamic_control(..) function above before we send 118 // TODO need an update_evse_dynamic_control(..) function above before we send 118
// 110.0.0 // 110.0.0
if (x102_chg_session.ControlProtocolNumberEV >= 0x03) { //Only send the following on Chademo 2.0 vehicles? if (x102_chg_session.ControlProtocolNumberEV >= 0x03) { //Only send the following on Chademo 2.0 vehicles?
#ifdef DEBUG_LOG
//FIXME REMOVE //FIXME REMOVE
logging.println("REMOVE: proto 2.0"); logging.println("REMOVE: proto 2.0");
#endif
transmit_can_frame(&CHADEMO_118); transmit_can_frame(&CHADEMO_118);
} }
} }
@ -656,16 +626,12 @@ void ChademoBattery::handle_chademo_sequence() {
/* ------------------- State override conditions checks ------------------- */ /* ------------------- State override conditions checks ------------------- */
/* ------------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------------ */
if (CHADEMO_Status >= CHADEMO_EV_ALLOWED && x102_chg_session.s.status.StatusVehicleShifterPosition) { if (CHADEMO_Status >= CHADEMO_EV_ALLOWED && x102_chg_session.s.status.StatusVehicleShifterPosition) {
#ifdef DEBUG_LOG
logging.println("Vehicle is not parked, abort."); logging.println("Vehicle is not parked, abort.");
#endif
CHADEMO_Status = CHADEMO_STOP; CHADEMO_Status = CHADEMO_STOP;
} }
if (CHADEMO_Status >= CHADEMO_EV_ALLOWED && !vehicle_permission) { if (CHADEMO_Status >= CHADEMO_EV_ALLOWED && !vehicle_permission) {
#ifdef DEBUG_LOG
logging.println("Vehicle charge/discharge permission ended, stop."); logging.println("Vehicle charge/discharge permission ended, stop.");
#endif
CHADEMO_Status = CHADEMO_STOP; CHADEMO_Status = CHADEMO_STOP;
} }
@ -678,25 +644,19 @@ void ChademoBattery::handle_chademo_sequence() {
plug_inserted = digitalRead(pin7); plug_inserted = digitalRead(pin7);
if (!plug_inserted) { if (!plug_inserted) {
#ifdef DEBUG_LOG // Commented unless needed for debug
// Commented unless needed for debug // logging.println("CHADEMO plug is not inserted.");
// logging.println("CHADEMO plug is not inserted.");
#endif
return; return;
} }
CHADEMO_Status = CHADEMO_CONNECTED; CHADEMO_Status = CHADEMO_CONNECTED;
#ifdef DEBUG_LOG
logging.println("CHADEMO plug is inserted. Provide EVSE power to vehicle to trigger initialization."); logging.println("CHADEMO plug is inserted. Provide EVSE power to vehicle to trigger initialization.");
#endif
break; break;
case CHADEMO_CONNECTED: case CHADEMO_CONNECTED:
#ifdef DEBUG_LOG
// Commented unless needed for debug // Commented unless needed for debug
//logging.println("CHADEMO_CONNECTED State"); //logging.println("CHADEMO_CONNECTED State");
#endif
/* plug_inserted is .. essentially a volatile of sorts, so verify */ /* plug_inserted is .. essentially a volatile of sorts, so verify */
if (plug_inserted) { if (plug_inserted) {
/* If connection is detectable, jumpstart handshake by /* If connection is detectable, jumpstart handshake by
@ -729,17 +689,13 @@ void ChademoBattery::handle_chademo_sequence() {
/* Vehicle and EVSE dance */ /* Vehicle and EVSE dance */
//TODO if pin 4 / j goes high, //TODO if pin 4 / j goes high,
#ifdef DEBUG_LOG // Commented unless needed for debug
// Commented unless needed for debug // logging.println("CHADEMO_NEGOTIATE State");
// logging.println("CHADEMO_NEGOTIATE State");
#endif
x109_evse_state.s.status.ChgDischStopControl = 1; x109_evse_state.s.status.ChgDischStopControl = 1;
break; break;
case CHADEMO_EV_ALLOWED: case CHADEMO_EV_ALLOWED:
#ifdef DEBUG_LOG
// Commented unless needed for debug // Commented unless needed for debug
logging.println("CHADEMO_EV_ALLOWED State"); logging.println("CHADEMO_EV_ALLOWED State");
#endif
// If we are in this state, vehicle_permission was already set to true...but re-verify // If we are in this state, vehicle_permission was already set to true...but re-verify
// that pin 4 (j) reads high // that pin 4 (j) reads high
if (vehicle_permission) { if (vehicle_permission) {
@ -754,10 +710,8 @@ void ChademoBattery::handle_chademo_sequence() {
} }
break; break;
case CHADEMO_EVSE_PREPARE: case CHADEMO_EVSE_PREPARE:
#ifdef DEBUG_LOG
// Commented unless needed for debug // Commented unless needed for debug
logging.println("CHADEMO_EVSE_PREPARE State"); logging.println("CHADEMO_EVSE_PREPARE State");
#endif
/* TODO voltage check of output < 20v /* TODO voltage check of output < 20v
* insulation test hypothetically happens here before triggering PIN 10 high * insulation test hypothetically happens here before triggering PIN 10 high
* see Table A.28Requirements for the insulation test for output DC circuit * see Table A.28Requirements for the insulation test for output DC circuit
@ -790,19 +744,15 @@ void ChademoBattery::handle_chademo_sequence() {
//state changes to CHADEMO_EVSE_START only upon receipt of charging session request //state changes to CHADEMO_EVSE_START only upon receipt of charging session request
break; break;
case CHADEMO_EVSE_START: case CHADEMO_EVSE_START:
#ifdef DEBUG_LOG
// Commented unless needed for debug // Commented unless needed for debug
logging.println("CHADEMO_EVSE_START State"); logging.println("CHADEMO_EVSE_START State");
#endif
datalayer.system.status.battery_allows_contactor_closing = true; datalayer.system.status.battery_allows_contactor_closing = true;
x109_evse_state.s.status.ChgDischStopControl = 1; x109_evse_state.s.status.ChgDischStopControl = 1;
x109_evse_state.s.status.EVSE_status = 0; x109_evse_state.s.status.EVSE_status = 0;
CHADEMO_Status = CHADEMO_EVSE_CONTACTORS_ENABLED; CHADEMO_Status = CHADEMO_EVSE_CONTACTORS_ENABLED;
#ifdef DEBUG_LOG
logging.println("Initiating contactors"); logging.println("Initiating contactors");
#endif
/* break rather than fall through because contactors are not instantaneous; /* break rather than fall through because contactors are not instantaneous;
* worth giving it a cycle to finish * worth giving it a cycle to finish
@ -810,18 +760,14 @@ void ChademoBattery::handle_chademo_sequence() {
break; break;
case CHADEMO_EVSE_CONTACTORS_ENABLED: case CHADEMO_EVSE_CONTACTORS_ENABLED:
#ifdef DEBUG_LOG
// Commented unless needed for debug // Commented unless needed for debug
logging.println("CHADEMO_EVSE_CONTACTORS State"); logging.println("CHADEMO_EVSE_CONTACTORS State");
#endif
/* check whether contactors ready, because externally dependent upon inverter allow during discharge */ /* check whether contactors ready, because externally dependent upon inverter allow during discharge */
if (contactors_ready) { if (contactors_ready) {
#ifdef DEBUG_LOG
logging.println("Contactors ready"); logging.println("Contactors ready");
logging.print("Voltage: "); logging.print("Voltage: ");
logging.println(get_measured_voltage()); logging.println(get_measured_voltage());
#endif
/* transition to POWERFLOW state if discharge compatible on both sides */ /* transition to POWERFLOW state if discharge compatible on both sides */
if (x109_evse_state.discharge_compatible && x102_chg_session.s.status.StatusVehicleDischargeCompatible && if (x109_evse_state.discharge_compatible && x102_chg_session.s.status.StatusVehicleDischargeCompatible &&
(EVSE_mode == CHADEMO_DISCHARGE || EVSE_mode == CHADEMO_BIDIRECTIONAL)) { (EVSE_mode == CHADEMO_DISCHARGE || EVSE_mode == CHADEMO_BIDIRECTIONAL)) {
@ -840,10 +786,8 @@ void ChademoBattery::handle_chademo_sequence() {
/* break or fall through ? TODO */ /* break or fall through ? TODO */
break; break;
case CHADEMO_POWERFLOW: case CHADEMO_POWERFLOW:
#ifdef DEBUG_LOG
// Commented unless needed for debug // Commented unless needed for debug
logging.println("CHADEMO_POWERFLOW State"); logging.println("CHADEMO_POWERFLOW State");
#endif
/* POWERFLOW for charging, discharging, and bidirectional */ /* POWERFLOW for charging, discharging, and bidirectional */
/* Interpretation */ /* Interpretation */
if (x102_chg_session.s.status.StatusVehicleShifterPosition) { if (x102_chg_session.s.status.StatusVehicleShifterPosition) {
@ -860,9 +804,7 @@ void ChademoBattery::handle_chademo_sequence() {
} }
if (get_measured_voltage() <= x200_discharge_limits.MinimumDischargeVoltage) { if (get_measured_voltage() <= x200_discharge_limits.MinimumDischargeVoltage) {
#ifdef DEBUG_LOG
logging.println("x200 minimum discharge voltage met or exceeded, stopping."); logging.println("x200 minimum discharge voltage met or exceeded, stopping.");
#endif
CHADEMO_Status = CHADEMO_STOP; CHADEMO_Status = CHADEMO_STOP;
} }
@ -871,10 +813,8 @@ void ChademoBattery::handle_chademo_sequence() {
x109_evse_state.s.status.EVSE_status = 1; x109_evse_state.s.status.EVSE_status = 1;
break; break;
case CHADEMO_STOP: case CHADEMO_STOP:
#ifdef DEBUG_LOG
// Commented unless needed for debug // Commented unless needed for debug
logging.println("CHADEMO_STOP State"); logging.println("CHADEMO_STOP State");
#endif
/* back to CHADEMO_IDLE after teardown */ /* back to CHADEMO_IDLE after teardown */
x109_evse_state.s.status.ChgDischStopControl = 1; x109_evse_state.s.status.ChgDischStopControl = 1;
x109_evse_state.s.status.EVSE_status = 0; x109_evse_state.s.status.EVSE_status = 0;
@ -899,17 +839,13 @@ void ChademoBattery::handle_chademo_sequence() {
break; break;
case CHADEMO_FAULT: case CHADEMO_FAULT:
#ifdef DEBUG_LOG
// Commented unless needed for debug // Commented unless needed for debug
logging.println("CHADEMO_FAULT State"); logging.println("CHADEMO_FAULT State");
#endif
/* Once faulted, never departs CHADEMO_FAULT state unless device is power cycled as a safety measure */ /* Once faulted, never departs CHADEMO_FAULT state unless device is power cycled as a safety measure */
x109_evse_state.s.status.EVSE_error = 1; x109_evse_state.s.status.EVSE_error = 1;
x109_evse_state.s.status.ChgDischError = 1; x109_evse_state.s.status.ChgDischError = 1;
x109_evse_state.s.status.ChgDischStopControl = 1; x109_evse_state.s.status.ChgDischStopControl = 1;
#ifdef DEBUG_LOG
logging.println("CHADEMO fault encountered, tearing down to make safe"); logging.println("CHADEMO fault encountered, tearing down to make safe");
#endif
digitalWrite(pin10, LOW); digitalWrite(pin10, LOW);
digitalWrite(pin2, LOW); digitalWrite(pin2, LOW);
evse_permission = false; evse_permission = false;
@ -919,9 +855,7 @@ void ChademoBattery::handle_chademo_sequence() {
break; break;
default: default:
#ifdef DEBUG_LOG
logging.println("UNHANDLED CHADEMO_STATE, setting FAULT"); logging.println("UNHANDLED CHADEMO_STATE, setting FAULT");
#endif
CHADEMO_Status = CHADEMO_FAULT; CHADEMO_Status = CHADEMO_FAULT;
break; break;
} }

View file

@ -75,12 +75,9 @@ void ImievCZeroIonBattery::
} }
if (!BMU_Detected) { if (!BMU_Detected) {
#ifdef DEBUG_LOG
logging.println("BMU not detected, check wiring!"); logging.println("BMU not detected, check wiring!");
#endif
} }
#ifdef DEBUG_LOG
logging.println("Battery Values"); logging.println("Battery Values");
logging.print("BMU SOC: "); logging.print("BMU SOC: ");
logging.print(BMU_SOC); logging.print(BMU_SOC);
@ -90,15 +87,6 @@ void ImievCZeroIonBattery::
logging.print(BMU_PackVoltage); logging.print(BMU_PackVoltage);
logging.print(" BMU_Power: "); logging.print(" BMU_Power: ");
logging.print(BMU_Power); logging.print(BMU_Power);
logging.print(" Cell max voltage: ");
logging.print(max_volt_cel);
logging.print(" Cell min voltage: ");
logging.print(min_volt_cel);
logging.print(" Cell max temp: ");
logging.print(max_temp_cel);
logging.print(" Cell min temp: ");
logging.println(min_temp_cel);
#endif
} }
void ImievCZeroIonBattery::handle_incoming_can_frame(CAN_frame rx_frame) { void ImievCZeroIonBattery::handle_incoming_can_frame(CAN_frame rx_frame) {

View file

@ -102,21 +102,6 @@ void JaguarIpaceBattery::update_values() {
} else { } else {
clear_event(EVENT_BATTERY_ISOLATION); clear_event(EVENT_BATTERY_ISOLATION);
} }
/*Finally print out values to serial if configured to do so*/
#ifdef DEBUG_LOG
logging.println("Values going to inverter");
print_units("SOH%: ", (datalayer.battery.status.soh_pptt * 0.01), "% ");
print_units(", SOC%: ", (datalayer.battery.status.reported_soc * 0.01), "% ");
print_units(", Voltage: ", (datalayer.battery.status.voltage_dV * 0.1), "V ");
print_units(", Max discharge power: ", datalayer.battery.status.max_discharge_power_W, "W ");
print_units(", Max charge power: ", datalayer.battery.status.max_charge_power_W, "W ");
print_units(", Max temp: ", (datalayer.battery.status.temperature_max_dC * 0.1), "°C ");
print_units(", Min temp: ", (datalayer.battery.status.temperature_min_dC * 0.1), "°C ");
print_units(", Max cell voltage: ", datalayer.battery.status.cell_max_voltage_mV, "mV ");
print_units(", Min cell voltage: ", datalayer.battery.status.cell_min_voltage_mV, "mV ");
logging.println("");
#endif
} }
void JaguarIpaceBattery::handle_incoming_can_frame(CAN_frame rx_frame) { void JaguarIpaceBattery::handle_incoming_can_frame(CAN_frame rx_frame) {

View file

@ -55,7 +55,6 @@ uint16_t KiaEGmpBattery::estimateSOC(uint16_t packVoltage, uint16_t cellCount, i
// Calculate average cell voltage in millivolts // Calculate average cell voltage in millivolts
uint16_t avgCellVoltage = compensatedPackVoltageMv / cellCount; uint16_t avgCellVoltage = compensatedPackVoltageMv / cellCount;
#ifdef DEBUG_LOG
logging.print("Pack: "); logging.print("Pack: ");
logging.print(packVoltage / 10.0); logging.print(packVoltage / 10.0);
logging.print("V, Current: "); logging.print("V, Current: ");
@ -67,7 +66,6 @@ uint16_t KiaEGmpBattery::estimateSOC(uint16_t packVoltage, uint16_t cellCount, i
logging.print("V, Avg Cell: "); logging.print("V, Avg Cell: ");
logging.print(avgCellVoltage); logging.print(avgCellVoltage);
logging.println("mV"); logging.println("mV");
#endif
// Use the cell voltage lookup table to estimate SOC // Use the cell voltage lookup table to estimate SOC
return estimateSOCFromCell(avgCellVoltage); return estimateSOCFromCell(avgCellVoltage);
@ -187,7 +185,6 @@ void KiaEGmpBattery::update_values() {
/* Safeties verified. Perform USB serial printout if configured to do so */ /* Safeties verified. Perform USB serial printout if configured to do so */
#ifdef DEBUG_LOG
logging.println(); //sepatator logging.println(); //sepatator
logging.println("Values from battery: "); logging.println("Values from battery: ");
logging.print("SOC BMS: "); logging.print("SOC BMS: ");
@ -244,7 +241,6 @@ void KiaEGmpBattery::update_values() {
logging.print(" | Inverter "); logging.print(" | Inverter ");
logging.print(inverterVoltage); logging.print(inverterVoltage);
logging.println(" Volts"); logging.println(" Volts");
#endif
} }
// Getter implementations for HTML renderer // Getter implementations for HTML renderer

View file

@ -171,9 +171,7 @@ uint8_t vw_crc_calc(uint8_t* inputBytes, uint8_t length, uint32_t address) {
magicByte = MB16A954A6[counter]; magicByte = MB16A954A6[counter];
break; break;
default: // this won't lead to correct CRC checksums default: // this won't lead to correct CRC checksums
#ifdef DEBUG_LOG
logging.println("Checksum request unknown"); logging.println("Checksum request unknown");
#endif
magicByte = 0x00; magicByte = 0x00;
break; break;
} }
@ -310,9 +308,7 @@ void MebBattery::
void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) { void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
last_can_msg_timestamp = millis(); last_can_msg_timestamp = millis();
if (first_can_msg == 0) { if (first_can_msg == 0) {
#ifdef DEBUG_LOG
logging.printf("MEB: First CAN msg received\n"); logging.printf("MEB: First CAN msg received\n");
#endif
first_can_msg = last_can_msg_timestamp; first_can_msg = last_can_msg_timestamp;
} }
@ -326,9 +322,7 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
if (rx_frame.data.u8[0] != if (rx_frame.data.u8[0] !=
vw_crc_calc(rx_frame.data.u8, rx_frame.DLC, rx_frame.ID)) { //If CRC does not match calc vw_crc_calc(rx_frame.data.u8, rx_frame.DLC, rx_frame.ID)) { //If CRC does not match calc
datalayer.battery.status.CAN_error_counter++; datalayer.battery.status.CAN_error_counter++;
#ifdef DEBUG_LOG
logging.printf("MEB: Msg 0x%04X CRC error\n", rx_frame.ID); logging.printf("MEB: Msg 0x%04X CRC error\n", rx_frame.ID);
#endif
return; return;
} }
default: default:
@ -700,29 +694,23 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
case 3: // EXTERN CHARGING case 3: // EXTERN CHARGING
case 4: // AC_CHARGING case 4: // AC_CHARGING
case 6: // DC_CHARGING case 6: // DC_CHARGING
#ifdef DEBUG_LOG
if (!datalayer.system.status.battery_allows_contactor_closing) if (!datalayer.system.status.battery_allows_contactor_closing)
logging.printf("MEB: Contactors closed\n"); logging.printf("MEB: Contactors closed\n");
#endif
if (datalayer.battery.status.real_bms_status != BMS_FAULT) if (datalayer.battery.status.real_bms_status != BMS_FAULT)
datalayer.battery.status.real_bms_status = BMS_ACTIVE; datalayer.battery.status.real_bms_status = BMS_ACTIVE;
datalayer.system.status.battery_allows_contactor_closing = true; datalayer.system.status.battery_allows_contactor_closing = true;
hv_requested = false; hv_requested = false;
break; break;
case 5: // Error case 5: // Error
#ifdef DEBUG_LOG
if (datalayer.system.status.battery_allows_contactor_closing) if (datalayer.system.status.battery_allows_contactor_closing)
logging.printf("MEB: Contactors opened\n"); logging.printf("MEB: Contactors opened\n");
#endif
datalayer.battery.status.real_bms_status = BMS_FAULT; datalayer.battery.status.real_bms_status = BMS_FAULT;
datalayer.system.status.battery_allows_contactor_closing = false; datalayer.system.status.battery_allows_contactor_closing = false;
hv_requested = false; hv_requested = false;
break; break;
case 7: // Init case 7: // Init
#ifdef DEBUG_LOG
if (datalayer.system.status.battery_allows_contactor_closing) if (datalayer.system.status.battery_allows_contactor_closing)
logging.printf("MEB: Contactors opened\n"); logging.printf("MEB: Contactors opened\n");
#endif
if (datalayer.battery.status.real_bms_status != BMS_FAULT) if (datalayer.battery.status.real_bms_status != BMS_FAULT)
datalayer.battery.status.real_bms_status = BMS_STANDBY; datalayer.battery.status.real_bms_status = BMS_STANDBY;
datalayer.system.status.battery_allows_contactor_closing = false; datalayer.system.status.battery_allows_contactor_closing = false;
@ -730,10 +718,8 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
break; break;
case 2: // BALANCING case 2: // BALANCING
default: default:
#ifdef DEBUG_LOG
if (datalayer.system.status.battery_allows_contactor_closing) if (datalayer.system.status.battery_allows_contactor_closing)
logging.printf("MEB: Contactors opened\n"); logging.printf("MEB: Contactors opened\n");
#endif
if (datalayer.battery.status.real_bms_status != BMS_FAULT) if (datalayer.battery.status.real_bms_status != BMS_FAULT)
datalayer.battery.status.real_bms_status = BMS_STANDBY; datalayer.battery.status.real_bms_status = BMS_STANDBY;
datalayer.system.status.battery_allows_contactor_closing = false; datalayer.system.status.battery_allows_contactor_closing = false;
@ -1276,10 +1262,8 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
handle_obd_frame(rx_frame); handle_obd_frame(rx_frame);
break; break;
default: default:
#ifdef DEBUG_LOG
logging.printf("Unknown CAN frame received:\n"); logging.printf("Unknown CAN frame received:\n");
dump_can_frame(rx_frame, MSG_RX); dump_can_frame(rx_frame, MSG_RX);
#endif
break; break;
} }
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
@ -1292,10 +1276,8 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
void MebBattery::transmit_can(unsigned long currentMillis) { void MebBattery::transmit_can(unsigned long currentMillis) {
if (currentMillis - last_can_msg_timestamp > 500) { if (currentMillis - last_can_msg_timestamp > 500) {
#ifdef DEBUG_LOG
if (first_can_msg) if (first_can_msg)
logging.printf("MEB: No CAN msg received for 500ms\n"); logging.printf("MEB: No CAN msg received for 500ms\n");
#endif
can_msg_received = RX_DEFAULT; can_msg_received = RX_DEFAULT;
first_can_msg = 0; first_can_msg = 0;
if (datalayer.battery.status.real_bms_status != BMS_FAULT) { if (datalayer.battery.status.real_bms_status != BMS_FAULT) {
@ -1373,7 +1355,6 @@ void MebBattery::transmit_can(unsigned long currentMillis) {
((int32_t)datalayer_extended.meb.BMS_voltage_intermediate_dV)) < 200))))) { ((int32_t)datalayer_extended.meb.BMS_voltage_intermediate_dV)) < 200))))) {
hv_requested = true; hv_requested = true;
datalayer.system.settings.start_precharging = false; datalayer.system.settings.start_precharging = false;
#ifdef DEBUG_LOG
if (MEB_503.data.u8[3] == BMS_TARGET_HV_OFF) { if (MEB_503.data.u8[3] == BMS_TARGET_HV_OFF) {
logging.printf("MEB: Requesting HV\n"); logging.printf("MEB: Requesting HV\n");
} }
@ -1385,7 +1366,6 @@ void MebBattery::transmit_can(unsigned long currentMillis) {
logging.printf("MEB: Precharge bit set to inactive\n"); logging.printf("MEB: Precharge bit set to inactive\n");
} }
} }
#endif
MEB_503.data.u8[1] = MEB_503.data.u8[1] =
0x30 | (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING ? 0x80 : 0x00); 0x30 | (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING ? 0x80 : 0x00);
MEB_503.data.u8[3] = BMS_TARGET_AC_CHARGING; MEB_503.data.u8[3] = BMS_TARGET_AC_CHARGING;
@ -1399,7 +1379,6 @@ void MebBattery::transmit_can(unsigned long currentMillis) {
datalayer.system.settings.start_precharging = true; datalayer.system.settings.start_precharging = true;
} }
#ifdef DEBUG_LOG
if (MEB_503.data.u8[3] != BMS_TARGET_HV_OFF) { if (MEB_503.data.u8[3] != BMS_TARGET_HV_OFF) {
logging.printf("MEB: Requesting HV_OFF\n"); logging.printf("MEB: Requesting HV_OFF\n");
} }
@ -1411,7 +1390,6 @@ void MebBattery::transmit_can(unsigned long currentMillis) {
logging.printf("MEB: Precharge bit set to inactive\n"); logging.printf("MEB: Precharge bit set to inactive\n");
} }
} }
#endif
MEB_503.data.u8[1] = MEB_503.data.u8[1] =
0x10 | (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING ? 0x80 : 0x00); 0x10 | (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING ? 0x80 : 0x00);
MEB_503.data.u8[3] = BMS_TARGET_HV_OFF; MEB_503.data.u8[3] = BMS_TARGET_HV_OFF;

View file

@ -147,11 +147,9 @@ void MgHsPHEVBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
// 15 = isolation fault // 15 = isolation fault
// 0/8 = checking // 0/8 = checking
#ifdef DEBUG_LOG
if (rx_frame.data.u8[1] != previousState) { if (rx_frame.data.u8[1] != previousState) {
logging.printf("MG_HS_PHEV: Battery status changed to %d (%d)\n", rx_frame.data.u8[1], rx_frame.data.u8[0]); logging.printf("MG_HS_PHEV: Battery status changed to %d (%d)\n", rx_frame.data.u8[1], rx_frame.data.u8[0]);
} }
#endif
if (rx_frame.data.u8[1] == 0xf && previousState != 0xf) { if (rx_frame.data.u8[1] == 0xf && previousState != 0xf) {
// Isolation fault, set event // Isolation fault, set event
@ -168,18 +166,14 @@ void MgHsPHEVBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
// A weird 'stuck' state where the battery won't reconnect // A weird 'stuck' state where the battery won't reconnect
datalayer.system.status.battery_allows_contactor_closing = false; datalayer.system.status.battery_allows_contactor_closing = false;
if (!datalayer.system.status.BMS_startup_in_progress) { if (!datalayer.system.status.BMS_startup_in_progress) {
#ifdef DEBUG_LOG
logging.printf("MG_HS_PHEV: Stuck, resetting.\n"); logging.printf("MG_HS_PHEV: Stuck, resetting.\n");
#endif
start_bms_reset(); start_bms_reset();
} }
} else if (rx_frame.data.u8[1] == 0xf) { } else if (rx_frame.data.u8[1] == 0xf) {
// A fault state (likely isolation failure) // A fault state (likely isolation failure)
datalayer.system.status.battery_allows_contactor_closing = false; datalayer.system.status.battery_allows_contactor_closing = false;
if (!datalayer.system.status.BMS_startup_in_progress) { if (!datalayer.system.status.BMS_startup_in_progress) {
#ifdef DEBUG_LOG
logging.printf("MG_HS_PHEV: Fault, resetting.\n"); logging.printf("MG_HS_PHEV: Fault, resetting.\n");
#endif
start_bms_reset(); start_bms_reset();
} }
} else { } else {

View file

@ -51,39 +51,6 @@ void RenaultKangooBattery::
datalayer.battery.status.cell_min_voltage_mV = LB_Cell_Min_Voltage; datalayer.battery.status.cell_min_voltage_mV = LB_Cell_Min_Voltage;
datalayer.battery.status.cell_max_voltage_mV = LB_Cell_Max_Voltage; datalayer.battery.status.cell_max_voltage_mV = LB_Cell_Max_Voltage;
#ifdef DEBUG_LOG
logging.println("Values going to inverter:");
logging.print("SOH%: ");
logging.print(datalayer.battery.status.soh_pptt);
logging.print(", SOC% scaled: ");
logging.print(datalayer.battery.status.reported_soc);
logging.print(", Voltage: ");
logging.print(datalayer.battery.status.voltage_dV);
logging.print(", Max discharge power: ");
logging.print(datalayer.battery.status.max_discharge_power_W);
logging.print(", Max charge power: ");
logging.print(datalayer.battery.status.max_charge_power_W);
logging.print(", Max temp: ");
logging.print(datalayer.battery.status.temperature_max_dC);
logging.print(", Min temp: ");
logging.print(datalayer.battery.status.temperature_min_dC);
logging.print(", BMS Status (3=OK): ");
logging.print(datalayer.battery.status.bms_status);
logging.println("Battery values: ");
logging.print("Real SOC: ");
logging.print(LB_SOC);
logging.print(", Current: ");
logging.print(LB_Current);
logging.print(", kWh remain: ");
logging.print(LB_kWh_Remaining);
logging.print(", max mV: ");
logging.print(LB_Cell_Max_Voltage);
logging.print(", min mV: ");
logging.print(LB_Cell_Min_Voltage);
#endif
} }
void RenaultKangooBattery::handle_incoming_can_frame(CAN_frame rx_frame) { void RenaultKangooBattery::handle_incoming_can_frame(CAN_frame rx_frame) {

View file

@ -720,13 +720,9 @@ void TeslaBattery::
//Start the BMS ECU reset statemachine, only if contactors are OPEN and BMS ECU allows it //Start the BMS ECU reset statemachine, only if contactors are OPEN and BMS ECU allows it
stateMachineBMSReset = 0; stateMachineBMSReset = 0;
datalayer.battery.settings.user_requests_tesla_bms_reset = false; datalayer.battery.settings.user_requests_tesla_bms_reset = false;
#ifdef DEBUG_LOG
logging.println("BMS reset requested"); logging.println("BMS reset requested");
#endif //DEBUG_LOG
} else { } else {
#ifdef DEBUG_LOG
logging.println("ERROR: BMS reset failed due to contactors not being open, or BMS ECU not allowing it"); logging.println("ERROR: BMS reset failed due to contactors not being open, or BMS ECU not allowing it");
#endif //DEBUG_LOG
stateMachineBMSReset = 0xFF; stateMachineBMSReset = 0xFF;
datalayer.battery.settings.user_requests_tesla_bms_reset = false; datalayer.battery.settings.user_requests_tesla_bms_reset = false;
} }
@ -736,13 +732,9 @@ void TeslaBattery::
//Start the SOC reset statemachine, only if SOC < 15% or > 90% //Start the SOC reset statemachine, only if SOC < 15% or > 90%
stateMachineSOCReset = 0; stateMachineSOCReset = 0;
datalayer.battery.settings.user_requests_tesla_soc_reset = false; datalayer.battery.settings.user_requests_tesla_soc_reset = false;
#ifdef DEBUG_LOG
logging.println("SOC reset requested"); logging.println("SOC reset requested");
#endif //DEBUG_LOG
} else { } else {
#ifdef DEBUG_LOG
logging.println("ERROR: SOC reset failed due to SOC not being less than 15 or greater than 90"); logging.println("ERROR: SOC reset failed due to SOC not being less than 15 or greater than 90");
#endif //DEBUG_LOG
stateMachineSOCReset = 0xFF; stateMachineSOCReset = 0xFF;
datalayer.battery.settings.user_requests_tesla_soc_reset = false; datalayer.battery.settings.user_requests_tesla_soc_reset = false;
} }
@ -1002,8 +994,6 @@ void TeslaBattery::
} }
} }
#ifdef DEBUG_LOG
printFaultCodesIfActive(); printFaultCodesIfActive();
logging.print("BMS Contactors State: "); logging.print("BMS Contactors State: ");
logging.print(getBMSContactorState(battery_contactor)); // Display what state the BMS thinks the contactors are in logging.print(getBMSContactorState(battery_contactor)); // Display what state the BMS thinks the contactors are in
@ -1061,7 +1051,6 @@ void TeslaBattery::
logging.printf("PCS_ambientTemp: %.2f°C, DCDC_Temp: %.2f°C, ChgPhA: %.2f°C, ChgPhB: %.2f°C, ChgPhC: %.2f°C.\n", logging.printf("PCS_ambientTemp: %.2f°C, DCDC_Temp: %.2f°C, ChgPhA: %.2f°C, ChgPhB: %.2f°C, ChgPhC: %.2f°C.\n",
PCS_ambientTemp * 0.1 + 40, PCS_dcdcTemp * 0.1 + 40, PCS_chgPhATemp * 0.1 + 40, PCS_ambientTemp * 0.1 + 40, PCS_dcdcTemp * 0.1 + 40, PCS_chgPhATemp * 0.1 + 40,
PCS_chgPhBTemp * 0.1 + 40, PCS_chgPhCTemp * 0.1 + 40); PCS_chgPhBTemp * 0.1 + 40, PCS_chgPhCTemp * 0.1 + 40);
#endif //DEBUG_LOG
} }
void TeslaBattery::handle_incoming_can_frame(CAN_frame rx_frame) { void TeslaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
@ -1911,9 +1900,7 @@ void TeslaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
if (stateMachineBMSQuery != 0xFF && stateMachineBMSReset == 0xFF) { if (stateMachineBMSQuery != 0xFF && stateMachineBMSReset == 0xFF) {
if (memcmp(rx_frame.data.u8, "\x02\x50\x03\xAA\xAA\xAA\xAA\xAA", 8) == 0) { if (memcmp(rx_frame.data.u8, "\x02\x50\x03\xAA\xAA\xAA\xAA\xAA", 8) == 0) {
//Received initial response, proceed to actual query //Received initial response, proceed to actual query
#ifdef DEBUG_LOG
logging.println("CAN UDS: Received BMS query initial handshake reply"); logging.println("CAN UDS: Received BMS query initial handshake reply");
#endif //DEBUG_LOG
stateMachineBMSQuery = 1; stateMachineBMSQuery = 1;
break; break;
} }
@ -1922,9 +1909,7 @@ void TeslaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
battery_partNumber[0] = rx_frame.data.u8[5]; battery_partNumber[0] = rx_frame.data.u8[5];
battery_partNumber[1] = rx_frame.data.u8[6]; battery_partNumber[1] = rx_frame.data.u8[6];
battery_partNumber[2] = rx_frame.data.u8[7]; battery_partNumber[2] = rx_frame.data.u8[7];
#ifdef DEBUG_LOG
logging.println("CAN UDS: Received BMS query data frame"); logging.println("CAN UDS: Received BMS query data frame");
#endif //DEBUG_LOG
stateMachineBMSQuery = 2; stateMachineBMSQuery = 2;
break; break;
} }
@ -1937,32 +1922,25 @@ void TeslaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
battery_partNumber[7] = rx_frame.data.u8[5]; battery_partNumber[7] = rx_frame.data.u8[5];
battery_partNumber[8] = rx_frame.data.u8[6]; battery_partNumber[8] = rx_frame.data.u8[6];
battery_partNumber[9] = rx_frame.data.u8[7]; battery_partNumber[9] = rx_frame.data.u8[7];
#ifdef DEBUG_LOG
logging.println("CAN UDS: Received BMS query second data frame"); logging.println("CAN UDS: Received BMS query second data frame");
#endif //DEBUG_LOG
break; break;
} }
if (memcmp(&rx_frame.data.u8[0], "\x22", 1) == 0) { if (memcmp(&rx_frame.data.u8[0], "\x22", 1) == 0) {
//Final part of part number //Final part of part number
battery_partNumber[10] = rx_frame.data.u8[1]; battery_partNumber[10] = rx_frame.data.u8[1];
battery_partNumber[11] = rx_frame.data.u8[2]; battery_partNumber[11] = rx_frame.data.u8[2];
#ifdef DEBUG_LOG
logging.println("CAN UDS: Received BMS query final data frame"); logging.println("CAN UDS: Received BMS query final data frame");
#endif //DEBUG_LOG
break; break;
} }
if (memcmp(rx_frame.data.u8, "\x23\x00\x00\x00\xAA\xAA\xAA\xAA", 8) == 0) { if (memcmp(rx_frame.data.u8, "\x23\x00\x00\x00\xAA\xAA\xAA\xAA", 8) == 0) {
//Received final frame //Received final frame
#ifdef DEBUG_LOG
logging.println("CAN UDS: Received BMS query termination frame"); logging.println("CAN UDS: Received BMS query termination frame");
#endif //DEBUG_LOG
parsed_battery_partNumber = true; parsed_battery_partNumber = true;
stateMachineBMSQuery = 0xFF; stateMachineBMSQuery = 0xFF;
break; break;
} }
} }
//BMS Reset //BMS Reset
#ifdef DEBUG_LOG
if (stateMachineBMSQuery == 0xFF) { // Make sure this is reset request not query if (stateMachineBMSQuery == 0xFF) { // Make sure this is reset request not query
if (memcmp(rx_frame.data.u8, "\x02\x67\x06\xAA\xAA\xAA\xAA\xAA", 8) == 0) { if (memcmp(rx_frame.data.u8, "\x02\x67\x06\xAA\xAA\xAA\xAA\xAA", 8) == 0) {
logging.println("CAN UDS: ECU unlocked"); logging.println("CAN UDS: ECU unlocked");
@ -1972,7 +1950,6 @@ void TeslaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
logging.println("CAN UDS: ECU reset positive response, 1 second downtime"); logging.println("CAN UDS: ECU reset positive response, 1 second downtime");
} }
} }
#endif //DEBUG_LOG
break; break;
default: default:
break; break;
@ -2375,25 +2352,19 @@ void TeslaBattery::transmit_can(unsigned long currentMillis) {
switch (stateMachineBMSQuery) { switch (stateMachineBMSQuery) {
case 0: case 0:
//Initial request //Initial request
#ifdef DEBUG_LOG
logging.println("CAN UDS: Sending BMS query initial handshake"); logging.println("CAN UDS: Sending BMS query initial handshake");
#endif //DEBUG_LOG
TESLA_602.data = {0x02, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}; TESLA_602.data = {0x02, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00};
transmit_can_frame(&TESLA_602); transmit_can_frame(&TESLA_602);
break; break;
case 1: case 1:
//Send query //Send query
#ifdef DEBUG_LOG
logging.println("CAN UDS: Sending BMS query for pack part number"); logging.println("CAN UDS: Sending BMS query for pack part number");
#endif //DEBUG_LOG
TESLA_602.data = {0x03, 0x22, 0xF0, 0x14, 0x00, 0x00, 0x00, 0x00}; TESLA_602.data = {0x03, 0x22, 0xF0, 0x14, 0x00, 0x00, 0x00, 0x00};
transmit_can_frame(&TESLA_602); transmit_can_frame(&TESLA_602);
break; break;
case 2: case 2:
//Flow control //Flow control
#ifdef DEBUG_LOG
logging.println("CAN UDS: Sending BMS query flow control"); logging.println("CAN UDS: Sending BMS query flow control");
#endif //DEBUG_LOG
TESLA_602.data = {0x30, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00}; TESLA_602.data = {0x30, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00};
transmit_can_frame(&TESLA_602); transmit_can_frame(&TESLA_602);
break; break;

View file

@ -42,21 +42,6 @@ void TestFakeBattery::
//Fake that we get CAN messages //Fake that we get CAN messages
datalayer_battery->status.CAN_battery_still_alive = CAN_STILL_ALIVE; datalayer_battery->status.CAN_battery_still_alive = CAN_STILL_ALIVE;
/*Finally print out values to serial if configured to do so*/
#ifdef DEBUG_LOG
logging.println("FAKE Values going to inverter");
print_units("SOH%: ", (datalayer_battery->status.soh_pptt * 0.01), "% ");
print_units(", SOC%: ", (datalayer_battery->status.reported_soc * 0.01), "% ");
print_units(", Voltage: ", (datalayer_battery->status.voltage_dV * 0.1), "V ");
print_units(", Max discharge power: ", datalayer_battery->status.max_discharge_power_W, "W ");
print_units(", Max charge power: ", datalayer_battery->status.max_charge_power_W, "W ");
print_units(", Max temp: ", (datalayer_battery->status.temperature_max_dC * 0.1), "°C ");
print_units(", Min temp: ", (datalayer_battery->status.temperature_min_dC * 0.1), "°C ");
print_units(", Max cell voltage: ", datalayer_battery->status.cell_max_voltage_mV, "mV ");
print_units(", Min cell voltage: ", datalayer_battery->status.cell_min_voltage_mV, "mV ");
logging.println("");
#endif
} }
void TestFakeBattery::handle_incoming_can_frame(CAN_frame rx_frame) { void TestFakeBattery::handle_incoming_can_frame(CAN_frame rx_frame) {

View file

@ -85,51 +85,6 @@ void VolvoSpaBattery::
datalayer.battery.info.total_capacity_Wh = 69511; datalayer.battery.info.total_capacity_Wh = 69511;
} }
} }
#ifdef DEBUG_LOG
uint8_t cnt = 0;
logging.print("BMS reported SOC%: ");
logging.println(SOC_BMS);
logging.print("Calculated SOC%: ");
logging.println(SOC_CALC);
logging.print("Rescaled SOC%: ");
logging.println(datalayer.battery.status.reported_soc / 100);
logging.print("Battery current: ");
logging.println(BATT_I);
logging.print("Battery voltage: ");
logging.println(BATT_U);
logging.print("Battery maximum voltage limit: ");
logging.println(MAX_U);
logging.print("Battery minimum voltage limit: ");
logging.println(MIN_U);
logging.print("Discharge limit: ");
logging.println(HvBattPwrLimDchaSoft);
logging.print("Battery Error Indication: ");
logging.println(BATT_ERR_INDICATION);
logging.print("Maximum battery temperature: ");
logging.println(BATT_T_MAX / 10);
logging.print("Minimum battery temperature: ");
logging.println(BATT_T_MIN / 10);
logging.print("Average battery temperature: ");
logging.println(BATT_T_AVG / 10);
logging.print("BMS Highest cell voltage: ");
logging.println(CELL_U_MAX * 10);
logging.print("BMS Lowest cell voltage: ");
logging.println(CELL_U_MIN * 10);
logging.print("BMS Highest cell nr: ");
logging.println(CELL_ID_U_MAX);
logging.print("Highest cell voltage: ");
logging.println(min_max_voltage[1]);
logging.print("Lowest cell voltage: ");
logging.println(min_max_voltage[0]);
logging.print("Cell voltage,");
while (cnt < 108) {
logging.print(cell_voltages[cnt++]);
logging.print(",");
}
cnt = 0;
logging.println(";");
#endif
} }
void VolvoSpaBattery::handle_incoming_can_frame(CAN_frame rx_frame) { void VolvoSpaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
@ -140,9 +95,7 @@ void VolvoSpaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
BATT_I = (0 - ((((rx_frame.data.u8[6] & 0x7F) * 256.0 + rx_frame.data.u8[7]) * 0.1) - 1638)); BATT_I = (0 - ((((rx_frame.data.u8[6] & 0x7F) * 256.0 + rx_frame.data.u8[7]) * 0.1) - 1638));
else { else {
BATT_I = 0; BATT_I = 0;
#ifdef DEBUG_LOG
logging.println("BATT_I not valid"); logging.println("BATT_I not valid");
#endif
} }
if ((rx_frame.data.u8[2] & 0x08) == 0x08) if ((rx_frame.data.u8[2] & 0x08) == 0x08)
@ -195,9 +148,7 @@ void VolvoSpaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
BATT_ERR_INDICATION = ((rx_frame.data.u8[0] & 0x40) >> 6); BATT_ERR_INDICATION = ((rx_frame.data.u8[0] & 0x40) >> 6);
else { else {
BATT_ERR_INDICATION = 0; BATT_ERR_INDICATION = 0;
#ifdef DEBUG_LOG
logging.println("BATT_ERR_INDICATION not valid"); logging.println("BATT_ERR_INDICATION not valid");
#endif
} }
if ((rx_frame.data.u8[0] & 0x20) == 0x20) { if ((rx_frame.data.u8[0] & 0x20) == 0x20) {
BATT_T_MAX = ((rx_frame.data.u8[2] & 0x1F) * 256.0 + rx_frame.data.u8[3]); BATT_T_MAX = ((rx_frame.data.u8[2] & 0x1F) * 256.0 + rx_frame.data.u8[3]);
@ -207,9 +158,7 @@ void VolvoSpaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
BATT_T_MAX = 0; BATT_T_MAX = 0;
BATT_T_MIN = 0; BATT_T_MIN = 0;
BATT_T_AVG = 0; BATT_T_AVG = 0;
#ifdef DEBUG_LOG
logging.println("BATT_T not valid"); logging.println("BATT_T not valid");
#endif
} }
break; break;
case 0x369: case 0x369:
@ -217,9 +166,7 @@ void VolvoSpaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
HvBattPwrLimDchaSoft = (((rx_frame.data.u8[6] & 0x03) * 256 + rx_frame.data.u8[6]) >> 2); HvBattPwrLimDchaSoft = (((rx_frame.data.u8[6] & 0x03) * 256 + rx_frame.data.u8[6]) >> 2);
} else { } else {
HvBattPwrLimDchaSoft = 0; HvBattPwrLimDchaSoft = 0;
#ifdef DEBUG_LOG
logging.println("HvBattPwrLimDchaSoft not valid"); logging.println("HvBattPwrLimDchaSoft not valid");
#endif
} }
break; break;
case 0x175: case 0x175:
@ -246,9 +193,7 @@ void VolvoSpaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
SOC_BMS = ((rx_frame.data.u8[6] & 0x03) * 256 + rx_frame.data.u8[7]); SOC_BMS = ((rx_frame.data.u8[6] & 0x03) * 256 + rx_frame.data.u8[7]);
} else { } else {
SOC_BMS = 0; SOC_BMS = 0;
#ifdef DEBUG_LOG
logging.println("SOC_BMS not valid"); logging.println("SOC_BMS not valid");
#endif
} }
if ((rx_frame.data.u8[0] & 0x04) == 0x04) { if ((rx_frame.data.u8[0] & 0x04) == 0x04) {

View file

@ -70,51 +70,6 @@ void VolvoSpaHybridBattery::
for (int i = 0; i < 102; ++i) { for (int i = 0; i < 102; ++i) {
datalayer.battery.status.cell_voltages_mV[i] = cell_voltages[i]; datalayer.battery.status.cell_voltages_mV[i] = cell_voltages[i];
} }
#ifdef DEBUG_LOG
logging.print("BMS reported SOC%: ");
logging.println(SOC_BMS);
logging.print("Calculated SOC%: ");
logging.println(SOC_CALC);
logging.print("Rescaled SOC%: ");
logging.println(datalayer.battery.status.reported_soc / 100);
logging.print("Battery current: ");
logging.println(BATT_I);
logging.print("Battery voltage: ");
logging.println(BATT_U);
logging.print("Battery maximum voltage limit: ");
logging.println(MAX_U);
logging.print("Battery minimum voltage limit: ");
logging.println(MIN_U);
logging.print("Remaining Energy: ");
logging.println(remaining_capacity);
logging.print("Discharge limit: ");
logging.println(HvBattPwrLimDchaSoft);
logging.print("Battery Error Indication: ");
logging.println(BATT_ERR_INDICATION);
logging.print("Maximum battery temperature: ");
logging.println(BATT_T_MAX / 10);
logging.print("Minimum battery temperature: ");
logging.println(BATT_T_MIN / 10);
logging.print("Average battery temperature: ");
logging.println(BATT_T_AVG / 10);
logging.print("BMS Highest cell voltage: ");
logging.println(CELL_U_MAX);
logging.print("BMS Lowest cell voltage: ");
logging.println(CELL_U_MIN);
logging.print("BMS Highest cell nr: ");
logging.println(CELL_ID_U_MAX);
logging.print("Highest cell voltage: ");
logging.println(min_max_voltage[1]);
logging.print("Lowest cell voltage: ");
logging.println(min_max_voltage[0]);
logging.print("Cell voltage,");
while (cnt < 102) {
logging.print(cell_voltages[cnt++]);
logging.print(",");
}
logging.println(";");
#endif
} }
void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) { void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
@ -125,9 +80,7 @@ void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
BATT_I = (0 - ((((rx_frame.data.u8[6] & 0x7F) * 256.0 + rx_frame.data.u8[7]) * 0.1) - 1638)); BATT_I = (0 - ((((rx_frame.data.u8[6] & 0x7F) * 256.0 + rx_frame.data.u8[7]) * 0.1) - 1638));
else { else {
BATT_I = 0; BATT_I = 0;
#ifdef DEBUG_LOG
logging.println("BATT_I not valid"); logging.println("BATT_I not valid");
#endif
} }
if ((rx_frame.data.u8[2] & 0x08) == 0x08) if ((rx_frame.data.u8[2] & 0x08) == 0x08)
@ -148,9 +101,7 @@ void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
BATT_U = (((rx_frame.data.u8[0] & 0x07) * 256.0 + rx_frame.data.u8[1]) * 0.25); BATT_U = (((rx_frame.data.u8[0] & 0x07) * 256.0 + rx_frame.data.u8[1]) * 0.25);
else { else {
BATT_U = 0; BATT_U = 0;
#ifdef DEBUG_LOG
logging.println("BATT_U not valid"); logging.println("BATT_U not valid");
#endif
} }
if ((rx_frame.data.u8[0] & 0x40) == 0x40) if ((rx_frame.data.u8[0] & 0x40) == 0x40)
@ -185,9 +136,7 @@ void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
BATT_ERR_INDICATION = ((rx_frame.data.u8[0] & 0x40) >> 6); BATT_ERR_INDICATION = ((rx_frame.data.u8[0] & 0x40) >> 6);
else { else {
BATT_ERR_INDICATION = 0; BATT_ERR_INDICATION = 0;
#ifdef DEBUG_LOG
logging.println("BATT_ERR_INDICATION not valid"); logging.println("BATT_ERR_INDICATION not valid");
#endif
} }
if ((rx_frame.data.u8[0] & 0x20) == 0x20) { if ((rx_frame.data.u8[0] & 0x20) == 0x20) {
BATT_T_MAX = ((rx_frame.data.u8[2] & 0x1F) * 256.0 + rx_frame.data.u8[3]); BATT_T_MAX = ((rx_frame.data.u8[2] & 0x1F) * 256.0 + rx_frame.data.u8[3]);
@ -197,9 +146,7 @@ void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
BATT_T_MAX = 0; BATT_T_MAX = 0;
BATT_T_MIN = 0; BATT_T_MIN = 0;
BATT_T_AVG = 0; BATT_T_AVG = 0;
#ifdef DEBUG_LOG
logging.println("BATT_T not valid"); logging.println("BATT_T not valid");
#endif
} }
break; break;
case 0x369: case 0x369:
@ -207,9 +154,7 @@ void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
HvBattPwrLimDchaSoft = (((rx_frame.data.u8[6] & 0x03) * 256 + rx_frame.data.u8[6]) >> 2); HvBattPwrLimDchaSoft = (((rx_frame.data.u8[6] & 0x03) * 256 + rx_frame.data.u8[6]) >> 2);
} else { } else {
HvBattPwrLimDchaSoft = 0; HvBattPwrLimDchaSoft = 0;
#ifdef DEBUG_LOG
logging.println("HvBattPwrLimDchaSoft not valid"); logging.println("HvBattPwrLimDchaSoft not valid");
#endif
} }
break; break;
case 0x175: case 0x175:
@ -240,9 +185,7 @@ void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
SOC_BMS = ((rx_frame.data.u8[6] & 0x03) * 256 + rx_frame.data.u8[7]); SOC_BMS = ((rx_frame.data.u8[6] & 0x03) * 256 + rx_frame.data.u8[7]);
} else { } else {
SOC_BMS = 0; SOC_BMS = 0;
#ifdef DEBUG_LOG
logging.println("SOC_BMS not valid"); logging.println("SOC_BMS not valid");
#endif
} }
if ((rx_frame.data.u8[0] & 0x04) == 0x04) if ((rx_frame.data.u8[0] & 0x04) == 0x04)
@ -251,9 +194,7 @@ void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
else { else {
//CELL_U_MAX = 0; //CELL_U_MAX = 0;
; ;
#ifdef DEBUG_LOG
logging.println("CELL_U_MAX not valid"); logging.println("CELL_U_MAX not valid");
#endif
} }
if ((rx_frame.data.u8[0] & 0x02) == 0x02) if ((rx_frame.data.u8[0] & 0x02) == 0x02)
@ -262,9 +203,7 @@ void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
else { else {
//CELL_U_MIN = 0; //CELL_U_MIN = 0;
; ;
#ifdef DEBUG_LOG
logging.println("CELL_U_MIN not valid"); logging.println("CELL_U_MIN not valid");
#endif
} }
if ((rx_frame.data.u8[0] & 0x08) == 0x08) if ((rx_frame.data.u8[0] & 0x08) == 0x08)
@ -273,9 +212,7 @@ void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
else { else {
//CELL_ID_U_MAX = 0; //CELL_ID_U_MAX = 0;
; ;
#ifdef DEBUG_LOG
logging.println("CELL_ID_U_MAX not valid"); logging.println("CELL_ID_U_MAX not valid");
#endif
} }
break; break;
case 0x635: // Diag request response case 0x635: // Diag request response
@ -545,9 +482,7 @@ void VolvoSpaHybridBattery::transmit_can(unsigned long currentMillis) {
previousMillis60s = currentMillis; previousMillis60s = currentMillis;
if (true) { if (true) {
readCellVoltages(); readCellVoltages();
#ifdef DEBUG_LOG
logging.println("Requesting cell voltages"); logging.println("Requesting cell voltages");
#endif
} }
} }
} }

View file

@ -71,9 +71,6 @@ void ChevyVoltCharger::map_can_frame_to_variable(CAN_frame rx_frame) {
datalayer.charger.CAN_charger_still_alive = CAN_STILL_ALIVE; // Let system know charger is sending CAN datalayer.charger.CAN_charger_still_alive = CAN_STILL_ALIVE; // Let system know charger is sending CAN
break; break;
default: default:
#ifdef DEBUG_LOG
logging.printf("CAN Rcv unknown frame MsgID=%x\n", rx_frame.ID);
#endif
break; break;
} }
} }
@ -146,7 +143,6 @@ void ChevyVoltCharger::transmit_can(unsigned long currentMillis) {
transmit_can_frame(&charger_set_targets); transmit_can_frame(&charger_set_targets);
} }
#ifdef DEBUG_LOG
/* Serial echo every 5s of charger stats */ /* Serial echo every 5s of charger stats */
if (currentMillis - previousMillis5000ms >= INTERVAL_5_S) { if (currentMillis - previousMillis5000ms >= INTERVAL_5_S) {
previousMillis5000ms = currentMillis; previousMillis5000ms = currentMillis;
@ -156,5 +152,4 @@ void ChevyVoltCharger::transmit_can(unsigned long currentMillis) {
logging.printf("Charger mode=%s\n", (charger_mode > MODE_DISABLED) ? "Enabled" : "Disabled"); logging.printf("Charger mode=%s\n", (charger_mode > MODE_DISABLED) ? "Enabled" : "Disabled");
logging.printf("Charger HVset=%uV,%uA finishCurrent=%uA\n", setpoint_HV_VDC, setpoint_HV_IDC, setpoint_HV_IDC_END); logging.printf("Charger HVset=%uV,%uA finishCurrent=%uA\n", setpoint_HV_VDC, setpoint_HV_IDC, setpoint_HV_IDC_END);
} }
#endif
} }

View file

@ -99,9 +99,7 @@ bool init_CAN() {
return false; return false;
} }
#ifdef DEBUG_LOG
logging.println("Dual CAN Bus (ESP32+MCP2515) selected"); logging.println("Dual CAN Bus (ESP32+MCP2515) selected");
#endif // DEBUG_LOG
gBuffer.initWithSize(25); gBuffer.initWithSize(25);
can2515 = new ACAN2515(cs_pin, SPI2515, int_pin); can2515 = new ACAN2515(cs_pin, SPI2515, int_pin);
@ -115,14 +113,10 @@ bool init_CAN() {
settings2515->mRequestedMode = ACAN2515Settings::NormalMode; settings2515->mRequestedMode = ACAN2515Settings::NormalMode;
const uint16_t errorCode2515 = can2515->begin(*settings2515, [] { can2515->isr(); }); const uint16_t errorCode2515 = can2515->begin(*settings2515, [] { can2515->isr(); });
if (errorCode2515 == 0) { if (errorCode2515 == 0) {
#ifdef DEBUG_LOG
logging.println("Can ok"); logging.println("Can ok");
#endif // DEBUG_LOG
} else { } else {
#ifdef DEBUG_LOG
logging.print("Error Can: 0x"); logging.print("Error Can: 0x");
logging.println(errorCode2515, HEX); logging.println(errorCode2515, HEX);
#endif // DEBUG_LOG
set_event(EVENT_CANMCP2515_INIT_FAILURE, (uint8_t)errorCode2515); set_event(EVENT_CANMCP2515_INIT_FAILURE, (uint8_t)errorCode2515);
return false; return false;
} }
@ -147,9 +141,7 @@ bool init_CAN() {
canfd = new ACAN2517FD(cs_pin, SPI2517, int_pin); canfd = new ACAN2517FD(cs_pin, SPI2517, int_pin);
#ifdef DEBUG_LOG
logging.println("CAN FD add-on (ESP32+MCP2517) selected"); logging.println("CAN FD add-on (ESP32+MCP2517) selected");
#endif // DEBUG_LOG
SPI2517.begin(sck_pin, sdo_pin, sdi_pin); SPI2517.begin(sck_pin, sdo_pin, sdi_pin);
auto bitRate = (int)speed * 1000UL; auto bitRate = (int)speed * 1000UL;
settings2517 = new ACAN2517FDSettings( settings2517 = new ACAN2517FDSettings(
@ -162,7 +154,6 @@ bool init_CAN() {
const uint32_t errorCode2517 = canfd->begin(*settings2517, [] { canfd->isr(); }); const uint32_t errorCode2517 = canfd->begin(*settings2517, [] { canfd->isr(); });
canfd->poll(); canfd->poll();
if (errorCode2517 == 0) { if (errorCode2517 == 0) {
#ifdef DEBUG_LOG
logging.print("Bit Rate prescaler: "); logging.print("Bit Rate prescaler: ");
logging.println(settings2517->mBitRatePrescaler); logging.println(settings2517->mBitRatePrescaler);
logging.print("Arbitration Phase segment 1: "); logging.print("Arbitration Phase segment 1: ");
@ -179,12 +170,9 @@ bool init_CAN() {
logging.print("Arbitration Sample point: "); logging.print("Arbitration Sample point: ");
logging.print(settings2517->arbitrationSamplePointFromBitStart()); logging.print(settings2517->arbitrationSamplePointFromBitStart());
logging.println("%"); logging.println("%");
#endif // DEBUG_LOG
} else { } else {
#ifdef DEBUG_LOG
logging.print("CAN-FD Configuration error 0x"); logging.print("CAN-FD Configuration error 0x");
logging.println(errorCode2517, HEX); logging.println(errorCode2517, HEX);
#endif // DEBUG_LOG
set_event(EVENT_CANMCP2517FD_INIT_FAILURE, (uint8_t)errorCode2517); set_event(EVENT_CANMCP2517FD_INIT_FAILURE, (uint8_t)errorCode2517);
return false; return false;
} }

View file

@ -24,7 +24,6 @@ void show_dtc(uint8_t byte0, uint8_t byte1) {
} }
void handle_obd_frame(CAN_frame& rx_frame) { void handle_obd_frame(CAN_frame& rx_frame) {
#ifdef DEBUG_LOG
if (rx_frame.data.u8[1] == 0x7F) { if (rx_frame.data.u8[1] == 0x7F) {
const char* error_str = "?"; const char* error_str = "?";
switch (rx_frame.data.u8[3]) { // See https://automotive.wiki/index.php/ISO_14229 switch (rx_frame.data.u8[3]) { // See https://automotive.wiki/index.php/ISO_14229
@ -107,7 +106,6 @@ void handle_obd_frame(CAN_frame& rx_frame) {
} }
} }
dump_can_frame(rx_frame, MSG_RX); dump_can_frame(rx_frame, MSG_RX);
#endif
} }
void transmit_obd_can_frame(unsigned int address, int interface, bool canFD) { void transmit_obd_can_frame(unsigned int address, int interface, bool canFD) {

View file

@ -147,12 +147,10 @@ bool init_contactors() {
} }
static void dbg_contactors(const char* state) { static void dbg_contactors(const char* state) {
#ifdef DEBUG_LOG
logging.print("["); logging.print("[");
logging.print(millis()); logging.print(millis());
logging.print(" ms] contactors control: "); logging.print(" ms] contactors control: ");
logging.println(state); logging.println(state);
#endif
} }
// Main functions of the handle_contactors include checking if inverter allows for closing, checking battery 2, checking BMS power output, and actual contactor closing/precharge via GPIO // Main functions of the handle_contactors include checking if inverter allows for closing, checking battery 2, checking BMS power output, and actual contactor closing/precharge via GPIO

View file

@ -40,9 +40,7 @@ bool init_precharge_control() {
} }
// Setup PWM Channel Frequency and Resolution // Setup PWM Channel Frequency and Resolution
#ifdef DEBUG_LOG
logging.printf("Precharge control initialised\n"); logging.printf("Precharge control initialised\n");
#endif
auto hia4v1_pin = esp32hal->HIA4V1_PIN(); auto hia4v1_pin = esp32hal->HIA4V1_PIN();
auto inverter_disconnect_contactor_pin = esp32hal->INVERTER_DISCONNECT_CONTACTOR_PIN(); auto inverter_disconnect_contactor_pin = esp32hal->INVERTER_DISCONNECT_CONTACTOR_PIN();
@ -79,9 +77,7 @@ void handle_precharge_control(unsigned long currentMillis) {
ledcWriteTone(hia4v1_pin, freq); // Set frequency and set dutycycle to 50% ledcWriteTone(hia4v1_pin, freq); // Set frequency and set dutycycle to 50%
prechargeStartTime = currentMillis; prechargeStartTime = currentMillis;
datalayer.system.status.precharge_status = AUTO_PRECHARGE_PRECHARGING; datalayer.system.status.precharge_status = AUTO_PRECHARGE_PRECHARGING;
#ifdef DEBUG_LOG
logging.printf("Precharge: Starting sequence\n"); logging.printf("Precharge: Starting sequence\n");
#endif
digitalWrite(inverter_disconnect_contactor_pin, OFF); digitalWrite(inverter_disconnect_contactor_pin, OFF);
break; break;
@ -106,10 +102,8 @@ void handle_precharge_control(unsigned long currentMillis) {
freq = Precharge_max_PWM_Freq; freq = Precharge_max_PWM_Freq;
if (freq < Precharge_min_PWM_Freq) if (freq < Precharge_min_PWM_Freq)
freq = Precharge_min_PWM_Freq; freq = Precharge_min_PWM_Freq;
#ifdef DEBUG_LOG
logging.printf("Precharge: Target: %d V Extern: %d V Frequency: %u\n", target_voltage / 10, logging.printf("Precharge: Target: %d V Extern: %d V Frequency: %u\n", target_voltage / 10,
external_voltage / 10, freq); external_voltage / 10, freq);
#endif
ledcWriteTone(hia4v1_pin, freq); ledcWriteTone(hia4v1_pin, freq);
} }
@ -120,18 +114,14 @@ void handle_precharge_control(unsigned long currentMillis) {
digitalWrite(hia4v1_pin, LOW); digitalWrite(hia4v1_pin, LOW);
digitalWrite(inverter_disconnect_contactor_pin, ON); digitalWrite(inverter_disconnect_contactor_pin, ON);
datalayer.system.status.precharge_status = AUTO_PRECHARGE_IDLE; datalayer.system.status.precharge_status = AUTO_PRECHARGE_IDLE;
#ifdef DEBUG_LOG
logging.printf("Precharge: Disabling Precharge bms not standby/active or equipment stop\n"); logging.printf("Precharge: Disabling Precharge bms not standby/active or equipment stop\n");
#endif
} else if (currentMillis - prechargeStartTime >= MAX_PRECHARGE_TIME_MS || } else if (currentMillis - prechargeStartTime >= MAX_PRECHARGE_TIME_MS ||
datalayer.battery.status.real_bms_status == BMS_FAULT) { datalayer.battery.status.real_bms_status == BMS_FAULT) {
pinMode(hia4v1_pin, OUTPUT); pinMode(hia4v1_pin, OUTPUT);
digitalWrite(hia4v1_pin, LOW); digitalWrite(hia4v1_pin, LOW);
digitalWrite(inverter_disconnect_contactor_pin, ON); digitalWrite(inverter_disconnect_contactor_pin, ON);
datalayer.system.status.precharge_status = AUTO_PRECHARGE_OFF; datalayer.system.status.precharge_status = AUTO_PRECHARGE_OFF;
#ifdef DEBUG_LOG
logging.printf("Precharge: Disabled (timeout reached / BMS fault) -> AUTO_PRECHARGE_OFF\n"); logging.printf("Precharge: Disabled (timeout reached / BMS fault) -> AUTO_PRECHARGE_OFF\n");
#endif
set_event(EVENT_AUTOMATIC_PRECHARGE_FAILURE, 0); set_event(EVENT_AUTOMATIC_PRECHARGE_FAILURE, 0);
// Add event // Add event
@ -140,18 +130,14 @@ void handle_precharge_control(unsigned long currentMillis) {
digitalWrite(hia4v1_pin, LOW); digitalWrite(hia4v1_pin, LOW);
digitalWrite(inverter_disconnect_contactor_pin, ON); digitalWrite(inverter_disconnect_contactor_pin, ON);
datalayer.system.status.precharge_status = AUTO_PRECHARGE_COMPLETED; datalayer.system.status.precharge_status = AUTO_PRECHARGE_COMPLETED;
#ifdef DEBUG_LOG
logging.printf("Precharge: Disabled (contacts closed) -> COMPLETED\n"); logging.printf("Precharge: Disabled (contacts closed) -> COMPLETED\n");
#endif
} }
break; break;
case AUTO_PRECHARGE_COMPLETED: case AUTO_PRECHARGE_COMPLETED:
if (datalayer.system.settings.equipment_stop_active || datalayer.battery.status.bms_status != ACTIVE) { if (datalayer.system.settings.equipment_stop_active || datalayer.battery.status.bms_status != ACTIVE) {
datalayer.system.status.precharge_status = AUTO_PRECHARGE_IDLE; datalayer.system.status.precharge_status = AUTO_PRECHARGE_IDLE;
#ifdef DEBUG_LOG
logging.printf("Precharge: equipment stop activated -> IDLE\n"); logging.printf("Precharge: equipment stop activated -> IDLE\n");
#endif
} }
break; break;
@ -162,9 +148,7 @@ void handle_precharge_control(unsigned long currentMillis) {
datalayer.system.status.precharge_status = AUTO_PRECHARGE_IDLE; datalayer.system.status.precharge_status = AUTO_PRECHARGE_IDLE;
pinMode(hia4v1_pin, OUTPUT); pinMode(hia4v1_pin, OUTPUT);
digitalWrite(hia4v1_pin, LOW); digitalWrite(hia4v1_pin, LOW);
#ifdef DEBUG_LOG
logging.printf("Precharge: equipment stop activated -> IDLE\n"); logging.printf("Precharge: equipment stop activated -> IDLE\n");
#endif
} }
break; break;

View file

@ -319,9 +319,7 @@ static bool publish_common_info(void) {
serializeJson(doc, mqtt_msg); serializeJson(doc, mqtt_msg);
if (mqtt_publish(state_topic.c_str(), mqtt_msg, false) == false) { if (mqtt_publish(state_topic.c_str(), mqtt_msg, false) == false) {
#ifdef DEBUG_LOG
logging.println("Common info MQTT msg could not be sent"); logging.println("Common info MQTT msg could not be sent");
#endif // DEBUG_LOG
return false; return false;
} }
doc.clear(); doc.clear();
@ -392,9 +390,7 @@ static bool publish_cell_voltages(void) {
serializeJson(doc, mqtt_msg, sizeof(mqtt_msg)); serializeJson(doc, mqtt_msg, sizeof(mqtt_msg));
if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) { if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) {
#ifdef DEBUG_LOG
logging.println("Cell voltage MQTT msg could not be sent"); logging.println("Cell voltage MQTT msg could not be sent");
#endif // DEBUG_LOG
return false; return false;
} }
doc.clear(); doc.clear();
@ -413,9 +409,7 @@ static bool publish_cell_voltages(void) {
serializeJson(doc, mqtt_msg, sizeof(mqtt_msg)); serializeJson(doc, mqtt_msg, sizeof(mqtt_msg));
if (!mqtt_publish(state_topic_2.c_str(), mqtt_msg, false)) { if (!mqtt_publish(state_topic_2.c_str(), mqtt_msg, false)) {
#ifdef DEBUG_LOG
logging.println("Cell voltage MQTT msg could not be sent"); logging.println("Cell voltage MQTT msg could not be sent");
#endif // DEBUG_LOG
return false; return false;
} }
doc.clear(); doc.clear();
@ -440,9 +434,7 @@ static bool publish_cell_balancing(void) {
serializeJson(doc, mqtt_msg, sizeof(mqtt_msg)); serializeJson(doc, mqtt_msg, sizeof(mqtt_msg));
if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) { if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) {
#ifdef DEBUG_LOG
logging.println("Cell balancing MQTT msg could not be sent"); logging.println("Cell balancing MQTT msg could not be sent");
#endif // DEBUG_LOG
return false; return false;
} }
doc.clear(); doc.clear();
@ -460,9 +452,7 @@ static bool publish_cell_balancing(void) {
serializeJson(doc, mqtt_msg, sizeof(mqtt_msg)); serializeJson(doc, mqtt_msg, sizeof(mqtt_msg));
if (!mqtt_publish(state_topic_2.c_str(), mqtt_msg, false)) { if (!mqtt_publish(state_topic_2.c_str(), mqtt_msg, false)) {
#ifdef DEBUG_LOG
logging.println("Cell balancing MQTT msg could not be sent"); logging.println("Cell balancing MQTT msg could not be sent");
#endif // DEBUG_LOG
return false; return false;
} }
doc.clear(); doc.clear();
@ -523,9 +513,7 @@ bool publish_events() {
serializeJson(doc, mqtt_msg); serializeJson(doc, mqtt_msg);
if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) { if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) {
#ifdef DEBUG_LOG
logging.println("Common info MQTT msg could not be sent"); logging.println("Common info MQTT msg could not be sent");
#endif // DEBUG_LOG
return false; return false;
} else { } else {
set_event_MQTTpublished(event_handle); set_event_MQTTpublished(event_handle);
@ -541,9 +529,7 @@ bool publish_events() {
static bool publish_buttons_discovery(void) { static bool publish_buttons_discovery(void) {
if (ha_autodiscovery_enabled) { if (ha_autodiscovery_enabled) {
if (ha_buttons_published == false) { if (ha_buttons_published == false) {
#ifdef DEBUG_LOG
logging.println("Publishing buttons discovery"); logging.println("Publishing buttons discovery");
#endif // DEBUG_LOG
static JsonDocument doc; static JsonDocument doc;
for (int i = 0; i < sizeof(buttonConfigs) / sizeof(buttonConfigs[0]); i++) { for (int i = 0; i < sizeof(buttonConfigs) / sizeof(buttonConfigs[0]); i++) {
@ -573,16 +559,12 @@ void mqtt_message_received(char* topic_raw, int topic_len, char* data, int data_
char* topic = strndup(topic_raw, topic_len); char* topic = strndup(topic_raw, topic_len);
#ifdef DEBUG_LOG
logging.printf("MQTT message arrived: [%.*s]\n", topic_len, topic); logging.printf("MQTT message arrived: [%.*s]\n", topic_len, topic);
#endif // DEBUG_LOG
#ifdef REMOTE_BMS_RESET #ifdef REMOTE_BMS_RESET
const char* bmsreset_topic = generateButtonTopic("BMSRESET").c_str(); const char* bmsreset_topic = generateButtonTopic("BMSRESET").c_str();
if (strcmp(topic, bmsreset_topic) == 0) { if (strcmp(topic, bmsreset_topic) == 0) {
#ifdef DEBUG_LOG
logging.println("Triggering BMS reset"); logging.println("Triggering BMS reset");
#endif // DEBUG_LOG
start_bms_reset(); start_bms_reset();
} }
#endif // REMOTE_BMS_RESET #endif // REMOTE_BMS_RESET
@ -616,21 +598,16 @@ static void mqtt_event_handler(void* handler_args, esp_event_base_t base, int32_
publish_buttons_discovery(); publish_buttons_discovery();
subscribe(); subscribe();
#ifdef DEBUG_LOG
logging.println("MQTT connected"); logging.println("MQTT connected");
#endif // DEBUG_LOG
break; break;
case MQTT_EVENT_DISCONNECTED: case MQTT_EVENT_DISCONNECTED:
set_event(EVENT_MQTT_DISCONNECT, 0); set_event(EVENT_MQTT_DISCONNECT, 0);
#ifdef DEBUG_LOG
logging.println("MQTT disconnected!"); logging.println("MQTT disconnected!");
#endif // DEBUG_LOG
break; break;
case MQTT_EVENT_DATA: case MQTT_EVENT_DATA:
mqtt_message_received(event->topic, event->topic_len, event->data, event->data_len); mqtt_message_received(event->topic, event->topic_len, event->data, event->data_len);
break; break;
case MQTT_EVENT_ERROR: case MQTT_EVENT_ERROR:
#ifdef DEBUG_LOG
logging.println("MQTT_ERROR"); logging.println("MQTT_ERROR");
logging.print("reported from esp-tls"); logging.print("reported from esp-tls");
logging.println(event->error_handle->esp_tls_last_esp_err); logging.println(event->error_handle->esp_tls_last_esp_err);
@ -638,7 +615,6 @@ static void mqtt_event_handler(void* handler_args, esp_event_base_t base, int32_
logging.println(event->error_handle->esp_tls_stack_err); logging.println(event->error_handle->esp_tls_stack_err);
logging.print("captured as transport's socket errno"); logging.print("captured as transport's socket errno");
logging.println(strerror(event->error_handle->esp_transport_sock_errno)); logging.println(strerror(event->error_handle->esp_transport_sock_errno));
#endif // DEBUG_LOG
break; break;
} }
} }
@ -723,9 +699,7 @@ void mqtt_loop(void) {
if (client_started == false) { if (client_started == false) {
esp_mqtt_client_start(client); esp_mqtt_client_start(client);
client_started = true; client_started = true;
#ifdef DEBUG_LOG
logging.println("MQTT initialized"); logging.println("MQTT initialized");
#endif // DEBUG_LOG
return; return;
} }

View file

@ -164,9 +164,7 @@ void init_logging_buffers() {
#if defined(LOG_CAN_TO_SD) #if defined(LOG_CAN_TO_SD)
can_bufferHandle = xRingbufferCreate(32 * 1024, RINGBUF_TYPE_BYTEBUF); can_bufferHandle = xRingbufferCreate(32 * 1024, RINGBUF_TYPE_BYTEBUF);
if (can_bufferHandle == NULL) { if (can_bufferHandle == NULL) {
#ifdef DEBUG_LOG
logging.println("Failed to create CAN ring buffer!"); logging.println("Failed to create CAN ring buffer!");
#endif // DEBUG_LOG
return; return;
} }
#endif // defined(LOG_CAN_TO_SD) #endif // defined(LOG_CAN_TO_SD)
@ -174,9 +172,7 @@ void init_logging_buffers() {
#if defined(LOG_TO_SD) #if defined(LOG_TO_SD)
log_bufferHandle = xRingbufferCreate(1024, RINGBUF_TYPE_BYTEBUF); log_bufferHandle = xRingbufferCreate(1024, RINGBUF_TYPE_BYTEBUF);
if (log_bufferHandle == NULL) { if (log_bufferHandle == NULL) {
#ifdef DEBUG_LOG
logging.println("Failed to create log ring buffer!"); logging.println("Failed to create log ring buffer!");
#endif // DEBUG_LOG
return; return;
} }
#endif // defined(LOG_TO_SD) #endif // defined(LOG_TO_SD)
@ -196,22 +192,16 @@ bool init_sdcard() {
SD_MMC.setPins(sclk_pin, mosi_pin, miso_pin); SD_MMC.setPins(sclk_pin, mosi_pin, miso_pin);
if (!SD_MMC.begin("/root", true, true, SDMMC_FREQ_HIGHSPEED)) { if (!SD_MMC.begin("/root", true, true, SDMMC_FREQ_HIGHSPEED)) {
set_event_latched(EVENT_SD_INIT_FAILED, 0); set_event_latched(EVENT_SD_INIT_FAILED, 0);
#ifdef DEBUG_LOG
logging.println("SD Card initialization failed!"); logging.println("SD Card initialization failed!");
#endif // DEBUG_LOG
return false; return false;
} }
clear_event(EVENT_SD_INIT_FAILED); clear_event(EVENT_SD_INIT_FAILED);
#ifdef DEBUG_LOG
logging.println("SD Card initialization successful."); logging.println("SD Card initialization successful.");
#endif // DEBUG_LOG
sd_card_active = true; sd_card_active = true;
#ifdef DEBUG_LOG
log_sdcard_details(); log_sdcard_details();
#endif // DEBUG_LOG
return true; return true;
} }

View file

@ -159,9 +159,7 @@ void reset_all_events() {
} }
events.level = EVENT_LEVEL_INFO; events.level = EVENT_LEVEL_INFO;
update_bms_status(); update_bms_status();
#ifdef DEBUG_LOG
logging.println("All events have been cleared."); logging.println("All events have been cleared.");
#endif
} }
void set_event_MQTTpublished(EVENTS_ENUM_TYPE event) { void set_event_MQTTpublished(EVENTS_ENUM_TYPE event) {

View file

@ -46,12 +46,6 @@ String events_processor(const String& var) {
EVENTS_ENUM_TYPE event_handle = event.event_handle; EVENTS_ENUM_TYPE event_handle = event.event_handle;
event_pointer = event.event_pointer; event_pointer = event.event_pointer;
#ifdef DEBUG_LOG
logging.println("Showing Event: " + String(get_event_enum_string(event_handle)) +
" count: " + String(event_pointer->occurences) + " seconds: " + String(event_pointer->timestamp) +
" data: " + String(event_pointer->data) +
" level: " + String(get_event_level_string(event_handle)));
#endif
content.concat("<div class='event'>"); content.concat("<div class='event'>");
content.concat("<div>" + String(get_event_enum_string(event_handle)) + "</div>"); content.concat("<div>" + String(get_event_enum_string(event_handle)) + "</div>");
content.concat("<div>" + String(get_event_level_string(event_handle)) + "</div>"); content.concat("<div>" + String(get_event_level_string(event_handle)) + "</div>");

View file

@ -1470,9 +1470,7 @@ void onOTAProgress(size_t current, size_t final) {
// Log every 1 second // Log every 1 second
if (millis() - ota_progress_millis > 1000) { if (millis() - ota_progress_millis > 1000) {
ota_progress_millis = millis(); ota_progress_millis = millis();
#ifdef DEBUG_LOG
logging.printf("OTA Progress Current: %u bytes, Final: %u bytes\n", current, final); logging.printf("OTA Progress Current: %u bytes, Final: %u bytes\n", current, final);
#endif // DEBUG_LOG
// Reset the "watchdog" // Reset the "watchdog"
ota_timeout_timer.reset(); ota_timeout_timer.reset();
} }
@ -1489,13 +1487,9 @@ void onOTAEnd(bool success) {
// Max Charge/Discharge = 0; CAN = stop; contactors = open // Max Charge/Discharge = 0; CAN = stop; contactors = open
setBatteryPause(true, true, true, false); setBatteryPause(true, true, true, false);
// a reboot will be done by the OTA library. no need to do anything here // a reboot will be done by the OTA library. no need to do anything here
#ifdef DEBUG_LOG
logging.println("OTA update finished successfully!"); logging.println("OTA update finished successfully!");
#endif // DEBUG_LOG
} else { } else {
#ifdef DEBUG_LOG
logging.println("There was an error during OTA update!"); logging.println("There was an error during OTA update!");
#endif // DEBUG_LOG
//try to Resume the battery pause and CAN communication //try to Resume the battery pause and CAN communication
setBatteryPause(false, false); setBatteryPause(false, false);
} }

View file

@ -130,33 +130,22 @@ void wifi_monitor() {
// Try WiFi.reconnect() if it was successfully connected at least once // Try WiFi.reconnect() if it was successfully connected at least once
if (hasConnectedBefore) { if (hasConnectedBefore) {
lastReconnectAttempt = currentMillis; // Reset reconnection attempt timer lastReconnectAttempt = currentMillis; // Reset reconnection attempt timer
#ifdef DEBUG_LOG
logging.println("Wi-Fi reconnect attempt..."); logging.println("Wi-Fi reconnect attempt...");
#endif
if (WiFi.reconnect()) { if (WiFi.reconnect()) {
#ifdef DEBUG_LOG
logging.println("Wi-Fi reconnect attempt sucess..."); logging.println("Wi-Fi reconnect attempt sucess...");
#endif
reconnectAttempts = 0; // Reset the attempt counter on successful reconnect reconnectAttempts = 0; // Reset the attempt counter on successful reconnect
} else { } else {
#ifdef DEBUG_LOG
logging.println("Wi-Fi reconnect attempt error..."); logging.println("Wi-Fi reconnect attempt error...");
#endif
reconnectAttempts++; reconnectAttempts++;
if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) { if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
#ifdef DEBUG_LOG
logging.println("Failed to reconnect multiple times, forcing a full connection attempt..."); logging.println("Failed to reconnect multiple times, forcing a full connection attempt...");
#endif
FullReconnectToWiFi(); FullReconnectToWiFi();
} }
} }
} else { } else {
// If no previous connection, force a full connection attempt // If no previous connection, force a full connection attempt
if (currentMillis - lastReconnectAttempt > current_full_reconnect_interval) { if (currentMillis - lastReconnectAttempt > current_full_reconnect_interval) {
#ifdef DEBUG_LOG
logging.println("No previous OK connection, force a full connection attempt..."); logging.println("No previous OK connection, force a full connection attempt...");
#endif
wifiap_enabled = true; wifiap_enabled = true;
WiFi.mode(WIFI_AP_STA); WiFi.mode(WIFI_AP_STA);
init_WiFi_AP(); init_WiFi_AP();
@ -188,17 +177,13 @@ void connectToWiFi() {
if (WiFi.status() != WL_CONNECTED) { if (WiFi.status() != WL_CONNECTED) {
lastReconnectAttempt = millis(); // Reset the reconnect attempt timer lastReconnectAttempt = millis(); // Reset the reconnect attempt timer
#ifdef DEBUG_LOG
logging.println("Connecting to Wi-Fi..."); logging.println("Connecting to Wi-Fi...");
#endif
DEBUG_PRINTF("Connecting to Wi-Fi SSID: %s, password: %s, Channel: %d\n", ssid.c_str(), password.c_str(), DEBUG_PRINTF("Connecting to Wi-Fi SSID: %s, password: %s, Channel: %d\n", ssid.c_str(), password.c_str(),
wifi_channel); wifi_channel);
WiFi.begin(ssid.c_str(), password.c_str(), wifi_channel); WiFi.begin(ssid.c_str(), password.c_str(), wifi_channel);
} else { } else {
#ifdef DEBUG_LOG
logging.println("Wi-Fi already connected."); logging.println("Wi-Fi already connected.");
#endif
} }
} }
@ -220,11 +205,9 @@ void onWifiConnect(WiFiEvent_t event, WiFiEventInfo_t info) {
void onWifiGotIP(WiFiEvent_t event, WiFiEventInfo_t info) { void onWifiGotIP(WiFiEvent_t event, WiFiEventInfo_t info) {
//clear disconnects events if we got a IP //clear disconnects events if we got a IP
clear_event(EVENT_WIFI_DISCONNECT); clear_event(EVENT_WIFI_DISCONNECT);
#ifdef DEBUG_LOG
logging.print("Wi-Fi Got IP. "); logging.print("Wi-Fi Got IP. ");
logging.print("IP address: "); logging.print("IP address: ");
logging.println(WiFi.localIP().toString()); logging.println(WiFi.localIP().toString());
#endif
} }
// Event handler for Wi-Fi disconnection // Event handler for Wi-Fi disconnection
@ -233,9 +216,7 @@ void onWifiDisconnect(WiFiEvent_t event, WiFiEventInfo_t info) {
if (connected_once) { if (connected_once) {
set_event(EVENT_WIFI_DISCONNECT, 0); set_event(EVENT_WIFI_DISCONNECT, 0);
} }
#ifdef DEBUG_LOG
logging.println("Wi-Fi disconnected."); logging.println("Wi-Fi disconnected.");
#endif
//we dont do anything here, the reconnect will be handled by the monitor //we dont do anything here, the reconnect will be handled by the monitor
//too many events received when the connection is lost //too many events received when the connection is lost
//normal reconnect retry start at first 2 seconds //normal reconnect retry start at first 2 seconds
@ -254,9 +235,7 @@ void init_mDNS() {
// Initialize mDNS .local resolution // Initialize mDNS .local resolution
if (!MDNS.begin(mdnsHost)) { if (!MDNS.begin(mdnsHost)) {
#ifdef DEBUG_LOG
logging.println("Error setting up MDNS responder!"); logging.println("Error setting up MDNS responder!");
#endif
} else { } else {
// Advertise via bonjour the service so we can auto discover these battery emulators on the local network. // Advertise via bonjour the service so we can auto discover these battery emulators on the local network.
MDNS.addService(mdnsHost, "tcp", 80); MDNS.addService(mdnsHost, "tcp", 80);

View file

@ -523,40 +523,23 @@ void FoxessCanInverter::map_can_frame_to_variable(CAN_frame rx_frame) {
if (rx_frame.ID == 0x1871) { if (rx_frame.ID == 0x1871) {
datalayer.system.status.CAN_inverter_still_alive = CAN_STILL_ALIVE; datalayer.system.status.CAN_inverter_still_alive = CAN_STILL_ALIVE;
if (rx_frame.data.u8[0] == 0x03) { //0x1871 [0x03, 0x06, 0x17, 0x05, 0x09, 0x09, 0x28, 0x22] if (rx_frame.data.u8[0] == 0x03) { //0x1871 [0x03, 0x06, 0x17, 0x05, 0x09, 0x09, 0x28, 0x22]
//This message is sent by the inverter every '6' seconds (0.5s after the pack serial numbers) //This message is sent by the inverter every '6' seconds (0.5s after the pack serial numbers)
//and contains a timestamp in bytes 2-7 i.e. <YY>,<MM>,<DD>,<HH>,<mm>,<ss> //and contains a timestamp in bytes 2-7 i.e. <YY>,<MM>,<DD>,<HH>,<mm>,<ss>
#ifdef DEBUG_LOG
logging.println("Inverter sends current time and date");
#endif
} else if (rx_frame.data.u8[0] == 0x01) { } else if (rx_frame.data.u8[0] == 0x01) {
if (rx_frame.data.u8[4] == 0x00) { if (rx_frame.data.u8[4] == 0x00) {
// Inverter wants to know bms info (every 1s) // Inverter wants to know bms info (every 1s)
#ifdef DEBUG_LOG
logging.println("Inverter requests 1s BMS info, we reply");
#endif
send_bms_info = true; send_bms_info = true;
} else if (rx_frame.data.u8[4] == 0x01) { // b4 0x01 , 0x1871 [0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00] } else if (rx_frame.data.u8[4] == 0x01) { // b4 0x01 , 0x1871 [0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00]
//Inverter wants to know all individual cellvoltages (occurs 6 seconds after valid BMS reply) //Inverter wants to know all individual cellvoltages (occurs 6 seconds after valid BMS reply)
#ifdef DEBUG_LOG
logging.println("Inverter requests individual battery pack status, we reply");
#endif
send_individual_pack_status = true; send_individual_pack_status = true;
} else if (rx_frame.data.u8[4] == 0x04) { // b4 0x01 , 0x1871 [0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00] } else if (rx_frame.data.u8[4] == 0x04) { // b4 0x01 , 0x1871 [0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00]
//Inverter wants to know all individual cellvoltages (occurs 6 seconds after valid BMS reply) //Inverter wants to know all individual cellvoltages (occurs 6 seconds after valid BMS reply)
#ifdef DEBUG_LOG
logging.println("Inverter requests cellvoltages and temps, we reply");
#endif
send_cellvoltages = true; send_cellvoltages = true;
} }
} else if (rx_frame.data.u8[0] == 0x02) { //0x1871 [0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00] } else if (rx_frame.data.u8[0] == 0x02) { //0x1871 [0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00]
// Ack message // Ack message
#ifdef DEBUG_LOG
logging.println("Inverter acks, no reply needed");
#endif
} else if (rx_frame.data.u8[0] == 0x05) { //0x1871 [0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00] } else if (rx_frame.data.u8[0] == 0x05) { //0x1871 [0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
#ifdef DEBUG_LOG // Inverter wants to know serial numbers, we reply
logging.println("Inverter wants to know serial numbers, we reply");
#endif
send_serial_numbers = true; send_serial_numbers = true;
} }
} }

View file

@ -35,9 +35,7 @@ ModbusMessage ModbusInverterProtocol::FC03(ModbusMessage request) {
if ((addr + words) > MBPV_MAX) { if ((addr + words) > MBPV_MAX) {
// Yes - send respective error response // Yes - send respective error response
response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_DATA_ADDRESS); response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_DATA_ADDRESS);
#ifdef DEBUG_LOG
logging.printf("Modbus FC03 error: illegal request addr=%d words=%d\n", addr, words); logging.printf("Modbus FC03 error: illegal request addr=%d words=%d\n", addr, words);
#endif
return response; return response;
} }
@ -48,10 +46,6 @@ ModbusMessage ModbusInverterProtocol::FC03(ModbusMessage request) {
response.add((uint16_t)(mbPV[addr + i])); response.add((uint16_t)(mbPV[addr + i]));
} }
// #ifdef DEBUG_LOG
// logging.printf("Modbus FC03 response: %d %d\n", addr, mbPV[addr]);
// #endif
return response; return response;
} }
@ -67,9 +61,7 @@ ModbusMessage ModbusInverterProtocol::FC06(ModbusMessage request) {
if ((addr) > MBPV_MAX) { if ((addr) > MBPV_MAX) {
// Yes - send respective error response // Yes - send respective error response
response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_DATA_ADDRESS); response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_DATA_ADDRESS);
#ifdef DEBUG_LOG
logging.printf("Modbus FC06 error: illegal request addr=%d val=%d\n", addr, val); logging.printf("Modbus FC06 error: illegal request addr=%d val=%d\n", addr, val);
#endif
return response; return response;
} }
@ -97,18 +89,14 @@ ModbusMessage ModbusInverterProtocol::FC16(ModbusMessage request) {
|| (words > 123)) // can't support more than this in request packet || (words > 123)) // can't support more than this in request packet
{ // Yes - send respective error response { // Yes - send respective error response
response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_DATA_VALUE); response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_DATA_VALUE);
#ifdef DEBUG_LOG
logging.printf("Modbus FC16 error: bad registers addr=%d words=%d bytes=%d\n", addr, words, bytes); logging.printf("Modbus FC16 error: bad registers addr=%d words=%d bytes=%d\n", addr, words, bytes);
#endif
return response; return response;
} }
// Address overflow? // Address overflow?
if ((addr + words) > MBPV_MAX) { if ((addr + words) > MBPV_MAX) {
// Yes - send respective error response // Yes - send respective error response
response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_DATA_ADDRESS); response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_DATA_ADDRESS);
#ifdef DEBUG_LOG
logging.printf("Modbus FC16 error: overflow addr=%d words=%d\n", addr, words); logging.printf("Modbus FC16 error: overflow addr=%d words=%d\n", addr, words);
#endif
return response; return response;
} }
@ -145,20 +133,16 @@ ModbusMessage ModbusInverterProtocol::FC23(ModbusMessage request) {
|| (read_words > 125)) // can't fit more than this in the response packet || (read_words > 125)) // can't fit more than this in the response packet
{ // Yes - send respective error response { // Yes - send respective error response
response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_DATA_VALUE); response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_DATA_VALUE);
#ifdef DEBUG_LOG
logging.printf("Modbus FC23 error: bad registers write_addr=%d write_words=%d write_bytes=%d read_words=%d\n", logging.printf("Modbus FC23 error: bad registers write_addr=%d write_words=%d write_bytes=%d read_words=%d\n",
write_addr, write_words, write_bytes, read_words); write_addr, write_words, write_bytes, read_words);
#endif
return response; return response;
} }
// Address overflow? // Address overflow?
if (((write_addr + write_words) > MBPV_MAX) || if (((write_addr + write_words) > MBPV_MAX) ||
((read_addr + read_words) > MBPV_MAX)) { // Yes - send respective error response ((read_addr + read_words) > MBPV_MAX)) { // Yes - send respective error response
response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_DATA_ADDRESS); response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_DATA_ADDRESS);
#ifdef DEBUG_LOG
logging.printf("Modbus FC23 error: overflow write_addr=%d write_words=%d read_addr=%d read_words=%d\n", write_addr, logging.printf("Modbus FC23 error: overflow write_addr=%d write_words=%d read_addr=%d read_words=%d\n", write_addr,
write_words, read_addr, read_words); write_words, read_addr, read_words);
#endif
return response; return response;
} }

View file

@ -227,9 +227,7 @@ void SmaBydHInverter::map_can_frame_to_variable(CAN_frame rx_frame) {
break; break;
case 0x5E7: //Message originating from SMA inverter - Pairing request case 0x5E7: //Message originating from SMA inverter - Pairing request
case 0x660: //Message originating from SMA inverter - Pairing request case 0x660: //Message originating from SMA inverter - Pairing request
#ifdef DEBUG_LOG
logging.println("Received SMA pairing request"); logging.println("Received SMA pairing request");
#endif // DEBUG_LOG
pairing_events++; pairing_events++;
set_event(EVENT_SMA_PAIRING, pairing_events); set_event(EVENT_SMA_PAIRING, pairing_events);
datalayer.system.status.CAN_inverter_still_alive = CAN_STILL_ALIVE; datalayer.system.status.CAN_inverter_still_alive = CAN_STILL_ALIVE;

View file

@ -218,9 +218,7 @@ void SmaBydHvsInverter::map_can_frame_to_variable(CAN_frame rx_frame) {
break; break;
case 0x5E7: //Message originating from SMA inverter - Pairing request case 0x5E7: //Message originating from SMA inverter - Pairing request
case 0x660: //Message originating from SMA inverter - Pairing request case 0x660: //Message originating from SMA inverter - Pairing request
#ifdef DEBUG_LOG
logging.println("Received SMA pairing request"); logging.println("Received SMA pairing request");
#endif // DEBUG_LOG
pairing_events++; pairing_events++;
set_event(EVENT_SMA_PAIRING, pairing_events); set_event(EVENT_SMA_PAIRING, pairing_events);
datalayer.system.status.CAN_inverter_still_alive = CAN_STILL_ALIVE; datalayer.system.status.CAN_inverter_still_alive = CAN_STILL_ALIVE;

View file

@ -126,9 +126,7 @@ void SmaTripowerInverter::map_can_frame_to_variable(CAN_frame rx_frame) {
break; break;
case 0x5E7: //Message originating from SMA inverter - Pairing request case 0x5E7: //Message originating from SMA inverter - Pairing request
case 0x660: //Message originating from SMA inverter - Pairing request case 0x660: //Message originating from SMA inverter - Pairing request
#ifdef DEBUG_LOG
logging.println("Received SMA pairing request"); logging.println("Received SMA pairing request");
#endif // DEBUG_LOG
pairing_events++; pairing_events++;
set_event(EVENT_SMA_PAIRING, pairing_events); set_event(EVENT_SMA_PAIRING, pairing_events);
datalayer.system.status.CAN_inverter_still_alive = CAN_STILL_ALIVE; datalayer.system.status.CAN_inverter_still_alive = CAN_STILL_ALIVE;

View file

@ -147,9 +147,7 @@ void SolaxInverter::map_can_frame_to_variable(CAN_frame rx_frame) {
switch (STATE) { switch (STATE) {
case (BATTERY_ANNOUNCE): case (BATTERY_ANNOUNCE):
#ifdef DEBUG_LOG
logging.println("Solax Battery State: Announce"); logging.println("Solax Battery State: Announce");
#endif
datalayer.system.status.inverter_allows_contactor_closing = false; datalayer.system.status.inverter_allows_contactor_closing = false;
SOLAX_1875.data.u8[4] = (0x00); // Inform Inverter: Contactor 0=off, 1=on. SOLAX_1875.data.u8[4] = (0x00); // Inform Inverter: Contactor 0=off, 1=on.
for (uint8_t i = 0; i < number_of_batteries; i++) { for (uint8_t i = 0; i < number_of_batteries; i++) {
@ -183,9 +181,7 @@ void SolaxInverter::map_can_frame_to_variable(CAN_frame rx_frame) {
transmit_can_frame(&SOLAX_1878); transmit_can_frame(&SOLAX_1878);
transmit_can_frame(&SOLAX_1801); // Announce that the battery will be connected transmit_can_frame(&SOLAX_1801); // Announce that the battery will be connected
STATE = CONTACTOR_CLOSED; // Jump to Contactor Closed State STATE = CONTACTOR_CLOSED; // Jump to Contactor Closed State
#ifdef DEBUG_LOG
logging.println("Solax Battery State: Contactor Closed"); logging.println("Solax Battery State: Contactor Closed");
#endif
break; break;
case (CONTACTOR_CLOSED): case (CONTACTOR_CLOSED):
@ -213,14 +209,10 @@ void SolaxInverter::map_can_frame_to_variable(CAN_frame rx_frame) {
if (rx_frame.ID == 0x1871 && rx_frame.data.u64 == __builtin_bswap64(0x0500010000000000)) { if (rx_frame.ID == 0x1871 && rx_frame.data.u64 == __builtin_bswap64(0x0500010000000000)) {
transmit_can_frame(&SOLAX_1881); transmit_can_frame(&SOLAX_1881);
transmit_can_frame(&SOLAX_1882); transmit_can_frame(&SOLAX_1882);
#ifdef DEBUG_LOG
logging.println("1871 05-frame received from inverter"); logging.println("1871 05-frame received from inverter");
#endif
} }
if (rx_frame.ID == 0x1871 && rx_frame.data.u8[0] == (0x03)) { if (rx_frame.ID == 0x1871 && rx_frame.data.u8[0] == (0x03)) {
#ifdef DEBUG_LOG
logging.println("1871 03-frame received from inverter"); logging.println("1871 03-frame received from inverter");
#endif
} }
} }