Skip to content

Commit

Permalink
Replace charge_ac and charge_three_phase bool members with charge_mod…
Browse files Browse the repository at this point in the history
…e enum

Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
  • Loading branch information
hikinggrass committed Nov 7, 2024
1 parent 536e8fb commit 17c9998
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
53 changes: 26 additions & 27 deletions modules/EvManager/main/car_simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
9 changes: 7 additions & 2 deletions modules/EvManager/main/car_simulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ class CarSimulation {
const module::Conf& config;
std::chrono::time_point<std::chrono::steady_clock> timepoint_last_update;
double charge_current_a{0};

Check notice on line 115 in modules/EvManager/main/car_simulation.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/EvManager/main/car_simulation.hpp#L115

class member 'CarSimulation::charge_current_a' is never used.
bool charge_ac{false};
bool charge_three_phase{false};

enum class ChargeMode {
None,
AC,
ACThreePhase,
DC,
} charge_mode{ChargeMode::None};

const std::unique_ptr<ev_board_supportIntf>& r_ev_board_support;
const std::vector<std::unique_ptr<ISO15118_evIntf>>& r_ev;
Expand Down

0 comments on commit 17c9998

Please sign in to comment.