Skip to content

Commit c92a4e2

Browse files
committed
Sync EnergyEvseDelegateImpl.cpp from Example Energy Management
1 parent 0fdf9cc commit c92a4e2

File tree

1 file changed

+60
-49
lines changed

1 file changed

+60
-49
lines changed

examples/all-clusters-app/all-clusters-common/src/EnergyEvseDelegateImpl.cpp

+60-49
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Status EnergyEvseDelegate::Disable()
6464
break;
6565

6666
default:
67-
ChipLogError(AppServer, "Unexpected EVSE hardware state\n");
67+
ChipLogError(AppServer, "Unexpected EVSE hardware state");
6868
SetState(StateEnum::kFault);
6969
break;
7070
}
@@ -138,10 +138,13 @@ Status EnergyEvseDelegate::EnableCharging(const DataModel::Nullable<uint32_t> &
138138
switch (mHwState)
139139
{
140140
case StateEnum::kNotPluggedIn:
141+
// TODO handle errors here
141142
SetState(StateEnum::kNotPluggedIn);
142143
break;
143144

144145
case StateEnum::kPluggedInNoDemand:
146+
// TODO handle errors here
147+
// TODO REFACTOR per Andrei's comment in PR30857 - can we collapse this switch statement?
145148
SetState(StateEnum::kPluggedInNoDemand);
146149
break;
147150

@@ -151,12 +154,12 @@ Status EnergyEvseDelegate::EnableCharging(const DataModel::Nullable<uint32_t> &
151154
break;
152155

153156
default:
154-
ChipLogError(AppServer, "Unexpected EVSE hardware state\n");
157+
ChipLogError(AppServer, "Unexpected EVSE hardware state");
155158
SetState(StateEnum::kFault);
156159
break;
157160
}
158161

159-
/* update SupplyState */
162+
/* update SupplyState to say that charging is now enabled */
160163
SetSupplyState(SupplyStateEnum::kChargingEnabled);
161164

162165
/* If it looks ok, store the min & max charging current */
@@ -208,7 +211,6 @@ Status EnergyEvseDelegate::StartDiagnostics()
208211
* FUNCTIONS BELOW:
209212
* - EVSE Hardware interface
210213
*
211-
* RegisterEvseHardwareCallback( callbackType, callbackFnc )
212214
* SetMaxHardwareCurrentLimit( currentmA )
213215
* SetCircuitCapacity( currentmA )
214216
* SetCableAssemblyLimit( currentmA )
@@ -217,25 +219,13 @@ Status EnergyEvseDelegate::StartDiagnostics()
217219
*
218220
*/
219221

220-
/**
221-
* @brief Called by EVSE Hardware to register a callback
222-
*
223-
* @param Callback function
224-
*/
225-
#if 0
226-
Status EnergyEvseDelegate::HwRegisterEvseHardwareCallback(int Callback) // TODO
227-
{
228-
// TODO
229-
return CHIP_NO_ERROR;
230-
}
231-
#endif
232222
/**
233223
* @brief Called by EVSE Hardware to notify the delegate of the maximum
234224
* current limit supported by the hardware.
235225
*
236226
* This is normally called at start-up.
237227
*
238-
* @param currentmA
228+
* @param currentmA - Maximum current limit supported by the hardware
239229
*/
240230
Status EnergyEvseDelegate::HwSetMaxHardwareCurrentLimit(int64_t currentmA)
241231
{
@@ -257,7 +247,7 @@ Status EnergyEvseDelegate::HwSetMaxHardwareCurrentLimit(int64_t currentmA)
257247
* This is normally called at start-up when reading from DIP-switch
258248
* settings.
259249
*
260-
* @param currentmA
250+
* @param currentmA - Maximum current limit specified by electrician
261251
*/
262252
Status EnergyEvseDelegate::HwSetCircuitCapacity(int64_t currentmA)
263253
{
@@ -282,7 +272,7 @@ Status EnergyEvseDelegate::HwSetCircuitCapacity(int64_t currentmA)
282272
* using different resistors, which results in different voltages
283273
* measured by the EVSE.
284274
*
285-
* @param currentmA
275+
* @param currentmA - Maximum current limit detected from Cable assembly
286276
*/
287277
Status EnergyEvseDelegate::HwSetCableAssemblyLimit(int64_t currentmA)
288278
{
@@ -298,17 +288,17 @@ Status EnergyEvseDelegate::HwSetCableAssemblyLimit(int64_t currentmA)
298288
}
299289

300290
/**
301-
* @brief Called by EVSE Hardware to indicate a fault
291+
* @brief Called by EVSE Hardware to indicate if EV is detected
302292
*
303-
* @param StateEnum
293+
* The only allowed states that the EVSE hardware can set are:
294+
* kNotPluggedIn
295+
* kPluggedInNoDemand
296+
* kPluggedInDemand
297+
*
298+
* @param StateEnum - the state of the EV being plugged in and asking for demand etc
304299
*/
305300
Status EnergyEvseDelegate::HwSetState(StateEnum state)
306301
{
307-
/* the only allowed states that the EVSE hardware can set are:
308-
* kNotPluggedIn
309-
* kPluggedInNoDemand
310-
* kPluggedInDemand
311-
*/
312302
switch (state)
313303
{
314304
case StateEnum::kNotPluggedIn:
@@ -336,7 +326,7 @@ Status EnergyEvseDelegate::HwSetState(StateEnum state)
336326
/**
337327
* @brief Called by EVSE Hardware to indicate a fault
338328
*
339-
* @param FaultStateEnum
329+
* @param FaultStateEnum - the fault condition detected
340330
*/
341331
Status EnergyEvseDelegate::HwSetFault(FaultStateEnum fault)
342332
{
@@ -382,6 +372,7 @@ Status EnergyEvseDelegate::HwSetRFID(ByteSpan uid)
382372

383373
return Status::Success;
384374
}
375+
385376
/**
386377
* @brief Called by EVSE Hardware to share the VehicleID
387378
*
@@ -393,31 +384,33 @@ Status EnergyEvseDelegate::HwSetRFID(ByteSpan uid)
393384
Status EnergyEvseDelegate::HwSetVehicleID(const CharSpan & newValue)
394385
{
395386
// TODO this code to be refactored - See Issue #30993
396-
if (mVehicleID.IsNull() || !newValue.data_equal(mVehicleID.Value()))
387+
if (!mVehicleID.IsNull() && newValue.data_equal(mVehicleID.Value()))
397388
{
398-
/* create a copy of the string so the callee doesn't have to keep it */
399-
char * destinationBuffer = new char[kMaxVehicleIDBufSize];
400-
401-
MutableCharSpan destinationString(destinationBuffer, kMaxVehicleIDBufSize);
402-
CHIP_ERROR err = CopyCharSpanToMutableCharSpan(newValue, destinationString);
403-
if (err != CHIP_NO_ERROR)
404-
{
405-
ChipLogError(AppServer, "HwSetVehicleID - could not copy vehicleID");
406-
delete[] destinationBuffer;
407-
return Status::Failure;
408-
}
389+
return Status::Success;
390+
}
409391

410-
if (!mVehicleID.IsNull())
411-
{
412-
delete[] mVehicleID.Value().data();
413-
}
392+
/* create a copy of the string so the callee doesn't have to keep it */
393+
char * destinationBuffer = new char[kMaxVehicleIDBufSize];
414394

415-
mVehicleID = MakeNullable(static_cast<CharSpan>(destinationString));
395+
MutableCharSpan destinationString(destinationBuffer, kMaxVehicleIDBufSize);
396+
CHIP_ERROR err = CopyCharSpanToMutableCharSpan(newValue, destinationString);
397+
if (err != CHIP_NO_ERROR)
398+
{
399+
ChipLogError(AppServer, "HwSetVehicleID - could not copy vehicleID");
400+
delete[] destinationBuffer;
401+
return Status::Failure;
402+
}
416403

417-
ChipLogDetail(AppServer, "VehicleID updated");
418-
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, VehicleID::Id);
404+
if (!mVehicleID.IsNull())
405+
{
406+
delete[] mVehicleID.Value().data();
419407
}
420408

409+
mVehicleID = MakeNullable(static_cast<CharSpan>(destinationString));
410+
411+
ChipLogDetail(AppServer, "VehicleID updated %.*s", static_cast<int>(mVehicleID.Value().size()), mVehicleID.Value().data());
412+
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, VehicleID::Id);
413+
421414
return Status::Success;
422415
}
423416

@@ -468,6 +461,7 @@ StateEnum EnergyEvseDelegate::GetState()
468461
{
469462
return mState;
470463
}
464+
471465
CHIP_ERROR EnergyEvseDelegate::SetState(StateEnum newValue)
472466
{
473467
StateEnum oldValue = mState;
@@ -479,7 +473,7 @@ CHIP_ERROR EnergyEvseDelegate::SetState(StateEnum newValue)
479473
mState = newValue;
480474
if (oldValue != mState)
481475
{
482-
ChipLogDetail(AppServer, "State updated to %d", (int) mState);
476+
ChipLogDetail(AppServer, "State updated to %d", static_cast<int>(mState));
483477
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, State::Id);
484478
}
485479

@@ -491,6 +485,7 @@ SupplyStateEnum EnergyEvseDelegate::GetSupplyState()
491485
{
492486
return mSupplyState;
493487
}
488+
494489
CHIP_ERROR EnergyEvseDelegate::SetSupplyState(SupplyStateEnum newValue)
495490
{
496491
SupplyStateEnum oldValue = mSupplyState;
@@ -503,7 +498,7 @@ CHIP_ERROR EnergyEvseDelegate::SetSupplyState(SupplyStateEnum newValue)
503498
mSupplyState = newValue;
504499
if (oldValue != mSupplyState)
505500
{
506-
ChipLogDetail(AppServer, "SupplyState updated to %d", (int) mSupplyState);
501+
ChipLogDetail(AppServer, "SupplyState updated to %d", static_cast<int>(mSupplyState));
507502
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, SupplyState::Id);
508503
}
509504
return CHIP_NO_ERROR;
@@ -514,6 +509,7 @@ FaultStateEnum EnergyEvseDelegate::GetFaultState()
514509
{
515510
return mFaultState;
516511
}
512+
517513
CHIP_ERROR EnergyEvseDelegate::SetFaultState(FaultStateEnum newValue)
518514
{
519515
FaultStateEnum oldValue = mFaultState;
@@ -526,7 +522,7 @@ CHIP_ERROR EnergyEvseDelegate::SetFaultState(FaultStateEnum newValue)
526522
mFaultState = newValue;
527523
if (oldValue != mFaultState)
528524
{
529-
ChipLogDetail(AppServer, "FaultState updated to %d", (int) mFaultState);
525+
ChipLogDetail(AppServer, "FaultState updated to %d", static_cast<int>(mFaultState));
530526
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, FaultState::Id);
531527
}
532528
return CHIP_NO_ERROR;
@@ -537,6 +533,7 @@ DataModel::Nullable<uint32_t> EnergyEvseDelegate::GetChargingEnabledUntil()
537533
{
538534
return mChargingEnabledUntil;
539535
}
536+
540537
CHIP_ERROR EnergyEvseDelegate::SetChargingEnabledUntil(uint32_t newValue)
541538
{
542539
DataModel::Nullable<uint32_t> oldValue = mChargingEnabledUntil;
@@ -550,11 +547,13 @@ CHIP_ERROR EnergyEvseDelegate::SetChargingEnabledUntil(uint32_t newValue)
550547
}
551548
return CHIP_NO_ERROR;
552549
}
550+
553551
/* DischargingEnabledUntil */
554552
DataModel::Nullable<uint32_t> EnergyEvseDelegate::GetDischargingEnabledUntil()
555553
{
556554
return mDischargingEnabledUntil;
557555
}
556+
558557
CHIP_ERROR EnergyEvseDelegate::SetDischargingEnabledUntil(uint32_t newValue)
559558
{
560559
DataModel::Nullable<uint32_t> oldValue = mDischargingEnabledUntil;
@@ -568,11 +567,13 @@ CHIP_ERROR EnergyEvseDelegate::SetDischargingEnabledUntil(uint32_t newValue)
568567
}
569568
return CHIP_NO_ERROR;
570569
}
570+
571571
/* CircuitCapacity */
572572
int64_t EnergyEvseDelegate::GetCircuitCapacity()
573573
{
574574
return mCircuitCapacity;
575575
}
576+
576577
CHIP_ERROR EnergyEvseDelegate::SetCircuitCapacity(int64_t newValue)
577578
{
578579
int64_t oldValue = mCircuitCapacity;
@@ -590,11 +591,13 @@ CHIP_ERROR EnergyEvseDelegate::SetCircuitCapacity(int64_t newValue)
590591
}
591592
return CHIP_NO_ERROR;
592593
}
594+
593595
/* MinimumChargeCurrent */
594596
int64_t EnergyEvseDelegate::GetMinimumChargeCurrent()
595597
{
596598
return mMinimumChargeCurrent;
597599
}
600+
598601
CHIP_ERROR EnergyEvseDelegate::SetMinimumChargeCurrent(int64_t newValue)
599602
{
600603
int64_t oldValue = mMinimumChargeCurrent;
@@ -618,6 +621,7 @@ int64_t EnergyEvseDelegate::GetMaximumChargeCurrent()
618621
{
619622
return mMaximumChargeCurrent;
620623
}
624+
621625
CHIP_ERROR EnergyEvseDelegate::SetMaximumChargeCurrent(int64_t newValue)
622626
{
623627
int64_t oldValue = mMaximumChargeCurrent;
@@ -635,11 +639,13 @@ CHIP_ERROR EnergyEvseDelegate::SetMaximumChargeCurrent(int64_t newValue)
635639
}
636640
return CHIP_NO_ERROR;
637641
}
642+
638643
/* MaximumDischargeCurrent */
639644
int64_t EnergyEvseDelegate::GetMaximumDischargeCurrent()
640645
{
641646
return mMaximumDischargeCurrent;
642647
}
648+
643649
CHIP_ERROR EnergyEvseDelegate::SetMaximumDischargeCurrent(int64_t newValue)
644650
{
645651
int64_t oldValue = mMaximumDischargeCurrent;
@@ -657,11 +663,13 @@ CHIP_ERROR EnergyEvseDelegate::SetMaximumDischargeCurrent(int64_t newValue)
657663
}
658664
return CHIP_NO_ERROR;
659665
}
666+
660667
/* UserMaximumChargeCurrent */
661668
int64_t EnergyEvseDelegate::GetUserMaximumChargeCurrent()
662669
{
663670
return mUserMaximumChargeCurrent;
664671
}
672+
665673
CHIP_ERROR EnergyEvseDelegate::SetUserMaximumChargeCurrent(int64_t newValue)
666674
{
667675
if ((newValue < 0) || (newValue > kMaximumChargeCurrent))
@@ -679,11 +687,13 @@ CHIP_ERROR EnergyEvseDelegate::SetUserMaximumChargeCurrent(int64_t newValue)
679687

680688
return CHIP_NO_ERROR;
681689
}
690+
682691
/* RandomizationDelayWindow */
683692
uint32_t EnergyEvseDelegate::GetRandomizationDelayWindow()
684693
{
685694
return mRandomizationDelayWindow;
686695
}
696+
687697
CHIP_ERROR EnergyEvseDelegate::SetRandomizationDelayWindow(uint32_t newValue)
688698
{
689699
uint32_t oldValue = mRandomizationDelayWindow;
@@ -733,6 +743,7 @@ DataModel::Nullable<uint16_t> EnergyEvseDelegate::GetApproximateEVEfficiency()
733743
{
734744
return mApproximateEVEfficiency;
735745
}
746+
736747
CHIP_ERROR EnergyEvseDelegate::SetApproximateEVEfficiency(uint16_t newValue)
737748
{
738749
DataModel::Nullable<uint16_t> oldValue = mApproximateEVEfficiency;

0 commit comments

Comments
 (0)