@@ -103,17 +103,18 @@ CHIP_ERROR EVSEManufacturer::Shutdown()
103
103
return CHIP_NO_ERROR;
104
104
}
105
105
106
- CHIP_ERROR FindNextTarget (const uint8_t dayOfWeekMap, uint32_t minutesPastMidnight_m, DataModel::Nullable<uint32_t > & targetTime_m,
107
- DataModel::Nullable<Percent> & targetSoC, DataModel::Nullable<int64_t > & addedEnergy_mWh)
106
+ CHIP_ERROR FindNextTarget (const uint8_t dayOfWeekMap, uint16_t minutesPastMidnightNow_m,
107
+ DataModel::Nullable<uint32_t > & targetTime_m, DataModel::Nullable<Percent> & targetSoC,
108
+ DataModel::Nullable<int64_t > & addedEnergy_mWh)
108
109
{
109
110
110
111
CHIP_ERROR err = CHIP_NO_ERROR;
111
112
112
113
EvseTargetEntry chargingTargetScheduleEntry;
113
114
EnergyEvse::Structs::ChargingTargetScheduleStruct::Type entry;
114
115
115
- int32_t minTimeToTarget_m = 1440 ; // 24 hours
116
- int32_t timeToTarget_m;
116
+ uint16_t minTimeToTarget_m = 1440 ; // 24 hours
117
+ uint16_t timeToTarget_m;
117
118
bool bFound = false ;
118
119
119
120
EVSEManufacturer * mn = GetEvseManufacturer ();
@@ -133,18 +134,22 @@ CHIP_ERROR FindNextTarget(const uint8_t dayOfWeekMap, uint32_t minutesPastMidnig
133
134
// We've found today's schedule
134
135
for (const EvseChargingTarget & chargingTarget : chargingTargetScheduleEntry.dailyChargingTargets )
135
136
{
136
- timeToTarget_m = chargingTarget.targetTimeMinutesPastMidnight - minutesPastMidnight_m;
137
- if (timeToTarget_m < 0 )
137
+ if (chargingTarget.targetTimeMinutesPastMidnight < minutesPastMidnightNow_m)
138
138
{
139
139
// This target is in the past - ignore it
140
140
continue ;
141
141
}
142
142
143
+ timeToTarget_m = chargingTarget.targetTimeMinutesPastMidnight - minutesPastMidnightNow_m;
144
+
143
145
if (timeToTarget_m < minTimeToTarget_m)
144
146
{
145
147
// This is the closest target found in the day's targets so far
148
+ bFound = true ;
146
149
minTimeToTarget_m = timeToTarget_m;
150
+
147
151
targetTime_m.SetNonNull (chargingTarget.targetTimeMinutesPastMidnight );
152
+
148
153
if (chargingTarget.targetSoC .HasValue ())
149
154
{
150
155
targetSoC.SetNonNull (chargingTarget.targetSoC .Value ());
@@ -153,6 +158,7 @@ CHIP_ERROR FindNextTarget(const uint8_t dayOfWeekMap, uint32_t minutesPastMidnig
153
158
{
154
159
targetSoC.SetNull ();
155
160
}
161
+
156
162
if (chargingTarget.addedEnergy .HasValue ())
157
163
{
158
164
addedEnergy_mWh.SetNonNull (chargingTarget.addedEnergy .Value ());
@@ -161,7 +167,6 @@ CHIP_ERROR FindNextTarget(const uint8_t dayOfWeekMap, uint32_t minutesPastMidnig
161
167
{
162
168
addedEnergy_mWh.SetNull ();
163
169
}
164
- bFound = true ;
165
170
}
166
171
}
167
172
}
@@ -194,8 +199,8 @@ CHIP_ERROR EVSEManufacturer::ComputeChargingSchedule()
194
199
uint8_t dayOfWeekMap = 0 ;
195
200
ReturnErrorOnFailure (GetDayOfWeekNow (dayOfWeekMap));
196
201
197
- uint32_t minutesPastMidnight_m = 0 ;
198
- ReturnErrorOnFailure (GetMinutesPastMidnight (minutesPastMidnight_m ));
202
+ uint16_t minutesPastMidnightNow_m = 0 ;
203
+ ReturnErrorOnFailure (GetMinutesPastMidnight (minutesPastMidnightNow_m ));
199
204
200
205
DataModel::Nullable<uint32_t > startTime_m;
201
206
DataModel::Nullable<uint32_t > targetTime_m;
@@ -214,7 +219,7 @@ CHIP_ERROR EVSEManufacturer::ComputeChargingSchedule()
214
219
uint8_t dayOffset = 0 ;
215
220
while (dayOffset < 2 )
216
221
{
217
- err = FindNextTarget (dayOfWeekMap, minutesPastMidnight_m , targetTime_m, targetSoC, addedEnergy_mWh);
222
+ err = FindNextTarget (dayOfWeekMap, minutesPastMidnightNow_m , targetTime_m, targetSoC, addedEnergy_mWh);
218
223
if (err == CHIP_ERROR_NOT_FOUND)
219
224
{
220
225
// We didn't find one for today, try tomorrow
@@ -241,7 +246,7 @@ CHIP_ERROR EVSEManufacturer::ComputeChargingSchedule()
241
246
}
242
247
// We don't know the Vehicle SoC so we must charge now
243
248
// TODO make this use the SoC featureMap to determine if this is an error
244
- startTime_m.SetNonNull (minutesPastMidnight_m );
249
+ startTime_m.SetNonNull (minutesPastMidnightNow_m );
245
250
}
246
251
else
247
252
{
@@ -261,8 +266,8 @@ CHIP_ERROR EVSEManufacturer::ComputeChargingSchedule()
261
266
power_W = 7000 ;
262
267
263
268
// Time to charge(seconds) = (3600 * Energy(mWh) / Power(W)) / 1000
264
- // to avoid using floats we multiply by 36 and then divide by 100 (instead of x3600 and dividing by 1000)
265
- chargingDuration_s = static_cast <uint32_t >(((addedEnergy_mWh.Value () / power_W) * 36 ) / 100 );
269
+ // to avoid using floats we multiply by 36 and then divide by 10 (instead of x3600 and dividing by 1000)
270
+ chargingDuration_s = static_cast <uint32_t >(((addedEnergy_mWh.Value () / power_W) * 36 ) / 10 );
266
271
chargingDuration_m = chargingDuration_s / 60 ;
267
272
268
273
// Add in 15 minutes leeway to account for slow starting vehicles
@@ -275,10 +280,10 @@ CHIP_ERROR EVSEManufacturer::ComputeChargingSchedule()
275
280
int tempStartTime_m = targetTime_m.Value () - chargingDuration_m + (dayOffset * 1440 );
276
281
// if tempStartTime_m is negative it means that it will take more than 24hrs to charge the vehicle
277
282
278
- if ((tempStartTime_m < 0 ) || (tempStartTime_m < static_cast <int >(minutesPastMidnight_m )))
283
+ if ((tempStartTime_m < 0 ) || (tempStartTime_m < static_cast <int >(minutesPastMidnightNow_m )))
279
284
{
280
285
// we need to turn on the EVSE now - it won't have enough time to reach the target
281
- startTime_m.SetNonNull (minutesPastMidnight_m );
286
+ startTime_m.SetNonNull (minutesPastMidnightNow_m );
282
287
// TODO call function to turn on the EV
283
288
}
284
289
else
0 commit comments