From 2610a92cada8696469427a107c20dcab231a50fb Mon Sep 17 00:00:00 2001 From: MarzellT Date: Fri, 17 May 2024 10:13:20 +0200 Subject: [PATCH] refactors variable and function names to snake_case Signed-off-by: MarzellT --- modules/EvManager/main/CarSimulation.cpp | 54 ++++---- modules/EvManager/main/CarSimulation.hpp | 40 +++--- modules/EvManager/main/SimulationCommand.cpp | 65 ++++----- modules/EvManager/main/SimulationCommand.hpp | 18 +-- modules/EvManager/main/SimulationData.hpp | 12 +- modules/EvManager/main/car_simulatorImpl.cpp | 128 +++++++++--------- modules/EvManager/main/car_simulatorImpl.hpp | 24 ++-- .../EvManager/tests/CommandRegistryTest.cpp | 22 +-- modules/EvManager/tests/SimCommandTest.cpp | 18 +-- 9 files changed, 191 insertions(+), 190 deletions(-) diff --git a/modules/EvManager/main/CarSimulation.cpp b/modules/EvManager/main/CarSimulation.cpp index d4a8a7641d..8475c58625 100644 --- a/modules/EvManager/main/CarSimulation.cpp +++ b/modules/EvManager/main/CarSimulation.cpp @@ -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) { @@ -43,7 +43,7 @@ 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); @@ -51,24 +51,24 @@ void CarSimulation::state_machine() { 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; @@ -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(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(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; @@ -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; } @@ -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(1 / static_cast(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; @@ -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; diff --git a/modules/EvManager/main/CarSimulation.hpp b/modules/EvManager/main/CarSimulation.hpp index f741bb16e7..8534931bb6 100644 --- a/modules/EvManager/main/CarSimulation.hpp +++ b/modules/EvManager/main/CarSimulation.hpp @@ -24,7 +24,7 @@ class CarSimulation { sim_data = SimulationData(); } - const SimState& getState() const { + const SimState& get_state() const { return sim_data.state; } @@ -32,44 +32,44 @@ class CarSimulation { 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(); diff --git a/modules/EvManager/main/SimulationCommand.cpp b/modules/EvManager/main/SimulationCommand.cpp index e08ea01dd4..6ebf4c2d01 100644 --- a/modules/EvManager/main/SimulationCommand.cpp +++ b/modules/EvManager/main/SimulationCommand.cpp @@ -9,26 +9,27 @@ #include #include -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::parseSimCommands(const std::string& value, - const CommandRegistry& commandRegistry) { - auto commandsVector{convertCommandsStringToVector(value)}; +std::queue 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(), @@ -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{}; + auto commands_vector = std::vector{}; - 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& commandsVector) { - auto commandsWithArguments = std::vector>>{}; +SimulationCommand::split_into_commands_with_arguments(std::vector& commands_vector) { + auto commands_with_arguments = std::vector>>{}; - 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{}; // 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::compileCommands(CommandsWithArguments& commandsWithArguments, - const CommandRegistry& commandRegistry) { - auto compiledCommands = std::queue{}; +std::queue SimulationCommand::compile_commands(CommandsWithArguments& commands_with_arguments, + const CommandRegistry& command_registry) { + auto compiled_commands = std::queue{}; - 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; } diff --git a/modules/EvManager/main/SimulationCommand.hpp b/modules/EvManager/main/SimulationCommand.hpp index aa013bcddf..3505d184b8 100644 --- a/modules/EvManager/main/SimulationCommand.hpp +++ b/modules/EvManager/main/SimulationCommand.hpp @@ -18,24 +18,24 @@ using CmdArguments = std::vector; 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 parseSimCommands(const std::string& value, - const CommandRegistry& registeredCommands); + static std::queue parse_sim_commands(const std::string& value, + const CommandRegistry& command_registry); private: using RawCommands = std::vector; using CommandWithArguments = std::pair; using CommandsWithArguments = std::vector; - static RawCommands convertCommandsStringToVector(const std::string& commands); - static CommandsWithArguments splitIntoCommandsWithArguments(std::vector& commandsVector); - static CommandWithArguments splitIntoCommandWithArguments(std::string& command); - static std::queue 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& commands_vector); + static CommandWithArguments split_into_command_with_arguments(std::string& command); + static std::queue compile_commands(CommandsWithArguments& commands_with_arguments, + const CommandRegistry& command_registry); std::vector arguments; - const RegisteredCommandBase* registeredCommand; + const RegisteredCommandBase* registered_command; }; diff --git a/modules/EvManager/main/SimulationData.hpp b/modules/EvManager/main/SimulationData.hpp index 256a9bcde6..194160f896 100644 --- a/modules/EvManager/main/SimulationData.hpp +++ b/modules/EvManager/main/SimulationData.hpp @@ -30,14 +30,14 @@ struct SimulationData { SimulationData() = default; SimState state{SimState::UNPLUGGED}; - SimState lastState{SimState::UNDEFINED}; - std::string slacState{"UNMATCHED"}; - std::optional sleepTicksLeft{}; + SimState last_state{SimState::UNDEFINED}; + std::string slac_state{"UNMATCHED"}; + std::optional sleep_ticks_left{}; bool v2g_finished{false}; bool iso_stopped{false}; size_t evse_maxcurrent{0}; - size_t maxCurrent{0}; + size_t max_current{0}; std::string payment{"ExternalPayment"}; bool iso_pwr_ready{false}; @@ -46,11 +46,11 @@ struct SimulationData { bool bcb_toggle_C{true}; types::board_support_common::Ampacity pp; - float rcd_current_mA{0.0f}; + float rcd_current_ma{0.0f}; float pwm_duty_cycle{0.0f}; float last_pwm_duty_cycle{0.0f}; bool dc_power_on{false}; - types::board_support_common::Event actualBspEvent{}; + types::board_support_common::Event actual_bsp_event{}; }; diff --git a/modules/EvManager/main/car_simulatorImpl.cpp b/modules/EvManager/main/car_simulatorImpl.cpp index 4721fe9049..7c52c53f73 100644 --- a/modules/EvManager/main/car_simulatorImpl.cpp +++ b/modules/EvManager/main/car_simulatorImpl.cpp @@ -9,10 +9,10 @@ namespace module::main { void car_simulatorImpl::init() { - loopIntervalMs = constants::DEFAULT_LOOP_INTERVAL_MS; - registerAllCommands(); - subscribeToExternalMQTT(); - subscribeToVariablesOnInit(); + loop_interval_ms = constants::DEFAULT_LOOP_INTERVAL_MS; + register_all_commands(); + subscribe_to_external_mqtt(); + subscribe_to_variables_on_init(); std::thread(&car_simulatorImpl::run, this).detach(); } @@ -21,15 +21,15 @@ void car_simulatorImpl::ready() { car_simulation = std::make_unique(mod->r_ev_board_support, mod->r_ev, mod->r_slac); - setupEVParameters(); + setup_ev_parameters(); if (mod->config.auto_enable) { - auto enableCopy = mod->config.auto_enable; - handle_enable(enableCopy); + auto enable_copy = mod->config.auto_enable; + handle_enable(enable_copy); } if (mod->config.auto_exec) { - auto valueCopy = mod->config.auto_exec_commands; - handle_executeChargingSession(valueCopy); + auto value_copy = mod->config.auto_exec_commands; + handle_executeChargingSession(value_copy); } } @@ -40,9 +40,9 @@ void car_simulatorImpl::handle_enable(bool& value) { return; } - resetCarSimulationDefaults(); + reset_car_simulation_defaults(); - callEVBoardSupportFunctions(); + call_ev_board_support_functions(); enabled = value; @@ -51,18 +51,18 @@ void car_simulatorImpl::handle_enable(bool& value) { } void car_simulatorImpl::handle_executeChargingSession(std::string& value) { - if (!checkCanExecute()) { + if (!check_can_execute()) { return; } - executionActive = false; - resetCarSimulationDefaults(); + execution_active = false; + reset_car_simulation_defaults(); - updateCommandQueue(value); + update_command_queue(value); - const std::lock_guard lock{carSimulationMutex}; - if (!commandQueue.empty()) { - executionActive = true; + const std::lock_guard lock{car_simulation_mutex}; + if (!command_queue.empty()) { + execution_active = true; } } @@ -72,27 +72,27 @@ void car_simulatorImpl::handle_modifyChargingSession(std::string& value) { return; } - executionActive = false; + execution_active = false; - updateCommandQueue(value); + update_command_queue(value); - const std::lock_guard lock{carSimulationMutex}; - if (!commandQueue.empty()) { - executionActive = true; + const std::lock_guard lock{car_simulation_mutex}; + if (!command_queue.empty()) { + execution_active = true; } } void car_simulatorImpl::run() { while (true) { - if (enabled == true && executionActive == true) { + if (enabled == true && execution_active == true) { const auto finished = run_simulation_loop(); if (finished) { EVLOG_info << "Finished simulation."; - this->executionActive = false; + this->execution_active = false; - resetCarSimulationDefaults(); + reset_car_simulation_defaults(); // If we have auto_exec_infinite configured, restart simulation when it is done if (mod->config.auto_exec && mod->config.auto_exec_infinite) { @@ -101,15 +101,15 @@ void car_simulatorImpl::run() { } } } - std::this_thread::sleep_for(std::chrono::milliseconds(loopIntervalMs)); + std::this_thread::sleep_for(std::chrono::milliseconds(loop_interval_ms)); } } -void car_simulatorImpl::registerAllCommands() { +void car_simulatorImpl::register_all_commands() { command_registry = std::make_unique(); command_registry->register_command("sleep", 1, [this](const CmdArguments& arguments) { - return this->car_simulation->sleep(arguments, loopIntervalMs); + return this->car_simulation->sleep(arguments, loop_interval_ms); }); command_registry->register_command("iec_wait_pwr_ready", 0, [this](const CmdArguments& arguments) { return this->car_simulation->iec_wait_pwr_ready(arguments); @@ -161,7 +161,7 @@ void car_simulatorImpl::registerAllCommands() { return this->car_simulation->iso_stop_charging(arguments); }); command_registry->register_command("iso_wait_for_stop", 1, [this](const CmdArguments& arguments) { - return this->car_simulation->iso_wait_for_stop(arguments, loopIntervalMs); + return this->car_simulation->iso_wait_for_stop(arguments, loop_interval_ms); }); command_registry->register_command("iso_wait_v2g_session_stopped", 0, [this](const CmdArguments& arguments) { return this->car_simulation->iso_wait_v2g_session_stopped(arguments); @@ -180,20 +180,20 @@ void car_simulatorImpl::registerAllCommands() { bool car_simulatorImpl::run_simulation_loop() { // Execute sim commands until a command blocks, or we are finished - const std::lock_guard lock{carSimulationMutex}; - while (executionActive && !commandQueue.empty()) { - auto& currentCommand = commandQueue.front(); + const std::lock_guard lock{car_simulation_mutex}; + while (execution_active && !command_queue.empty()) { + auto& current_command = command_queue.front(); auto command_blocked = false; try { - command_blocked = !currentCommand.execute(); + command_blocked = !current_command.execute(); } catch (const std::exception& e) { EVLOG_error << e.what(); } if (!command_blocked) { - commandQueue.pop(); + command_queue.pop(); } else { break; // command blocked, wait for timer to run this function again } @@ -201,18 +201,18 @@ bool car_simulatorImpl::run_simulation_loop() { car_simulation->state_machine(); - if (commandQueue.empty()) { + if (command_queue.empty()) { return true; } return false; } -bool car_simulatorImpl::checkCanExecute() { +bool car_simulatorImpl::check_can_execute() { if (!enabled) { EVLOG_warning << "Simulation disabled, cannot execute charging simulation."; return false; } - if (executionActive) { + if (execution_active) { EVLOG_warning << "Execution of charging session simulation already running, cannot start new one."; return false; } @@ -220,15 +220,15 @@ bool car_simulatorImpl::checkCanExecute() { return true; } -void car_simulatorImpl::subscribeToVariablesOnInit() { +void car_simulatorImpl::subscribe_to_variables_on_init() { // subscribe bsp_event - const std::lock_guard lock{carSimulationMutex}; + const std::lock_guard lock{car_simulation_mutex}; using types::board_support_common::BspEvent; mod->r_ev_board_support->subscribe_bsp_event([this](const auto& bsp_event) { - car_simulation->setBspEvent(bsp_event.event); + car_simulation->set_bsp_event(bsp_event.event); if (bsp_event.event == types::board_support_common::Event::Disconnected && - car_simulation->getState() != SimState::UNPLUGGED) { - executionActive = false; + car_simulation->get_state() != SimState::UNPLUGGED) { + execution_active = false; car_simulation->set_state(SimState::UNPLUGGED); } }); @@ -236,29 +236,29 @@ void car_simulatorImpl::subscribeToVariablesOnInit() { // subscribe bsp_measurement using types::board_support_common::BspMeasurement; mod->r_ev_board_support->subscribe_bsp_measurement([this](const auto& measurement) { - car_simulation->setPp(measurement.proximity_pilot.ampacity); - car_simulation->setRcdCurrent(measurement.rcd_current_mA.value()); - car_simulation->setPwmDutyCycle(measurement.cp_pwm_duty_cycle); + car_simulation->set_pp(measurement.proximity_pilot.ampacity); + car_simulation->setr_rcd_current(measurement.rcd_current_mA.value()); + car_simulation->set_pwm_duty_cycle(measurement.cp_pwm_duty_cycle); }); // subscribe slac_state if (!mod->r_slac.empty()) { const auto& slac = mod->r_slac.at(0); - slac->subscribe_state([this](const auto& state) { car_simulation->setSlacState(state); }); + slac->subscribe_state([this](const auto& state) { car_simulation->set_slac_state(state); }); } // subscribe ev events if (!mod->r_ev.empty()) { const auto& _ev = mod->r_ev.at(0); - _ev->subscribe_AC_EVPowerReady([this](auto value) { car_simulation->setIsoPwrReady(value); }); - _ev->subscribe_AC_EVSEMaxCurrent([this](auto value) { car_simulation->setEVSEMaxCurrent(value); }); - _ev->subscribe_AC_StopFromCharger([this]() { car_simulation->setIsoStopped(true); }); - _ev->subscribe_V2G_Session_Finished([this]() { car_simulation->setV2gFinished(true); }); - _ev->subscribe_DC_PowerOn([this]() { car_simulation->setDcPowerOn(true); }); + _ev->subscribe_AC_EVPowerReady([this](auto value) { car_simulation->set_iso_pwr_ready(value); }); + _ev->subscribe_AC_EVSEMaxCurrent([this](auto value) { car_simulation->set_evse_max_current(value); }); + _ev->subscribe_AC_StopFromCharger([this]() { car_simulation->set_iso_stopped(true); }); + _ev->subscribe_V2G_Session_Finished([this]() { car_simulation->set_v2g_finished(true); }); + _ev->subscribe_DC_PowerOn([this]() { car_simulation->set_dc_power_on(true); }); } } -void car_simulatorImpl::setupEVParameters() { +void car_simulatorImpl::setup_ev_parameters() { if (!mod->r_ev.empty()) { mod->r_ev[0]->call_set_dc_params({mod->config.dc_max_current_limit, mod->config.dc_max_power_limit, mod->config.dc_max_voltage_limit, mod->config.dc_energy_capacity, @@ -272,14 +272,14 @@ void car_simulatorImpl::setupEVParameters() { } } -void car_simulatorImpl::callEVBoardSupportFunctions() { +void car_simulatorImpl::call_ev_board_support_functions() { mod->r_ev_board_support->call_allow_power_on(false); mod->r_ev_board_support->call_set_ac_max_current(mod->config.max_current); mod->r_ev_board_support->call_set_three_phases(mod->config.three_phases); } -void car_simulatorImpl::subscribeToExternalMQTT() { +void car_simulatorImpl::subscribe_to_external_mqtt() { const auto& mqtt = mod->mqtt; mqtt.subscribe("everest_external/nodered/" + std::to_string(mod->config.connector_id) + "/carsim/cmd/enable", [this](const std::string& message) { @@ -294,23 +294,23 @@ void car_simulatorImpl::subscribeToExternalMQTT() { mqtt.subscribe("everest_external/nodered/" + std::to_string(mod->config.connector_id) + "/carsim/cmd/execute_charging_session", [this](const auto data) { - auto dataCopy{data}; - handle_executeChargingSession(dataCopy); + auto data_copy{data}; + handle_executeChargingSession(data_copy); }); mqtt.subscribe("everest_external/nodered/" + std::to_string(mod->config.connector_id) + "/carsim/cmd/modify_charging_session", [this](auto data) { - auto dataCopy = data; - handle_modifyChargingSession(dataCopy); + auto data_copy = data; + handle_modifyChargingSession(data_copy); }); } -void car_simulatorImpl::resetCarSimulationDefaults() { - const std::lock_guard lock{carSimulationMutex}; +void car_simulatorImpl::reset_car_simulation_defaults() { + const std::lock_guard lock{car_simulation_mutex}; car_simulation->reset(); } -void car_simulatorImpl::updateCommandQueue(std::string& value) { - const std::lock_guard lock{carSimulationMutex}; - commandQueue = SimulationCommand::parseSimCommands(value, *command_registry); +void car_simulatorImpl::update_command_queue(std::string& value) { + const std::lock_guard lock{car_simulation_mutex}; + command_queue = SimulationCommand::parse_sim_commands(value, *command_registry); } } // namespace module::main diff --git a/modules/EvManager/main/car_simulatorImpl.hpp b/modules/EvManager/main/car_simulatorImpl.hpp index 8dab5505bc..0408ac4254 100644 --- a/modules/EvManager/main/car_simulatorImpl.hpp +++ b/modules/EvManager/main/car_simulatorImpl.hpp @@ -53,26 +53,26 @@ class car_simulatorImpl : public car_simulatorImplBase { void run(); void handle_modifyChargingSession(std::string& value); - bool checkCanExecute(); + bool check_can_execute(); bool run_simulation_loop(); - void registerAllCommands(); - void subscribeToVariablesOnInit(); - void setupEVParameters(); - void callEVBoardSupportFunctions(); - void subscribeToExternalMQTT(); - void resetCarSimulationDefaults(); - void updateCommandQueue(std::string& value); + void register_all_commands(); + void subscribe_to_variables_on_init(); + void setup_ev_parameters(); + void call_ev_board_support_functions(); + void subscribe_to_external_mqtt(); + void reset_car_simulation_defaults(); + void update_command_queue(std::string& value); std::unique_ptr command_registry; - std::mutex carSimulationMutex; + std::mutex car_simulation_mutex; std::unique_ptr car_simulation; bool enabled{false}; - std::atomic executionActive{false}; - size_t loopIntervalMs{}; + std::atomic execution_active{false}; + size_t loop_interval_ms{}; - std::queue commandQueue; + std::queue command_queue; // ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1 }; diff --git a/modules/EvManager/tests/CommandRegistryTest.cpp b/modules/EvManager/tests/CommandRegistryTest.cpp index 097ee8c064..d539934287 100644 --- a/modules/EvManager/tests/CommandRegistryTest.cpp +++ b/modules/EvManager/tests/CommandRegistryTest.cpp @@ -10,7 +10,7 @@ SCENARIO("Commands can be registered", "[RegisteredCommand]") { GIVEN("A command with 0 arguments") { auto command_registry = CommandRegistry(); - const auto command_name = std::string{"testCommand0"}; + const auto command_name = std::string{"test_command0"}; const auto argument_count = 0; const auto test_comand_0_function = [](const std::vector& arguments) { return arguments.empty(); }; @@ -24,11 +24,11 @@ SCENARIO("Commands can be registered", "[RegisteredCommand]") { } THEN("The command throws when the number of arguments is invalid") { CHECK(registered_command({}) == true); - CHECK_THROWS_WITH(registered_command({"arg1"}), "Invalid number of arguments for: testCommand0"); + CHECK_THROWS_WITH(registered_command({"arg1"}), "Invalid number of arguments for: test_command0"); CHECK_THROWS_WITH(registered_command({"arg1", "arg2"}), - "Invalid number of arguments for: testCommand0"); + "Invalid number of arguments for: test_command0"); CHECK_THROWS_WITH(registered_command({"arg1", "arg2", "arg3"}), - "Invalid number of arguments for: testCommand0"); + "Invalid number of arguments for: test_command0"); } } } @@ -36,7 +36,7 @@ SCENARIO("Commands can be registered", "[RegisteredCommand]") { GIVEN("A command with 1 argument") { auto command_registry = CommandRegistry(); - const auto command_name = std::string{"testCommand1"}; + const auto command_name = std::string{"test_command1"}; const auto argument_count = 1; const auto test_comand_1_function = [](const std::vector& arguments) { return arguments.size() == 1; @@ -51,9 +51,9 @@ SCENARIO("Commands can be registered", "[RegisteredCommand]") { CHECK(registered_command({"arg1"}) == true); } THEN("The command throws when the number of arguments is invalid") { - CHECK_THROWS_WITH(registered_command({}), "Invalid number of arguments for: testCommand1"); + CHECK_THROWS_WITH(registered_command({}), "Invalid number of arguments for: test_command1"); CHECK_THROWS_WITH(registered_command({"arg1", "arg2"}), - "Invalid number of arguments for: testCommand1"); + "Invalid number of arguments for: test_command1"); } } } @@ -61,7 +61,7 @@ SCENARIO("Commands can be registered", "[RegisteredCommand]") { GIVEN("A command with 2 arguments") { auto command_registry = CommandRegistry(); - const auto command_name = std::string{"testCommand2"}; + const auto command_name = std::string{"test_command2"}; const auto argument_count = 2; const auto test_comand_2_function = [](const std::vector& arguments) { return arguments.size() == 2; @@ -76,10 +76,10 @@ SCENARIO("Commands can be registered", "[RegisteredCommand]") { CHECK(registered_command({"arg1", "arg2"}) == true); } THEN("The command throws when the number of arguments is invalid") { - CHECK_THROWS_WITH(registered_command({}), "Invalid number of arguments for: testCommand2"); - CHECK_THROWS_WITH(registered_command({"arg1"}), "Invalid number of arguments for: testCommand2"); + CHECK_THROWS_WITH(registered_command({}), "Invalid number of arguments for: test_command2"); + CHECK_THROWS_WITH(registered_command({"arg1"}), "Invalid number of arguments for: test_command2"); CHECK_THROWS_WITH(registered_command({"arg1", "arg2", "arg3"}), - "Invalid number of arguments for: testCommand2"); + "Invalid number of arguments for: test_command2"); } } } diff --git a/modules/EvManager/tests/SimCommandTest.cpp b/modules/EvManager/tests/SimCommandTest.cpp index 4ca163e6a0..8921f25a5e 100644 --- a/modules/EvManager/tests/SimCommandTest.cpp +++ b/modules/EvManager/tests/SimCommandTest.cpp @@ -9,8 +9,8 @@ #include SCENARIO("SimCommands can be created", "[SimCommand]") { - GIVEN("A command with 0 arguments called testCommand is registered") { - const auto command_name = std::string{"testCommand"}; + GIVEN("A command with 0 arguments called test_command is registered") { + const auto command_name = std::string{"test_command"}; const auto argument_count = 0; const auto test_command_function = [](const std::vector& arguments) { return arguments.empty(); }; auto command_registry = CommandRegistry(); @@ -29,7 +29,7 @@ SCENARIO("SimCommands can be created", "[SimCommand]") { SimulationCommand{&command_registry.get_registered_command(command_name), {"arg1"}}; THEN("The command throws") { - CHECK_THROWS_WITH(sim_command.execute(), "Invalid number of arguments for: testCommand"); + CHECK_THROWS_WITH(sim_command.execute(), "Invalid number of arguments for: test_command"); } } } @@ -54,8 +54,8 @@ SCENARIO("SimCommands can be parsed", "[SimCommand]") { command_registry.register_command(command_name_c, argument_count_c, command_function_c); WHEN("A correct command string is to be parsed") { - const auto command_string = "commandA;commandB 0;commandC abc 0.0"; - auto parsed_commands = SimulationCommand::parseSimCommands(command_string, command_registry); + const auto command_string = "commanda;commandb 0;commandc abc 0.0"; + auto parsed_commands = SimulationCommand::parse_sim_commands(command_string, command_registry); THEN("A queue of executable SimCommands exists.") { CHECK(parsed_commands.front().execute()); @@ -79,8 +79,8 @@ SCENARIO("SimCommands can be parsed", "[SimCommand]") { } WHEN("A command string with wrong arguments is to be parsed") { - const auto command_string = "commandA 1;commandB;commandC abc 0.0 def"; - auto parsed_commands = SimulationCommand::parseSimCommands(command_string, command_registry); + const auto command_string = "commanda 1;commandb;commandc abc 0.0 def"; + auto parsed_commands = SimulationCommand::parse_sim_commands(command_string, command_registry); THEN("The execution of the commands should fail.") { CHECK_THROWS_WITH(parsed_commands.front().execute(), "Invalid number of arguments for: commanda"); @@ -97,14 +97,14 @@ SCENARIO("SimCommands can be parsed", "[SimCommand]") { const auto command_string = "commandd;commande;commandf"; THEN("Parsing should fail") { - CHECK_THROWS_WITH(SimulationCommand::parseSimCommands(command_string, command_registry), + CHECK_THROWS_WITH(SimulationCommand::parse_sim_commands(command_string, command_registry), "Command not found: commandd"); } } WHEN("An empty string is to be parsed") { const auto command_string = ""; - const auto parsed_commands = SimulationCommand::parseSimCommands(command_string, command_registry); + const auto parsed_commands = SimulationCommand::parse_sim_commands(command_string, command_registry); THEN("It should create an empty queue") { CHECK(parsed_commands.empty());