Skip to content

Commit

Permalink
Add filtering of signed meter values
Browse files Browse the repository at this point in the history
Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass committed Feb 19, 2024
1 parent 7e0ce54 commit c8a1997
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
9 changes: 7 additions & 2 deletions include/ocpp/v201/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,24 @@ bool meter_value_has_any_measurand(const MeterValue& _meter_value, const std::ve
/// SampledValue, the SampledValue will also be omitted.
/// \param _meter_value the meter value to be filtered
/// \param measurands applied measurands
/// \param include_signed if signed meter values should be included or not
/// \return filtered meter value
MeterValue get_meter_value_with_measurands_applied(const MeterValue& _meter_value,
const std::vector<MeasurandEnum>& measurands);
const std::vector<MeasurandEnum>& measurands,
bool include_signed = true);

/// \brief Applies the given measurands to \p meter_values based on their ReadingContext.
/// Transaction_Begin, Interruption_Begin, Transaction_End, Interruption_End and Sample_Periodic will be filtered using
/// \p sampled_tx_ended_measurands.
/// Sample_Clock will be filtered using \p aligned_tx_ended_measurands
/// Any metervalue after \p max_timestamp will also be removed.
/// \p include_sampled_signed if a sampled signed meter values should be included or not
/// \p include_aligned_signed if a sampled aligned meter values should be included or not
/// \retval filtered meter values
std::vector<MeterValue> get_meter_values_with_measurands_applied(
const std::vector<MeterValue>& meter_values, const std::vector<MeasurandEnum>& sampled_tx_ended_measurands,
const std::vector<MeasurandEnum>& aligned_tx_ended_measurands, ocpp::DateTime max_timestamp);
const std::vector<MeasurandEnum>& aligned_tx_ended_measurands, ocpp::DateTime max_timestamp,
bool include_sampled_signed = true, bool include_aligned_signed = true);

/// \brief Converts the given \p stop_reason to a TriggerReasonEnum
/// \param stop_reason
Expand Down
6 changes: 5 additions & 1 deletion lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,11 @@ void ChargePoint::on_transaction_finished(const int32_t evse_id, const DateTime&
this->device_model->get_value<std::string>(ControllerComponentVariables::SampledDataTxEndedMeasurands)),
utils::get_measurands_vec(
this->device_model->get_value<std::string>(ControllerComponentVariables::AlignedDataTxEndedMeasurands)),
timestamp));
timestamp,
this->device_model->get_optional_value<bool>(ControllerComponentVariables::SampledDataSignReadings)
.value_or(false),
this->device_model->get_optional_value<bool>(ControllerComponentVariables::AlignedDataSignReadings)
.value_or(false)));

if (meter_values.value().empty()) {
meter_values.reset();
Expand Down
17 changes: 11 additions & 6 deletions lib/ocpp/v201/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,31 @@ bool meter_value_has_any_measurand(const MeterValue& _meter_value, const std::ve
}

MeterValue get_meter_value_with_measurands_applied(const MeterValue& _meter_value,
const std::vector<MeasurandEnum>& measurands) {
const std::vector<MeasurandEnum>& measurands, bool include_signed) {
auto meter_value = _meter_value;
for (auto it = meter_value.sampledValue.begin(); it != meter_value.sampledValue.end();) {
auto measurand = it->measurand;
if (measurand.has_value()) {
if (std::find(measurands.begin(), measurands.end(), measurand.value()) == measurands.end()) {
it = meter_value.sampledValue.erase(it);
} else {
if (not include_signed) {
it->signedMeterValue.reset();
}
++it;
}
} else {
it = meter_value.sampledValue.erase(it);
}
}

return meter_value;
}

std::vector<MeterValue> get_meter_values_with_measurands_applied(
const std::vector<MeterValue>& meter_values, const std::vector<MeasurandEnum>& sampled_tx_ended_measurands,
const std::vector<MeasurandEnum>& aligned_tx_ended_measurands, ocpp::DateTime max_timestamp) {
const std::vector<MeasurandEnum>& aligned_tx_ended_measurands, ocpp::DateTime max_timestamp,
bool include_sampled_signed, bool include_aligned_signed) {
std::vector<MeterValue> meter_values_result;

for (const auto& meter_value : meter_values) {
Expand All @@ -73,15 +78,15 @@ std::vector<MeterValue> get_meter_values_with_measurands_applied(
case ReadingContextEnum::Interruption_End:
case ReadingContextEnum::Sample_Periodic:
if (meter_value_has_any_measurand(meter_value, sampled_tx_ended_measurands)) {
meter_values_result.push_back(
get_meter_value_with_measurands_applied(meter_value, sampled_tx_ended_measurands));
meter_values_result.push_back(get_meter_value_with_measurands_applied(
meter_value, sampled_tx_ended_measurands, include_sampled_signed));
}
break;

case ReadingContextEnum::Sample_Clock:
if (meter_value_has_any_measurand(meter_value, aligned_tx_ended_measurands)) {
meter_values_result.push_back(
get_meter_value_with_measurands_applied(meter_value, aligned_tx_ended_measurands));
meter_values_result.push_back(get_meter_value_with_measurands_applied(
meter_value, aligned_tx_ended_measurands, include_aligned_signed));
}
break;

Expand Down

0 comments on commit c8a1997

Please sign in to comment.