Skip to content

Commit

Permalink
Fix bug where reservation was not removed from evse manager when plug…
Browse files Browse the repository at this point in the history
…in timed out (swipe of rfid but never a plugin of a connector)

Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
  • Loading branch information
maaikez committed Nov 13, 2024
1 parent 9ae31b5 commit 53aa3a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/EvseManager/EvseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,26 +1202,33 @@ bool EvseManager::reserve(int32_t id, const bool signal_reservation_event) {

// is the evse Unavailable?
if (charger->get_current_state() == Charger::EvseState::Disabled) {
EVLOG_info << "Rejecting reservation because charger is disabled.";
return false;
}

// is the evse faulted?
if (charger->stop_charging_on_fatal_error()) {
EVLOG_info << "Rejecting reservation because of a fatal error.";
return false;
}

// is the connector currently ready to accept a new car?
if (charger->get_current_state() not_eq Charger::EvseState::Idle) {
EVLOG_info << "Rejecting reservation because evse is not idle";
return false;
}

Everest::scoped_lock_timeout lock(reservation_mutex, Everest::MutexDescription::EVSE_reserve);

const bool overwrite_reservation = (reservation_id == id);

if (reserved) {
EVLOG_info << "Rejecting reservation because evse is already reserved";
}

// Check if this evse is not already reserved, or overwrite reservation if it is for the same reservation id.
if (not reserved || overwrite_reservation) {
EVLOG_debug << "Make the reservation for id " << id;
EVLOG_debug << "Make the reservation with id " << id;
reserved = true;
reservation_id = id;

Expand All @@ -1246,6 +1253,7 @@ void EvseManager::cancel_reservation(bool signal_event) {

Everest::scoped_lock_timeout lock(reservation_mutex, Everest::MutexDescription::EVSE_cancel_reservation);
if (reserved) {
EVLOG_debug << "Reservation cancelled";
reserved = false;
reservation_id = 0;

Expand Down
5 changes: 5 additions & 0 deletions modules/EvseManager/evse/evse_managerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ void evse_managerImpl::ready() {
session_finished.meter_value = mod->get_latest_powermeter_data_billing();
se.session_finished = session_finished;
session_log.evse(false, fmt::format("Session Finished"));
// Cancel reservation, reservation might be stored when swiping rfid, but timed out, so we should not
// set the reservation id here.
if (mod->is_reserved()) {
mod->cancel_reservation(false);
}
session_log.stopSession();
mod->telemetry.publish("session", "events",
{{"timestamp", Everest::Date::to_rfc3339(date::utc_clock::now())},
Expand Down

0 comments on commit 53aa3a5

Please sign in to comment.