From a1e5bc57d04d6dd553aa4c4fb23137b6d6d80360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Fri, 29 Aug 2025 23:16:36 +0300 Subject: [PATCH] Remove ifdef from logging --- Software/src/battery/BMW-IX-BATTERY.cpp | 40 +--------- Software/src/battery/BMW-PHEV-BATTERY.cpp | 22 +----- Software/src/battery/CHADEMO-BATTERY.cpp | 76 ++----------------- .../src/battery/IMIEV-CZERO-ION-BATTERY.cpp | 12 --- Software/src/battery/JAGUAR-IPACE-BATTERY.cpp | 15 ---- Software/src/battery/KIA-E-GMP-BATTERY.cpp | 4 - Software/src/battery/MEB-BATTERY.cpp | 22 ------ Software/src/battery/MG-HS-PHEV-BATTERY.cpp | 6 -- .../src/battery/RENAULT-KANGOO-BATTERY.cpp | 33 -------- Software/src/battery/TESLA-BATTERY.cpp | 29 ------- Software/src/battery/TEST-FAKE-BATTERY.cpp | 15 ---- Software/src/battery/VOLVO-SPA-BATTERY.cpp | 55 -------------- .../src/battery/VOLVO-SPA-HYBRID-BATTERY.cpp | 65 ---------------- Software/src/charger/CHEVY-VOLT-CHARGER.cpp | 5 -- Software/src/communication/can/comm_can.cpp | 12 --- Software/src/communication/can/obd.cpp | 2 - .../comm_contactorcontrol.cpp | 2 - .../precharge_control/precharge_control.cpp | 16 ---- Software/src/devboard/mqtt/mqtt.cpp | 26 ------- Software/src/devboard/sdcard/sdcard.cpp | 10 --- Software/src/devboard/utils/events.cpp | 2 - .../src/devboard/webserver/events_html.cpp | 6 -- Software/src/devboard/webserver/webserver.cpp | 6 -- Software/src/devboard/wifi/wifi.cpp | 21 ----- Software/src/inverter/FOXESS-CAN.cpp | 27 ++----- .../src/inverter/ModbusInverterProtocol.cpp | 16 ---- Software/src/inverter/SMA-BYD-H-CAN.cpp | 2 - Software/src/inverter/SMA-BYD-HVS-CAN.cpp | 2 - Software/src/inverter/SMA-TRIPOWER-CAN.cpp | 2 - Software/src/inverter/SOLAX-CAN.cpp | 8 -- 30 files changed, 14 insertions(+), 545 deletions(-) diff --git a/Software/src/battery/BMW-IX-BATTERY.cpp b/Software/src/battery/BMW-IX-BATTERY.cpp index d7117ed0..be16b640 100644 --- a/Software/src/battery/BMW-IX-BATTERY.cpp +++ b/Software/src/battery/BMW-IX-BATTERY.cpp @@ -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 || (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"); -#endif // DEBUG_LOG //set_event(EVENT_BATTERY_VALUE_UNAVAILABLE, (millis())); //Eventually need new Info level event type transmit_can_frame(&BMWiX_6F4_REQUEST_HARD_RESET); } 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 if (ContactorCloseRequest.previous == false && ContactorCloseRequest.present == true) { // Rising edge detected -#ifdef DEBUG_LOG logging.println("Rising edge detected. Resetting 10ms counter."); -#endif // DEBUG_LOG counter_10ms = 0; // reset counter } else if (ContactorCloseRequest.previous == true && ContactorCloseRequest.present == false) { // Dropping edge detected -#ifdef DEBUG_LOG logging.println("Dropping edge detected. Resetting 10ms counter."); -#endif // DEBUG_LOG counter_10ms = 0; // reset counter } ContactorCloseRequest.previous = ContactorCloseRequest.present; @@ -465,12 +459,10 @@ void BmwIXBattery::setup(void) { // Performs one time setup at startup void BmwIXBattery::HandleIncomingUserRequest(void) { // Debug user request to open or close the contactors -#ifdef DEBUG_LOG logging.print("User request: contactor close: "); logging.print(userRequestContactorClose); logging.print(" User request: contactor open: "); logging.println(userRequestContactorOpen); -#endif // DEBUG_LOG if ((userRequestContactorClose == false) && (userRequestContactorOpen == false)) { // do nothing } else if ((userRequestContactorClose == true) && (userRequestContactorOpen == false)) { @@ -487,11 +479,9 @@ void BmwIXBattery::HandleIncomingUserRequest(void) { // set user request to false userRequestContactorClose = false; userRequestContactorOpen = false; -// print error, as both these flags shall not be true at the same time -#ifdef DEBUG_LOG + // print error, as both these flags shall not be true at the same time logging.println( "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; // Detect edge if (InverterContactorCloseRequest.previous == false && InverterContactorCloseRequest.present == true) { -// Rising edge detected -#ifdef DEBUG_LOG + // Rising edge detected logging.println("Inverter requests to close contactors"); -#endif // DEBUG_LOG BmwIxCloseContactors(); } else if (InverterContactorCloseRequest.previous == true && InverterContactorCloseRequest.present == false) { -// Falling edge detected -#ifdef DEBUG_LOG + // Falling edge detected logging.println("Inverter requests to open contactors"); -#endif // DEBUG_LOG BmwIxOpenContactors(); } // else: do nothing @@ -517,16 +503,12 @@ void BmwIXBattery::HandleIncomingInverterRequest(void) { } void BmwIXBattery::BmwIxCloseContactors(void) { -#ifdef DEBUG_LOG logging.println("Closing contactors"); -#endif // DEBUG_LOG contactorCloseReq = true; } void BmwIXBattery::BmwIxOpenContactors(void) { -#ifdef DEBUG_LOG logging.println("Opening contactors"); -#endif // DEBUG_LOG contactorCloseReq = false; 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) { // @0 ms transmit_can_frame(&BMWiX_510); -#ifdef DEBUG_LOG logging.println("Transmitted 0x510 - 1/6"); -#endif // DEBUG_LOG } else if (counter_10ms == 5) { // @50 ms transmit_can_frame(&BMWiX_276); -#ifdef DEBUG_LOG logging.println("Transmitted 0x276 - 2/6"); -#endif // DEBUG_LOG } else if (counter_10ms == 10) { // @100 ms BMWiX_510.data.u8[2] = 0x04; // TODO: check if needed transmit_can_frame(&BMWiX_510); -#ifdef DEBUG_LOG logging.println("Transmitted 0x510 - 3/6"); -#endif // DEBUG_LOG } else if (counter_10ms == 20) { // @200 ms BMWiX_510.data.u8[2] = 0x10; // TODO: check if needed BMWiX_510.data.u8[5] = 0x80; // needed to close contactors transmit_can_frame(&BMWiX_510); -#ifdef DEBUG_LOG logging.println("Transmitted 0x510 - 4/6"); -#endif // DEBUG_LOG } else if (counter_10ms == 30) { // @300 ms BMWiX_16E.data.u8[0] = 0x6A; BMWiX_16E.data.u8[1] = 0xAD; transmit_can_frame(&BMWiX_16E); -#ifdef DEBUG_LOG logging.println("Transmitted 0x16E - 5/6"); -#endif // DEBUG_LOG } else if (counter_10ms == 50) { // @500 ms BMWiX_16E.data.u8[0] = 0x03; BMWiX_16E.data.u8[1] = 0xA9; transmit_can_frame(&BMWiX_16E); -#ifdef DEBUG_LOG logging.println("Transmitted 0x16E - 6/6"); -#endif // DEBUG_LOG ContactorState.closed = true; 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 if (counter_100ms == 0) { -#ifdef DEBUG_LOG logging.println("Sending keep contactors closed messages started"); -#endif // DEBUG_LOG // @0 ms transmit_can_frame(&BMWiX_510); } 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[1] = 0xA7; transmit_can_frame(&BMWiX_16E); -#ifdef DEBUG_LOG logging.println("Sending keep contactors closed messages finished"); -#endif // DEBUG_LOG } else if (counter_100ms == 140) { // @14000 ms // reset counter (outside of this function) diff --git a/Software/src/battery/BMW-PHEV-BATTERY.cpp b/Software/src/battery/BMW-PHEV-BATTERY.cpp index 8241c74a..8d76e34b 100644 --- a/Software/src/battery/BMW-PHEV-BATTERY.cpp +++ b/Software/src/battery/BMW-PHEV-BATTERY.cpp @@ -122,9 +122,7 @@ bool BmwPhevBattery::storeUDSPayload(const uint8_t* payload, uint8_t length) { if (gUDSContext.UDS_bytesReceived + length > sizeof(gUDSContext.UDS_buffer)) { // Overflow => abort gUDSContext.UDS_inProgress = false; -#ifdef DEBUG_LOG logging.println("UDS Payload Overflow"); -#endif // DEBUG_LOG return false; } memcpy(&gUDSContext.UDS_buffer[gUDSContext.UDS_bytesReceived], payload, length); @@ -134,9 +132,7 @@ bool BmwPhevBattery::storeUDSPayload(const uint8_t* payload, uint8_t length) { // If we’ve reached or exceeded the expected length, mark complete if (gUDSContext.UDS_bytesReceived >= gUDSContext.UDS_expectedLength) { gUDSContext.UDS_inProgress = false; - // #ifdef DEBUG_LOG // logging.println("Recived all expected UDS bytes"); - // #endif // DEBUG_LOG } return true; } @@ -196,9 +192,7 @@ void BmwPhevBattery::wake_battery_via_canbus() { change_can_speed(original_speed); -#ifdef DEBUG_LOG 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 @@ -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_max_voltage_mV = 9999; //Stale values force stop set_event(EVENT_STALE_VALUE, 0); -#ifdef DEBUG_LOG logging.println("Stale Min/Max voltage values detected during charge/discharge sending - 9999mV..."); -#endif // DEBUG_LOG } else { 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] == 0xAD) { //Balancing Status 01 Active 03 Not Active 7DLC F1 05 71 03 AD 6B 01 balancing_status = (rx_frame.data.u8[6]); - // #ifdef DEBUG_LOG - - // logging.println("Balancing Status received"); - - // #endif // DEBUG_LOG + //logging.println("Balancing Status received"); } 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) | (gUDSContext.UDS_buffer[5] << 8) | gUDSContext.UDS_buffer[6])) * 0.1; -#ifdef DEBUG_LOG logging.print("Received current/amps measurement data: "); logging.print(battery_current); logging.print(" - "); @@ -538,7 +525,6 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) { logging.print(" "); } logging.println(); // new line at the end -#endif // DEBUG_LOG } //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; max_cell_voltage = (gUDSContext.UDS_buffer[11] << 8 | gUDSContext.UDS_buffer[12]) / 10; } else { -#ifdef DEBUG_LOG logging.println("Cell Min Max Invalid 65535 or 0..."); logging.print("Received data: "); 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.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) { battery_temperature_min = (rx_frame.data.u8[6] - 50); } else { -#ifdef DEBUG_LOG logging.println("Pre parsed Cell Temp Min is Invalid "); -#endif } if (rx_frame.data.u8[7] > 0 && rx_frame.data.u8[7] < 255) { battery_temperature_max = (rx_frame.data.u8[7] - 50); } else { -#ifdef DEBUG_LOG logging.println("Pre parsed Cell Temp Max is Invalid "); -#endif } break; diff --git a/Software/src/battery/CHADEMO-BATTERY.cpp b/Software/src/battery/CHADEMO-BATTERY.cpp index 5ec6217f..07257708 100644 --- a/Software/src/battery/CHADEMO-BATTERY.cpp +++ b/Software/src/battery/CHADEMO-BATTERY.cpp @@ -116,7 +116,6 @@ void ChademoBattery::process_vehicle_charging_session(CAN_frame rx_frame) { x102_chg_session.ChargingCurrentRequest = newChargingCurrentRequest; x102_chg_session.TargetBatteryVoltage = newTargetBatteryVoltage; -#ifdef DEBUG_LOG //Note on p131 uint8_t chargingrate = 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.println(chargingrate); } -#endif //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) || (x102_chg_session.s.status.StatusVehicleChargingEnabled && !vehicle_permission)) { -#ifdef DEBUG_LOG logging.println("Inconsistent charge/discharge state."); -#endif CHADEMO_Status = CHADEMO_FAULT; return; } if (x102_chg_session.f.fault.FaultBatteryOverVoltage) { -#ifdef DEBUG_LOG logging.println("Vehicle indicates fault, battery over voltage."); -#endif CHADEMO_Status = CHADEMO_STOP; return; } if (x102_chg_session.f.fault.FaultBatteryUnderVoltage) { -#ifdef DEBUG_LOG logging.println("Vehicle indicates fault, battery under voltage."); -#endif CHADEMO_Status = CHADEMO_STOP; return; } if (x102_chg_session.f.fault.FaultBatteryCurrentDeviation) { -#ifdef DEBUG_LOG logging.println("Vehicle indicates fault, battery current deviation. Possible EVSE issue?"); -#endif CHADEMO_Status = CHADEMO_STOP; return; } if (x102_chg_session.f.fault.FaultBatteryVoltageDeviation) { -#ifdef DEBUG_LOG logging.println("Vehicle indicates fault, battery voltage deviation. Possible EVSE issue?"); -#endif CHADEMO_Status = CHADEMO_STOP; 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 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"); -#endif CHADEMO_Status = CHADEMO_STOP; return; } if (vehicle_permission && CHADEMO_Status == CHADEMO_NEGOTIATE) { CHADEMO_Status = CHADEMO_EV_ALLOWED; -#ifdef DEBUG_LOG logging.println("STATE shift to CHADEMO_EV_ALLOWED in process_vehicle_charging_session()"); -#endif return; } @@ -203,23 +187,17 @@ void ChademoBattery::process_vehicle_charging_session(CAN_frame rx_frame) { // consider relocating if (vehicle_permission && CHADEMO_Status == CHADEMO_EVSE_PREPARE && priorTargetBatteryVoltage == 0 && newTargetBatteryVoltage > 0 && x102_chg_session.s.status.StatusVehicleChargingEnabled) { -#ifdef DEBUG_LOG logging.println("STATE SHIFT to EVSE_START reached in process_vehicle_charging_session()"); -#endif CHADEMO_Status = CHADEMO_EVSE_START; return; } if (vehicle_permission && evse_permission && CHADEMO_Status == CHADEMO_POWERFLOW) { -#ifdef DEBUG_LOG logging.println("updating vehicle request in process_vehicle_charging_session()"); -#endif return; } -#ifdef DEBUG_LOG logging.println("UNHANDLED CHADEMO STATE, try unplugging chademo cable, reboot emulator, and retry!"); -#endif 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.MaxRemainingCapacityForCharging = rx_frame.data.u8[7]; -#ifdef DEBUG_LOG -/* unsigned long currentMillis = millis(); + /* unsigned long currentMillis = millis(); if (currentMillis - previousMillis5000 >= INTERVAL_5_S) { previousMillis5000 = currentMillis; 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); } */ -#endif 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.print("Measured: "); logging.print(get_measured_voltage()); logging.print("Minimum voltage: "); logging.print(x200_discharge_limits.MinimumDischargeVoltage); -#endif 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.AvailableVehicleEnergy = ((rx_frame.data.u8[4] << 8) | rx_frame.data.u8[3]); -#ifdef DEBUG_LOG if (currentMillis - previousMillis5000 >= INTERVAL_5_S) { previousMillis5000 = currentMillis; 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.println(x201_discharge_estimate.ApproxDischargeCompletionTime); } -#endif } 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 // 110.0.0 if (x102_chg_session.ControlProtocolNumberEV >= 0x03) { //Only send the following on Chademo 2.0 vehicles? -#ifdef DEBUG_LOG //FIXME REMOVE logging.println("REMOVE: proto 2.0"); -#endif transmit_can_frame(&CHADEMO_118); } } @@ -656,16 +626,12 @@ void ChademoBattery::handle_chademo_sequence() { /* ------------------- State override conditions checks ------------------- */ /* ------------------------------------------------------------------------------ */ if (CHADEMO_Status >= CHADEMO_EV_ALLOWED && x102_chg_session.s.status.StatusVehicleShifterPosition) { -#ifdef DEBUG_LOG logging.println("Vehicle is not parked, abort."); -#endif CHADEMO_Status = CHADEMO_STOP; } if (CHADEMO_Status >= CHADEMO_EV_ALLOWED && !vehicle_permission) { -#ifdef DEBUG_LOG logging.println("Vehicle charge/discharge permission ended, stop."); -#endif CHADEMO_Status = CHADEMO_STOP; } @@ -678,25 +644,19 @@ void ChademoBattery::handle_chademo_sequence() { plug_inserted = digitalRead(pin7); if (!plug_inserted) { -#ifdef DEBUG_LOG -// Commented unless needed for debug -// logging.println("CHADEMO plug is not inserted."); -#endif + // Commented unless needed for debug + // logging.println("CHADEMO plug is not inserted."); return; } CHADEMO_Status = CHADEMO_CONNECTED; -#ifdef DEBUG_LOG logging.println("CHADEMO plug is inserted. Provide EVSE power to vehicle to trigger initialization."); -#endif break; case CHADEMO_CONNECTED: -#ifdef DEBUG_LOG // Commented unless needed for debug //logging.println("CHADEMO_CONNECTED State"); -#endif /* plug_inserted is .. essentially a volatile of sorts, so verify */ if (plug_inserted) { /* If connection is detectable, jumpstart handshake by @@ -729,17 +689,13 @@ void ChademoBattery::handle_chademo_sequence() { /* Vehicle and EVSE dance */ //TODO if pin 4 / j goes high, -#ifdef DEBUG_LOG -// Commented unless needed for debug -// logging.println("CHADEMO_NEGOTIATE State"); -#endif + // Commented unless needed for debug + // logging.println("CHADEMO_NEGOTIATE State"); x109_evse_state.s.status.ChgDischStopControl = 1; break; case CHADEMO_EV_ALLOWED: -#ifdef DEBUG_LOG // Commented unless needed for debug logging.println("CHADEMO_EV_ALLOWED State"); -#endif // If we are in this state, vehicle_permission was already set to true...but re-verify // that pin 4 (j) reads high if (vehicle_permission) { @@ -754,10 +710,8 @@ void ChademoBattery::handle_chademo_sequence() { } break; case CHADEMO_EVSE_PREPARE: -#ifdef DEBUG_LOG // Commented unless needed for debug logging.println("CHADEMO_EVSE_PREPARE State"); -#endif /* TODO voltage check of output < 20v * insulation test hypothetically happens here before triggering PIN 10 high * see Table A.28—Requirements 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 break; case CHADEMO_EVSE_START: -#ifdef DEBUG_LOG // Commented unless needed for debug logging.println("CHADEMO_EVSE_START State"); -#endif datalayer.system.status.battery_allows_contactor_closing = true; x109_evse_state.s.status.ChgDischStopControl = 1; x109_evse_state.s.status.EVSE_status = 0; CHADEMO_Status = CHADEMO_EVSE_CONTACTORS_ENABLED; -#ifdef DEBUG_LOG logging.println("Initiating contactors"); -#endif /* break rather than fall through because contactors are not instantaneous; * worth giving it a cycle to finish @@ -810,18 +760,14 @@ void ChademoBattery::handle_chademo_sequence() { break; case CHADEMO_EVSE_CONTACTORS_ENABLED: -#ifdef DEBUG_LOG // Commented unless needed for debug logging.println("CHADEMO_EVSE_CONTACTORS State"); -#endif /* check whether contactors ready, because externally dependent upon inverter allow during discharge */ if (contactors_ready) { -#ifdef DEBUG_LOG logging.println("Contactors ready"); logging.print("Voltage: "); logging.println(get_measured_voltage()); -#endif /* transition to POWERFLOW state if discharge compatible on both sides */ if (x109_evse_state.discharge_compatible && x102_chg_session.s.status.StatusVehicleDischargeCompatible && (EVSE_mode == CHADEMO_DISCHARGE || EVSE_mode == CHADEMO_BIDIRECTIONAL)) { @@ -840,10 +786,8 @@ void ChademoBattery::handle_chademo_sequence() { /* break or fall through ? TODO */ break; case CHADEMO_POWERFLOW: -#ifdef DEBUG_LOG // Commented unless needed for debug logging.println("CHADEMO_POWERFLOW State"); -#endif /* POWERFLOW for charging, discharging, and bidirectional */ /* Interpretation */ if (x102_chg_session.s.status.StatusVehicleShifterPosition) { @@ -860,9 +804,7 @@ void ChademoBattery::handle_chademo_sequence() { } if (get_measured_voltage() <= x200_discharge_limits.MinimumDischargeVoltage) { -#ifdef DEBUG_LOG logging.println("x200 minimum discharge voltage met or exceeded, stopping."); -#endif CHADEMO_Status = CHADEMO_STOP; } @@ -871,10 +813,8 @@ void ChademoBattery::handle_chademo_sequence() { x109_evse_state.s.status.EVSE_status = 1; break; case CHADEMO_STOP: -#ifdef DEBUG_LOG // Commented unless needed for debug logging.println("CHADEMO_STOP State"); -#endif /* back to CHADEMO_IDLE after teardown */ x109_evse_state.s.status.ChgDischStopControl = 1; x109_evse_state.s.status.EVSE_status = 0; @@ -899,17 +839,13 @@ void ChademoBattery::handle_chademo_sequence() { break; case CHADEMO_FAULT: -#ifdef DEBUG_LOG // Commented unless needed for debug logging.println("CHADEMO_FAULT State"); -#endif /* 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.ChgDischError = 1; x109_evse_state.s.status.ChgDischStopControl = 1; -#ifdef DEBUG_LOG logging.println("CHADEMO fault encountered, tearing down to make safe"); -#endif digitalWrite(pin10, LOW); digitalWrite(pin2, LOW); evse_permission = false; @@ -919,9 +855,7 @@ void ChademoBattery::handle_chademo_sequence() { break; default: -#ifdef DEBUG_LOG logging.println("UNHANDLED CHADEMO_STATE, setting FAULT"); -#endif CHADEMO_Status = CHADEMO_FAULT; break; } diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp index 85f3519a..694a6d09 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -75,12 +75,9 @@ void ImievCZeroIonBattery:: } if (!BMU_Detected) { -#ifdef DEBUG_LOG logging.println("BMU not detected, check wiring!"); -#endif } -#ifdef DEBUG_LOG logging.println("Battery Values"); logging.print("BMU SOC: "); logging.print(BMU_SOC); @@ -90,15 +87,6 @@ void ImievCZeroIonBattery:: logging.print(BMU_PackVoltage); 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) { diff --git a/Software/src/battery/JAGUAR-IPACE-BATTERY.cpp b/Software/src/battery/JAGUAR-IPACE-BATTERY.cpp index 443e6d98..2f43438f 100644 --- a/Software/src/battery/JAGUAR-IPACE-BATTERY.cpp +++ b/Software/src/battery/JAGUAR-IPACE-BATTERY.cpp @@ -102,21 +102,6 @@ void JaguarIpaceBattery::update_values() { } else { 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) { diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.cpp b/Software/src/battery/KIA-E-GMP-BATTERY.cpp index a4c8bd95..ba6b1c06 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.cpp +++ b/Software/src/battery/KIA-E-GMP-BATTERY.cpp @@ -55,7 +55,6 @@ uint16_t KiaEGmpBattery::estimateSOC(uint16_t packVoltage, uint16_t cellCount, i // Calculate average cell voltage in millivolts uint16_t avgCellVoltage = compensatedPackVoltageMv / cellCount; -#ifdef DEBUG_LOG logging.print("Pack: "); logging.print(packVoltage / 10.0); 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(avgCellVoltage); logging.println("mV"); -#endif // Use the cell voltage lookup table to estimate SOC return estimateSOCFromCell(avgCellVoltage); @@ -187,7 +185,6 @@ void KiaEGmpBattery::update_values() { /* Safeties verified. Perform USB serial printout if configured to do so */ -#ifdef DEBUG_LOG logging.println(); //sepatator logging.println("Values from battery: "); logging.print("SOC BMS: "); @@ -244,7 +241,6 @@ void KiaEGmpBattery::update_values() { logging.print(" | Inverter "); logging.print(inverterVoltage); logging.println(" Volts"); -#endif } // Getter implementations for HTML renderer diff --git a/Software/src/battery/MEB-BATTERY.cpp b/Software/src/battery/MEB-BATTERY.cpp index ebd02f7a..0fe468f7 100644 --- a/Software/src/battery/MEB-BATTERY.cpp +++ b/Software/src/battery/MEB-BATTERY.cpp @@ -171,9 +171,7 @@ uint8_t vw_crc_calc(uint8_t* inputBytes, uint8_t length, uint32_t address) { magicByte = MB16A954A6[counter]; break; default: // this won't lead to correct CRC checksums -#ifdef DEBUG_LOG logging.println("Checksum request unknown"); -#endif magicByte = 0x00; break; } @@ -310,9 +308,7 @@ void MebBattery:: void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) { last_can_msg_timestamp = millis(); if (first_can_msg == 0) { -#ifdef DEBUG_LOG logging.printf("MEB: First CAN msg received\n"); -#endif 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] != 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++; -#ifdef DEBUG_LOG logging.printf("MEB: Msg 0x%04X CRC error\n", rx_frame.ID); -#endif return; } default: @@ -700,29 +694,23 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) { case 3: // EXTERN CHARGING case 4: // AC_CHARGING case 6: // DC_CHARGING -#ifdef DEBUG_LOG if (!datalayer.system.status.battery_allows_contactor_closing) logging.printf("MEB: Contactors closed\n"); -#endif if (datalayer.battery.status.real_bms_status != BMS_FAULT) datalayer.battery.status.real_bms_status = BMS_ACTIVE; datalayer.system.status.battery_allows_contactor_closing = true; hv_requested = false; break; case 5: // Error -#ifdef DEBUG_LOG if (datalayer.system.status.battery_allows_contactor_closing) logging.printf("MEB: Contactors opened\n"); -#endif datalayer.battery.status.real_bms_status = BMS_FAULT; datalayer.system.status.battery_allows_contactor_closing = false; hv_requested = false; break; case 7: // Init -#ifdef DEBUG_LOG if (datalayer.system.status.battery_allows_contactor_closing) logging.printf("MEB: Contactors opened\n"); -#endif if (datalayer.battery.status.real_bms_status != BMS_FAULT) datalayer.battery.status.real_bms_status = BMS_STANDBY; datalayer.system.status.battery_allows_contactor_closing = false; @@ -730,10 +718,8 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) { break; case 2: // BALANCING default: -#ifdef DEBUG_LOG if (datalayer.system.status.battery_allows_contactor_closing) logging.printf("MEB: Contactors opened\n"); -#endif if (datalayer.battery.status.real_bms_status != BMS_FAULT) datalayer.battery.status.real_bms_status = BMS_STANDBY; 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); break; default: -#ifdef DEBUG_LOG logging.printf("Unknown CAN frame received:\n"); dump_can_frame(rx_frame, MSG_RX); -#endif break; } 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) { if (currentMillis - last_can_msg_timestamp > 500) { -#ifdef DEBUG_LOG if (first_can_msg) logging.printf("MEB: No CAN msg received for 500ms\n"); -#endif can_msg_received = RX_DEFAULT; first_can_msg = 0; 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))))) { hv_requested = true; datalayer.system.settings.start_precharging = false; -#ifdef DEBUG_LOG if (MEB_503.data.u8[3] == BMS_TARGET_HV_OFF) { 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"); } } -#endif MEB_503.data.u8[1] = 0x30 | (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING ? 0x80 : 0x00); 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; } -#ifdef DEBUG_LOG if (MEB_503.data.u8[3] != BMS_TARGET_HV_OFF) { 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"); } } -#endif MEB_503.data.u8[1] = 0x10 | (datalayer.system.status.precharge_status == AUTO_PRECHARGE_PRECHARGING ? 0x80 : 0x00); MEB_503.data.u8[3] = BMS_TARGET_HV_OFF; diff --git a/Software/src/battery/MG-HS-PHEV-BATTERY.cpp b/Software/src/battery/MG-HS-PHEV-BATTERY.cpp index 5250e346..a8395067 100644 --- a/Software/src/battery/MG-HS-PHEV-BATTERY.cpp +++ b/Software/src/battery/MG-HS-PHEV-BATTERY.cpp @@ -147,11 +147,9 @@ void MgHsPHEVBattery::handle_incoming_can_frame(CAN_frame rx_frame) { // 15 = isolation fault // 0/8 = checking -#ifdef DEBUG_LOG 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]); } -#endif if (rx_frame.data.u8[1] == 0xf && previousState != 0xf) { // 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 datalayer.system.status.battery_allows_contactor_closing = false; if (!datalayer.system.status.BMS_startup_in_progress) { -#ifdef DEBUG_LOG logging.printf("MG_HS_PHEV: Stuck, resetting.\n"); -#endif start_bms_reset(); } } else if (rx_frame.data.u8[1] == 0xf) { // A fault state (likely isolation failure) datalayer.system.status.battery_allows_contactor_closing = false; if (!datalayer.system.status.BMS_startup_in_progress) { -#ifdef DEBUG_LOG logging.printf("MG_HS_PHEV: Fault, resetting.\n"); -#endif start_bms_reset(); } } else { diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp index 3de1cbf0..3de224e9 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp @@ -51,39 +51,6 @@ void RenaultKangooBattery:: datalayer.battery.status.cell_min_voltage_mV = LB_Cell_Min_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) { diff --git a/Software/src/battery/TESLA-BATTERY.cpp b/Software/src/battery/TESLA-BATTERY.cpp index 1211be41..f5a3db24 100644 --- a/Software/src/battery/TESLA-BATTERY.cpp +++ b/Software/src/battery/TESLA-BATTERY.cpp @@ -720,13 +720,9 @@ void TeslaBattery:: //Start the BMS ECU reset statemachine, only if contactors are OPEN and BMS ECU allows it stateMachineBMSReset = 0; datalayer.battery.settings.user_requests_tesla_bms_reset = false; -#ifdef DEBUG_LOG logging.println("BMS reset requested"); -#endif //DEBUG_LOG } else { -#ifdef DEBUG_LOG logging.println("ERROR: BMS reset failed due to contactors not being open, or BMS ECU not allowing it"); -#endif //DEBUG_LOG stateMachineBMSReset = 0xFF; 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% stateMachineSOCReset = 0; datalayer.battery.settings.user_requests_tesla_soc_reset = false; -#ifdef DEBUG_LOG logging.println("SOC reset requested"); -#endif //DEBUG_LOG } else { -#ifdef DEBUG_LOG logging.println("ERROR: SOC reset failed due to SOC not being less than 15 or greater than 90"); -#endif //DEBUG_LOG stateMachineSOCReset = 0xFF; datalayer.battery.settings.user_requests_tesla_soc_reset = false; } @@ -1002,8 +994,6 @@ void TeslaBattery:: } } -#ifdef DEBUG_LOG - printFaultCodesIfActive(); logging.print("BMS Contactors State: "); 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", 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); -#endif //DEBUG_LOG } 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 (memcmp(rx_frame.data.u8, "\x02\x50\x03\xAA\xAA\xAA\xAA\xAA", 8) == 0) { //Received initial response, proceed to actual query -#ifdef DEBUG_LOG logging.println("CAN UDS: Received BMS query initial handshake reply"); -#endif //DEBUG_LOG stateMachineBMSQuery = 1; 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[1] = rx_frame.data.u8[6]; battery_partNumber[2] = rx_frame.data.u8[7]; -#ifdef DEBUG_LOG logging.println("CAN UDS: Received BMS query data frame"); -#endif //DEBUG_LOG stateMachineBMSQuery = 2; 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[8] = rx_frame.data.u8[6]; battery_partNumber[9] = rx_frame.data.u8[7]; -#ifdef DEBUG_LOG logging.println("CAN UDS: Received BMS query second data frame"); -#endif //DEBUG_LOG break; } if (memcmp(&rx_frame.data.u8[0], "\x22", 1) == 0) { //Final part of part number battery_partNumber[10] = rx_frame.data.u8[1]; battery_partNumber[11] = rx_frame.data.u8[2]; -#ifdef DEBUG_LOG logging.println("CAN UDS: Received BMS query final data frame"); -#endif //DEBUG_LOG break; } if (memcmp(rx_frame.data.u8, "\x23\x00\x00\x00\xAA\xAA\xAA\xAA", 8) == 0) { //Received final frame -#ifdef DEBUG_LOG logging.println("CAN UDS: Received BMS query termination frame"); -#endif //DEBUG_LOG parsed_battery_partNumber = true; stateMachineBMSQuery = 0xFF; break; } } //BMS Reset -#ifdef DEBUG_LOG 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) { 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"); } } -#endif //DEBUG_LOG break; default: break; @@ -2375,25 +2352,19 @@ void TeslaBattery::transmit_can(unsigned long currentMillis) { switch (stateMachineBMSQuery) { case 0: //Initial request -#ifdef DEBUG_LOG logging.println("CAN UDS: Sending BMS query initial handshake"); -#endif //DEBUG_LOG TESLA_602.data = {0x02, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}; transmit_can_frame(&TESLA_602); break; case 1: //Send query -#ifdef DEBUG_LOG 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}; transmit_can_frame(&TESLA_602); break; case 2: //Flow control -#ifdef DEBUG_LOG logging.println("CAN UDS: Sending BMS query flow control"); -#endif //DEBUG_LOG TESLA_602.data = {0x30, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00}; transmit_can_frame(&TESLA_602); break; diff --git a/Software/src/battery/TEST-FAKE-BATTERY.cpp b/Software/src/battery/TEST-FAKE-BATTERY.cpp index eb3acd54..b7b18bc8 100644 --- a/Software/src/battery/TEST-FAKE-BATTERY.cpp +++ b/Software/src/battery/TEST-FAKE-BATTERY.cpp @@ -42,21 +42,6 @@ void TestFakeBattery:: //Fake that we get CAN messages 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) { diff --git a/Software/src/battery/VOLVO-SPA-BATTERY.cpp b/Software/src/battery/VOLVO-SPA-BATTERY.cpp index 8b28d0df..e251f9c7 100644 --- a/Software/src/battery/VOLVO-SPA-BATTERY.cpp +++ b/Software/src/battery/VOLVO-SPA-BATTERY.cpp @@ -85,51 +85,6 @@ void VolvoSpaBattery:: 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) { @@ -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)); else { BATT_I = 0; -#ifdef DEBUG_LOG logging.println("BATT_I not valid"); -#endif } 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); else { BATT_ERR_INDICATION = 0; -#ifdef DEBUG_LOG logging.println("BATT_ERR_INDICATION not valid"); -#endif } if ((rx_frame.data.u8[0] & 0x20) == 0x20) { 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_MIN = 0; BATT_T_AVG = 0; -#ifdef DEBUG_LOG logging.println("BATT_T not valid"); -#endif } break; 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); } else { HvBattPwrLimDchaSoft = 0; -#ifdef DEBUG_LOG logging.println("HvBattPwrLimDchaSoft not valid"); -#endif } break; 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]); } else { SOC_BMS = 0; -#ifdef DEBUG_LOG logging.println("SOC_BMS not valid"); -#endif } if ((rx_frame.data.u8[0] & 0x04) == 0x04) { diff --git a/Software/src/battery/VOLVO-SPA-HYBRID-BATTERY.cpp b/Software/src/battery/VOLVO-SPA-HYBRID-BATTERY.cpp index 9d54b8fd..7afc2ada 100644 --- a/Software/src/battery/VOLVO-SPA-HYBRID-BATTERY.cpp +++ b/Software/src/battery/VOLVO-SPA-HYBRID-BATTERY.cpp @@ -70,51 +70,6 @@ void VolvoSpaHybridBattery:: for (int i = 0; i < 102; ++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) { @@ -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)); else { BATT_I = 0; -#ifdef DEBUG_LOG logging.println("BATT_I not valid"); -#endif } 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); else { BATT_U = 0; -#ifdef DEBUG_LOG logging.println("BATT_U not valid"); -#endif } 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); else { BATT_ERR_INDICATION = 0; -#ifdef DEBUG_LOG logging.println("BATT_ERR_INDICATION not valid"); -#endif } if ((rx_frame.data.u8[0] & 0x20) == 0x20) { 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_MIN = 0; BATT_T_AVG = 0; -#ifdef DEBUG_LOG logging.println("BATT_T not valid"); -#endif } break; 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); } else { HvBattPwrLimDchaSoft = 0; -#ifdef DEBUG_LOG logging.println("HvBattPwrLimDchaSoft not valid"); -#endif } break; 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]); } else { SOC_BMS = 0; -#ifdef DEBUG_LOG logging.println("SOC_BMS not valid"); -#endif } if ((rx_frame.data.u8[0] & 0x04) == 0x04) @@ -251,9 +194,7 @@ void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) { else { //CELL_U_MAX = 0; ; -#ifdef DEBUG_LOG logging.println("CELL_U_MAX not valid"); -#endif } if ((rx_frame.data.u8[0] & 0x02) == 0x02) @@ -262,9 +203,7 @@ void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) { else { //CELL_U_MIN = 0; ; -#ifdef DEBUG_LOG logging.println("CELL_U_MIN not valid"); -#endif } if ((rx_frame.data.u8[0] & 0x08) == 0x08) @@ -273,9 +212,7 @@ void VolvoSpaHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) { else { //CELL_ID_U_MAX = 0; ; -#ifdef DEBUG_LOG logging.println("CELL_ID_U_MAX not valid"); -#endif } break; case 0x635: // Diag request response @@ -545,9 +482,7 @@ void VolvoSpaHybridBattery::transmit_can(unsigned long currentMillis) { previousMillis60s = currentMillis; if (true) { readCellVoltages(); -#ifdef DEBUG_LOG logging.println("Requesting cell voltages"); -#endif } } } diff --git a/Software/src/charger/CHEVY-VOLT-CHARGER.cpp b/Software/src/charger/CHEVY-VOLT-CHARGER.cpp index 62dad719..f981e869 100644 --- a/Software/src/charger/CHEVY-VOLT-CHARGER.cpp +++ b/Software/src/charger/CHEVY-VOLT-CHARGER.cpp @@ -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 break; default: -#ifdef DEBUG_LOG - logging.printf("CAN Rcv unknown frame MsgID=%x\n", rx_frame.ID); -#endif break; } } @@ -146,7 +143,6 @@ void ChevyVoltCharger::transmit_can(unsigned long currentMillis) { transmit_can_frame(&charger_set_targets); } -#ifdef DEBUG_LOG /* Serial echo every 5s of charger stats */ if (currentMillis - previousMillis5000ms >= INTERVAL_5_S) { 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 HVset=%uV,%uA finishCurrent=%uA\n", setpoint_HV_VDC, setpoint_HV_IDC, setpoint_HV_IDC_END); } -#endif } diff --git a/Software/src/communication/can/comm_can.cpp b/Software/src/communication/can/comm_can.cpp index 4efec199..5ba5b868 100644 --- a/Software/src/communication/can/comm_can.cpp +++ b/Software/src/communication/can/comm_can.cpp @@ -99,9 +99,7 @@ bool init_CAN() { return false; } -#ifdef DEBUG_LOG logging.println("Dual CAN Bus (ESP32+MCP2515) selected"); -#endif // DEBUG_LOG gBuffer.initWithSize(25); can2515 = new ACAN2515(cs_pin, SPI2515, int_pin); @@ -115,14 +113,10 @@ bool init_CAN() { settings2515->mRequestedMode = ACAN2515Settings::NormalMode; const uint16_t errorCode2515 = can2515->begin(*settings2515, [] { can2515->isr(); }); if (errorCode2515 == 0) { -#ifdef DEBUG_LOG logging.println("Can ok"); -#endif // DEBUG_LOG } else { -#ifdef DEBUG_LOG logging.print("Error Can: 0x"); logging.println(errorCode2515, HEX); -#endif // DEBUG_LOG set_event(EVENT_CANMCP2515_INIT_FAILURE, (uint8_t)errorCode2515); return false; } @@ -147,9 +141,7 @@ bool init_CAN() { canfd = new ACAN2517FD(cs_pin, SPI2517, int_pin); -#ifdef DEBUG_LOG logging.println("CAN FD add-on (ESP32+MCP2517) selected"); -#endif // DEBUG_LOG SPI2517.begin(sck_pin, sdo_pin, sdi_pin); auto bitRate = (int)speed * 1000UL; settings2517 = new ACAN2517FDSettings( @@ -162,7 +154,6 @@ bool init_CAN() { const uint32_t errorCode2517 = canfd->begin(*settings2517, [] { canfd->isr(); }); canfd->poll(); if (errorCode2517 == 0) { -#ifdef DEBUG_LOG logging.print("Bit Rate prescaler: "); logging.println(settings2517->mBitRatePrescaler); logging.print("Arbitration Phase segment 1: "); @@ -179,12 +170,9 @@ bool init_CAN() { logging.print("Arbitration Sample point: "); logging.print(settings2517->arbitrationSamplePointFromBitStart()); logging.println("%"); -#endif // DEBUG_LOG } else { -#ifdef DEBUG_LOG logging.print("CAN-FD Configuration error 0x"); logging.println(errorCode2517, HEX); -#endif // DEBUG_LOG set_event(EVENT_CANMCP2517FD_INIT_FAILURE, (uint8_t)errorCode2517); return false; } diff --git a/Software/src/communication/can/obd.cpp b/Software/src/communication/can/obd.cpp index c01d9b24..ec2bc49b 100644 --- a/Software/src/communication/can/obd.cpp +++ b/Software/src/communication/can/obd.cpp @@ -24,7 +24,6 @@ void show_dtc(uint8_t byte0, uint8_t byte1) { } void handle_obd_frame(CAN_frame& rx_frame) { -#ifdef DEBUG_LOG if (rx_frame.data.u8[1] == 0x7F) { const char* error_str = "?"; 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); -#endif } void transmit_obd_can_frame(unsigned int address, int interface, bool canFD) { diff --git a/Software/src/communication/contactorcontrol/comm_contactorcontrol.cpp b/Software/src/communication/contactorcontrol/comm_contactorcontrol.cpp index 6ea7798a..8983807e 100644 --- a/Software/src/communication/contactorcontrol/comm_contactorcontrol.cpp +++ b/Software/src/communication/contactorcontrol/comm_contactorcontrol.cpp @@ -147,12 +147,10 @@ bool init_contactors() { } static void dbg_contactors(const char* state) { -#ifdef DEBUG_LOG logging.print("["); logging.print(millis()); logging.print(" ms] contactors control: "); 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 diff --git a/Software/src/communication/precharge_control/precharge_control.cpp b/Software/src/communication/precharge_control/precharge_control.cpp index efdf3ff9..743bf0c5 100644 --- a/Software/src/communication/precharge_control/precharge_control.cpp +++ b/Software/src/communication/precharge_control/precharge_control.cpp @@ -40,9 +40,7 @@ bool init_precharge_control() { } // Setup PWM Channel Frequency and Resolution -#ifdef DEBUG_LOG logging.printf("Precharge control initialised\n"); -#endif auto hia4v1_pin = esp32hal->HIA4V1_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% prechargeStartTime = currentMillis; datalayer.system.status.precharge_status = AUTO_PRECHARGE_PRECHARGING; -#ifdef DEBUG_LOG logging.printf("Precharge: Starting sequence\n"); -#endif digitalWrite(inverter_disconnect_contactor_pin, OFF); break; @@ -106,10 +102,8 @@ void handle_precharge_control(unsigned long currentMillis) { freq = Precharge_max_PWM_Freq; if (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, external_voltage / 10, freq); -#endif ledcWriteTone(hia4v1_pin, freq); } @@ -120,18 +114,14 @@ void handle_precharge_control(unsigned long currentMillis) { digitalWrite(hia4v1_pin, LOW); digitalWrite(inverter_disconnect_contactor_pin, ON); datalayer.system.status.precharge_status = AUTO_PRECHARGE_IDLE; -#ifdef DEBUG_LOG logging.printf("Precharge: Disabling Precharge bms not standby/active or equipment stop\n"); -#endif } else if (currentMillis - prechargeStartTime >= MAX_PRECHARGE_TIME_MS || datalayer.battery.status.real_bms_status == BMS_FAULT) { pinMode(hia4v1_pin, OUTPUT); digitalWrite(hia4v1_pin, LOW); digitalWrite(inverter_disconnect_contactor_pin, ON); datalayer.system.status.precharge_status = AUTO_PRECHARGE_OFF; -#ifdef DEBUG_LOG logging.printf("Precharge: Disabled (timeout reached / BMS fault) -> AUTO_PRECHARGE_OFF\n"); -#endif set_event(EVENT_AUTOMATIC_PRECHARGE_FAILURE, 0); // Add event @@ -140,18 +130,14 @@ void handle_precharge_control(unsigned long currentMillis) { digitalWrite(hia4v1_pin, LOW); digitalWrite(inverter_disconnect_contactor_pin, ON); datalayer.system.status.precharge_status = AUTO_PRECHARGE_COMPLETED; -#ifdef DEBUG_LOG logging.printf("Precharge: Disabled (contacts closed) -> COMPLETED\n"); -#endif } break; case AUTO_PRECHARGE_COMPLETED: if (datalayer.system.settings.equipment_stop_active || datalayer.battery.status.bms_status != ACTIVE) { datalayer.system.status.precharge_status = AUTO_PRECHARGE_IDLE; -#ifdef DEBUG_LOG logging.printf("Precharge: equipment stop activated -> IDLE\n"); -#endif } break; @@ -162,9 +148,7 @@ void handle_precharge_control(unsigned long currentMillis) { datalayer.system.status.precharge_status = AUTO_PRECHARGE_IDLE; pinMode(hia4v1_pin, OUTPUT); digitalWrite(hia4v1_pin, LOW); -#ifdef DEBUG_LOG logging.printf("Precharge: equipment stop activated -> IDLE\n"); -#endif } break; diff --git a/Software/src/devboard/mqtt/mqtt.cpp b/Software/src/devboard/mqtt/mqtt.cpp index 067c2b6c..f23d3be4 100644 --- a/Software/src/devboard/mqtt/mqtt.cpp +++ b/Software/src/devboard/mqtt/mqtt.cpp @@ -319,9 +319,7 @@ static bool publish_common_info(void) { serializeJson(doc, mqtt_msg); if (mqtt_publish(state_topic.c_str(), mqtt_msg, false) == false) { -#ifdef DEBUG_LOG logging.println("Common info MQTT msg could not be sent"); -#endif // DEBUG_LOG return false; } doc.clear(); @@ -392,9 +390,7 @@ static bool publish_cell_voltages(void) { serializeJson(doc, mqtt_msg, sizeof(mqtt_msg)); if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) { -#ifdef DEBUG_LOG logging.println("Cell voltage MQTT msg could not be sent"); -#endif // DEBUG_LOG return false; } doc.clear(); @@ -413,9 +409,7 @@ static bool publish_cell_voltages(void) { serializeJson(doc, mqtt_msg, sizeof(mqtt_msg)); if (!mqtt_publish(state_topic_2.c_str(), mqtt_msg, false)) { -#ifdef DEBUG_LOG logging.println("Cell voltage MQTT msg could not be sent"); -#endif // DEBUG_LOG return false; } doc.clear(); @@ -440,9 +434,7 @@ static bool publish_cell_balancing(void) { serializeJson(doc, mqtt_msg, sizeof(mqtt_msg)); if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) { -#ifdef DEBUG_LOG logging.println("Cell balancing MQTT msg could not be sent"); -#endif // DEBUG_LOG return false; } doc.clear(); @@ -460,9 +452,7 @@ static bool publish_cell_balancing(void) { serializeJson(doc, mqtt_msg, sizeof(mqtt_msg)); if (!mqtt_publish(state_topic_2.c_str(), mqtt_msg, false)) { -#ifdef DEBUG_LOG logging.println("Cell balancing MQTT msg could not be sent"); -#endif // DEBUG_LOG return false; } doc.clear(); @@ -523,9 +513,7 @@ bool publish_events() { serializeJson(doc, mqtt_msg); if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) { -#ifdef DEBUG_LOG logging.println("Common info MQTT msg could not be sent"); -#endif // DEBUG_LOG return false; } else { set_event_MQTTpublished(event_handle); @@ -541,9 +529,7 @@ bool publish_events() { static bool publish_buttons_discovery(void) { if (ha_autodiscovery_enabled) { if (ha_buttons_published == false) { -#ifdef DEBUG_LOG logging.println("Publishing buttons discovery"); -#endif // DEBUG_LOG static JsonDocument doc; 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); -#ifdef DEBUG_LOG logging.printf("MQTT message arrived: [%.*s]\n", topic_len, topic); -#endif // DEBUG_LOG #ifdef REMOTE_BMS_RESET const char* bmsreset_topic = generateButtonTopic("BMSRESET").c_str(); if (strcmp(topic, bmsreset_topic) == 0) { -#ifdef DEBUG_LOG logging.println("Triggering BMS reset"); -#endif // DEBUG_LOG start_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(); subscribe(); -#ifdef DEBUG_LOG logging.println("MQTT connected"); -#endif // DEBUG_LOG break; case MQTT_EVENT_DISCONNECTED: set_event(EVENT_MQTT_DISCONNECT, 0); -#ifdef DEBUG_LOG logging.println("MQTT disconnected!"); -#endif // DEBUG_LOG break; case MQTT_EVENT_DATA: mqtt_message_received(event->topic, event->topic_len, event->data, event->data_len); break; case MQTT_EVENT_ERROR: -#ifdef DEBUG_LOG logging.println("MQTT_ERROR"); logging.print("reported from esp-tls"); 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.print("captured as transport's socket errno"); logging.println(strerror(event->error_handle->esp_transport_sock_errno)); -#endif // DEBUG_LOG break; } } @@ -723,9 +699,7 @@ void mqtt_loop(void) { if (client_started == false) { esp_mqtt_client_start(client); client_started = true; -#ifdef DEBUG_LOG logging.println("MQTT initialized"); -#endif // DEBUG_LOG return; } diff --git a/Software/src/devboard/sdcard/sdcard.cpp b/Software/src/devboard/sdcard/sdcard.cpp index 078b6301..0948c1b4 100644 --- a/Software/src/devboard/sdcard/sdcard.cpp +++ b/Software/src/devboard/sdcard/sdcard.cpp @@ -164,9 +164,7 @@ void init_logging_buffers() { #if defined(LOG_CAN_TO_SD) can_bufferHandle = xRingbufferCreate(32 * 1024, RINGBUF_TYPE_BYTEBUF); if (can_bufferHandle == NULL) { -#ifdef DEBUG_LOG logging.println("Failed to create CAN ring buffer!"); -#endif // DEBUG_LOG return; } #endif // defined(LOG_CAN_TO_SD) @@ -174,9 +172,7 @@ void init_logging_buffers() { #if defined(LOG_TO_SD) log_bufferHandle = xRingbufferCreate(1024, RINGBUF_TYPE_BYTEBUF); if (log_bufferHandle == NULL) { -#ifdef DEBUG_LOG logging.println("Failed to create log ring buffer!"); -#endif // DEBUG_LOG return; } #endif // defined(LOG_TO_SD) @@ -196,22 +192,16 @@ bool init_sdcard() { SD_MMC.setPins(sclk_pin, mosi_pin, miso_pin); if (!SD_MMC.begin("/root", true, true, SDMMC_FREQ_HIGHSPEED)) { set_event_latched(EVENT_SD_INIT_FAILED, 0); -#ifdef DEBUG_LOG logging.println("SD Card initialization failed!"); -#endif // DEBUG_LOG return false; } clear_event(EVENT_SD_INIT_FAILED); -#ifdef DEBUG_LOG logging.println("SD Card initialization successful."); -#endif // DEBUG_LOG sd_card_active = true; -#ifdef DEBUG_LOG log_sdcard_details(); -#endif // DEBUG_LOG return true; } diff --git a/Software/src/devboard/utils/events.cpp b/Software/src/devboard/utils/events.cpp index 2ce9c1bf..33dfbc87 100644 --- a/Software/src/devboard/utils/events.cpp +++ b/Software/src/devboard/utils/events.cpp @@ -159,9 +159,7 @@ void reset_all_events() { } events.level = EVENT_LEVEL_INFO; update_bms_status(); -#ifdef DEBUG_LOG logging.println("All events have been cleared."); -#endif } void set_event_MQTTpublished(EVENTS_ENUM_TYPE event) { diff --git a/Software/src/devboard/webserver/events_html.cpp b/Software/src/devboard/webserver/events_html.cpp index 737e8735..53fd4d14 100644 --- a/Software/src/devboard/webserver/events_html.cpp +++ b/Software/src/devboard/webserver/events_html.cpp @@ -46,12 +46,6 @@ String events_processor(const String& var) { EVENTS_ENUM_TYPE event_handle = event.event_handle; 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("
"); content.concat("
" + String(get_event_enum_string(event_handle)) + "
"); content.concat("
" + String(get_event_level_string(event_handle)) + "
"); diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index c40373f3..90dd64a0 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -1470,9 +1470,7 @@ void onOTAProgress(size_t current, size_t final) { // Log every 1 second if (millis() - ota_progress_millis > 1000) { ota_progress_millis = millis(); -#ifdef DEBUG_LOG logging.printf("OTA Progress Current: %u bytes, Final: %u bytes\n", current, final); -#endif // DEBUG_LOG // Reset the "watchdog" ota_timeout_timer.reset(); } @@ -1489,13 +1487,9 @@ void onOTAEnd(bool success) { // Max Charge/Discharge = 0; CAN = stop; contactors = open setBatteryPause(true, true, true, false); // a reboot will be done by the OTA library. no need to do anything here -#ifdef DEBUG_LOG logging.println("OTA update finished successfully!"); -#endif // DEBUG_LOG } else { -#ifdef DEBUG_LOG logging.println("There was an error during OTA update!"); -#endif // DEBUG_LOG //try to Resume the battery pause and CAN communication setBatteryPause(false, false); } diff --git a/Software/src/devboard/wifi/wifi.cpp b/Software/src/devboard/wifi/wifi.cpp index 58a98814..53425b0d 100644 --- a/Software/src/devboard/wifi/wifi.cpp +++ b/Software/src/devboard/wifi/wifi.cpp @@ -130,33 +130,22 @@ void wifi_monitor() { // Try WiFi.reconnect() if it was successfully connected at least once if (hasConnectedBefore) { lastReconnectAttempt = currentMillis; // Reset reconnection attempt timer -#ifdef DEBUG_LOG logging.println("Wi-Fi reconnect attempt..."); -#endif if (WiFi.reconnect()) { -#ifdef DEBUG_LOG logging.println("Wi-Fi reconnect attempt sucess..."); -#endif reconnectAttempts = 0; // Reset the attempt counter on successful reconnect } else { -#ifdef DEBUG_LOG logging.println("Wi-Fi reconnect attempt error..."); -#endif reconnectAttempts++; if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) { -#ifdef DEBUG_LOG logging.println("Failed to reconnect multiple times, forcing a full connection attempt..."); -#endif FullReconnectToWiFi(); } } } else { // If no previous connection, force a full connection attempt if (currentMillis - lastReconnectAttempt > current_full_reconnect_interval) { -#ifdef DEBUG_LOG logging.println("No previous OK connection, force a full connection attempt..."); -#endif - wifiap_enabled = true; WiFi.mode(WIFI_AP_STA); init_WiFi_AP(); @@ -188,17 +177,13 @@ void connectToWiFi() { if (WiFi.status() != WL_CONNECTED) { lastReconnectAttempt = millis(); // Reset the reconnect attempt timer -#ifdef DEBUG_LOG 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(), wifi_channel); WiFi.begin(ssid.c_str(), password.c_str(), wifi_channel); } else { -#ifdef DEBUG_LOG 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) { //clear disconnects events if we got a IP clear_event(EVENT_WIFI_DISCONNECT); -#ifdef DEBUG_LOG logging.print("Wi-Fi Got IP. "); logging.print("IP address: "); logging.println(WiFi.localIP().toString()); -#endif } // Event handler for Wi-Fi disconnection @@ -233,9 +216,7 @@ void onWifiDisconnect(WiFiEvent_t event, WiFiEventInfo_t info) { if (connected_once) { set_event(EVENT_WIFI_DISCONNECT, 0); } -#ifdef DEBUG_LOG logging.println("Wi-Fi disconnected."); -#endif //we dont do anything here, the reconnect will be handled by the monitor //too many events received when the connection is lost //normal reconnect retry start at first 2 seconds @@ -254,9 +235,7 @@ void init_mDNS() { // Initialize mDNS .local resolution if (!MDNS.begin(mdnsHost)) { -#ifdef DEBUG_LOG logging.println("Error setting up MDNS responder!"); -#endif } else { // Advertise via bonjour the service so we can auto discover these battery emulators on the local network. MDNS.addService(mdnsHost, "tcp", 80); diff --git a/Software/src/inverter/FOXESS-CAN.cpp b/Software/src/inverter/FOXESS-CAN.cpp index d9148d83..772120a6 100644 --- a/Software/src/inverter/FOXESS-CAN.cpp +++ b/Software/src/inverter/FOXESS-CAN.cpp @@ -523,40 +523,23 @@ void FoxessCanInverter::map_can_frame_to_variable(CAN_frame rx_frame) { if (rx_frame.ID == 0x1871) { 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] -//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. ,,
,,, -#ifdef DEBUG_LOG - logging.println("Inverter sends current time and date"); -#endif + //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. ,,
,,, } else if (rx_frame.data.u8[0] == 0x01) { if (rx_frame.data.u8[4] == 0x00) { -// Inverter wants to know bms info (every 1s) -#ifdef DEBUG_LOG - logging.println("Inverter requests 1s BMS info, we reply"); -#endif + // Inverter wants to know bms info (every 1s) send_bms_info = true; } 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) -#ifdef DEBUG_LOG - logging.println("Inverter requests individual battery pack status, we reply"); -#endif send_individual_pack_status = true; } 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) -#ifdef DEBUG_LOG - logging.println("Inverter requests cellvoltages and temps, we reply"); -#endif send_cellvoltages = true; } } else if (rx_frame.data.u8[0] == 0x02) { //0x1871 [0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00] -// Ack message -#ifdef DEBUG_LOG - logging.println("Inverter acks, no reply needed"); -#endif + // Ack message } else if (rx_frame.data.u8[0] == 0x05) { //0x1871 [0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00] -#ifdef DEBUG_LOG - logging.println("Inverter wants to know serial numbers, we reply"); -#endif + // Inverter wants to know serial numbers, we reply send_serial_numbers = true; } } diff --git a/Software/src/inverter/ModbusInverterProtocol.cpp b/Software/src/inverter/ModbusInverterProtocol.cpp index b669f955..244ebab3 100644 --- a/Software/src/inverter/ModbusInverterProtocol.cpp +++ b/Software/src/inverter/ModbusInverterProtocol.cpp @@ -35,9 +35,7 @@ ModbusMessage ModbusInverterProtocol::FC03(ModbusMessage request) { if ((addr + words) > MBPV_MAX) { // Yes - send respective error response 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); -#endif return response; } @@ -48,10 +46,6 @@ ModbusMessage ModbusInverterProtocol::FC03(ModbusMessage request) { response.add((uint16_t)(mbPV[addr + i])); } - // #ifdef DEBUG_LOG - // logging.printf("Modbus FC03 response: %d %d\n", addr, mbPV[addr]); - // #endif - return response; } @@ -67,9 +61,7 @@ ModbusMessage ModbusInverterProtocol::FC06(ModbusMessage request) { if ((addr) > MBPV_MAX) { // Yes - send respective error response 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); -#endif return response; } @@ -97,18 +89,14 @@ ModbusMessage ModbusInverterProtocol::FC16(ModbusMessage request) { || (words > 123)) // can't support more than this in request packet { // Yes - send respective error response 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); -#endif return response; } // Address overflow? if ((addr + words) > MBPV_MAX) { // Yes - send respective error response 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); -#endif return response; } @@ -145,20 +133,16 @@ ModbusMessage ModbusInverterProtocol::FC23(ModbusMessage request) { || (read_words > 125)) // can't fit more than this in the response packet { // Yes - send respective error response 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", write_addr, write_words, write_bytes, read_words); -#endif return response; } // Address overflow? if (((write_addr + write_words) > MBPV_MAX) || ((read_addr + read_words) > MBPV_MAX)) { // Yes - send respective error response 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, write_words, read_addr, read_words); -#endif return response; } diff --git a/Software/src/inverter/SMA-BYD-H-CAN.cpp b/Software/src/inverter/SMA-BYD-H-CAN.cpp index 8a878484..0b0184e5 100644 --- a/Software/src/inverter/SMA-BYD-H-CAN.cpp +++ b/Software/src/inverter/SMA-BYD-H-CAN.cpp @@ -227,9 +227,7 @@ void SmaBydHInverter::map_can_frame_to_variable(CAN_frame rx_frame) { break; case 0x5E7: //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"); -#endif // DEBUG_LOG pairing_events++; set_event(EVENT_SMA_PAIRING, pairing_events); datalayer.system.status.CAN_inverter_still_alive = CAN_STILL_ALIVE; diff --git a/Software/src/inverter/SMA-BYD-HVS-CAN.cpp b/Software/src/inverter/SMA-BYD-HVS-CAN.cpp index 4fa07ae7..1c4727aa 100644 --- a/Software/src/inverter/SMA-BYD-HVS-CAN.cpp +++ b/Software/src/inverter/SMA-BYD-HVS-CAN.cpp @@ -218,9 +218,7 @@ void SmaBydHvsInverter::map_can_frame_to_variable(CAN_frame rx_frame) { break; case 0x5E7: //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"); -#endif // DEBUG_LOG pairing_events++; set_event(EVENT_SMA_PAIRING, pairing_events); datalayer.system.status.CAN_inverter_still_alive = CAN_STILL_ALIVE; diff --git a/Software/src/inverter/SMA-TRIPOWER-CAN.cpp b/Software/src/inverter/SMA-TRIPOWER-CAN.cpp index 341ea255..172cd4c0 100644 --- a/Software/src/inverter/SMA-TRIPOWER-CAN.cpp +++ b/Software/src/inverter/SMA-TRIPOWER-CAN.cpp @@ -126,9 +126,7 @@ void SmaTripowerInverter::map_can_frame_to_variable(CAN_frame rx_frame) { break; case 0x5E7: //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"); -#endif // DEBUG_LOG pairing_events++; set_event(EVENT_SMA_PAIRING, pairing_events); datalayer.system.status.CAN_inverter_still_alive = CAN_STILL_ALIVE; diff --git a/Software/src/inverter/SOLAX-CAN.cpp b/Software/src/inverter/SOLAX-CAN.cpp index 16df4f2a..4117a2a9 100644 --- a/Software/src/inverter/SOLAX-CAN.cpp +++ b/Software/src/inverter/SOLAX-CAN.cpp @@ -147,9 +147,7 @@ void SolaxInverter::map_can_frame_to_variable(CAN_frame rx_frame) { switch (STATE) { case (BATTERY_ANNOUNCE): -#ifdef DEBUG_LOG logging.println("Solax Battery State: Announce"); -#endif datalayer.system.status.inverter_allows_contactor_closing = false; SOLAX_1875.data.u8[4] = (0x00); // Inform Inverter: Contactor 0=off, 1=on. 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_1801); // Announce that the battery will be connected STATE = CONTACTOR_CLOSED; // Jump to Contactor Closed State -#ifdef DEBUG_LOG logging.println("Solax Battery State: Contactor Closed"); -#endif break; 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)) { transmit_can_frame(&SOLAX_1881); transmit_can_frame(&SOLAX_1882); -#ifdef DEBUG_LOG logging.println("1871 05-frame received from inverter"); -#endif } if (rx_frame.ID == 0x1871 && rx_frame.data.u8[0] == (0x03)) { -#ifdef DEBUG_LOG logging.println("1871 03-frame received from inverter"); -#endif } }