@@ -31,6 +31,9 @@ using namespace chip::app::Clusters::MeterIdentification::Attributes;
31
31
using chip::app::Clusters::MeterIdentification::MeterTypeEnum;
32
32
using chip::app::Clusters::MeterIdentification::PowerThresholdSourceEnum;
33
33
34
+ constexpr size_t kUtilityNameSize = 16 ;
35
+ constexpr size_t kPointOfDeliverySize = 16 ;
36
+
34
37
CHIP_ERROR MeterIdentificationInstance::Init ()
35
38
{
36
39
return Instance::Init ();
@@ -60,11 +63,11 @@ chip::app::Clusters::MeterIdentification::MeterIdentificationDelegate::~MeterIde
60
63
61
64
void MeterIdentificationDelegate::Init ()
62
65
{
63
- SetMeterType (MeterTypeEnum:: kPrivate );
64
- SetUtilityName (CharSpan::fromCharString ( " Test Utility Name " ) );
65
- SetPointOfDelivery (CharSpan::fromCharString ( " Test PointOfDelivery " ) );
66
- SetPowerThreshold (100 );
67
- SetPowerThresholdSource (PowerThresholdSourceEnum:: kEquipment );
66
+ SetMeterType (std::nullopt );
67
+ SetUtilityName (std::nullopt );
68
+ SetPointOfDelivery (std::nullopt );
69
+ SetPowerThreshold (std::nullopt );
70
+ SetPowerThresholdSource (std::nullopt );
68
71
}
69
72
70
73
CHIP_ERROR MeterIdentificationDelegate::LoadJson (Json::Value & root)
@@ -164,11 +167,11 @@ CHIP_ERROR MeterIdentificationDelegate::SetUtilityName(DataModel::Nullable<CharS
164
167
165
168
if (!newValue.IsNull ())
166
169
{
167
- size_t len = newValue.Value ().size ();
168
- char * str = (char *) chip::Platform::MemoryAlloc (len);
169
- memcpy (str, newValue.Value ().data (), len);
170
- CharSpan nameString ( str, len) ;
171
- mUtilityName = MakeNullable (static_cast < CharSpan>(nameString ));
170
+ size_t len = min ( newValue.Value ().size (), kUtilityNameSize );
171
+ char * str = (char *) chip::Platform::MemoryAlloc (len + 1 );
172
+ strncpy (str, newValue.Value ().data (), len);
173
+ str[ len] = 0 ;
174
+ mUtilityName = MakeNullable (CharSpan::fromCharString (str ));
172
175
}
173
176
174
177
// if (!oldValue.data_equal(newValue))
@@ -191,11 +194,11 @@ CHIP_ERROR MeterIdentificationDelegate::SetPointOfDelivery(DataModel::Nullable<C
191
194
192
195
if (!newValue.IsNull ())
193
196
{
194
- size_t len = newValue.Value ().size ();
195
- char * str = (char *) chip::Platform::MemoryAlloc (len);
196
- memcpy (str, newValue.Value ().data (), len);
197
- CharSpan nameString ( str, len) ;
198
- mPointOfDelivery = MakeNullable (static_cast < CharSpan>(nameString ));
197
+ size_t len = min ( newValue.Value ().size (), kPointOfDeliverySize );
198
+ char * str = (char *) chip::Platform::MemoryAlloc (len + 1 );
199
+ strncpy (str, newValue.Value ().data (), len);
200
+ str[ len] = 0 ;
201
+ mPointOfDelivery = MakeNullable (CharSpan::fromCharString (str ));
199
202
}
200
203
201
204
// if (!oldValue.data_equal(newValue))
0 commit comments