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

Fixing transactionData omitted in StopTransaction.req #493

Merged
merged 15 commits into from
May 7, 2024
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
10 changes: 10 additions & 0 deletions include/ocpp/v16/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
std::optional<int32_t> reservation_id;
bool active;
bool finished;
bool has_signed_meter_values;

Check notice on line 41 in include/ocpp/v16/transaction.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/ocpp/v16/transaction.hpp#L41

class member 'Transaction::has_signed_meter_values' is never used.
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 @@ -130,6 +131,15 @@
/// \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 @@ -3379,7 +3379,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& connector, const std::string& session_id
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 @@ -118,6 +126,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
Loading