Skip to content

Commit

Permalink
inlined processSegment
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiaswong6 committed Jan 21, 2025
1 parent 2191d6a commit ee3e0ba
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions firmware/quadruna/BMS/src/app/app_diagnosticsMode.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,25 @@ void (*cellVoltageSetters[ACCUMULATOR_NUM_SEGMENTS][ACCUMULATOR_NUM_SERIES_CELLS
}
};

// Helper function to process a segment
void processSegment(uint8_t segment)
void app_diagnosticsMode_calculateDiagnosticTemperatureStats(void)
{
for (uint8_t cell = 0; cell < 16; cell++)
for (uint8_t curr_segment = 0U; curr_segment < ACCUMULATOR_NUM_SEGMENTS; curr_segment++)
{
cellVoltageSetters[segment][cell](io_ltc6813CellVoltages_getCellVoltage(segment, cell));
float sum_segment_temp = 0U;
for (uint8_t curr_reg_group = 0U; curr_reg_group < NUM_OF_AUX_REGISTER_GROUPS; curr_reg_group++)
{
for (uint8_t curr_thermistor = 0U; curr_thermistor < NUM_OF_READINGS_PER_REG_GROUP; curr_thermistor++)
{
if (IS_CELL_TEMP_READING(curr_reg_group, curr_thermistor))
{
const float curr_cell_temp = io_ltc6813CellTemperatures_getSpecificCellTempDegC(
curr_segment, curr_reg_group, curr_thermistor);
sum_segment_temp += curr_cell_temp;
}
}
}

segment_temps[curr_segment] = (uint8_t)(sum_segment_temp / NUM_OF_THERMISTORS_PER_SEGMENT);
}
}

Expand All @@ -76,28 +89,14 @@ void app_diagnosticsMode_broadcast(void)
// Update all cell voltages
for (uint8_t segment = 0; segment < 5; segment++)
{
processSegment(segment);
}

// Calculate and update all segment temperatures
for (uint8_t curr_segment = 0U; curr_segment < ACCUMULATOR_NUM_SEGMENTS; curr_segment++)
{
float sum_segment_temp = 0U;
for (uint8_t curr_reg_group = 0U; curr_reg_group < NUM_OF_AUX_REGISTER_GROUPS; curr_reg_group++)
for (uint8_t cell = 0; cell < 16; cell++)
{
for (uint8_t curr_thermistor = 0U; curr_thermistor < NUM_OF_READINGS_PER_REG_GROUP; curr_thermistor++)
{
if (IS_CELL_TEMP_READING(curr_reg_group, curr_thermistor))
{
const float curr_cell_temp = io_ltc6813CellTemperatures_getSpecificCellTempDegC(
curr_segment, curr_reg_group, curr_thermistor);
sum_segment_temp += curr_cell_temp;
}
}
cellVoltageSetters[segment][cell](io_ltc6813CellVoltages_getCellVoltage(segment, cell));
}

segment_temps[curr_segment] = (uint8_t)(sum_segment_temp / NUM_OF_THERMISTORS_PER_SEGMENT);
}

// Calculate and update all segment temperatures
app_diagnosticsMode_calculateDiagnosticTemperatureStats();
app_canTx_BMS_Seg0_Temp_set(segment_temps[0]);
app_canTx_BMS_Seg1_Temp_set(segment_temps[1]);
app_canTx_BMS_Seg2_Temp_set(segment_temps[2]);
Expand Down

0 comments on commit ee3e0ba

Please sign in to comment.