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

OCPP201: Prevent duplicate import Wh meter values #916

Merged
merged 2 commits into from
Oct 29, 2024
Merged
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
31 changes: 19 additions & 12 deletions modules/OCPP201/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,27 +140,34 @@ to_ocpp_meter_value(const types::powermeter::Powermeter& power_meter,
ocpp::v201::MeterValue meter_value;
meter_value.timestamp = ocpp_conversions::to_ocpp_datetime_or_now(power_meter.timestamp);

// signed_meter_value is intended for OCMF style blobs of signed meter value reports during transaction start or end
// This is interpreted as Energy.Active.Import.Register
bool energy_Wh_import_signed_total_added = false;
// individual signed meter values can be provided by the power_meter itself

ocpp::v201::SampledValue sampled_value = to_ocpp_sampled_value(
reading_context, ocpp::v201::MeasurandEnum::Energy_Active_Import_Register, "Wh", std::nullopt);
sampled_value.value = power_meter.energy_Wh_import.total;
// add signedMeterValue if present
if (signed_meter_value.has_value()) {
sampled_value.signedMeterValue = to_ocpp_signed_meter_value(signed_meter_value.value());
}
meter_value.sampledValue.push_back(sampled_value);

// individual signed meter values can be provided by the power_meter itself

// Energy.Active.Import.Register
if (power_meter.energy_Wh_import_signed.has_value()) {
sampled_value = to_ocpp_sampled_value(reading_context, ocpp::v201::MeasurandEnum::Energy_Active_Import_Register,
"Wh", std::nullopt);
sampled_value.value = power_meter.energy_Wh_import.total;
const auto& energy_Wh_import_signed = power_meter.energy_Wh_import_signed.value();
if (energy_Wh_import_signed.total.has_value()) {
sampled_value.signedMeterValue = to_ocpp_signed_meter_value(energy_Wh_import_signed.total.value());
energy_Wh_import_signed_total_added = true;
}
meter_value.sampledValue.push_back(sampled_value);
}

if (not energy_Wh_import_signed_total_added) {
// No signed meter value for Energy.Active.Import.Register added, either no signed meter values are available or
// just one global signed_meter_value is present signed_meter_value is intended for OCMF style blobs of signed
// meter value reports during transaction start or end
// This is interpreted as Energy.Active.Import.Register
sampled_value = to_ocpp_sampled_value(reading_context, ocpp::v201::MeasurandEnum::Energy_Active_Import_Register,
"Wh", std::nullopt);
sampled_value.value = power_meter.energy_Wh_import.total;
// add signedMeterValue if present
if (signed_meter_value.has_value()) {
sampled_value.signedMeterValue = to_ocpp_signed_meter_value(signed_meter_value.value());
}
meter_value.sampledValue.push_back(sampled_value);
}
Expand Down
Loading