Skip to content

Commit d659892

Browse files
Configure attribute
1 parent c2a7b5a commit d659892

File tree

5 files changed

+138
-26
lines changed

5 files changed

+138
-26
lines changed

examples/all-clusters-app/all-clusters-common/all-clusters-app.zap

+80
Original file line numberDiff line numberDiff line change
@@ -14240,6 +14240,38 @@
1424014240
"side": "server",
1424114241
"enabled": 1,
1424214242
"attributes": [
14243+
{
14244+
"name": "CalendarID",
14245+
"code": 0,
14246+
"mfgCode": null,
14247+
"side": "server",
14248+
"type": "int32u",
14249+
"included": 1,
14250+
"storageOption": "External",
14251+
"singleton": 0,
14252+
"bounded": 0,
14253+
"defaultValue": null,
14254+
"reportable": 1,
14255+
"minInterval": 1,
14256+
"maxInterval": 65534,
14257+
"reportableChange": 1
14258+
},
14259+
{
14260+
"name": "Name",
14261+
"code": 1,
14262+
"mfgCode": null,
14263+
"side": "server",
14264+
"type": "char_string",
14265+
"included": 1,
14266+
"storageOption": "External",
14267+
"singleton": 1,
14268+
"bounded": 0,
14269+
"defaultValue": null,
14270+
"reportable": 1,
14271+
"minInterval": 0,
14272+
"maxInterval": 65344,
14273+
"reportableChange": 1
14274+
},
1424314275
{
1424414276
"name": "FeatureMap",
1424514277
"code": 65532,
@@ -21789,6 +21821,54 @@
2178921821
"side": "server",
2179021822
"enabled": 1,
2179121823
"attributes": [
21824+
{
21825+
"name": "MeterType",
21826+
"code": 0,
21827+
"mfgCode": null,
21828+
"side": "server",
21829+
"type": "MeterTypeEnum",
21830+
"included": 1,
21831+
"storageOption": "External",
21832+
"singleton": 0,
21833+
"bounded": 0,
21834+
"defaultValue": null,
21835+
"reportable": 1,
21836+
"minInterval": 1,
21837+
"maxInterval": 65534,
21838+
"reportableChange": 1
21839+
},
21840+
{
21841+
"name": "UtilityName",
21842+
"code": 1,
21843+
"mfgCode": null,
21844+
"side": "server",
21845+
"type": "char_string",
21846+
"included": 1,
21847+
"storageOption": "External",
21848+
"singleton": 1,
21849+
"bounded": 0,
21850+
"defaultValue": null,
21851+
"reportable": 1,
21852+
"minInterval": 0,
21853+
"maxInterval": 65344,
21854+
"reportableChange": 1
21855+
},
21856+
{
21857+
"name": "PointOfDelivery",
21858+
"code": 2,
21859+
"mfgCode": null,
21860+
"side": "server",
21861+
"type": "char_string",
21862+
"included": 1,
21863+
"storageOption": "External",
21864+
"singleton": 1,
21865+
"bounded": 0,
21866+
"defaultValue": null,
21867+
"reportable": 1,
21868+
"minInterval": 0,
21869+
"maxInterval": 65344,
21870+
"reportableChange": 1
21871+
},
2179221872
{
2179321873
"name": "FeatureMap",
2179421874
"code": 65532,

examples/all-clusters-app/all-clusters-common/src/meter-identification-stub.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ void emberAfMeterIdentificationClusterInitCallback(chip::EndpointId endpointId)
3434
gMIDelegate = std::make_unique<MeterIdentificationDelegate>();
3535
if (gMIDelegate)
3636
{
37+
gMIDelegate->Init();
38+
3739
gMIInstance = std::make_unique<MeterIdentificationInstance>(endpointId, *gMIDelegate,
3840
BitMask<Feature, uint32_t>(Feature::kPowerThreshold));
3941

examples/energy-management-app/energy-management-common/include/MeterIdentificationDelegate.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class MeterIdentificationDelegate : public MeterIdentification::Delegate
3232
public:
3333
~MeterIdentificationDelegate() = default;
3434

35+
void Init();
36+
3537
CHIP_ERROR LoadJson(Json::Value & root);
3638

3739
// Attribute Accessors
@@ -44,8 +46,8 @@ class MeterIdentificationDelegate : public MeterIdentification::Delegate
4446

4547
// Internal Application API to set attribute values
4648
CHIP_ERROR SetMeterType(DataModel::Nullable<MeterTypeEnum>);
47-
CHIP_ERROR SetUtilityName(CharSpan & value);
48-
CHIP_ERROR SetPointOfDelivery(CharSpan & value);
49+
CHIP_ERROR SetUtilityName(CharSpan value);
50+
CHIP_ERROR SetPointOfDelivery(CharSpan value);
4951
CHIP_ERROR SetPowerThreshold(DataModel::Nullable<uint64_t>);
5052
CHIP_ERROR SetPowerThresholdSource(DataModel::Nullable<PowerThresholdSourceEnum>);
5153

examples/energy-management-app/energy-management-common/src/MeterIdentificationDelegate.cpp

+50-23
Original file line numberDiff line numberDiff line change
@@ -43,52 +43,55 @@ void MeterIdentificationInstance::Shutdown()
4343

4444
// --------------- Internal Attribute Set APIs
4545

46+
void MeterIdentificationDelegate::Init()
47+
{
48+
ChipLogProgress(Zcl, "MeterIdentificationDelegate::Init");
49+
50+
SetMeterType(MeterTypeEnum::kPrivate);
51+
SetUtilityName(CharSpan::fromCharString("Test Utility Name"));
52+
SetPointOfDelivery(CharSpan::fromCharString("Test PointOfDelivery"));
53+
SetPowerThreshold(100);
54+
SetPowerThresholdSource(PowerThresholdSourceEnum::kEquipment);
55+
}
56+
4657
CHIP_ERROR MeterIdentificationDelegate::LoadJson(Json::Value & root)
4758
{
4859
Json::Value value = root.get("MeterType", Json::Value());
4960
if (!value.empty())
5061
{
5162
if(value.isInt())
5263
{
53-
mMeterType.SetNonNull(static_cast<MeterTypeEnum>(value.asInt()));
64+
SetMeterType(static_cast<MeterTypeEnum>(value.asInt()));
5465
}
5566
else
5667
{
57-
mMeterType.SetNull();
68+
SetMeterType(std::nullopt);
5869
}
5970
}
6071

6172
value = root.get("UtilityName", Json::Value());
6273
if (!value.empty())
6374
{
64-
chip::Platform::MemoryFree((void*)mUtilityName.data());
6575
if(value.isString())
6676
{
67-
size_t len = value.asString().size()+1;
68-
char *str = (char*)chip::Platform::MemoryAlloc(len);
69-
memcpy(str, value.asCString(), len);
70-
mUtilityName = CharSpan(str, len);
77+
SetUtilityName(CharSpan::fromCharString(value.asCString()));
7178
}
7279
else
7380
{
74-
mUtilityName = CharSpan();
81+
SetUtilityName(CharSpan());
7582
}
7683
}
7784

7885
value = root.get("PointOfDelivery", Json::Value());
7986
if (!value.empty())
8087
{
81-
chip::Platform::MemoryFree((void*)mPointOfDelivery.data());
8288
if(value.isString())
8389
{
84-
size_t len = value.asString().size()+1;
85-
char *str = (char*)chip::Platform::MemoryAlloc(len);
86-
memcpy(str, value.asCString(), len);
87-
mPointOfDelivery = CharSpan(str, len);
90+
SetPointOfDelivery(CharSpan::fromCharString(value.asCString()));
8891
}
8992
else
9093
{
91-
mPointOfDelivery = CharSpan();
94+
SetPointOfDelivery(CharSpan());
9295
}
9396
}
9497

@@ -97,11 +100,11 @@ CHIP_ERROR MeterIdentificationDelegate::LoadJson(Json::Value & root)
97100
{
98101
if(value.isInt())
99102
{
100-
mPowerThreshold.SetNonNull(value.asInt());
103+
SetPowerThreshold(value.asInt());
101104
}
102105
else
103106
{
104-
mPowerThreshold.SetNull();
107+
SetPowerThreshold(std::nullopt);
105108
}
106109
}
107110

@@ -110,11 +113,11 @@ CHIP_ERROR MeterIdentificationDelegate::LoadJson(Json::Value & root)
110113
{
111114
if(value.isInt())
112115
{
113-
mPowerThresholdSource.SetNonNull(static_cast<PowerThresholdSourceEnum>(value.asInt()));
116+
SetPowerThresholdSource(static_cast<PowerThresholdSourceEnum>(value.asInt()));
114117
}
115118
else
116119
{
117-
mPowerThresholdSource.SetNull();
120+
SetPowerThresholdSource(std::nullopt);
118121
}
119122
}
120123

@@ -128,17 +131,29 @@ CHIP_ERROR MeterIdentificationDelegate::SetMeterType(DataModel::Nullable<MeterTy
128131
mMeterType = newValue;
129132
// if (oldValue != newValue)
130133
//{
131-
// MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, MeterType::Id);
134+
MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, MeterType::Id);
132135
// }
133136

134137
return CHIP_NO_ERROR;
135138
}
136139

137-
CHIP_ERROR MeterIdentificationDelegate::SetUtilityName(CharSpan & newValue)
140+
CHIP_ERROR MeterIdentificationDelegate::SetUtilityName(CharSpan newValue)
138141
{
139142
// CharSpan oldValue = mUtilityName;
140143

141-
mUtilityName = newValue;
144+
chip::Platform::MemoryFree((void*)mUtilityName.data());
145+
if (!newValue.empty())
146+
{
147+
size_t len = newValue.size();
148+
char *str = (char*)chip::Platform::MemoryAlloc(len);
149+
memcpy(str, newValue.data(), len);
150+
mUtilityName = CharSpan(str, len);
151+
}
152+
else
153+
{
154+
mUtilityName = CharSpan();
155+
}
156+
142157
// if (!oldValue.data_equal(newValue))
143158
//{
144159
// MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, UtilityName::Id);
@@ -147,11 +162,23 @@ CHIP_ERROR MeterIdentificationDelegate::SetUtilityName(CharSpan & newValue)
147162
return CHIP_NO_ERROR;
148163
}
149164

150-
CHIP_ERROR MeterIdentificationDelegate::SetPointOfDelivery(CharSpan & newValue)
165+
CHIP_ERROR MeterIdentificationDelegate::SetPointOfDelivery(CharSpan newValue)
151166
{
152167
// CharSpan oldValue = mPointOfDelivery;
153168

154-
mPointOfDelivery = newValue;
169+
chip::Platform::MemoryFree((void*)mPointOfDelivery.data());
170+
if (!newValue.empty())
171+
{
172+
size_t len = newValue.size();
173+
char *str = (char*)chip::Platform::MemoryAlloc(len);
174+
memcpy(str, newValue.data(), len);
175+
mPointOfDelivery = CharSpan(str, len);
176+
}
177+
else
178+
{
179+
mPointOfDelivery = CharSpan();
180+
}
181+
155182
// if (!oldValue.data_equal(newValue))
156183
//{
157184
// MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, PointOfDelivery::Id);

src/app/clusters/meter-identification-server/meter-identification-server.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ bool Instance::HasFeature(Feature aFeature) const
6464
// AttributeAccessInterface
6565
CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
6666
{
67+
ChipLogProgress(Zcl, "Meter Ind read attr %d", aPath.mAttributeId);
6768
switch (aPath.mAttributeId)
6869
{
6970
case FeatureMap::Id:
@@ -114,4 +115,4 @@ CHIP_ERROR Instance::Write(const ConcreteDataAttributePath & aPath, AttributeVal
114115
// -----------------------------------------------------------------------------
115116
// Plugin initialization
116117

117-
void MatterMeterIdentificationPluginServerInitCallback() {}
118+
void MatterMeterIdentificationPluginServerInitCallback() {}

0 commit comments

Comments
 (0)