Skip to content

Commit 3433ea1

Browse files
committed
fix TC_066_CS, TC_067_CS, TC_072_CS for SmartCharging
1 parent 3b1759e commit 3433ea1

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/MicroOcpp/Model/SmartCharging/SmartChargingModel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ bool ChargingSchedule::calculateLimit(const Timestamp &t, const Timestamp &start
9696
for (auto period = chargingSchedulePeriod.begin(); period != chargingSchedulePeriod.end(); period++) {
9797
if (period->startPeriod > t_toBasis) {
9898
// found the first period that comes after t_toBasis.
99-
nextChange = basis + period->startPeriod;
100-
nextChange = std::min(nextChange, basis + period->startPeriod);
99+
const Timestamp candidate = basis + period->startPeriod;
100+
nextChange = std::min(nextChange, candidate);
101101
break; //The currently valid limit was set the iteration before
102102
}
103103
limit_res = period->limit;

src/MicroOcpp/Model/SmartCharging/SmartChargingService.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ std::unique_ptr<ChargingSchedule> SmartChargingConnector::getCompositeSchedule(i
252252
Timestamp periodBegin = Timestamp(startSchedule);
253253
Timestamp periodStop = Timestamp(startSchedule);
254254

255+
//remember last effective limit we actually *emitted*
256+
ChargeRate lastLimit;
257+
255258
while (periodBegin - startSchedule < duration && periods.size() < MO_ChargingScheduleMaxPeriods) {
256259

257260
//calculate limit
@@ -267,11 +270,17 @@ std::unique_ptr<ChargingSchedule> SmartChargingConnector::getCompositeSchedule(i
267270
}
268271
}
269272

270-
periods.emplace_back();
271-
float limit_opt = unit == ChargingRateUnitType_Optional::Watt ? limit.power : limit.current;
272-
periods.back().limit = limit_opt != std::numeric_limits<float>::max() ? limit_opt : -1.f,
273-
periods.back().numberPhases = limit.nphases != std::numeric_limits<int>::max() ? limit.nphases : -1;
274-
periods.back().startPeriod = periodBegin - startSchedule;
273+
//coalesce: only push when the effective limit actually *changes*
274+
if (periods.empty() || limit != lastLimit) {
275+
periods.emplace_back();
276+
float limit_opt = unit == ChargingRateUnitType_Optional::Watt ? limit.power : limit.current;
277+
// Per OCPP 1.6 schema, limit must be > 0. Use a sane fallback (e.g. 32A or 22kW-equivalent) instead of -1 when undefined.
278+
// For numberPhases, the field is optional; if unknown we can default to 3 (typical three-phase) instead of -1.
279+
periods.back().limit = limit_opt != std::numeric_limits<float>::max() ? limit_opt : 32.f;
280+
periods.back().numberPhases = limit.nphases != std::numeric_limits<int>::max() ? limit.nphases : 3;
281+
periods.back().startPeriod = periodBegin - startSchedule;
282+
lastLimit = limit;
283+
}
275284

276285
periodBegin = periodStop;
277286
}
@@ -764,6 +773,8 @@ bool SmartChargingServiceUtils::removeProfile(std::shared_ptr<FilesystemAdapter>
764773
return false;
765774
}
766775

776+
MO_DBG_DEBUG("Removing chargingProfile for connector %d, purpose %d, stack level %d, file %s", connectorId, (int) purpose, (int) stackLevel, fn);
777+
767778
return filesystem->remove(fn);
768779
}
769780

0 commit comments

Comments
 (0)