Skip to content

Commit

Permalink
- prevent from divide-by-zero
Browse files Browse the repository at this point in the history
  • Loading branch information
meikjaeckle committed Feb 9, 2024
1 parent 155f57b commit 7095642
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/BmsData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ void setBmsChargePercentage(uint8_t devNr, uint8_t value)
bo_SOC100CellvolHasBeenReached[devNr]=true;
value=100;
}
else if(u16_CellvoltSoc100>0 && u16_CellvoltSoc0>0){
else if((u16_CellvoltSoc0 > 0) &&
(u16_CellvoltSoc100 > u16_CellvoltSoc0)) // Prevents from divide-by-zero and implict verifies (u16_CellvoltSoc100 > 0)
{
//Berechne SOC Linear
const int32_t hi = bmsData.bmsMaxCellVoltage[devNr];
const int32_t lo = bmsData.bmsMinCellVoltage[devNr];
Expand Down
6 changes: 5 additions & 1 deletion src/Canbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,11 @@ void sendCanMsg_355()
}
}

if(u8_lMultiBmsSocHandling==OPTION_MULTI_BMS_SOC_AVG) msgData.soc = (u16_avgSoc/u8_numberOfSocs);
if ((u8_numberOfSocs > 0) && // Prevents from divide-by-zero
(u8_lMultiBmsSocHandling==OPTION_MULTI_BMS_SOC_AVG))
{
msgData.soc = (u16_avgSoc / u8_numberOfSocs);
}
}
else if(u8_lMultiBmsSocHandling==OPTION_MULTI_BMS_SOC_BMS) // Wenn SoC durch ein bestimmtes BMS geregelt werden soll
{
Expand Down

0 comments on commit 7095642

Please sign in to comment.