From b81ccfcf4e3d636a81c706abf7ed23643ab8604f Mon Sep 17 00:00:00 2001 From: Cornelius Claussen Date: Fri, 8 Nov 2024 10:56:43 +0100 Subject: [PATCH] API: differntiate between Finished EVSE and EV Signed-off-by: Cornelius Claussen --- modules/API/API.cpp | 23 ++++++++++++++++++----- modules/API/API.hpp | 6 ++++-- modules/API/README.md | 3 +++ modules/EvseManager/Charger.cpp | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/modules/API/API.cpp b/modules/API/API.cpp index a31ba04b0..3b27cf9a0 100644 --- a/modules/API/API.cpp +++ b/modules/API/API.cpp @@ -106,13 +106,13 @@ static void remove_error_from_list(std::vector& list list.end()); } -void SessionInfo::update_state(const types::evse_manager::SessionEventEnum event) { +void SessionInfo::update_state(const types::evse_manager::SessionEvent event) { std::lock_guard lock(this->session_info_mutex); using Event = types::evse_manager::SessionEventEnum; // using switch since some code analysis tools can detect missing cases // (when new events are added) - switch (event) { + switch (event.event) { case Event::Enabled: this->state = State::Unplugged; break; @@ -141,10 +141,19 @@ void SessionInfo::update_state(const types::evse_manager::SessionEventEnum event this->state = State::WaitingForEnergy; break; case Event::ChargingFinished: - case Event::StoppingCharging: - case Event::TransactionFinished: this->state = State::Finished; break; + case Event::StoppingCharging: + this->state = State::FinishedEV; + break; + case Event::TransactionFinished: { + if (event.transaction_finished->reason == types::evse_manager::StopTransactionReason::Local) { + this->state = State::FinishedEVSE; + } else { + this->state = State::Finished; + } + break; + } case Event::PluginTimeout: this->state = State::AuthTimeout; break; @@ -186,6 +195,10 @@ std::string SessionInfo::state_to_string(SessionInfo::State s) { return "Charging"; case SessionInfo::State::Finished: return "Finished"; + case SessionInfo::State::FinishedEVSE: + return "FinishedEVSE"; + case SessionInfo::State::FinishedEV: + return "FinishedEV"; case SessionInfo::State::AuthTimeout: return "AuthTimeout"; } @@ -398,7 +411,7 @@ void API::init() { evse->subscribe_session_event( [this, var_session_info, var_logging_path, &session_info](types::evse_manager::SessionEvent session_event) { - session_info->update_state(session_event.event); + session_info->update_state(session_event); if (session_event.source.has_value()) { const auto source = session_event.source.value(); diff --git a/modules/API/API.hpp b/modules/API/API.hpp index 0969b4bf7..c83004ef8 100644 --- a/modules/API/API.hpp +++ b/modules/API/API.hpp @@ -54,7 +54,7 @@ class SessionInfo { false}; ///< Indicate if end export energy value (optional) has been received or not void reset(); - void update_state(const types::evse_manager::SessionEventEnum event); + void update_state(const types::evse_manager::SessionEvent event); void set_start_energy_import_wh(int32_t start_energy_import_wh); void set_end_energy_import_wh(int32_t end_energy_import_wh); void set_latest_energy_import_wh(int32_t latest_energy_wh); @@ -96,7 +96,9 @@ class SessionInfo { ChargingPausedEVSE, Charging, AuthTimeout, - Finished + Finished, + FinishedEVSE, + FinishedEV } state; bool is_state_charging(const SessionInfo::State current_state); diff --git a/modules/API/README.md b/modules/API/README.md index e574ded22..50f669f12 100644 --- a/modules/API/README.md +++ b/modules/API/README.md @@ -77,6 +77,9 @@ This variable is published every second and contains a json object with informat - ChargingPausedEV - ChargingPausedEVSE - Finished + - FinishedEV + - FinishedEVSE + - AuthTimeout ### everest_api/evse_manager/var/limits This variable is published every second and contains a json object with information diff --git a/modules/EvseManager/Charger.cpp b/modules/EvseManager/Charger.cpp index e85fdf0e0..6b5bc2618 100644 --- a/modules/EvseManager/Charger.cpp +++ b/modules/EvseManager/Charger.cpp @@ -735,7 +735,7 @@ void Charger::run_state_machine() { case EvseState::StoppingCharging: if (initialize_state) { bcb_toggle_reset(); - if (shared_context.transaction_active or shared_context.session_active) { + if (shared_context.transaction_active) { signal_simple_event(types::evse_manager::SessionEventEnum::StoppingCharging); }