@@ -43,52 +43,55 @@ void MeterIdentificationInstance::Shutdown()
43
43
44
44
// --------------- Internal Attribute Set APIs
45
45
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
+
46
57
CHIP_ERROR MeterIdentificationDelegate::LoadJson (Json::Value & root)
47
58
{
48
59
Json::Value value = root.get (" MeterType" , Json::Value ());
49
60
if (!value.empty ())
50
61
{
51
62
if (value.isInt ())
52
63
{
53
- mMeterType . SetNonNull (static_cast <MeterTypeEnum>(value.asInt ()));
64
+ SetMeterType (static_cast <MeterTypeEnum>(value.asInt ()));
54
65
}
55
66
else
56
67
{
57
- mMeterType . SetNull ( );
68
+ SetMeterType (std::nullopt );
58
69
}
59
70
}
60
71
61
72
value = root.get (" UtilityName" , Json::Value ());
62
73
if (!value.empty ())
63
74
{
64
- chip::Platform::MemoryFree ((void *)mUtilityName .data ());
65
75
if (value.isString ())
66
76
{
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 ()));
71
78
}
72
79
else
73
80
{
74
- mUtilityName = CharSpan ();
81
+ SetUtilityName ( CharSpan () );
75
82
}
76
83
}
77
84
78
85
value = root.get (" PointOfDelivery" , Json::Value ());
79
86
if (!value.empty ())
80
87
{
81
- chip::Platform::MemoryFree ((void *)mPointOfDelivery .data ());
82
88
if (value.isString ())
83
89
{
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 ()));
88
91
}
89
92
else
90
93
{
91
- mPointOfDelivery = CharSpan ();
94
+ SetPointOfDelivery ( CharSpan () );
92
95
}
93
96
}
94
97
@@ -97,11 +100,11 @@ CHIP_ERROR MeterIdentificationDelegate::LoadJson(Json::Value & root)
97
100
{
98
101
if (value.isInt ())
99
102
{
100
- mPowerThreshold . SetNonNull (value.asInt ());
103
+ SetPowerThreshold (value.asInt ());
101
104
}
102
105
else
103
106
{
104
- mPowerThreshold . SetNull ( );
107
+ SetPowerThreshold (std::nullopt );
105
108
}
106
109
}
107
110
@@ -110,11 +113,11 @@ CHIP_ERROR MeterIdentificationDelegate::LoadJson(Json::Value & root)
110
113
{
111
114
if (value.isInt ())
112
115
{
113
- mPowerThresholdSource . SetNonNull (static_cast <PowerThresholdSourceEnum>(value.asInt ()));
116
+ SetPowerThresholdSource (static_cast <PowerThresholdSourceEnum>(value.asInt ()));
114
117
}
115
118
else
116
119
{
117
- mPowerThresholdSource . SetNull ( );
120
+ SetPowerThresholdSource (std::nullopt );
118
121
}
119
122
}
120
123
@@ -128,17 +131,29 @@ CHIP_ERROR MeterIdentificationDelegate::SetMeterType(DataModel::Nullable<MeterTy
128
131
mMeterType = newValue;
129
132
// if (oldValue != newValue)
130
133
// {
131
- // MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, MeterType::Id);
134
+ MatterReportingAttributeChangeCallback (mEndpointId , MeterIdentification::Id, MeterType::Id);
132
135
// }
133
136
134
137
return CHIP_NO_ERROR;
135
138
}
136
139
137
- CHIP_ERROR MeterIdentificationDelegate::SetUtilityName (CharSpan & newValue)
140
+ CHIP_ERROR MeterIdentificationDelegate::SetUtilityName (CharSpan newValue)
138
141
{
139
142
// CharSpan oldValue = mUtilityName;
140
143
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
+
142
157
// if (!oldValue.data_equal(newValue))
143
158
// {
144
159
// MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, UtilityName::Id);
@@ -147,11 +162,23 @@ CHIP_ERROR MeterIdentificationDelegate::SetUtilityName(CharSpan & newValue)
147
162
return CHIP_NO_ERROR;
148
163
}
149
164
150
- CHIP_ERROR MeterIdentificationDelegate::SetPointOfDelivery (CharSpan & newValue)
165
+ CHIP_ERROR MeterIdentificationDelegate::SetPointOfDelivery (CharSpan newValue)
151
166
{
152
167
// CharSpan oldValue = mPointOfDelivery;
153
168
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
+
155
182
// if (!oldValue.data_equal(newValue))
156
183
// {
157
184
// MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, PointOfDelivery::Id);
0 commit comments