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

Add in helper vector with transactionsId already send triggered by tansaction_queue #906

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion include/ocpp/common/message_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@ template <typename M> class MessageQueue {
}

/// \brief Gets all persisted messages of normal message queue and persisted message queue from the database
void get_persisted_messages_from_db(bool ignore_security_event_notifications = false) {
void get_persisted_messages_from_db(std::vector<int>& transactionInFlight,
bool ignore_security_event_notifications = false) {
std::vector<QueueType> queue_types = {QueueType::Normal, QueueType::Transaction};
// do for Normal and Transaction queue
for (const auto queue_type : queue_types) {
Expand Down Expand Up @@ -610,6 +611,8 @@ template <typename M> class MessageQueue {
normal_message_queue.push_back(message);
} else if (queue_type == QueueType::Transaction) {
transaction_message_queue.push_back(message);
Call<v16::StopTransactionRequest> call = persisted_message.json_message;
transactionInFlight.push_back(call.msg.transactionId);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion include/ocpp/v16/charge_point_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@
/// resuming_session_ids contain the internal session_id, this function attempts to resume the transaction by
/// initializing it and adding it to the \ref transaction_handler. If the session_id is not part of \p
/// resuming_session_ids a StopTransaction.req is initiated to properly close the transaction.
void try_resume_transactions(const std::set<std::string>& resuming_session_ids);
void try_resume_transactions(const std::vector<int> transactionIdsInFlight,

Check warning on line 250 in include/ocpp/v16/charge_point_impl.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/ocpp/v16/charge_point_impl.hpp#L250

Function parameter 'transactionIdsInFlight' should be passed by const reference.
const std::set<std::string>& resuming_session_ids);
void stop_all_transactions();
void stop_all_transactions(Reason reason);
bool validate_against_cache_entries(CiString<20> id_tag);
Expand Down
18 changes: 13 additions & 5 deletions lib/ocpp/v16/charge_point_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ void ChargePointImpl::update_clock_aligned_meter_values_interval() {
}
}

void ChargePointImpl::try_resume_transactions(const std::set<std::string>& resuming_session_ids) {
void ChargePointImpl::try_resume_transactions(const std::vector<int>& transactionIdsInFlight,
const std::set<std::string>& resuming_session_ids) {
std::vector<ocpp::v16::TransactionEntry> transactions;
try {
transactions = this->database_handler->get_transactions(true);
Expand Down Expand Up @@ -514,10 +515,15 @@ void ChargePointImpl::try_resume_transactions(const std::set<std::string>& resum

EVLOG_info << "Trying to resume transaction with session_id: " << transaction_entry.session_id
<< " and transaction_id: " << transaction_entry.transaction_id;

if (this->message_queue->contains_stop_transaction_message(transaction_entry.transaction_id)) {
// The case is possible that the transacion_id is already earesed from this->message_queue,
// then the else case enters and the transaction is stopped again. To avoid, that the transactiondIdsInFlight
// are additionally checked.
if (this->message_queue->contains_stop_transaction_message(transaction_entry.transaction_id) ||
std::find(transactionIdsInFlight.begin(), transactionIdsInFlight.end(), transaction_entry.transaction_id) !=
transactionIdsInFlight.end()) {
// StopTransaction.req is already queued for the transaction in the database, so we mark the transaction as
// stopped and wait for the StopTransaction.conf
EVLOG_info << "Is already sent";
transaction->set_finished();
this->transaction_handler->add_stopped_transaction(transaction->get_connector());
} else {
Expand Down Expand Up @@ -1074,10 +1080,12 @@ bool ChargePointImpl::start(const std::map<int, ChargePointStatus>& connector_st
this->init_state_machine(connector_status_map);
this->init_websocket();
this->websocket->connect();
std::vector<int> transactionIdsInFlight;
// push transaction messages including SecurityEventNotification.req onto the message queue
this->message_queue->get_persisted_messages_from_db(this->configuration->getDisableSecurityEventNotifications());
this->message_queue->get_persisted_messages_from_db(transactionIdsInFlight,
this->configuration->getDisableSecurityEventNotifications());
this->boot_notification();
this->try_resume_transactions(resuming_session_ids);
this->try_resume_transactions(transactionIdsInFlight, resuming_session_ids);
this->call_set_connection_timeout();

switch (bootreason) {
Expand Down
Loading