Skip to content

Commit

Permalink
Fixing transactionData omitted in StopTransaction.req (#493)
Browse files Browse the repository at this point in the history
* transactionData omitted in StopTransaction.req (in case no aligned nor sampled value existed) bug fixed
---------

Signed-off-by: Mahdi Movahedi <[email protected]>
Signed-off-by: pietfried <[email protected]>
Co-authored-by: pietfried <[email protected]>
  • Loading branch information
movhdi and Pietfried authored May 7, 2024
1 parent f90b582 commit 8ad3c9a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
10 changes: 10 additions & 0 deletions include/ocpp/v16/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Transaction {
std::optional<int32_t> reservation_id;
bool active;
bool finished;
bool has_signed_meter_values;
std::unique_ptr<Everest::SteadyTimer> meter_values_sample_timer;
std::string start_transaction_message_id;
std::string stop_transaction_message_id;
Expand Down Expand Up @@ -135,6 +136,15 @@ class Transaction {
/// \brief Sets the finished flag for this transaction. This is done when a StopTransaction.req has been pushed to
/// the message queue
void set_finished();

/// \brief Sets the has_signed_meter_value flag for this transaction, this function is called
/// from \p on_transaction_started and \p on_transaction_stopped
void set_has_signed_meter_values();

/// \brief Indicates if this transaction has signed meter values or not, this function is called
/// from \p on_transaction_started and \p on_transaction_stopped
/// \returns a boolean value indicating if this transaction has signed meter values or not
bool get_has_signed_meter_values();
};

/// \brief Contains transactions for all available connectors and manages access to these transactions
Expand Down
3 changes: 2 additions & 1 deletion lib/ocpp/v16/charge_point_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3525,7 +3525,8 @@ ChargePointImpl::get_filtered_transaction_data(const std::shared_ptr<Transaction

std::vector<TransactionData> filtered_transaction_data_vec;

if (!stop_txn_sampled_data_measurands.empty() or !stop_txn_aligned_data_measurands.empty()) {
if (!stop_txn_sampled_data_measurands.empty() or !stop_txn_aligned_data_measurands.empty() or
transaction->get_has_signed_meter_values()) {
std::vector<TransactionData> transaction_data_vec = transaction->get_transaction_data();
for (const auto& entry : transaction_data_vec) {
std::vector<SampledValue> sampled_values;
Expand Down
17 changes: 17 additions & 0 deletions lib/ocpp/v16/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Transaction::Transaction(const int32_t internal_transaction_id, const int32_t& c
reservation_id(reservation_id),
active(true),
finished(false),
has_signed_meter_values(false),
meter_values_sample_timer(std::move(meter_values_sample_timer)),
start_transaction_message_id(""),
stop_transaction_message_id("") {
Expand All @@ -38,6 +39,13 @@ void Transaction::add_meter_value(MeterValue meter_value) {
if (this->active) {
std::lock_guard<std::mutex> lock(this->meter_values_mutex);
this->meter_values.push_back(meter_value);

if (std::find_if(meter_value.sampledValue.begin(), meter_value.sampledValue.end(),
[](SampledValue const& SampledValueItem) {
return SampledValueItem.format == ValueFormat::SignedData;
}) != meter_value.sampledValue.end()) {
this->set_has_signed_meter_values();
}
}
}

Expand Down Expand Up @@ -122,6 +130,15 @@ void Transaction::add_stop_energy_wh(std::shared_ptr<StampedEnergyWh> stop_energ
this->stop();
}

void Transaction::set_has_signed_meter_values() {
this->has_signed_meter_values = true;
}

bool Transaction::get_has_signed_meter_values() {
std::lock_guard<std::mutex> lock(this->meter_values_mutex);
return this->has_signed_meter_values;
}

std::shared_ptr<StampedEnergyWh> Transaction::get_stop_energy_wh() {
return this->stop_energy_wh;
}
Expand Down

0 comments on commit 8ad3c9a

Please sign in to comment.