Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetTransactionStatusRequest for v201 #228

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions include/ocpp/common/message_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <ocpp/common/database_handler_base.hpp>
#include <ocpp/common/types.hpp>
#include <ocpp/v16/types.hpp>
#include <ocpp/v201/messages/TransactionEvent.hpp>
#include <ocpp/v201/types.hpp>

namespace ocpp {
Expand Down Expand Up @@ -591,6 +592,24 @@ template <typename M> class MessageQueue {
EVLOG_debug << "resume() notified message queue";
}

bool is_transaction_message_queue_empty() {
std::lock_guard<std::mutex> lk(this->message_mutex);
return this->transaction_message_queue.empty();
}

bool contains_transaction_messages(const CiString<36> transaction_id) {
std::lock_guard<std::mutex> 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;
Expand Down
2 changes: 2 additions & 0 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <ocpp/v201/messages/GetLocalListVersion.hpp>
#include <ocpp/v201/messages/GetLog.hpp>
#include <ocpp/v201/messages/GetReport.hpp>
#include <ocpp/v201/messages/GetTransactionStatus.hpp>
#include <ocpp/v201/messages/GetVariables.hpp>
#include <ocpp/v201/messages/Heartbeat.hpp>
#include <ocpp/v201/messages/MeterValues.hpp>
Expand Down Expand Up @@ -329,6 +330,7 @@ class ChargePoint : ocpp::ChargingStationBase {

// Functional Block E: Transaction
void handle_start_transaction_event_response(const EnhancedMessage<v201::MessageType>& message);
void handle_get_transaction_status(const Call<GetTransactionStatusRequest> call);

// Function Block F: Remote transaction control
void handle_unlock_connector(Call<UnlockConnectorRequest> call);
Expand Down
26 changes: 26 additions & 0 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,9 @@ void ChargePoint::handle_message(const EnhancedMessage<v201::MessageType>& 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({}));
Expand Down Expand Up @@ -1811,6 +1814,29 @@ void ChargePoint::handle_start_transaction_event_response(const EnhancedMessage<
}
}

void ChargePoint::handle_get_transaction_status(const Call<GetTransactionStatusRequest> 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<GetTransactionStatusResponse> call_result(response, call.uniqueId);
this->send<GetTransactionStatusResponse>(call_result);
}

void ChargePoint::handle_unlock_connector(Call<UnlockConnectorRequest> call) {
const UnlockConnectorRequest& msg = call.msg;
const UnlockConnectorResponse unlock_response = callbacks.unlock_connector_callback(msg.evseId, msg.connectorId);
Expand Down