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..eda95a811 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,29 @@ void ChargePoint::handle_start_transaction_event_response(const EnhancedMessage< } } +void ChargePoint::handle_get_transaction_status(const Call call) { + const auto msg = call.msg; + + GetTransactionStatusResponse response; + response.messagesInQueue = false; + + if (msg.transactionId.has_value()) { + if (this->get_transaction_evseid(msg.transactionId.value()).has_value()) { + response.ongoingIndicator = true; + } else { + response.ongoingIndicator = false; + } + if (this->message_queue->contains_transaction_messages(msg.transactionId.value())) { + response.messagesInQueue = true; + } + } else if (!this->message_queue->is_transaction_message_queue_empty()) { + response.messagesInQueue = true; + } + + 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);