Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions app/src/bat_charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,19 @@ bool battery_conf_check(BatConf *bat_conf)
.text = "Load Disconnecct Voltage must be higher than Absolute Min Voltage + 0.4" },
{ .func =
[bat_conf]() {
return bat_conf->internal_resistance
< bat_conf->load_disconnect_voltage * 0.1f / DISCHARGE_CURRENT_MAX;
return bat_conf->internal_resistance >= 0.0F
&& bat_conf->internal_resistance
< bat_conf->load_disconnect_voltage * 0.1f / DISCHARGE_CURRENT_MAX;
},
.text = "Internal Battery Resistance must not cause more than 10% drop at Max Discharge "
.text = "Internal Battery Resistance must be non-negative and cause at most 10% drop at Max Discharge "
"Current" },
{ .func =
[bat_conf]() {
return bat_conf->wire_resistance
< bat_conf->topping_voltage * 0.03f / DISCHARGE_CURRENT_MAX;
return bat_conf->wire_resistance >= 0.0F
&& bat_conf->wire_resistance
< bat_conf->topping_voltage * 0.03f / DISCHARGE_CURRENT_MAX;
},
.text = "Wire Resistances must not cause more than 3% drop at Max Discharge Current" },
.text = "Wire Resistance must be non-negative and cause at most 3% drop at Max Discharge Current" },
{ .func =
[bat_conf]() {
return bat_conf->topping_cutoff_current < (bat_conf->nominal_capacity / 10.0f);
Expand Down
14 changes: 14 additions & 0 deletions tests/src/tests_bat_charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,24 @@ void no_soc_below_0()
TEST_ASSERT(0);
}

void reject_negative_compensation_resistance()
{
init_structs();
bat_conf.internal_resistance = -0.01F;
TEST_ASSERT_FALSE(battery_conf_check(&bat_conf));
bat_conf.internal_resistance = 0.0F;
bat_conf.wire_resistance = -0.01F;
TEST_ASSERT_FALSE(battery_conf_check(&bat_conf));
bat_conf.wire_resistance = 0.0F;
TEST_ASSERT_TRUE(battery_conf_check(&bat_conf));
}

int bat_charger_tests()
{
UNITY_BEGIN();

RUN_TEST(reject_negative_compensation_resistance);

// startup of charging
RUN_TEST(no_start_at_high_voltage);
RUN_TEST(no_start_after_short_rest);
Expand Down