From a77d02adf34c273a9dc9376b03f8f04a47d95ef6 Mon Sep 17 00:00:00 2001 From: pietfried Date: Thu, 26 Oct 2023 10:36:59 +0200 Subject: [PATCH 1/2] implemented GetTransactionStatusRequest for v201 Signed-off-by: pietfried --- include/ocpp/common/message_queue.hpp | 19 +++++++++++++++++ include/ocpp/v201/charge_point.hpp | 2 ++ lib/ocpp/v201/charge_point.cpp | 30 +++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/include/ocpp/common/message_queue.hpp b/include/ocpp/common/message_queue.hpp index f70c47c69..acfe26412 100644 --- a/include/ocpp/common/message_queue.hpp +++ b/include/ocpp/common/message_queue.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include namespace ocpp { @@ -591,6 +592,24 @@ template class MessageQueue { EVLOG_debug << "resume() notified message queue"; } + bool is_transaction_message_queue_empty() { + std::lock_guard lk(this->message_mutex); + return this->transaction_message_queue.empty(); + } + + bool contains_transaction_messages(const CiString<36> transaction_id) { + std::lock_guard lk(this->message_mutex); + for (const auto control_message : this->transaction_message_queue) { + if (control_message->messageType == v201::MessageType::TransactionEvent) { + v201::TransactionEventRequest req = control_message->message.at(CALL_PAYLOAD); + if (req.transactionInfo.transactionId == transaction_id) { + return true; + } + } + } + return false; + } + /// \brief Set transaction_message_attempts to given \p transaction_message_attempts void update_transaction_message_attempts(const int transaction_message_attempts) { this->transaction_message_attempts = transaction_message_attempts; diff --git a/include/ocpp/v201/charge_point.hpp b/include/ocpp/v201/charge_point.hpp index f8a2389e3..38cb9d529 100644 --- a/include/ocpp/v201/charge_point.hpp +++ b/include/ocpp/v201/charge_point.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -329,6 +330,7 @@ class ChargePoint : ocpp::ChargingStationBase { // Functional Block E: Transaction void handle_start_transaction_event_response(const EnhancedMessage& message); + void handle_get_transaction_status(const Call call); // Function Block F: Remote transaction control void handle_unlock_connector(Call call); diff --git a/lib/ocpp/v201/charge_point.cpp b/lib/ocpp/v201/charge_point.cpp index ff3a9729c..10b9b556f 100644 --- a/lib/ocpp/v201/charge_point.cpp +++ b/lib/ocpp/v201/charge_point.cpp @@ -747,6 +747,9 @@ void ChargePoint::handle_message(const EnhancedMessage& messa case MessageType::GetLocalListVersion: this->handle_get_local_authorization_list_version_req(json_message); break; + case MessageType::GetTransactionStatus: + this->handle_get_transaction_status(json_message); + break; default: if (message.messageTypeId == MessageTypeId::CALL) { const auto call_error = CallError(message.uniqueId, "NotImplemented", "", json({})); @@ -1811,6 +1814,33 @@ void ChargePoint::handle_start_transaction_event_response(const EnhancedMessage< } } +void ChargePoint::handle_get_transaction_status(const Call call) { + const auto msg = call.msg; + + std::optional ongoing_indicator; + bool messages_in_queue = false; + + if (msg.transactionId.has_value()) { + if (this->get_transaction_evseid(msg.transactionId.value()).has_value()) { + ongoing_indicator = true; + } else { + ongoing_indicator = false; + } + if (this->message_queue->contains_transaction_messages(msg.transactionId.value())) { + messages_in_queue = true; + } + } else if (!this->message_queue->is_transaction_message_queue_empty()) { + messages_in_queue = true; + } + + GetTransactionStatusResponse response; + response.ongoingIndicator = ongoing_indicator; + response.messagesInQueue = messages_in_queue; + + ocpp::CallResult call_result(response, call.uniqueId); + this->send(call_result); +} + void ChargePoint::handle_unlock_connector(Call call) { const UnlockConnectorRequest& msg = call.msg; const UnlockConnectorResponse unlock_response = callbacks.unlock_connector_callback(msg.evseId, msg.connectorId); From 3b8855ef64190a1d0fc6d5c4460f000e4aade70c Mon Sep 17 00:00:00 2001 From: pietfried Date: Tue, 31 Oct 2023 12:33:30 +0100 Subject: [PATCH 2/2] moved response to assign directly Signed-off-by: pietfried --- lib/ocpp/v201/charge_point.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/ocpp/v201/charge_point.cpp b/lib/ocpp/v201/charge_point.cpp index 10b9b556f..eda95a811 100644 --- a/lib/ocpp/v201/charge_point.cpp +++ b/lib/ocpp/v201/charge_point.cpp @@ -1817,26 +1817,22 @@ void ChargePoint::handle_start_transaction_event_response(const EnhancedMessage< void ChargePoint::handle_get_transaction_status(const Call call) { const auto msg = call.msg; - std::optional ongoing_indicator; - bool messages_in_queue = false; + GetTransactionStatusResponse response; + response.messagesInQueue = false; if (msg.transactionId.has_value()) { if (this->get_transaction_evseid(msg.transactionId.value()).has_value()) { - ongoing_indicator = true; + response.ongoingIndicator = true; } else { - ongoing_indicator = false; + response.ongoingIndicator = false; } if (this->message_queue->contains_transaction_messages(msg.transactionId.value())) { - messages_in_queue = true; + response.messagesInQueue = true; } } else if (!this->message_queue->is_transaction_message_queue_empty()) { - messages_in_queue = true; + response.messagesInQueue = true; } - GetTransactionStatusResponse response; - response.ongoingIndicator = ongoing_indicator; - response.messagesInQueue = messages_in_queue; - ocpp::CallResult call_result(response, call.uniqueId); this->send(call_result); }