Skip to content

Commit

Permalink
fixed reporting of similar sampled data in transaction data of StopTr…
Browse files Browse the repository at this point in the history
…ansaction.req

Signed-off-by: pietfried <[email protected]>
  • Loading branch information
Pietfried authored and valentin-dimov committed Nov 16, 2023
1 parent 20433aa commit 95db166
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
2 changes: 0 additions & 2 deletions include/ocpp/v16/charge_point_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ class ChargePointConfiguration {
std::string getStopTxnAlignedData();
bool setStopTxnAlignedData(std::string stop_txn_aligned_data);
KeyValue getStopTxnAlignedDataKeyValue();
std::vector<MeasurandWithPhase> getStopTxnAlignedDataVector();

// Core Profile - optional
std::optional<int32_t> getStopTxnAlignedDataMaxLength();
Expand All @@ -239,7 +238,6 @@ class ChargePointConfiguration {
std::string getStopTxnSampledData();
bool setStopTxnSampledData(std::string stop_txn_sampled_data);
KeyValue getStopTxnSampledDataKeyValue();
std::vector<MeasurandWithPhase> getStopTxnSampledDataVector();

// Core Profile - optional
std::optional<int32_t> getStopTxnSampledDataMaxLength();
Expand Down
5 changes: 5 additions & 0 deletions include/ocpp/v16/charge_point_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ class ChargePointImpl : ocpp::ChargingStationBase {
void stop_pending_transactions();
void stop_transaction(int32_t connector, Reason reason, std::optional<CiString<20>> id_tag_end);

/// \brief Converts the given \p measurands_csv to a vector of Measurands
/// \param measurands_csv
/// \return
std::vector<Measurand> get_measurands_vec(const std::string& measurands_csv);

/// \brief Returns transaction data that can be used to set the transactionData field in StopTransaction.req.
/// Filters the meter values of the transaction according to the values set within StopTxnAlignedData and
/// StopTxnSampledData
Expand Down
6 changes: 0 additions & 6 deletions lib/ocpp/v16/charge_point_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,9 +1189,6 @@ KeyValue ChargePointConfiguration::getStopTxnAlignedDataKeyValue() {
kv.value.emplace(this->getStopTxnAlignedData());
return kv;
}
std::vector<MeasurandWithPhase> ChargePointConfiguration::getStopTxnAlignedDataVector() {
return this->csv_to_measurand_with_phase_vector(this->getStopTxnAlignedData());
}

// Core Profile - optional
std::optional<int32_t> ChargePointConfiguration::getStopTxnAlignedDataMaxLength() {
Expand Down Expand Up @@ -1234,9 +1231,6 @@ KeyValue ChargePointConfiguration::getStopTxnSampledDataKeyValue() {
kv.value.emplace(this->getStopTxnSampledData());
return kv;
}
std::vector<MeasurandWithPhase> ChargePointConfiguration::getStopTxnSampledDataVector() {
return this->csv_to_measurand_with_phase_vector(this->getStopTxnSampledData());
}

// Core Profile - optional
std::optional<int32_t> ChargePointConfiguration::getStopTxnSampledDataMaxLength() {
Expand Down
41 changes: 28 additions & 13 deletions lib/ocpp/v16/charge_point_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3196,34 +3196,49 @@ void ChargePointImpl::stop_transaction(int32_t connector, Reason reason, std::op
this->transaction_handler->add_stopped_transaction(transaction->get_connector());
}

std::vector<Measurand> ChargePointImpl::get_measurands_vec(const std::string& measurands_csv) {
std::vector<Measurand> measurands;
std::vector<std::string> measurands_strings = ocpp::get_vector_from_csv(measurands_csv);

for (const auto& measurand_string : measurands_strings) {
try {
measurands.push_back(conversions::string_to_measurand(measurand_string));
} catch (std::out_of_range& e) {
EVLOG_warning << "Could not convert string: " << measurand_string << " to MeasurandEnum";
}
}
return measurands;
}

std::vector<TransactionData>
ChargePointImpl::get_filtered_transaction_data(const std::shared_ptr<Transaction>& transaction) {
const auto stop_txn_sampled_data = this->configuration->getStopTxnSampledDataVector();
const auto stop_txn_aligned_data = this->configuration->getStopTxnAlignedDataVector();
const auto stop_txn_sampled_data_measurands =
this->get_measurands_vec(this->configuration->getStopTxnSampledData());
const auto stop_txn_aligned_data_measurands =
this->get_measurands_vec(this->configuration->getStopTxnAlignedData());

std::vector<TransactionData> filtered_transaction_data_vec;

if (!stop_txn_sampled_data.empty() or !stop_txn_aligned_data.empty()) {
if (!stop_txn_sampled_data_measurands.empty() or !stop_txn_aligned_data_measurands.empty()) {
std::vector<TransactionData> transaction_data_vec = transaction->get_transaction_data();
for (const auto& entry : transaction_data_vec) {
std::vector<SampledValue> sampled_values;
for (const auto& meter_value : entry.sampledValue) {
if (meter_value.measurand.has_value()) {
// if Sample.Clock use StopTxnAlignedData
if (meter_value.context.has_value() and meter_value.context == ReadingContext::Sample_Clock) {
for (const auto& stop_txn_aligned_entry : stop_txn_aligned_data) {
if (stop_txn_aligned_entry.measurand == meter_value.measurand.value()) {
sampled_values.push_back(meter_value);
continue;
}
if (std::find(stop_txn_aligned_data_measurands.begin(), stop_txn_aligned_data_measurands.end(),
meter_value.measurand.value()) != stop_txn_aligned_data_measurands.end()) {
sampled_values.push_back(meter_value);
continue;
}
} else {
// else use StopTxnSampledData although spec is unclear about how to filter other ReadingContext
// values like Transaction.Begin , Trigger , etc.
for (const auto& stop_txn_sampled_entry : stop_txn_sampled_data) {
if (stop_txn_sampled_entry.measurand == meter_value.measurand.value()) {
sampled_values.push_back(meter_value);
continue;
}
if (std::find(stop_txn_sampled_data_measurands.begin(), stop_txn_sampled_data_measurands.end(),
meter_value.measurand.value()) != stop_txn_sampled_data_measurands.end()) {
sampled_values.push_back(meter_value);
continue;
}
}
} else {
Expand Down

0 comments on commit 95db166

Please sign in to comment.