diff --git a/Software/src/battery/VOLVO-SPA-BATTERY.cpp b/Software/src/battery/VOLVO-SPA-BATTERY.cpp index dabd9f14..8b28d0df 100644 --- a/Software/src/battery/VOLVO-SPA-BATTERY.cpp +++ b/Software/src/battery/VOLVO-SPA-BATTERY.cpp @@ -7,7 +7,6 @@ void VolvoSpaBattery:: update_values() { //This function maps all the values fetched via CAN to the correct parameters used for the inverter - uint8_t cnt = 0; // Update webserver datalayer datalayer_extended.VolvoPolestar.soc_bms = SOC_BMS; @@ -88,6 +87,7 @@ void VolvoSpaBattery:: } #ifdef DEBUG_LOG + uint8_t cnt = 0; logging.print("BMS reported SOC%: "); logging.println(SOC_BMS); logging.print("Calculated SOC%: "); @@ -127,6 +127,7 @@ void VolvoSpaBattery:: logging.print(cell_voltages[cnt++]); logging.print(","); } + cnt = 0; logging.println(";"); #endif } @@ -272,18 +273,33 @@ void VolvoSpaBattery::handle_incoming_can_frame(CAN_frame rx_frame) { (rx_frame.data.u8[3] == 0x42)) // BECM module voltage supply { datalayer_extended.VolvoPolestar.BECMsupplyVoltage = ((rx_frame.data.u8[4] << 8) | rx_frame.data.u8[5]); + transmit_can_frame(&VOLVO_BECM_HVIL_Status_Req); //Send HVIL status readout command + } else if ((rx_frame.data.u8[0] == 0x04) && (rx_frame.data.u8[1] == 0x62) && (rx_frame.data.u8[2] == 0x49) && + (rx_frame.data.u8[3] == 0x1A)) // BECM HVIL status + { + datalayer_extended.VolvoPolestar.HVILstatusBits = (rx_frame.data.u8[4]); + transmit_can_frame(&VOLVO_DTCreadout); //Send DTC readout command } else if ((rx_frame.data.u8[0] == 0x10) && (rx_frame.data.u8[1] == 0x0B) && (rx_frame.data.u8[2] == 0x62) && (rx_frame.data.u8[3] == 0x4B)) // First response frame of cell voltages { cell_voltages[battery_request_idx++] = ((rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6]); cell_voltages[battery_request_idx] = (rx_frame.data.u8[7] << 8); transmit_can_frame(&VOLVO_FlowControl); // Send flow control - rxConsecutiveFrames = 1; + rxConsecutiveFrames = true; } else if ((rx_frame.data.u8[0] == 0x10) && (rx_frame.data.u8[2] == 0x59) && (rx_frame.data.u8[3] == 0x03)) // First response frame for DTC with more than one code { + datalayer_extended.VolvoPolestar.DTCcount = ((rx_frame.data.u8[1] - 2) / 4); transmit_can_frame(&VOLVO_FlowControl); // Send flow control - } else if ((rx_frame.data.u8[0] == 0x21) && (rxConsecutiveFrames == 1)) { + } else if ((rx_frame.data.u8[1] == 0x59) && + (rx_frame.data.u8[2] == 0x03)) // Response frame for DTC with 0 or 1 code + { + if (rx_frame.data.u8[0] != 0x02) { + datalayer_extended.VolvoPolestar.DTCcount = 1; + } else { + datalayer_extended.VolvoPolestar.DTCcount = 0; + } + } else if ((rx_frame.data.u8[0] == 0x21) && (rxConsecutiveFrames)) { cell_voltages[battery_request_idx++] = cell_voltages[battery_request_idx] | rx_frame.data.u8[1]; cell_voltages[battery_request_idx++] = (rx_frame.data.u8[2] << 8) | rx_frame.data.u8[3]; cell_voltages[battery_request_idx++] = (rx_frame.data.u8[4] << 8) | rx_frame.data.u8[5]; @@ -303,7 +319,7 @@ void VolvoSpaBattery::handle_incoming_can_frame(CAN_frame rx_frame) { } transmit_can_frame(&VOLVO_SOH_Req); //Send SOH read request } - rxConsecutiveFrames = 0; + rxConsecutiveFrames = false; } break; default: @@ -314,7 +330,7 @@ void VolvoSpaBattery::handle_incoming_can_frame(CAN_frame rx_frame) { void VolvoSpaBattery::readCellVoltages() { battery_request_idx = 0; batteryModuleNumber = 0x10; - rxConsecutiveFrames = 0; + rxConsecutiveFrames = false; VOLVO_CELL_U_Req.data.u8[3] = batteryModuleNumber++; transmit_can_frame(&VOLVO_CELL_U_Req); //Send cell voltage read request for first module } diff --git a/Software/src/battery/VOLVO-SPA-BATTERY.h b/Software/src/battery/VOLVO-SPA-BATTERY.h index f9264f66..b5d4fcad 100644 --- a/Software/src/battery/VOLVO-SPA-BATTERY.h +++ b/Software/src/battery/VOLVO-SPA-BATTERY.h @@ -64,7 +64,7 @@ class VolvoSpaBattery : public CanBattery { uint16_t HvBattPwrLimChrgSlowAgi = 0; //0x177 uint8_t batteryModuleNumber = 0x10; // First battery module uint8_t battery_request_idx = 0; - uint8_t rxConsecutiveFrames = 0; + bool rxConsecutiveFrames = false; uint16_t min_max_voltage[2]; //contains cell min[0] and max[1] values in mV uint8_t cellcounter = 0; uint16_t cell_voltages[108]; //array with all the cellvoltages @@ -75,21 +75,17 @@ class VolvoSpaBattery : public CanBattery { .ext_ID = false, .DLC = 8, .ID = 0x536, - //.data = {0x00, 0x40, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00}}; //Network manage frame .data = {0x00, 0x40, 0x40, 0x01, 0x00, 0x00, 0x00, 0x00}}; //Network manage frame - CAN_frame VOLVO_140_CLOSE = {.FD = false, .ext_ID = false, .DLC = 8, .ID = 0x140, .data = {0x00, 0x02, 0x00, 0xB7, 0xFF, 0x03, 0xFF, 0x82}}; //Close contactors message - CAN_frame VOLVO_140_OPEN = {.FD = false, .ext_ID = false, .DLC = 8, .ID = 0x140, .data = {0x00, 0x02, 0x00, 0x9E, 0xFF, 0x03, 0xFF, 0x82}}; //Open contactor message - CAN_frame VOLVO_372 = { .FD = false, .ext_ID = false, @@ -117,6 +113,12 @@ class VolvoSpaBattery : public CanBattery { .DLC = 8, .ID = 0x735, .data = {0x03, 0x22, 0xF4, 0x42, 0x00, 0x00, 0x00, 0x00}}; //BECM supply voltage request frame + CAN_frame VOLVO_BECM_HVIL_Status_Req = { + .FD = false, + .ext_ID = false, + .DLC = 8, + .ID = 0x735, + .data = {0x03, 0x22, 0x49, 0x1A, 0x00, 0x00, 0x00, 0x00}}; //BECM HVIL status request frame CAN_frame VOLVO_DTC_Erase = {.FD = false, .ext_ID = false, .DLC = 8, diff --git a/Software/src/battery/VOLVO-SPA-HTML.h b/Software/src/battery/VOLVO-SPA-HTML.h index dd65c9a2..9d832d51 100644 --- a/Software/src/battery/VOLVO-SPA-HTML.h +++ b/Software/src/battery/VOLVO-SPA-HTML.h @@ -9,11 +9,11 @@ class VolvoSpaHtmlRenderer : public BatteryHtmlRenderer { public: String get_status_html() { String content; - - content += "