Skip to content

Commit

Permalink
Merge pull request #200 from thom-gh/fix/GetCompositeSchedule_DC
Browse files Browse the repository at this point in the history
Support GetCompositeSched without Unit using the first allowed unit
  • Loading branch information
c-jimenez authored Apr 11, 2024
2 parents 94ceef7 + 62ecbb8 commit 931b04c
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/chargepoint/smartcharging/SmartChargingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(m_mutex);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 931b04c

Please sign in to comment.