From 62ecbb87f91fdfe48ac16124f63a1b2bb954fc79 Mon Sep 17 00:00:00 2001 From: Thomas Ghesquiere Date: Tue, 9 Apr 2024 16:40:20 +0200 Subject: [PATCH] support GetCompositeSched without Unit using the first allowed unit --- .../smartcharging/SmartChargingManager.cpp | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/chargepoint/smartcharging/SmartChargingManager.cpp b/src/chargepoint/smartcharging/SmartChargingManager.cpp index e7c71fe2..3a46c9b1 100644 --- a/src/chargepoint/smartcharging/SmartChargingManager.cpp +++ b/src/chargepoint/smartcharging/SmartChargingManager.cpp @@ -356,9 +356,23 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::GetCompositeSched (void)error_code; (void)error_message; + ocpp::types::ChargingRateUnitType charging_rate_unit; + if (!request.chargingRateUnit.isSet()) + { + if (m_ocpp_config.chargingScheduleAllowedChargingRateUnit().find("Power") != std::string::npos) + { + charging_rate_unit = types::ChargingRateUnitType::W; + } else + { + charging_rate_unit = types::ChargingRateUnitType::A; + } + } else { + charging_rate_unit = request.chargingRateUnit.value(); + } + LOG_INFO << "GetCompositeSchedule requested : connectorId = " << request.connectorId << " - duration = " << request.duration - << " - chargingRateUnit = " - << (request.chargingRateUnit.isSet() ? ChargingRateUnitTypeHelper.toString(request.chargingRateUnit) : "not set"); + << " - chargingRateUnit = " << ChargingRateUnitTypeHelper.toString(charging_rate_unit) + << (!request.chargingRateUnit.isSet() ? " (from allowed charging unit)" : ""); // Lock profiles std::lock_guard lock(m_mutex); @@ -442,14 +456,8 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::GetCompositeSched ChargingSchedule& schedule = response.chargingSchedule.value(); schedule.duration = 0; - if (request.chargingRateUnit.isSet()) - { - schedule.chargingRateUnit = request.chargingRateUnit; - } - else - { - schedule.chargingRateUnit = ChargingRateUnitType::A; - } + schedule.chargingRateUnit = charging_rate_unit; + // Adjust start if needed since first period must start at 0 time_t offset = periods[0].start; schedule.startSchedule = DateTime(now.timestamp() + offset);