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
7 changes: 7 additions & 0 deletions modules/EV/EvManager/main/car_simulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class CarSimulation {
sim_data.battery_charge_wh = config.dc_energy_capacity * (soc / 100.0);
}

void set_soc(double soc) {
if (soc < 0 || soc > 100) {
throw std::out_of_range("SoC value " + std::to_string(soc) + " is out of range (0-100)");
}
sim_data.battery_charge_wh = config.dc_energy_capacity * (soc / 100.0);
}

const SimState& get_state() const {
return sim_data.state;
}
Expand Down
14 changes: 14 additions & 0 deletions modules/EV/EvManager/main/car_simulatorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ void car_simulatorImpl::register_all_commands() {
EVLOG_error << "plugin command called but \"plugin_commands\" config key not set";
return true;
});
command_registry->register_command("set_soc", 1, [this](const CmdArguments& arguments) {
try {
double soc = std::stod(arguments.at(0));
this->car_simulation->set_soc(soc);
} catch (const std::invalid_argument& e) {
EVLOG_error << "set_soc command called with invalid argument: " << arguments.at(0);
return true;
} catch (const std::out_of_range& e) {
EVLOG_error << "set_soc command called with out of range argument: " << arguments.at(0);
return true;
}

return true;
});

if (!mod->r_slac.empty()) {
command_registry->register_command("iso_wait_slac_matched", 0, [this](const CmdArguments& arguments) {
Expand Down
Loading