diff --git a/include/ocpp/v16/charge_point.hpp b/include/ocpp/v16/charge_point.hpp index 7626b97bc..8dac65e64 100644 --- a/include/ocpp/v16/charge_point.hpp +++ b/include/ocpp/v16/charge_point.hpp @@ -168,9 +168,9 @@ class ChargePoint { /// authorization or the connection of cable and/or EV to the given \p connector /// \param connector /// \param session_id unique id of the session - /// \param reason "Authorized" or "EVConnected" TODO(piet): Convert to enum + /// \param reason for the initiation of the session /// \param session_logging_path optional filesystem path to where the session log should be written - void on_session_started(int32_t connector, const std::string& session_id, const std::string& reason, + void on_session_started(int32_t connector, const std::string& session_id, const SessionStartedReason reason, const std::optional& session_logging_path); /// \brief Notifies chargepoint that a session has been stopped at the given \p connector. This function must be diff --git a/include/ocpp/v16/charge_point_impl.hpp b/include/ocpp/v16/charge_point_impl.hpp index 90046f09f..64273d848 100644 --- a/include/ocpp/v16/charge_point_impl.hpp +++ b/include/ocpp/v16/charge_point_impl.hpp @@ -468,9 +468,9 @@ class ChargePointImpl : ocpp::ChargingStationBase { /// authorization or the connection of cable and/or EV to the given \p connector /// \param connector /// \param session_id unique id of the session - /// \param reason "Authorized" or "EVConnected" TODO(piet): Convert to enum + /// \param reason for the initiation of the session /// \param session_logging_path optional filesystem path to where the session log should be written - void on_session_started(int32_t connector, const std::string& session_id, const std::string& reason, + void on_session_started(int32_t connector, const std::string& session_id, const SessionStartedReason reason, const std::optional& session_logging_path); /// \brief Notifies chargepoint that a session has been stopped at the given \p connector. This function must be @@ -575,7 +575,7 @@ class ChargePointImpl : ocpp::ChargingStationBase { void on_disabled(int32_t connector); /// \brief Notifies chargepoint that a ConnectionTimeout occured for the given \p connector . This function should - /// be called when an EV is plugged in but the authorization is present within the specified ConnectionTimeout + /// be called when an EV is plugged in but the authorization is not present within the specified ConnectionTimeout void on_plugin_timeout(int32_t connector); /// \brief Notifies chargepoint that a SecurityEvent occurs. This will send a SecurityEventNotification.req to the diff --git a/include/ocpp/v16/charge_point_state_machine.hpp b/include/ocpp/v16/charge_point_state_machine.hpp index fcb3763a2..f926681d5 100644 --- a/include/ocpp/v16/charge_point_state_machine.hpp +++ b/include/ocpp/v16/charge_point_state_machine.hpp @@ -50,7 +50,7 @@ class ChargePointFSM { const std::optional>& vendor_error_code)>; explicit ChargePointFSM(const StatusNotificationCallback& status_notification_callback, FSMState initial_state); - bool handle_event(FSMEvent event, const ocpp::DateTime timestamp); + bool handle_event(FSMEvent event, const ocpp::DateTime timestamp, const std::optional>& info); bool handle_error(const ChargePointErrorCode& error_code, const ocpp::DateTime& timestamp, const std::optional>& info, const std::optional>& vendor_id, const std::optional>& vendor_error_code); @@ -78,7 +78,8 @@ class ChargePointStates { ChargePointStates(const ConnectorStatusCallback& connector_status_callback); void reset(std::map connector_status_map); - void submit_event(const int connector_id, FSMEvent event, const ocpp::DateTime& timestamp); + void submit_event(const int connector_id, FSMEvent event, const ocpp::DateTime& timestamp, + const std::optional>& info = std::nullopt); void submit_fault(const int connector_id, const ChargePointErrorCode& error_code, const ocpp::DateTime& timestamp, const std::optional>& info, const std::optional>& vendor_id, const std::optional>& vendor_error_code); diff --git a/lib/ocpp/v16/charge_point.cpp b/lib/ocpp/v16/charge_point.cpp index 0ac308e52..7cf7303ef 100644 --- a/lib/ocpp/v16/charge_point.cpp +++ b/lib/ocpp/v16/charge_point.cpp @@ -83,7 +83,8 @@ void ChargePoint::on_max_current_offered(int32_t connector, int32_t max_current) this->charge_point->on_max_current_offered(connector, max_current); } -void ChargePoint::on_session_started(int32_t connector, const std::string& session_id, const std::string& reason, +void ChargePoint::on_session_started(int32_t connector, const std::string& session_id, + const ocpp::SessionStartedReason reason, const std::optional& session_logging_path) { this->charge_point->on_session_started(connector, session_id, reason, session_logging_path); diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index 3a5bf07f5..4c89746c6 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -3152,7 +3152,8 @@ void ChargePointImpl::start_transaction(std::shared_ptr transaction this->send(call); } -void ChargePointImpl::on_session_started(int32_t connector, const std::string& session_id, const std::string& reason, +void ChargePointImpl::on_session_started(int32_t connector, const std::string& session_id, + const ocpp::SessionStartedReason reason, const std::optional& session_logging_path) { EVLOG_debug << "Session on connector#" << connector << " started with reason " << reason; @@ -3161,13 +3162,12 @@ void ChargePointImpl::on_session_started(int32_t connector, const std::string& s this->logging->start_session_logging(session_id, session_logging_path.value()); } - const auto session_started_reason = ocpp::conversions::string_to_session_started_reason(reason); - // dont change to preparing when in reserved if ((this->status->get_state(connector) == ChargePointStatus::Reserved && - session_started_reason == SessionStartedReason::Authorized) || + reason == SessionStartedReason::Authorized) || this->status->get_state(connector) != ChargePointStatus::Reserved) { - this->status->submit_event(connector, FSMEvent::UsageInitiated, ocpp::DateTime()); + this->status->submit_event(connector, FSMEvent::UsageInitiated, ocpp::DateTime(), + ocpp::conversions::session_started_reason_to_string(reason)); } } @@ -3594,7 +3594,8 @@ void ChargePointImpl::on_disabled(int32_t connector) { } void ChargePointImpl::on_plugin_timeout(int32_t connector) { - this->status->submit_event(connector, FSMEvent::TransactionStoppedAndUserActionRequired, ocpp::DateTime()); + this->status->submit_event(connector, FSMEvent::TransactionStoppedAndUserActionRequired, ocpp::DateTime(), + "ConnectionTimeout"); } void ChargePointImpl::on_security_event(const std::string& type, const std::string& tech_info) { diff --git a/lib/ocpp/v16/charge_point_state_machine.cpp b/lib/ocpp/v16/charge_point_state_machine.cpp index bd8fea1e3..dcd4875d6 100644 --- a/lib/ocpp/v16/charge_point_state_machine.cpp +++ b/lib/ocpp/v16/charge_point_state_machine.cpp @@ -116,7 +116,8 @@ FSMState ChargePointFSM::get_state() const { return state; } -bool ChargePointFSM::handle_event(FSMEvent event, const ocpp::DateTime timestamp) { +bool ChargePointFSM::handle_event(FSMEvent event, const ocpp::DateTime timestamp, + const std::optional>& info) { const auto& transitions = FSM_DEF.at(state); const auto dest_state_it = transitions.find(event); @@ -129,7 +130,7 @@ bool ChargePointFSM::handle_event(FSMEvent event, const ocpp::DateTime timestamp state = dest_state_it->second; if (!faulted) { - status_notification_callback(state, this->error_code, timestamp, std::nullopt, std::nullopt, std::nullopt); + status_notification_callback(state, this->error_code, timestamp, info, std::nullopt, std::nullopt); } return true; @@ -212,13 +213,14 @@ void ChargePointStates::reset(std::map connector_status_ } } -void ChargePointStates::submit_event(const int connector_id, FSMEvent event, const ocpp::DateTime& timestamp) { +void ChargePointStates::submit_event(const int connector_id, FSMEvent event, const ocpp::DateTime& timestamp, + const std::optional>& info) { const std::lock_guard lck(state_machines_mutex); if (connector_id == 0) { - this->state_machine_connector_zero->handle_event(event, timestamp); + this->state_machine_connector_zero->handle_event(event, timestamp, info); } else if (connector_id > 0 && (size_t)connector_id <= this->state_machines.size()) { - this->state_machines.at(connector_id - 1).handle_event(event, timestamp); + this->state_machines.at(connector_id - 1).handle_event(event, timestamp, info); } }