Skip to content

Commit

Permalink
charge_manager: Try to wake up chargers that charged once already.
Browse files Browse the repository at this point in the history
We don't want to block a charger forever if it has charged a vehicle
once. This change allows to wake those chargers up again, but with a
lower priority. Waking up those chargers only happens if we still have
current left over after all other chargers have received their fair
share.
  • Loading branch information
rtrbt committed Dec 10, 2021
1 parent 5b8a2db commit c130445
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions software/modules/backend/charge_manager/charge_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ ChargeManager::ChargeManager()
{"supported_current", Config::Uint16(0)},
{"allowed_current", Config::Uint16(0)},
{"wants_to_charge", Config::Bool(false)},
{"wants_to_charge_low_priority", Config::Bool(false)},
{"is_charging", Config::Bool(false)},

{"last_sent_config", Config::Uint32(0)},
Expand Down Expand Up @@ -194,6 +195,7 @@ void ChargeManager::start_manager_task()
target.get("uptime")->updateUint(uptime);

target.get("wants_to_charge")->updateBool((charging_time == 0 && charge_release == 3 && vehicle_state == 1) || vehicle_state == 2); // CHARGE_RELEASE_CHARGE_MANAGEMENT
target.get("wants_to_charge_low_priority")->updateBool(charging_time != 0 && charge_release == 3 && vehicle_state == 1); // CHARGE_RELEASE_CHARGE_MANAGEMENT
target.get("is_charging")->updateBool(vehicle_state == 2); //VEHICLE_STATE_CHARGING
target.get("allowed_current")->updateUint(allowed_charging_current);
target.get("supported_current")->updateUint(supported_current);
Expand Down Expand Up @@ -473,6 +475,49 @@ void ChargeManager::distribute_current()
}
}

if (available_current > 0) {
LOCAL_LOG("stage 0: %u mA still available. Attempting to wake up chargers that already charged their vehicle once.", available_current);

uint16_t current_to_set = charge_manager_config_in_use.get("minimum_current")->asUint();
for (int i = 0; i < chargers.size(); ++i) {
auto &charger = chargers[idx_array[i]];

if (!charger.get("wants_to_charge_low_priority")->asBool()) {
continue;
}

auto &charger_cfg = configs[idx_array[i]];

uint16_t supported_current = charger.get("supported_current")->asUint();
if (supported_current < current_to_set) {
LOCAL_LOG("stage 0: Can't unblock %s (%s): It only supports %u mA, but %u mA is the configured minimum current.",
charger_cfg.get("name")->asString().c_str(),
charger_cfg.get("host")->asString().c_str(),
supported_current,
current_to_set);
continue;
}

if (available_current < current_to_set) {
LOCAL_LOG("stage 0: %u mA left, but %u mA required to unblock another charger. Blocking all following chargers.",available_current, current_to_set);
current_to_set = 0;
}

if (current_to_set > 0) {
++chargers_allocated_current_to;
}

current_array[idx_array[i]] = current_to_set;
available_current -= current_to_set;

LOCAL_LOG("stage 0: Calculated target for %s (%s) of %u mA. %u mA left.",
charger_cfg.get("name")->asString().c_str(),
charger_cfg.get("host")->asString().c_str(),
current_to_set,
available_current);
}
}

// Throttle chargers
bool skip_stage_2 = false;
for (int i = 0; i < chargers.size(); ++i) {
Expand Down
1 change: 1 addition & 0 deletions software/modules/frontend/charge_manager/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface Charger {
supported_current: number,
allowed_current: number,
wants_to_charge: boolean,
wants_to_charge_low_priority: boolean,
is_charging: boolean,
last_sent_config: number,
allocated_current: number,
Expand Down

0 comments on commit c130445

Please sign in to comment.