Skip to content

Commit

Permalink
implemented GetTransactionStatusRequest for v201
Browse files Browse the repository at this point in the history
Signed-off-by: pietfried <[email protected]>
  • Loading branch information
Pietfried committed Oct 26, 2023
1 parent a133941 commit 2602e6a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/ocpp/common/message_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <ocpp/common/types.hpp>
#include <ocpp/v16/types.hpp>
#include <ocpp/v201/types.hpp>
#include <ocpp/v201/messages/TransactionEvent.hpp>

namespace ocpp {

Expand Down Expand Up @@ -545,6 +546,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 @@ -326,6 +327,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
30 changes: 30 additions & 0 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,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 @@ -1803,6 +1806,33 @@ void ChargePoint::handle_start_transaction_event_response(const EnhancedMessage<
}
}

void ChargePoint::handle_get_transaction_status(const Call<GetTransactionStatusRequest> call) {
const auto msg = call.msg;

std::optional<bool> 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<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

0 comments on commit 2602e6a

Please sign in to comment.