From 697ecf57f0297487ac7d45b6d76348cd53b46dbf Mon Sep 17 00:00:00 2001 From: Sebastian Lukas <45936573+SebaLukas@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:44:38 +0100 Subject: [PATCH] Adding feedback dc_max_limits to dc_charge_parameter_discovery state (#45) Signed-off-by: Sebastian Lukas --- .../state/dc_charge_parameter_discovery.cpp | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/iso15118/d20/state/dc_charge_parameter_discovery.cpp b/src/iso15118/d20/state/dc_charge_parameter_discovery.cpp index 8d0f799..e4336c3 100644 --- a/src/iso15118/d20/state/dc_charge_parameter_discovery.cpp +++ b/src/iso15118/d20/state/dc_charge_parameter_discovery.cpp @@ -101,27 +101,30 @@ FsmSimpleState::HandleEventReturnType DC_ChargeParameterDiscovery::handle_event( const auto variant = ctx.pull_request(); if (const auto req = variant->get_if()) { - dt::RationalNumber max_current; - if (std::holds_alternative(req->transfer_mode)) { + auto dc_max_limits = session::feedback::DcMaximumLimits{}; - max_current = std::get<0>(req->transfer_mode).max_charge_current; + if (const auto* mode = std::get_if(&req->transfer_mode)) { + dc_max_limits.current = dt::from_RationalNumber(mode->max_charge_current); + dc_max_limits.voltage = dt::from_RationalNumber(mode->max_voltage); + dc_max_limits.power = dt::from_RationalNumber(mode->max_charge_power); - } else if (std::holds_alternative(req->transfer_mode)) { + logf_info("Max charge current %fA", dt::from_RationalNumber(mode->max_charge_current)); + } else if (const auto* mode = std::get_if(&req->transfer_mode)) { + dc_max_limits.current = dt::from_RationalNumber(mode->max_charge_current); + dc_max_limits.voltage = dt::from_RationalNumber(mode->max_voltage); + dc_max_limits.power = dt::from_RationalNumber(mode->max_charge_power); - max_current = std::get<1>(req->transfer_mode).max_charge_current; - - const auto& max_discharge_current = std::get<1>(req->transfer_mode).max_discharge_current; - - logf_info("Max discharge current %de%d", max_discharge_current.value, max_discharge_current.exponent); + logf_info("Max charge current %fA", dt::from_RationalNumber(mode->max_charge_current)); + logf_info("Max discharge current %fA", dt::from_RationalNumber(mode->max_discharge_current)); } - logf_info("Max charge current %de%d", max_current.value, max_current.exponent); - const auto res = handle_request(*req, ctx.session, ctx.session_config.dc_limits); ctx.respond(res); + ctx.feedback.dc_max_limits(dc_max_limits); + if (res.response_code >= dt::ResponseCode::FAILED) { ctx.session_stopped = true; return sa.PASS_ON;