Skip to content

Commit

Permalink
refactors variable and function names to snake_case
Browse files Browse the repository at this point in the history
Signed-off-by: MarzellT <tobias.marzell@pionix.de>
  • Loading branch information
MarzellT committed May 17, 2024
1 parent b530847 commit 2610a92
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 190 deletions.
54 changes: 27 additions & 27 deletions modules/EvManager/main/CarSimulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@
void CarSimulation::state_machine() {
using types::ev_board_support::EvCpState;

const auto stateHasChanged = sim_data.state != sim_data.lastState;
sim_data.lastState = sim_data.state;
const auto state_has_changed = sim_data.state != sim_data.last_state;
sim_data.last_state = sim_data.state;

switch (sim_data.state) {
case SimState::UNPLUGGED:
if (stateHasChanged) {
if (state_has_changed) {

r_ev_board_support->call_set_cp_state(EvCpState::A);
r_ev_board_support->call_allow_power_on(false);
// Wait for physical plugin (ev BSP sees state A on CP and not Disconnected)

sim_data.slacState = "UNMATCHED";
sim_data.slac_state = "UNMATCHED";
r_ev[0]->call_stop_charging();
}
break;
case SimState::PLUGGED_IN:
if (stateHasChanged) {
if (state_has_changed) {
r_ev_board_support->call_set_cp_state(EvCpState::B);
r_ev_board_support->call_allow_power_on(false);
}
break;
case SimState::CHARGING_REGULATED:
if (stateHasChanged || sim_data.pwm_duty_cycle != sim_data.last_pwm_duty_cycle) {
if (state_has_changed || sim_data.pwm_duty_cycle != sim_data.last_pwm_duty_cycle) {
sim_data.last_pwm_duty_cycle = sim_data.pwm_duty_cycle;
// do not draw power if EVSE paused by stopping PWM
if (sim_data.pwm_duty_cycle > 7.0 && sim_data.pwm_duty_cycle < 97.0) {
Expand All @@ -43,32 +43,32 @@ void CarSimulation::state_machine() {
break;
case SimState::CHARGING_FIXED:
// Todo(sl): What to do here
if (stateHasChanged) {
if (state_has_changed) {
// Also draw power if EVSE stopped PWM - this is a break the rules simulator->mode to test the charging
// implementation!
r_ev_board_support->call_set_cp_state(EvCpState::C);
}
break;

case SimState::ERROR_E:
if (stateHasChanged) {
if (state_has_changed) {
r_ev_board_support->call_set_cp_state(EvCpState::E);
r_ev_board_support->call_allow_power_on(false);
}
break;
case SimState::DIODE_FAIL:
if (stateHasChanged) {
if (state_has_changed) {
r_ev_board_support->call_diode_fail(true);
r_ev_board_support->call_allow_power_on(false);
}
break;
case SimState::ISO_POWER_READY:
if (stateHasChanged) {
if (state_has_changed) {
r_ev_board_support->call_set_cp_state(EvCpState::C);
}
break;
case SimState::ISO_CHARGING_REGULATED:
if (stateHasChanged) {
if (state_has_changed) {
r_ev_board_support->call_set_cp_state(EvCpState::C);
}
break;
Expand All @@ -89,14 +89,14 @@ void CarSimulation::state_machine() {
};

bool CarSimulation::sleep(const CmdArguments& arguments, size_t loop_interval_ms) {
if (!sim_data.sleepTicksLeft.has_value()) {
const auto sleepTime = std::stold(arguments[0]);
const auto sleepTimeMs = sleepTime * 1000;
sim_data.sleepTicksLeft = static_cast<long long>(sleepTimeMs / loop_interval_ms) + 1;
if (!sim_data.sleep_ticks_left.has_value()) {
const auto sleep_time = std::stold(arguments[0]);
const auto sleep_time_ms = sleep_time * 1000;
sim_data.sleep_ticks_left = static_cast<long long>(sleep_time_ms / loop_interval_ms) + 1;
}
sim_data.sleepTicksLeft = sim_data.sleepTicksLeft.value() - 1;
if (!(sim_data.sleepTicksLeft > 0)) {
sim_data.sleepTicksLeft.reset();
sim_data.sleep_ticks_left = sim_data.sleep_ticks_left.value() - 1;
if (!(sim_data.sleep_ticks_left > 0)) {
sim_data.sleep_ticks_left.reset();
return true;
} else {
return false;
Expand Down Expand Up @@ -149,22 +149,22 @@ bool CarSimulation::diode_fail(const CmdArguments& arguments) {
return true;
}
bool CarSimulation::rcd_current(const CmdArguments& arguments) {
sim_data.rcd_current_mA = std::stof(arguments[0]);
sim_data.rcd_current_ma = std::stof(arguments[0]);
return true;
}
bool CarSimulation::iso_wait_slac_matched(const CmdArguments& arguments) {
sim_data.state = SimState::PLUGGED_IN;

if (sim_data.slacState == "UNMATCHED") {
if (sim_data.slac_state == "UNMATCHED") {
EVLOG_debug << "Slac UNMATCHED";
if (!r_slac.empty()) {
EVLOG_debug << "Slac trigger matching";
r_slac[0]->call_reset();
r_slac[0]->call_trigger_matching();
sim_data.slacState = "TRIGGERED";
sim_data.slac_state = "TRIGGERED";
}
}
if (sim_data.slacState == "MATCHED") {
if (sim_data.slac_state == "MATCHED") {
EVLOG_debug << "Slac Matched";
return true;
}
Expand Down Expand Up @@ -219,12 +219,12 @@ bool CarSimulation::iso_stop_charging(const CmdArguments& arguments) {
return true;
}
bool CarSimulation::iso_wait_for_stop(const CmdArguments& arguments, size_t loop_interval_ms) {
if (!sim_data.sleepTicksLeft.has_value()) {
sim_data.sleepTicksLeft =
if (!sim_data.sleep_ticks_left.has_value()) {
sim_data.sleep_ticks_left =
std::stoll(arguments[0]) * static_cast<long>(1 / static_cast<float>(loop_interval_ms)) + 1;
}
sim_data.sleepTicksLeft = sim_data.sleepTicksLeft.value() - 1;
if (!sim_data.sleepTicksLeft > 0) {
sim_data.sleep_ticks_left = sim_data.sleep_ticks_left.value() - 1;
if (!sim_data.sleep_ticks_left > 0) {
r_ev[0]->call_stop_charging();
r_ev_board_support->call_allow_power_on(false);
sim_data.state = SimState::PLUGGED_IN;
Expand Down Expand Up @@ -264,7 +264,7 @@ bool CarSimulation::iso_start_bcb_toggle(const CmdArguments& arguments) {
}
bool CarSimulation::wait_for_real_plugin(const CmdArguments& arguments) {
using types::board_support_common::Event;
if (sim_data.actualBspEvent == Event::A) {
if (sim_data.actual_bsp_event == Event::A) {
EVLOG_info << "Real plugin detected";
sim_data.state = SimState::PLUGGED_IN;
return true;
Expand Down
40 changes: 20 additions & 20 deletions modules/EvManager/main/CarSimulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,52 +24,52 @@ class CarSimulation {
sim_data = SimulationData();
}

const SimState& getState() const {
const SimState& get_state() const {
return sim_data.state;
}

void set_state(SimState state) {
sim_data.state = state;
}

void setBspEvent(types::board_support_common::Event event) {
sim_data.actualBspEvent = event;
void set_bsp_event(types::board_support_common::Event event) {
sim_data.actual_bsp_event = event;
}

void setPp(types::board_support_common::Ampacity pp) {
void set_pp(types::board_support_common::Ampacity pp) {
sim_data.pp = pp;
}

void setRcdCurrent(float rcdCurrent) {
sim_data.rcd_current_mA = rcdCurrent;
void setr_rcd_current(float rcd_current) {
sim_data.rcd_current_ma = rcd_current;
}

void setPwmDutyCycle(float pwmDutyCycle) {
sim_data.pwm_duty_cycle = pwmDutyCycle;
void set_pwm_duty_cycle(float pwm_duty_cycle) {
sim_data.pwm_duty_cycle = pwm_duty_cycle;
}

void setSlacState(std::string slacState) {
sim_data.slacState = std::move(slacState);
void set_slac_state(std::string slac_state) {
sim_data.slac_state = std::move(slac_state);
}

void setIsoPwrReady(bool isoPwrReady) {
sim_data.iso_pwr_ready = isoPwrReady;
void set_iso_pwr_ready(bool iso_pwr_ready) {
sim_data.iso_pwr_ready = iso_pwr_ready;
}

void setEVSEMaxCurrent(size_t evseMaxCurrent) {
sim_data.evse_maxcurrent = evseMaxCurrent;
void set_evse_max_current(size_t evse_max_current) {
sim_data.evse_maxcurrent = evse_max_current;
}

void setIsoStopped(bool isoStopped) {
sim_data.iso_stopped = isoStopped;
void set_iso_stopped(bool iso_stopped) {
sim_data.iso_stopped = iso_stopped;
}

void setV2gFinished(bool v2gFinished) {
sim_data.v2g_finished = v2gFinished;
void set_v2g_finished(bool v2g_finished) {
sim_data.v2g_finished = v2g_finished;
}

void setDcPowerOn(bool dcPowerOn) {
sim_data.dc_power_on = dcPowerOn;
void set_dc_power_on(bool dc_power_on) {
sim_data.dc_power_on = dc_power_on;
}

void state_machine();
Expand Down
65 changes: 33 additions & 32 deletions modules/EvManager/main/SimulationCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@
#include <string>
#include <vector>

SimulationCommand::SimulationCommand(const RegisteredCommandBase* registeredCommandIn, const CmdArguments& arguments) :
arguments{arguments}, registeredCommand{registeredCommandIn} {
SimulationCommand::SimulationCommand(const RegisteredCommandBase* registered_command_in,
const CmdArguments& arguments_in) :
arguments{arguments_in}, registered_command{registered_command_in} {
}

bool SimulationCommand::execute() const {
return (*registeredCommand)(arguments);
return (*registered_command)(arguments);
}

std::queue<SimulationCommand> SimulationCommand::parseSimCommands(const std::string& value,
const CommandRegistry& commandRegistry) {
auto commandsVector{convertCommandsStringToVector(value)};
std::queue<SimulationCommand> SimulationCommand::parse_sim_commands(const std::string& value,
const CommandRegistry& command_registry) {
auto commands_vector{convert_commands_string_to_vector(value)};

auto commandsWithArguments{splitIntoCommandsWithArguments(commandsVector)};
auto commands_with_arguments{split_into_commands_with_arguments(commands_vector)};

return compileCommands(commandsWithArguments, commandRegistry);
return compile_commands(commands_with_arguments, command_registry);
}

SimulationCommand::RawCommands SimulationCommand::convertCommandsStringToVector(const std::string& commandsView) {
SimulationCommand::RawCommands SimulationCommand::convert_commands_string_to_vector(const std::string& commands_view) {

auto commands = std::string{commandsView};
auto commands = std::string{commands_view};

// convert to lower case inplace
std::transform(commands.begin(), commands.end(), commands.begin(),
Expand All @@ -38,52 +39,52 @@ SimulationCommand::RawCommands SimulationCommand::convertCommandsStringToVector(
std::replace(commands.begin(), commands.end(), '\n', ';');

// split by semicolons
std::stringstream commandsStream{commands};
std::stringstream commands_stream{commands};
auto command = std::string{};
auto commandsVector = std::vector<std::string>{};
auto commands_vector = std::vector<std::string>{};

while (std::getline(commandsStream, command, ';')) {
commandsVector.push_back(command);
while (std::getline(commands_stream, command, ';')) {
commands_vector.push_back(command);
}
return commandsVector;
return commands_vector;
}
SimulationCommand::CommandsWithArguments
SimulationCommand::splitIntoCommandsWithArguments(std::vector<std::string>& commandsVector) {
auto commandsWithArguments = std::vector<std::pair<std::string, std::vector<std::string>>>{};
SimulationCommand::split_into_commands_with_arguments(std::vector<std::string>& commands_vector) {
auto commands_with_arguments = std::vector<std::pair<std::string, std::vector<std::string>>>{};

for (auto& command : commandsVector) {
commandsWithArguments.push_back(splitIntoCommandWithArguments(command));
for (auto& command : commands_vector) {
commands_with_arguments.push_back(split_into_command_with_arguments(command));
}
return commandsWithArguments;
return commands_with_arguments;
}

SimulationCommand::CommandWithArguments SimulationCommand::splitIntoCommandWithArguments(std::string& command) {
SimulationCommand::CommandWithArguments SimulationCommand::split_into_command_with_arguments(std::string& command) {
// replace commas with spaces
std::replace(command.begin(), command.end(), ',', ' ');

// get command name and arguments
auto commandStream = std::stringstream{command};
auto commandName = std::string{};
auto command_stream = std::stringstream{command};
auto command_name = std::string{};
auto argument = std::string{};
auto arguments = std::vector<std::string>{};

// get command name
std::getline(commandStream, commandName, ' ');
std::getline(command_stream, command_name, ' ');

// get arguments
while (std::getline(commandStream, argument, ' ')) {
while (std::getline(command_stream, argument, ' ')) {
arguments.push_back(argument);
}

return {commandName, arguments};
return {command_name, arguments};
}
std::queue<SimulationCommand> SimulationCommand::compileCommands(CommandsWithArguments& commandsWithArguments,
const CommandRegistry& commandRegistry) {
auto compiledCommands = std::queue<SimulationCommand>{};
std::queue<SimulationCommand> SimulationCommand::compile_commands(CommandsWithArguments& commands_with_arguments,
const CommandRegistry& command_registry) {
auto compiled_commands = std::queue<SimulationCommand>{};

for (auto& [command, arguments] : commandsWithArguments) {
compiledCommands.emplace(&commandRegistry.get_registered_command(command), arguments);
for (auto& [command, arguments] : commands_with_arguments) {
compiled_commands.emplace(&command_registry.get_registered_command(command), arguments);
}

return compiledCommands;
return compiled_commands;
}
18 changes: 9 additions & 9 deletions modules/EvManager/main/SimulationCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ using CmdArguments = std::vector<std::string>;

class SimulationCommand {
public:
SimulationCommand(const RegisteredCommandBase* registeredCommandIn, const CmdArguments& argumentsIn);
SimulationCommand(const RegisteredCommandBase* registered_command_in, const CmdArguments& arguments_in);

bool execute() const;

static std::queue<SimulationCommand> parseSimCommands(const std::string& value,
const CommandRegistry& registeredCommands);
static std::queue<SimulationCommand> parse_sim_commands(const std::string& value,
const CommandRegistry& command_registry);

private:
using RawCommands = std::vector<std::string>;
using CommandWithArguments = std::pair<std::string, CmdArguments>;
using CommandsWithArguments = std::vector<CommandWithArguments>;

static RawCommands convertCommandsStringToVector(const std::string& commands);
static CommandsWithArguments splitIntoCommandsWithArguments(std::vector<std::string>& commandsVector);
static CommandWithArguments splitIntoCommandWithArguments(std::string& command);
static std::queue<SimulationCommand> compileCommands(CommandsWithArguments& commandsWithArguments,
const CommandRegistry& commandRegistry);
static RawCommands convert_commands_string_to_vector(const std::string& commands_view);
static CommandsWithArguments split_into_commands_with_arguments(std::vector<std::string>& commands_vector);
static CommandWithArguments split_into_command_with_arguments(std::string& command);
static std::queue<SimulationCommand> compile_commands(CommandsWithArguments& commands_with_arguments,
const CommandRegistry& command_registry);
std::vector<std::string> arguments;

Check notice on line 38 in modules/EvManager/main/SimulationCommand.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/EvManager/main/SimulationCommand.hpp#L38

class member 'SimulationCommand::arguments' is never used.

const RegisteredCommandBase* registeredCommand;
const RegisteredCommandBase* registered_command;
};
Loading

0 comments on commit 2610a92

Please sign in to comment.