forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnergyEvseDelegateImpl.cpp
847 lines (713 loc) · 24.9 KB
/
EnergyEvseDelegateImpl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <EnergyEvseDelegateImpl.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app/EventLogging.h>
using namespace chip;
using namespace chip::app;
using namespace chip::app::DataModel;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::EnergyEvse;
using namespace chip::app::Clusters::EnergyEvse::Attributes;
using chip::app::LogEvent;
using chip::Protocols::InteractionModel::Status;
EnergyEvseDelegate::~EnergyEvseDelegate()
{
// TODO Fix this as part of issue #30993 refactoring
if (!mVehicleID.IsNull())
{
ChipLogDetail(AppServer, "Freeing VehicleID");
delete[] mVehicleID.Value().data();
}
}
/**
* @brief Called when EVSE cluster receives Disable command
*/
Status EnergyEvseDelegate::Disable()
{
ChipLogProgress(AppServer, "EnergyEvseDelegate::Disable()");
/* Update State */
switch (mHwState)
{
case StateEnum::kNotPluggedIn:
SetState(StateEnum::kNotPluggedIn);
break;
case StateEnum::kPluggedInNoDemand:
SetState(StateEnum::kPluggedInNoDemand);
break;
case StateEnum::kPluggedInDemand:
SetState(StateEnum::kPluggedInDemand);
break;
default:
ChipLogError(AppServer, "Unexpected EVSE hardware state");
SetState(StateEnum::kFault);
break;
}
/* update SupplyState */
SetSupplyState(SupplyStateEnum::kDisabled);
/* update ChargingEnabledUntil & DischargingEnabledUntil to show 0 */
SetChargingEnabledUntil(0);
SetDischargingEnabledUntil(0);
/* update MinimumChargeCurrent & MaximumChargeCurrent to 0 */
SetMinimumChargeCurrent(0);
SetMaximumChargeCurrent(0);
/* update MaximumDischargeCurrent to 0 */
SetMaximumDischargeCurrent(0);
NotifyApplicationStateChange();
// TODO: Generate events
return Status::Success;
}
/**
* @brief Called when EVSE cluster receives EnableCharging command
*
* @param chargingEnabledUntil (can be null to indefinite charging)
* @param minimumChargeCurrent (in mA)
* @param maximumChargeCurrent (in mA)
*/
Status EnergyEvseDelegate::EnableCharging(const DataModel::Nullable<uint32_t> & chargingEnabledUntil,
const int64_t & minimumChargeCurrent, const int64_t & maximumChargeCurrent)
{
ChipLogProgress(AppServer, "EnergyEvseDelegate::EnableCharging()");
if (maximumChargeCurrent < kMinimumChargeCurrent || maximumChargeCurrent > kMaximumChargeCurrent)
{
ChipLogError(AppServer, "Maximum Current outside limits");
return Status::ConstraintError;
}
if (minimumChargeCurrent < kMinimumChargeCurrent || minimumChargeCurrent > kMaximumChargeCurrent)
{
ChipLogError(AppServer, "Maximum Current outside limits");
return Status::ConstraintError;
}
if (minimumChargeCurrent > maximumChargeCurrent)
{
ChipLogError(AppServer, "Minium Current > Maximum Current!");
return Status::ConstraintError;
}
if (chargingEnabledUntil.IsNull())
{
/* Charging enabled indefinitely */
ChipLogError(AppServer, "Charging enabled indefinitely");
}
else
{
/* check chargingEnabledUntil is in the future */
ChipLogError(AppServer, "Charging enabled until: %lu", static_cast<long unsigned int>(chargingEnabledUntil.Value()));
// TODO
// if (checkChargingEnabled)
}
/* Check current state isn't already enabled */
/* If charging is already enabled, check that the parameters may have
changed, these may override an existing charging command */
switch (mHwState)
{
case StateEnum::kNotPluggedIn:
// TODO handle errors here
SetState(StateEnum::kNotPluggedIn);
break;
case StateEnum::kPluggedInNoDemand:
// TODO handle errors here
// TODO REFACTOR per Andrei's comment in PR30857 - can we collapse this switch statement?
SetState(StateEnum::kPluggedInNoDemand);
break;
case StateEnum::kPluggedInDemand:
/* If the EVSE is asking for demand then enable charging */
SetState(StateEnum::kPluggedInCharging);
break;
default:
ChipLogError(AppServer, "Unexpected EVSE hardware state");
SetState(StateEnum::kFault);
break;
}
/* update SupplyState to say that charging is now enabled */
SetSupplyState(SupplyStateEnum::kChargingEnabled);
/* If it looks ok, store the min & max charging current */
mMaximumChargingCurrentLimitFromCommand = maximumChargeCurrent;
SetMinimumChargeCurrent(minimumChargeCurrent);
// TODO persist these to KVS
// TODO: Generate events
NotifyApplicationStateChange();
return this->ComputeMaxChargeCurrentLimit();
}
/**
* @brief Called when EVSE cluster receives EnableDischarging command
*
* @param dischargingEnabledUntil (can be null to indefinite discharging)
* @param maximumChargeCurrent (in mA)
*/
Status EnergyEvseDelegate::EnableDischarging(const DataModel::Nullable<uint32_t> & dischargingEnabledUntil,
const int64_t & maximumDischargeCurrent)
{
ChipLogProgress(AppServer, "EnergyEvseDelegate::EnableDischarging() called.");
/* update SupplyState */
SetSupplyState(SupplyStateEnum::kDischargingEnabled);
// TODO: Generate events
NotifyApplicationStateChange();
return Status::Success;
}
/**
* @brief Called when EVSE cluster receives StartDiagnostics command
*/
Status EnergyEvseDelegate::StartDiagnostics()
{
/* For EVSE manufacturers to customize */
ChipLogProgress(AppServer, "EnergyEvseDelegate::StartDiagnostics()");
/* update SupplyState to indicate we are now in Diagnostics mode */
SetSupplyState(SupplyStateEnum::kDisabledDiagnostics);
// TODO: Generate events
// TODO: Notify Application to implement Diagnostics
NotifyApplicationStateChange();
return Status::Success;
}
/* ---------------------------------------------------------------------------
* EVSE Hardware interface below
*/
/**
* @brief Called by EVSE Hardware to register a callback handler mechanism
*
* This is normally called at start-up.
*
* @param EVSECallbackFunct - function pointer to call
* @param intptr_t - optional context to provide back to callback handler
*/
Status EnergyEvseDelegate::HwRegisterEvseCallbackHandler(EVSECallbackFunc handler, intptr_t arg)
{
if (mCallbacks.handler != nullptr)
{
ChipLogError(AppServer, "Callback handler already initialized");
return Status::Failure;
}
mCallbacks.handler = handler;
mCallbacks.arg = arg;
return Status::Success;
}
/**
* @brief Called by EVSE Hardware to notify the delegate of the maximum
* current limit supported by the hardware.
*
* This is normally called at start-up.
*
* @param currentmA - Maximum current limit supported by the hardware
*/
Status EnergyEvseDelegate::HwSetMaxHardwareCurrentLimit(int64_t currentmA)
{
if (currentmA < kMinimumChargeCurrent || currentmA > kMaximumChargeCurrent)
{
return Status::ConstraintError;
}
/* there is no attribute to store this so store in private variable */
mMaxHardwareCurrentLimit = currentmA;
return this->ComputeMaxChargeCurrentLimit();
}
/**
* @brief Called by EVSE Hardware to notify the delegate of maximum electrician
* set current limit.
*
* This is normally called at start-up when reading from DIP-switch
* settings.
*
* @param currentmA - Maximum current limit specified by electrician
*/
Status EnergyEvseDelegate::HwSetCircuitCapacity(int64_t currentmA)
{
if (currentmA < kMinimumChargeCurrent || currentmA > kMaximumChargeCurrent)
{
return Status::ConstraintError;
}
mCircuitCapacity = currentmA;
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, CircuitCapacity::Id);
return this->ComputeMaxChargeCurrentLimit();
}
/**
* @brief Called by EVSE Hardware to notify the delegate of the cable assembly
* current limit.
*
* This is normally called when the EV is plugged into the EVSE and the
* PP voltage is measured by the EVSE. A pull-up resistor in the cable
* causes a voltage drop. Different current limits can be indicated
* using different resistors, which results in different voltages
* measured by the EVSE.
*
* @param currentmA - Maximum current limit detected from Cable assembly
*/
Status EnergyEvseDelegate::HwSetCableAssemblyLimit(int64_t currentmA)
{
if (currentmA < kMinimumChargeCurrent || currentmA > kMaximumChargeCurrent)
{
return Status::ConstraintError;
}
/* there is no attribute to store this so store in private variable */
mCableAssemblyCurrentLimit = currentmA;
return this->ComputeMaxChargeCurrentLimit();
}
/**
* @brief Called by EVSE Hardware to indicate if EV is detected
*
* The only allowed states that the EVSE hardware can set are:
* kNotPluggedIn
* kPluggedInNoDemand
* kPluggedInDemand
*
* @param StateEnum - the state of the EV being plugged in and asking for demand etc
*/
Status EnergyEvseDelegate::HwSetState(StateEnum state)
{
switch (state)
{
case StateEnum::kNotPluggedIn:
// TODO - work out logic here
mHwState = state;
break;
case StateEnum::kPluggedInNoDemand:
// TODO - work out logic here
mHwState = state;
break;
case StateEnum::kPluggedInDemand:
// TODO - work out logic here
mHwState = state;
break;
default:
/* All other states should be managed by the Delegate */
// TODO (assert?)
break;
}
return Status::Success;
}
/**
* @brief Called by EVSE Hardware to indicate a fault
*
* @param FaultStateEnum - the fault condition detected
*/
Status EnergyEvseDelegate::HwSetFault(FaultStateEnum fault)
{
ChipLogProgress(AppServer, "EnergyEvseDelegate::Fault()");
if (fault == FaultStateEnum::kNoError)
{
/* Update State to previous state */
// TODO: need to work out the logic here!
/* Update SupplyState to previous state */
}
else
{
/* Update State & SupplyState */
SetState(StateEnum::kFault);
SetSupplyState(SupplyStateEnum::kDisabledError);
}
/* Update FaultState */
SetFaultState(fault);
// TODO: Generate events
return Status::Success;
}
/**
* @brief Called by EVSE Hardware to Send a RFID event
*
* @param ByteSpan RFID tag value (max 10 octets)
*/
Status EnergyEvseDelegate::HwSetRFID(ByteSpan uid)
{
Events::Rfid::Type event{ .uid = uid };
EventNumber eventNumber;
CHIP_ERROR error = LogEvent(event, mEndpointId, eventNumber);
if (CHIP_NO_ERROR != error)
{
ChipLogError(Zcl, "[Notify] Unable to send notify event: %s [endpointId=%d]", error.AsString(), mEndpointId);
return Status::Failure;
}
return Status::Success;
}
/**
* @brief Called by EVSE Hardware to share the VehicleID
*
* This routine will make a copy of the string so the callee doesn't
* have to hold onto it forever.
*
* @param CharSpan containing up to 32 chars.
*/
Status EnergyEvseDelegate::HwSetVehicleID(const CharSpan & newValue)
{
// TODO this code to be refactored - See Issue #30993
if (!mVehicleID.IsNull() && newValue.data_equal(mVehicleID.Value()))
{
return Status::Success;
}
/* create a copy of the string so the callee doesn't have to keep it */
char * destinationBuffer = new char[kMaxVehicleIDBufSize];
MutableCharSpan destinationString(destinationBuffer, kMaxVehicleIDBufSize);
CHIP_ERROR err = CopyCharSpanToMutableCharSpan(newValue, destinationString);
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "HwSetVehicleID - could not copy vehicleID");
delete[] destinationBuffer;
return Status::Failure;
}
if (!mVehicleID.IsNull())
{
delete[] mVehicleID.Value().data();
}
mVehicleID = MakeNullable(static_cast<CharSpan>(destinationString));
ChipLogDetail(AppServer, "VehicleID updated %.*s", static_cast<int>(mVehicleID.Value().size()), mVehicleID.Value().data());
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, VehicleID::Id);
return Status::Success;
}
/* ---------------------------------------------------------------------------
* Functions below are private helper functions internal to the delegate
*/
/**
* @brief Called to compute the safe charging current limit
*
* mActualChargingCurrentLimit is the minimum of:
* - MaxHardwareCurrentLimit (of the hardware)
* - CircuitCapacity (set by the electrician - less than the hardware)
* - CableAssemblyLimit (detected when the cable is inserted)
* - MaximumChargeCurrent (from charging command)
* - UserMaximumChargeCurrent (could dynamically change)
*
*/
Status EnergyEvseDelegate::ComputeMaxChargeCurrentLimit()
{
int64_t oldValue;
oldValue = mActualChargingCurrentLimit;
mActualChargingCurrentLimit = mMaxHardwareCurrentLimit;
mActualChargingCurrentLimit = min(mActualChargingCurrentLimit, mCircuitCapacity);
mActualChargingCurrentLimit = min(mActualChargingCurrentLimit, mCableAssemblyCurrentLimit);
mActualChargingCurrentLimit = min(mActualChargingCurrentLimit, mMaximumChargingCurrentLimitFromCommand);
mActualChargingCurrentLimit = min(mActualChargingCurrentLimit, mUserMaximumChargeCurrent);
/* Set the actual max charging current attribute */
mMaximumChargeCurrent = mActualChargingCurrentLimit;
if (oldValue != mMaximumChargeCurrent)
{
ChipLogDetail(AppServer, "MaximumChargeCurrent updated to %ld", static_cast<long>(mMaximumChargeCurrent));
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, MaximumChargeCurrent::Id);
/* Call the EV Charger hardware current limit callback */
NotifyApplicationCurrentLimitChange(mMaximumChargeCurrent);
}
return Status::Success;
}
Status EnergyEvseDelegate::NotifyApplicationCurrentLimitChange(int64_t maximumChargeCurrent)
{
EVSECbInfo cbInfo;
cbInfo.type = EVSECallbackType::ChargeCurrentChanged;
cbInfo.ChargingCurrent.maximumChargeCurrent = maximumChargeCurrent;
if (mCallbacks.handler != nullptr)
{
mCallbacks.handler(&cbInfo, mCallbacks.arg);
}
return Status::Success;
}
Status EnergyEvseDelegate::NotifyApplicationStateChange()
{
EVSECbInfo cbInfo;
cbInfo.type = EVSECallbackType::StateChanged;
cbInfo.StateChange.state = mState;
cbInfo.StateChange.supplyState = mSupplyState;
if (mCallbacks.handler != nullptr)
{
mCallbacks.handler(&cbInfo, mCallbacks.arg);
}
return Status::Success;
}
/**
* Attribute methods
*/
/* State */
StateEnum EnergyEvseDelegate::GetState()
{
return mState;
}
CHIP_ERROR EnergyEvseDelegate::SetState(StateEnum newValue)
{
StateEnum oldValue = mState;
if (newValue >= StateEnum::kUnknownEnumValue)
{
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
mState = newValue;
if (oldValue != mState)
{
ChipLogDetail(AppServer, "State updated to %d", static_cast<int>(mState));
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, State::Id);
}
return CHIP_NO_ERROR;
}
/* SupplyState */
SupplyStateEnum EnergyEvseDelegate::GetSupplyState()
{
return mSupplyState;
}
CHIP_ERROR EnergyEvseDelegate::SetSupplyState(SupplyStateEnum newValue)
{
SupplyStateEnum oldValue = mSupplyState;
if (newValue >= SupplyStateEnum::kUnknownEnumValue)
{
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
mSupplyState = newValue;
if (oldValue != mSupplyState)
{
ChipLogDetail(AppServer, "SupplyState updated to %d", static_cast<int>(mSupplyState));
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, SupplyState::Id);
}
return CHIP_NO_ERROR;
}
/* FaultState */
FaultStateEnum EnergyEvseDelegate::GetFaultState()
{
return mFaultState;
}
CHIP_ERROR EnergyEvseDelegate::SetFaultState(FaultStateEnum newValue)
{
FaultStateEnum oldValue = mFaultState;
if (newValue >= FaultStateEnum::kUnknownEnumValue)
{
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
mFaultState = newValue;
if (oldValue != mFaultState)
{
ChipLogDetail(AppServer, "FaultState updated to %d", static_cast<int>(mFaultState));
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, FaultState::Id);
}
return CHIP_NO_ERROR;
}
/* ChargingEnabledUntil */
DataModel::Nullable<uint32_t> EnergyEvseDelegate::GetChargingEnabledUntil()
{
return mChargingEnabledUntil;
}
CHIP_ERROR EnergyEvseDelegate::SetChargingEnabledUntil(uint32_t newValue)
{
DataModel::Nullable<uint32_t> oldValue = mChargingEnabledUntil;
mChargingEnabledUntil = MakeNullable(newValue);
if ((oldValue.IsNull()) || (oldValue.Value() != newValue))
{
ChipLogDetail(AppServer, "ChargingEnabledUntil updated to %lu",
static_cast<unsigned long int>(mChargingEnabledUntil.Value()));
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, ChargingEnabledUntil::Id);
}
return CHIP_NO_ERROR;
}
/* DischargingEnabledUntil */
DataModel::Nullable<uint32_t> EnergyEvseDelegate::GetDischargingEnabledUntil()
{
return mDischargingEnabledUntil;
}
CHIP_ERROR EnergyEvseDelegate::SetDischargingEnabledUntil(uint32_t newValue)
{
DataModel::Nullable<uint32_t> oldValue = mDischargingEnabledUntil;
mDischargingEnabledUntil = MakeNullable(newValue);
if ((oldValue.IsNull()) || (oldValue.Value() != newValue))
{
ChipLogDetail(AppServer, "DischargingEnabledUntil updated to %lu",
static_cast<unsigned long int>(mDischargingEnabledUntil.Value()));
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, DischargingEnabledUntil::Id);
}
return CHIP_NO_ERROR;
}
/* CircuitCapacity */
int64_t EnergyEvseDelegate::GetCircuitCapacity()
{
return mCircuitCapacity;
}
CHIP_ERROR EnergyEvseDelegate::SetCircuitCapacity(int64_t newValue)
{
int64_t oldValue = mCircuitCapacity;
if (newValue >= kMaximumChargeCurrent)
{
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
mCircuitCapacity = newValue;
if (oldValue != mCircuitCapacity)
{
ChipLogDetail(AppServer, "CircuitCapacity updated to %ld", static_cast<long>(mCircuitCapacity));
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, CircuitCapacity::Id);
}
return CHIP_NO_ERROR;
}
/* MinimumChargeCurrent */
int64_t EnergyEvseDelegate::GetMinimumChargeCurrent()
{
return mMinimumChargeCurrent;
}
CHIP_ERROR EnergyEvseDelegate::SetMinimumChargeCurrent(int64_t newValue)
{
int64_t oldValue = mMinimumChargeCurrent;
if (newValue >= kMaximumChargeCurrent)
{
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
mMinimumChargeCurrent = newValue;
if (oldValue != mMinimumChargeCurrent)
{
ChipLogDetail(AppServer, "MinimumChargeCurrent updated to %ld", static_cast<long>(mMinimumChargeCurrent));
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, MinimumChargeCurrent::Id);
}
return CHIP_NO_ERROR;
}
/* MaximumChargeCurrent */
int64_t EnergyEvseDelegate::GetMaximumChargeCurrent()
{
return mMaximumChargeCurrent;
}
CHIP_ERROR EnergyEvseDelegate::SetMaximumChargeCurrent(int64_t newValue)
{
int64_t oldValue = mMaximumChargeCurrent;
if (newValue >= kMaximumChargeCurrent)
{
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
mMaximumChargeCurrent = newValue;
if (oldValue != mMaximumChargeCurrent)
{
ChipLogDetail(AppServer, "MaximumChargeCurrent updated to %ld", static_cast<long>(mMaximumChargeCurrent));
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, MaximumChargeCurrent::Id);
}
return CHIP_NO_ERROR;
}
/* MaximumDischargeCurrent */
int64_t EnergyEvseDelegate::GetMaximumDischargeCurrent()
{
return mMaximumDischargeCurrent;
}
CHIP_ERROR EnergyEvseDelegate::SetMaximumDischargeCurrent(int64_t newValue)
{
int64_t oldValue = mMaximumDischargeCurrent;
if (newValue >= kMaximumChargeCurrent)
{
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
mMaximumDischargeCurrent = newValue;
if (oldValue != mMaximumDischargeCurrent)
{
ChipLogDetail(AppServer, "MaximumDischargeCurrent updated to %ld", static_cast<long>(mMaximumDischargeCurrent));
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, MaximumDischargeCurrent::Id);
}
return CHIP_NO_ERROR;
}
/* UserMaximumChargeCurrent */
int64_t EnergyEvseDelegate::GetUserMaximumChargeCurrent()
{
return mUserMaximumChargeCurrent;
}
CHIP_ERROR EnergyEvseDelegate::SetUserMaximumChargeCurrent(int64_t newValue)
{
if ((newValue < 0) || (newValue > kMaximumChargeCurrent))
{
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
int64_t oldValue = mUserMaximumChargeCurrent;
mUserMaximumChargeCurrent = newValue;
if (oldValue != newValue)
{
ChipLogDetail(AppServer, "UserMaximumChargeCurrent updated to %ld", static_cast<long>(mUserMaximumChargeCurrent));
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, UserMaximumChargeCurrent::Id);
}
return CHIP_NO_ERROR;
}
/* RandomizationDelayWindow */
uint32_t EnergyEvseDelegate::GetRandomizationDelayWindow()
{
return mRandomizationDelayWindow;
}
CHIP_ERROR EnergyEvseDelegate::SetRandomizationDelayWindow(uint32_t newValue)
{
uint32_t oldValue = mRandomizationDelayWindow;
if (newValue > kMaxRandomizationDelayWindow)
{
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
mRandomizationDelayWindow = newValue;
if (oldValue != newValue)
{
ChipLogDetail(AppServer, "RandomizationDelayWindow updated to %lu",
static_cast<unsigned long int>(mRandomizationDelayWindow));
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, RandomizationDelayWindow::Id);
}
return CHIP_NO_ERROR;
}
/* PREF attributes */
uint8_t EnergyEvseDelegate::GetNumberOfWeeklyTargets()
{
return mNumberOfWeeklyTargets;
}
uint8_t EnergyEvseDelegate::GetNumberOfDailyTargets()
{
return mNumberOfDailyTargets;
}
DataModel::Nullable<uint32_t> EnergyEvseDelegate::GetNextChargeStartTime()
{
return mNextChargeStartTime;
}
DataModel::Nullable<uint32_t> EnergyEvseDelegate::GetNextChargeTargetTime()
{
return mNextChargeTargetTime;
}
DataModel::Nullable<int64_t> EnergyEvseDelegate::GetNextChargeRequiredEnergy()
{
return mNextChargeRequiredEnergy;
}
DataModel::Nullable<Percent> EnergyEvseDelegate::GetNextChargeTargetSoC()
{
return mNextChargeTargetSoC;
}
/* ApproximateEVEfficiency */
DataModel::Nullable<uint16_t> EnergyEvseDelegate::GetApproximateEVEfficiency()
{
return mApproximateEVEfficiency;
}
CHIP_ERROR EnergyEvseDelegate::SetApproximateEVEfficiency(uint16_t newValue)
{
DataModel::Nullable<uint16_t> oldValue = mApproximateEVEfficiency;
mApproximateEVEfficiency = MakeNullable(newValue);
if ((oldValue.IsNull()) || (oldValue.Value() != newValue))
{
ChipLogDetail(AppServer, "ApproximateEVEfficiency updated to %d", mApproximateEVEfficiency.Value());
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, ApproximateEVEfficiency::Id);
}
return CHIP_NO_ERROR;
}
/* SOC attributes */
DataModel::Nullable<Percent> EnergyEvseDelegate::GetStateOfCharge()
{
return mStateOfCharge;
}
DataModel::Nullable<int64_t> EnergyEvseDelegate::GetBatteryCapacity()
{
return mBatteryCapacity;
}
/* PNC attributes*/
DataModel::Nullable<CharSpan> EnergyEvseDelegate::GetVehicleID()
{
return mVehicleID;
}
/* Session SESS attributes */
DataModel::Nullable<uint32_t> EnergyEvseDelegate::GetSessionID()
{
return mSessionID;
}
DataModel::Nullable<uint32_t> EnergyEvseDelegate::GetSessionDuration()
{
return mSessionDuration;
}
DataModel::Nullable<int64_t> EnergyEvseDelegate::GetSessionEnergyCharged()
{
return mSessionEnergyCharged;
}
DataModel::Nullable<int64_t> EnergyEvseDelegate::GetSessionEnergyDischarged()
{
return mSessionEnergyDischarged;
}