Skip to content

Commit

Permalink
Add in helper vector with transactionsId already send triggered by tr…
Browse files Browse the repository at this point in the history
…ansaction_queue

Signed-off-by: Matthias Suess <[email protected]>
  • Loading branch information
Matthias-NIDEC committed Dec 10, 2024
1 parent c234ccc commit 0ebef1d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
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 @@ class ChargePointImpl : ocpp::ChargingStationBase {
/// 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

0 comments on commit 0ebef1d

Please sign in to comment.