Skip to content

Commit 1a15051

Browse files
committed
[smartcharging] Fix merge with local limitations during charge
1 parent 4dc6237 commit 1a15051

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

src/chargepoint/smartcharging/SmartChargingManager.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,16 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::GetCompositeSched
408408
// Get local limitations
409409
ChargingProfile local_profile;
410410
local_profile.chargingProfileId = 0;
411-
local_profile.chargingProfileKind = ChargingProfileKindType::Relative;
411+
local_profile.chargingProfileKind = ChargingProfileKindType::Absolute;
412412
local_profile.chargingProfilePurpose = ChargingProfilePurposeType::TxDefaultProfile;
413413
local_profile.stackLevel = 0;
414414
if (m_events_handler.getLocalLimitationsSchedule(request.connectorId, request.duration, local_profile.chargingSchedule) &&
415415
!local_profile.chargingSchedule.chargingSchedulePeriod.empty())
416416
{
417-
// Ensure profile is relative with the requested duration
417+
// Ensure profile is absolute with the requested duration
418418
local_profile.chargingSchedule.startSchedule.clear();
419-
local_profile.chargingSchedule.duration = request.duration;
419+
local_profile.chargingSchedule.startSchedule = now;
420+
local_profile.chargingSchedule.duration = request.duration;
420421

421422
// Merge periods
422423
std::vector<Period> local_periods = getProfilePeriods(connector, local_profile, now, request.duration);

tests/chargepoint/smartcharging/test_composite_schedule3.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,80 @@ TEST_SUITE("Get composite schedule - multiple OCPP profiles")
323323
CHECK_EQ(schedule.chargingSchedulePeriod[4].numberPhases.value(), 1);
324324
}
325325

326+
TEST_CASE("1 profile (relative) + local limitations - charging")
327+
{
328+
SmartChargingManager smartcharging_mgr(
329+
stack_config, ocpp_config, database, event_handler, timer_pool, worker_pool, connectors, msgs_converter, msg_dispatcher);
330+
clearAllProfiles(smartcharging_mgr);
331+
332+
DateTime now = DateTime::now();
333+
334+
Connector* connector = connectors.getConnector(1);
335+
connector->transaction_id = 1;
336+
connector->transaction_start = DateTime(now.timestamp() - 100);
337+
338+
ChargingProfile profile1;
339+
profile1.chargingProfileId = 1;
340+
profile1.stackLevel = 5;
341+
profile1.chargingProfilePurpose = ChargingProfilePurposeType::TxDefaultProfile;
342+
profile1.chargingProfileKind = ChargingProfileKindType::Relative;
343+
344+
ChargingSchedulePeriod charging_period;
345+
charging_period.limit = 16.f;
346+
charging_period.startPeriod = 0;
347+
charging_period.numberPhases = 1;
348+
profile1.chargingSchedule.chargingSchedulePeriod.push_back(charging_period);
349+
charging_period.limit = 10.f;
350+
charging_period.startPeriod = 1000;
351+
charging_period.numberPhases = 2;
352+
profile1.chargingSchedule.chargingSchedulePeriod.push_back(charging_period);
353+
charging_period.limit = 32.f;
354+
charging_period.startPeriod = 1700;
355+
charging_period.numberPhases = 3;
356+
profile1.chargingSchedule.chargingSchedulePeriod.push_back(charging_period);
357+
profile1.chargingSchedule.chargingRateUnit = ChargingRateUnitType::A;
358+
profile1.chargingSchedule.startSchedule = DateTime(now.timestamp() + 300);
359+
CHECK(installProfile(1, profile1, smartcharging_mgr));
360+
361+
ChargingSchedule& local_schedule = event_handler.schedule;
362+
local_schedule.chargingSchedulePeriod.clear();
363+
charging_period.limit = 8.f;
364+
charging_period.startPeriod = 0;
365+
charging_period.numberPhases = 2;
366+
local_schedule.chargingSchedulePeriod.push_back(charging_period);
367+
charging_period.limit = 20.f;
368+
charging_period.startPeriod = 200;
369+
charging_period.numberPhases = 3;
370+
local_schedule.chargingSchedulePeriod.push_back(charging_period);
371+
charging_period.limit = 18.f;
372+
charging_period.startPeriod = 1400;
373+
charging_period.numberPhases = 3;
374+
local_schedule.chargingSchedulePeriod.push_back(charging_period);
375+
local_schedule.chargingRateUnit = ChargingRateUnitType::A;
376+
377+
ChargingSchedule schedule;
378+
CHECK(getCompositeSchedule(1, 3600, ChargingRateUnitType::A, schedule, smartcharging_mgr));
379+
380+
CHECK_EQ(schedule.duration, 3600);
381+
CHECK_EQ(schedule.chargingRateUnit, ChargingRateUnitType::A);
382+
CHECK_GE(schedule.startSchedule.value(), now);
383+
CHECK_LE(schedule.startSchedule.value(), DateTime(now.timestamp() + 1));
384+
CHECK_EQ(schedule.chargingSchedulePeriod.size(), 4);
385+
386+
CHECK_EQ(schedule.chargingSchedulePeriod[0].startPeriod, 0);
387+
CHECK_EQ(schedule.chargingSchedulePeriod[0].limit, 8.f);
388+
CHECK_EQ(schedule.chargingSchedulePeriod[0].numberPhases.value(), 2);
389+
CHECK_EQ(schedule.chargingSchedulePeriod[1].startPeriod, 200);
390+
CHECK_EQ(schedule.chargingSchedulePeriod[1].limit, 16.f);
391+
CHECK_EQ(schedule.chargingSchedulePeriod[1].numberPhases.value(), 1);
392+
CHECK_EQ(schedule.chargingSchedulePeriod[2].startPeriod, 900);
393+
CHECK_EQ(schedule.chargingSchedulePeriod[2].limit, 10.f);
394+
CHECK_EQ(schedule.chargingSchedulePeriod[2].numberPhases.value(), 2);
395+
CHECK_EQ(schedule.chargingSchedulePeriod[3].startPeriod, 1600);
396+
CHECK_EQ(schedule.chargingSchedulePeriod[3].limit, 18.f);
397+
CHECK_EQ(schedule.chargingSchedulePeriod[3].numberPhases.value(), 3);
398+
}
399+
326400
TEST_CASE("Cleanup")
327401
{
328402
CHECK(database.close());

0 commit comments

Comments
 (0)