Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command "iso_wait_for_stop" now works as intended in EvManager #800

Merged
merged 1 commit into from
Jul 29, 2024
Merged
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
16 changes: 9 additions & 7 deletions modules/EvManager/main/car_simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ bool CarSimulation::sleep(const CmdArguments& arguments, size_t loop_interval_ms
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.sleep_ticks_left = sim_data.sleep_ticks_left.value() - 1;
if (!(sim_data.sleep_ticks_left > 0)) {
sim_data.sleep_ticks_left.value() -= 1;
if (not(sim_data.sleep_ticks_left.value() > 0)) {
sim_data.sleep_ticks_left.reset();
return true;
} else {
Expand Down Expand Up @@ -234,21 +234,23 @@ bool CarSimulation::iso_stop_charging(const CmdArguments& arguments) {
}

bool CarSimulation::iso_wait_for_stop(const CmdArguments& arguments, size_t loop_interval_ms) {
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;
if (not sim_data.sleep_ticks_left.has_value()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not introduced in this PR, but std::stoll et al are used without catching exceptions here and in other places in EVManager. We should add try catch everywhere probably in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I'll plan that.

const auto sleep_time_ms = std::stold(arguments[0]) * 1000;
sim_data.sleep_ticks_left = static_cast<long long>(sleep_time_ms / loop_interval_ms) + 1;
}
sim_data.sleep_ticks_left = sim_data.sleep_ticks_left.value() - 1;
if (!sim_data.sleep_ticks_left > 0) {
sim_data.sleep_ticks_left.value() -= 1;
if (not(sim_data.sleep_ticks_left.value() > 0)) {
r_ev[0]->call_stop_charging();
r_ev_board_support->call_allow_power_on(false);
sim_data.state = SimState::PLUGGED_IN;
sim_data.sleep_ticks_left.reset();
return true;
}
if (sim_data.iso_stopped) {
EVLOG_info << "POWER OFF iso stopped";
r_ev_board_support->call_allow_power_on(false);
sim_data.state = SimState::PLUGGED_IN;
sim_data.sleep_ticks_left.reset();
return true;
}
return false;
Expand Down
Loading