Skip to content

Commit

Permalink
Merge pull request #731 from dalathegreat/bugfix/leaf-cellv-regression
Browse files Browse the repository at this point in the history
Regression: LEAF, Speedup polling, fix requests for cellvoltage
  • Loading branch information
dalathegreat authored Jan 2, 2025
2 parents 184d929 + b3435e6 commit af53aa6
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Software/src/battery/NISSAN-LEAF-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CAN_frame LEAF_GROUP_REQUEST = {.FD = false,
.ext_ID = false,
.DLC = 8,
.ID = 0x79B,
.data = {0x02, 0x21, PIDgroups[0], 0, 0, 0, 0, 0}};
.data = {2, 0x21, 1, 0, 0, 0, 0, 0}};
CAN_frame LEAF_NEXT_LINE_REQUEST = {.FD = false,
.ext_ID = false,
.DLC = 8,
Expand Down Expand Up @@ -110,8 +110,8 @@ static bool battery_Batt_Heater_Mail_Send_Request = false; //Stores info when a
static uint8_t battery_request_idx = 0;
static uint8_t group_7bb = 0;
static bool stop_battery_query = true;
static uint8_t hold_off_with_polling_10seconds = 10;
static uint16_t battery_cell_voltages[97]; //array with all the cellvoltages
static uint8_t hold_off_with_polling_10seconds = 2; //Paused for 20 seconds on startup
static uint16_t battery_cell_voltages[97]; //array with all the cellvoltages
static uint8_t battery_cellcounter = 0;
static uint16_t battery_min_max_voltage[2]; //contains cell min[0] and max[1] values in mV
static uint16_t battery_HX = 0; //Internal resistance
Expand Down Expand Up @@ -612,10 +612,11 @@ void handle_incoming_can_frame_battery2(CAN_frame rx_frame) {
//First check which group data we are getting
if (rx_frame.data.u8[0] == 0x10) { //First message of a group
battery2_group_7bb = rx_frame.data.u8[3];
transmit_can_frame(&LEAF_NEXT_LINE_REQUEST, can_config.battery_double);
}

if (battery2_group_7bb == 1) //High precision SOC, Current, voltages etc.
transmit_can_frame(&LEAF_NEXT_LINE_REQUEST, can_config.battery_double);

if (battery2_group_7bb == 0x01) //High precision SOC, Current, voltages etc.
{
if (rx_frame.data.u8[0] == 0x10) { //First frame
//High precision battery2_current_1 resides here, but has been deemed unusable by 62kWh owners
Expand All @@ -633,7 +634,7 @@ void handle_incoming_can_frame_battery2(CAN_frame rx_frame) {
}
}

if (battery2_group_7bb == 2) //Cell Voltages
if (battery2_group_7bb == 0x02) //Cell Voltages
{
if (rx_frame.data.u8[0] == 0x10) { //first frame is anomalous
battery2_request_idx = 0;
Expand Down Expand Up @@ -676,7 +677,7 @@ void handle_incoming_can_frame_battery2(CAN_frame rx_frame) {
}
}

if (battery2_group_7bb == 4) { //Temperatures
if (battery2_group_7bb == 0x04) { //Temperatures
if (rx_frame.data.u8[0] == 0x10) { //First message
battery2_temp_raw_1 = (rx_frame.data.u8[4] << 8) | rx_frame.data.u8[5];
battery2_temp_raw_2_highnibble = rx_frame.data.u8[7];
Expand Down Expand Up @@ -869,11 +870,11 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
//First check which group data we are getting
if (rx_frame.data.u8[0] == 0x10) { //First message of a group
group_7bb = rx_frame.data.u8[3];

transmit_can_frame(&LEAF_NEXT_LINE_REQUEST, can_config.battery); //Request the next frame for the group
}

if (group_7bb == 1) //High precision SOC, Current, voltages etc.
transmit_can_frame(&LEAF_NEXT_LINE_REQUEST, can_config.battery); //Request the next frame for the group

if (group_7bb == 0x01) //High precision SOC, Current, voltages etc.
{
if (rx_frame.data.u8[0] == 0x10) { //First frame
//High precision Battery_current_1 resides here, but has been deemed unusable by 62kWh owners
Expand All @@ -891,7 +892,7 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
}
}

if (group_7bb == 2) //Cell Voltages
if (group_7bb == 0x02) //Cell Voltages
{
if (rx_frame.data.u8[0] == 0x10) { //first frame is anomalous
battery_request_idx = 0;
Expand Down Expand Up @@ -934,7 +935,7 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
}
}

if (group_7bb == 4) { //Temperatures
if (group_7bb == 0x04) { //Temperatures
if (rx_frame.data.u8[0] == 0x10) { //First message
battery_temp_raw_1 = (rx_frame.data.u8[4] << 8) | rx_frame.data.u8[5];
battery_temp_raw_2_highnibble = rx_frame.data.u8[7];
Expand Down

0 comments on commit af53aa6

Please sign in to comment.