diff --git a/modules/EvManager/main/car_simulation.cpp b/modules/EvManager/main/car_simulation.cpp index ae878a2c8..9313508a8 100644 --- a/modules/EvManager/main/car_simulation.cpp +++ b/modules/EvManager/main/car_simulation.cpp @@ -110,18 +110,25 @@ void CarSimulation::simulate_soc() { const double factor = MS_FACTOR * ms; double power = 0.0; types::evse_manager::EVInfo ev_info; - if (charge_ac) { - if (charge_three_phase) { - power = charge_current_a * config.ac_nominal_voltage * 3.0; - } else { - power = charge_current_a * config.ac_nominal_voltage; - } + switch (charge_mode) { + case ChargeMode::None: + // nothing to do + break; + case ChargeMode::AC: + power = charge_current_a * config.ac_nominal_voltage; ev_info.target_current = charge_current_a; ev_info.target_voltage = 0; - } else { + break; + case ChargeMode::ACThreePhase: + power = charge_current_a * config.ac_nominal_voltage * 3.0; + ev_info.target_current = charge_current_a; + ev_info.target_voltage = 0; + break; + case ChargeMode::DC: power = config.dc_target_current * config.dc_target_voltage; ev_info.target_current = config.dc_target_current; ev_info.target_voltage = config.dc_target_voltage; + break; } if (sim_data.battery_charge_wh > sim_data.battery_capacity_wh) { @@ -171,12 +178,10 @@ bool CarSimulation::draw_power_regulated(const CmdArguments& arguments) { r_ev_board_support->call_set_ac_max_current(charge_current_a); if (arguments[1] == constants::THREE_PHASES) { r_ev_board_support->call_set_three_phases(true); - charge_ac = true; - charge_three_phase = true; + charge_mode = ChargeMode::ACThreePhase; } else { r_ev_board_support->call_set_three_phases(false); - charge_ac = true; - charge_three_phase = false; + charge_mode = ChargeMode::AC; } sim_data.state = SimState::CHARGING_REGULATED; return true; @@ -187,12 +192,10 @@ bool CarSimulation::draw_power_fixed(const CmdArguments& arguments) { r_ev_board_support->call_set_ac_max_current(charge_current_a); if (arguments[1] == constants::THREE_PHASES) { r_ev_board_support->call_set_three_phases(true); - charge_ac = true; - charge_three_phase = true; + charge_mode = ChargeMode::ACThreePhase; } else { r_ev_board_support->call_set_three_phases(false); - charge_ac = true; - charge_three_phase = false; + charge_mode = ChargeMode::AC; } sim_data.state = SimState::CHARGING_FIXED; return true; @@ -205,6 +208,7 @@ bool CarSimulation::pause(const CmdArguments& arguments) { bool CarSimulation::unplug(const CmdArguments& arguments) { sim_data.state = SimState::UNPLUGGED; + charge_mode = ChargeMode::None; return true; } @@ -256,8 +260,7 @@ bool CarSimulation::iso_dc_power_on(const CmdArguments& arguments) { if (sim_data.dc_power_on) { sim_data.state = SimState::ISO_CHARGING_REGULATED; r_ev_board_support->call_allow_power_on(true); - charge_ac = false; - charge_three_phase = false; + charge_mode = ChargeMode::DC; return true; } return false; @@ -269,17 +272,14 @@ bool CarSimulation::iso_start_v2g_session(const CmdArguments& arguments, bool th if (energy_mode == constants::AC) { if (three_phases == false) { r_ev[0]->call_start_charging(types::iso15118_ev::EnergyTransferMode::AC_single_phase_core); - charge_ac = true; - charge_three_phase = false; + charge_mode = ChargeMode::AC; } else { r_ev[0]->call_start_charging(types::iso15118_ev::EnergyTransferMode::AC_three_phase_core); - charge_ac = true; - charge_three_phase = true; + charge_mode = ChargeMode::ACThreePhase; } } else if (energy_mode == constants::DC) { r_ev[0]->call_start_charging(types::iso15118_ev::EnergyTransferMode::DC_extended); - charge_ac = false; - charge_three_phase = false; + charge_mode = ChargeMode::DC; } else { return false; } @@ -291,12 +291,10 @@ bool CarSimulation::iso_draw_power_regulated(const CmdArguments& arguments) { r_ev_board_support->call_set_ac_max_current(charge_current_a); if (arguments[1] == constants::THREE_PHASES) { r_ev_board_support->call_set_three_phases(true); - charge_ac = true; - charge_three_phase = true; + charge_mode = ChargeMode::ACThreePhase; } else { r_ev_board_support->call_set_three_phases(false); - charge_ac = true; - charge_three_phase = false; + charge_mode = ChargeMode::AC; } sim_data.state = SimState::ISO_CHARGING_REGULATED; return true; @@ -306,6 +304,7 @@ bool CarSimulation::iso_stop_charging(const CmdArguments& arguments) { r_ev[0]->call_stop_charging(); r_ev_board_support->call_allow_power_on(false); sim_data.state = SimState::PLUGGED_IN; + charge_mode = ChargeMode::None; return true; } diff --git a/modules/EvManager/main/car_simulation.hpp b/modules/EvManager/main/car_simulation.hpp index cc40ee51e..0613bb8d4 100644 --- a/modules/EvManager/main/car_simulation.hpp +++ b/modules/EvManager/main/car_simulation.hpp @@ -113,8 +113,13 @@ class CarSimulation { const module::Conf& config; std::chrono::time_point timepoint_last_update; double charge_current_a{0}; - bool charge_ac{false}; - bool charge_three_phase{false}; + + enum class ChargeMode { + None, + AC, + ACThreePhase, + DC, + } charge_mode{ChargeMode::None}; const std::unique_ptr& r_ev_board_support; const std::vector>& r_ev;