From 784013102dbf47814f1f9444e1667c051808b70a Mon Sep 17 00:00:00 2001 From: "Maaike Zijderveld, iolar" Date: Fri, 22 Nov 2024 16:08:48 +0100 Subject: [PATCH] Some changes to check if there is a reservation for an evse / id token (needed for remote start). Signed-off-by: Maaike Zijderveld, iolar --- include/ocpp/common/types.hpp | 9 +++++++++ include/ocpp/v16/charge_point.hpp | 2 +- include/ocpp/v16/charge_point_impl.hpp | 5 +++-- include/ocpp/v201/charge_point.hpp | 12 +++-------- include/ocpp/v201/charge_point_callbacks.hpp | 8 ++++---- lib/ocpp/v16/charge_point.cpp | 2 +- lib/ocpp/v16/charge_point_impl.cpp | 21 +++++++++++++------- lib/ocpp/v201/charge_point.cpp | 21 ++++++++++---------- tests/lib/ocpp/v201/test_charge_point.cpp | 4 ++-- 9 files changed, 48 insertions(+), 36 deletions(-) diff --git a/include/ocpp/common/types.hpp b/include/ocpp/common/types.hpp index 9c48d096a..0458517fe 100644 --- a/include/ocpp/common/types.hpp +++ b/include/ocpp/common/types.hpp @@ -834,6 +834,15 @@ struct CompositeScheduleDefaultLimits { int32_t number_phases; }; +/// \brief Status of a reservation check. +enum class ReservationCheckStatus { + NotReserved, ///< @brief No reservation of this evse and / or id token + ReservedForToken, ///< @brief Reservation for this token. + ReservedForOtherTokenAndParentToken, ///< @brief Reserved for other token and parent token. + ReservedForOtherTokenAndHasNoParentToken, ///< @brief Reserved for other token and reservation has no parent token. + ReservedForOtherTokenAndHasParentToken, ///< @brief Reserved for other token but reservation has a parent token. +}; + } // namespace ocpp #endif diff --git a/include/ocpp/v16/charge_point.hpp b/include/ocpp/v16/charge_point.hpp index 67746d726..7817159ac 100644 --- a/include/ocpp/v16/charge_point.hpp +++ b/include/ocpp/v16/charge_point.hpp @@ -563,7 +563,7 @@ class ChargePoint { /// \param callback /// \ingroup ocpp16_callbacks void register_is_token_reserved_for_connector_callback( - const std::function& callback); + const std::function& callback); /// \brief Registers a callback function for the session cost datatransfer message (California Pricing Requirements) /// \param session_cost_callback The callback. diff --git a/include/ocpp/v16/charge_point_impl.hpp b/include/ocpp/v16/charge_point_impl.hpp index 0f79a59d9..000c246fe 100644 --- a/include/ocpp/v16/charge_point_impl.hpp +++ b/include/ocpp/v16/charge_point_impl.hpp @@ -187,7 +187,8 @@ class ChargePointImpl : ocpp::ChargingStationBase { transaction_updated_callback; std::function transaction_stopped_callback; - std::function is_token_reserved_for_connector_callback; + std::function + is_token_reserved_for_connector_callback; // iso15118 callback std::function& callback); + const std::function& callback); void register_session_cost_callback( const std::function& diff --git a/include/ocpp/v201/charge_point.hpp b/include/ocpp/v201/charge_point.hpp index bc3309a86..984dc1932 100644 --- a/include/ocpp/v201/charge_point.hpp +++ b/include/ocpp/v201/charge_point.hpp @@ -568,16 +568,10 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa /// \param evse The evse id that must be checked. Reservation will be checked for all connectors. /// \param id_token The id token to check if it is reserved for that token. /// \param group_id_token The group id token to check if it is reserved for that group id. - /// \return True when one of the EVSE connectors is reserved for another id token or group id token than the given - /// tokens. - /// If id_token is different than reserved id_token, but group_id_token is equal to reserved group_id_token, - /// returns true. - /// If both are different, returns true. - /// If id_token is equal to reserved id_token or group_id_token is equal, return false. - /// If there is no reservation, return false. + /// \return The status of the reservation for this evse, id token and group id token. /// - bool is_evse_reserved_for_other(EvseInterface& evse, const IdToken& id_token, - const std::optional& group_id_token) const; + ReservationCheckStatus is_evse_reserved_for_other(EvseInterface& evse, const IdToken& id_token, + const std::optional& group_id_token) const; /// /// \brief Check if one of the connectors of the evse is available (both connectors faulted or unavailable or on of diff --git a/include/ocpp/v201/charge_point_callbacks.hpp b/include/ocpp/v201/charge_point_callbacks.hpp index 9450fbc59..7da44d87d 100644 --- a/include/ocpp/v201/charge_point_callbacks.hpp +++ b/include/ocpp/v201/charge_point_callbacks.hpp @@ -79,13 +79,13 @@ struct Callbacks { std::function remote_start_transaction_callback; + /// /// \brief Check if the current reservation for the given evse id is made for the id token / group id token. - /// \return True if evse is reserved for the given id token / group id token, false if it is reserved for another - /// one. + /// \return The reservation check status of this evse / id token. /// - std::function idToken, - const std::optional> groupIdToken)> + std::function idToken, + const std::optional> groupIdToken)> is_reservation_for_token_callback; std::function update_firmware_request_callback; // callback to be called when a variable has been changed by the CSMS diff --git a/lib/ocpp/v16/charge_point.cpp b/lib/ocpp/v16/charge_point.cpp index 69cc94194..b73467f8c 100644 --- a/lib/ocpp/v16/charge_point.cpp +++ b/lib/ocpp/v16/charge_point.cpp @@ -328,7 +328,7 @@ void ChargePoint::register_security_event_callback( } void ChargePoint::register_is_token_reserved_for_connector_callback( - const std::function& callback) { + const std::function& callback) { this->charge_point->register_is_token_reserved_for_connector_callback(callback); } diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index 0c9501f69..93ffb71b2 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -1957,11 +1957,18 @@ void ChargePointImpl::handleRemoteStartTransactionRequest(ocpp::Callis_token_reserved_for_connector_callback != nullptr && - this->status->get_state(connector) == ChargePointStatus::Reserved && - !this->is_token_reserved_for_connector_callback(connector, call.msg.idTag.get())) { - obtainable = false; - continue; + if (this->is_token_reserved_for_connector_callback != nullptr) { + const ocpp::ReservationCheckStatus reservation_status = + is_token_reserved_for_connector_callback(connector, call.msg.idTag.get()); + + const bool is_reserved = + (reservation_status == ocpp::ReservationCheckStatus::ReservedForOtherTokenAndHasNoParentToken || + reservation_status == ocpp::ReservationCheckStatus::ReservedForOtherTokenAndParentToken); + + if (this->status->get_state(connector) == ChargePointStatus::Reserved && is_reserved) { + obtainable = false; + continue; + } } if (obtainable) { @@ -2018,7 +2025,7 @@ void ChargePointImpl::handleRemoteStartTransactionRequest(ocpp::Callprovide_token_callback(call.msg.idTag.get(), referenced_connectors, true); // prevalidated } - }; + } } bool ChargePointImpl::validate_against_cache_entries(CiString<20> id_tag) { @@ -4490,7 +4497,7 @@ void ChargePointImpl::register_security_event_callback( } void ChargePointImpl::register_is_token_reserved_for_connector_callback( - const std::function& callback) { + const std::function& callback) { this->is_token_reserved_for_connector_callback = callback; } diff --git a/lib/ocpp/v201/charge_point.cpp b/lib/ocpp/v201/charge_point.cpp index ce265dd05..a79445933 100644 --- a/lib/ocpp/v201/charge_point.cpp +++ b/lib/ocpp/v201/charge_point.cpp @@ -1968,17 +1968,13 @@ std::optional ChargePoint::get_transaction_evseid(const CiString<36>& t return std::nullopt; } -bool ChargePoint::is_evse_reserved_for_other(EvseInterface& evse, const IdToken& id_token, - const std::optional& group_id_token) const { - const uint32_t connectors = evse.get_number_of_connectors(); +ocpp::ReservationCheckStatus +ChargePoint::is_evse_reserved_for_other(EvseInterface& evse, const IdToken& id_token, + const std::optional& group_id_token) const { const std::optional> groupIdToken = group_id_token.has_value() ? group_id_token.value().idToken : std::optional>{}; - if (!callbacks.is_reservation_for_token_callback(evse.get_id(), id_token.idToken, groupIdToken)) { - return true; - } - - return false; + return callbacks.is_reservation_for_token_callback(evse.get_id(), id_token.idToken, groupIdToken); } bool ChargePoint::is_evse_connector_available(EvseInterface& evse) const { @@ -3184,9 +3180,14 @@ void ChargePoint::handle_remote_start_transaction_request(Call remote_start_transaction_callback_mock; - testing::MockFunction idToken, - const std::optional> groupIdToken)> + testing::MockFunction idToken, + const std::optional> groupIdToken)> is_reservation_for_token_callback_mock; testing::MockFunction update_firmware_request_callback_mock;