Skip to content

Commit b8c97b8

Browse files
Switch on the Time sync cluster in the all-cluster-app
Fix bug: reset string attributes Fix max size string attributes
1 parent 62a6b00 commit b8c97b8

File tree

7 files changed

+202
-54
lines changed

7 files changed

+202
-54
lines changed

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

+155-7
Original file line numberDiff line numberDiff line change
@@ -7963,6 +7963,154 @@
79637963
}
79647964
]
79657965
},
7966+
{
7967+
"name": "Time Synchronization",
7968+
"code": 56,
7969+
"mfgCode": null,
7970+
"define": "TIME_SYNCHRONIZATION_CLUSTER",
7971+
"side": "server",
7972+
"enabled": 1,
7973+
"commands": [
7974+
{
7975+
"name": "SetUTCTime",
7976+
"code": 0,
7977+
"mfgCode": null,
7978+
"source": "client",
7979+
"isIncoming": 1,
7980+
"isEnabled": 1
7981+
}
7982+
],
7983+
"attributes": [
7984+
{
7985+
"name": "UTCTime",
7986+
"code": 0,
7987+
"mfgCode": null,
7988+
"side": "server",
7989+
"type": "epoch_us",
7990+
"included": 1,
7991+
"storageOption": "External",
7992+
"singleton": 0,
7993+
"bounded": 0,
7994+
"defaultValue": "",
7995+
"reportable": 1,
7996+
"minInterval": 1,
7997+
"maxInterval": 65534,
7998+
"reportableChange": 0
7999+
},
8000+
{
8001+
"name": "Granularity",
8002+
"code": 1,
8003+
"mfgCode": null,
8004+
"side": "server",
8005+
"type": "GranularityEnum",
8006+
"included": 1,
8007+
"storageOption": "External",
8008+
"singleton": 0,
8009+
"bounded": 0,
8010+
"defaultValue": "",
8011+
"reportable": 1,
8012+
"minInterval": 1,
8013+
"maxInterval": 65534,
8014+
"reportableChange": 0
8015+
},
8016+
{
8017+
"name": "GeneratedCommandList",
8018+
"code": 65528,
8019+
"mfgCode": null,
8020+
"side": "server",
8021+
"type": "array",
8022+
"included": 1,
8023+
"storageOption": "External",
8024+
"singleton": 0,
8025+
"bounded": 0,
8026+
"defaultValue": "",
8027+
"reportable": 1,
8028+
"minInterval": 1,
8029+
"maxInterval": 65534,
8030+
"reportableChange": 0
8031+
},
8032+
{
8033+
"name": "AcceptedCommandList",
8034+
"code": 65529,
8035+
"mfgCode": null,
8036+
"side": "server",
8037+
"type": "array",
8038+
"included": 1,
8039+
"storageOption": "External",
8040+
"singleton": 0,
8041+
"bounded": 0,
8042+
"defaultValue": "",
8043+
"reportable": 1,
8044+
"minInterval": 1,
8045+
"maxInterval": 65534,
8046+
"reportableChange": 0
8047+
},
8048+
{
8049+
"name": "EventList",
8050+
"code": 65530,
8051+
"mfgCode": null,
8052+
"side": "server",
8053+
"type": "array",
8054+
"included": 1,
8055+
"storageOption": "External",
8056+
"singleton": 0,
8057+
"bounded": 0,
8058+
"defaultValue": "",
8059+
"reportable": 1,
8060+
"minInterval": 1,
8061+
"maxInterval": 65534,
8062+
"reportableChange": 0
8063+
},
8064+
{
8065+
"name": "AttributeList",
8066+
"code": 65531,
8067+
"mfgCode": null,
8068+
"side": "server",
8069+
"type": "array",
8070+
"included": 1,
8071+
"storageOption": "External",
8072+
"singleton": 0,
8073+
"bounded": 0,
8074+
"defaultValue": "",
8075+
"reportable": 1,
8076+
"minInterval": 1,
8077+
"maxInterval": 65534,
8078+
"reportableChange": 0
8079+
},
8080+
{
8081+
"name": "FeatureMap",
8082+
"code": 65532,
8083+
"mfgCode": null,
8084+
"side": "server",
8085+
"type": "bitmap32",
8086+
"included": 1,
8087+
"storageOption": "RAM",
8088+
"singleton": 0,
8089+
"bounded": 0,
8090+
"defaultValue": "0",
8091+
"reportable": 1,
8092+
"minInterval": 1,
8093+
"maxInterval": 65534,
8094+
"reportableChange": 0
8095+
},
8096+
{
8097+
"name": "ClusterRevision",
8098+
"code": 65533,
8099+
"mfgCode": null,
8100+
"side": "server",
8101+
"type": "int16u",
8102+
"included": 1,
8103+
"storageOption": "RAM",
8104+
"singleton": 0,
8105+
"bounded": 0,
8106+
"defaultValue": "2",
8107+
"reportable": 1,
8108+
"minInterval": 1,
8109+
"maxInterval": 65534,
8110+
"reportableChange": 0
8111+
}
8112+
]
8113+
},
79668114
{
79678115
"name": "Switch",
79688116
"code": 59,
@@ -14330,7 +14478,7 @@
1433014478
"storageOption": "External",
1433114479
"singleton": 0,
1433214480
"bounded": 0,
14333-
"defaultValue": "",
14481+
"defaultValue": null,
1433414482
"reportable": 1,
1433514483
"minInterval": 1,
1433614484
"maxInterval": 65534,
@@ -14346,7 +14494,7 @@
1434614494
"storageOption": "External",
1434714495
"singleton": 0,
1434814496
"bounded": 0,
14349-
"defaultValue": "",
14497+
"defaultValue": null,
1435014498
"reportable": 1,
1435114499
"minInterval": 1,
1435214500
"maxInterval": 65534,
@@ -14362,7 +14510,7 @@
1436214510
"storageOption": "External",
1436314511
"singleton": 0,
1436414512
"bounded": 0,
14365-
"defaultValue": "",
14513+
"defaultValue": null,
1436614514
"reportable": 1,
1436714515
"minInterval": 1,
1436814516
"maxInterval": 65534,
@@ -14378,7 +14526,7 @@
1437814526
"storageOption": "External",
1437914527
"singleton": 0,
1438014528
"bounded": 0,
14381-
"defaultValue": "",
14529+
"defaultValue": null,
1438214530
"reportable": 1,
1438314531
"minInterval": 1,
1438414532
"maxInterval": 65534,
@@ -14394,7 +14542,7 @@
1439414542
"storageOption": "External",
1439514543
"singleton": 0,
1439614544
"bounded": 0,
14397-
"defaultValue": "",
14545+
"defaultValue": null,
1439814546
"reportable": 1,
1439914547
"minInterval": 1,
1440014548
"maxInterval": 65534,
@@ -14410,7 +14558,7 @@
1441014558
"storageOption": "External",
1441114559
"singleton": 0,
1441214560
"bounded": 0,
14413-
"defaultValue": "",
14561+
"defaultValue": null,
1441414562
"reportable": 1,
1441514563
"minInterval": 1,
1441614564
"maxInterval": 65534,
@@ -14426,7 +14574,7 @@
1442614574
"storageOption": "External",
1442714575
"singleton": 0,
1442814576
"bounded": 0,
14429-
"defaultValue": "",
14577+
"defaultValue": null,
1443014578
"reportable": 1,
1443114579
"minInterval": 1,
1443214580
"maxInterval": 65534,

examples/all-clusters-app/all-clusters-common/include/energy-calendar-instance.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@ class CalendarProviderInstance : public CalendarProvider
5858
void ErrorMessage(EndpointId ep, const char * msg, ...) override;
5959

6060
private:
61-
//uint32_t mDate;
62-
//uint32_t mTime;
63-
6461
// Attributes contaners allocated memory
65-
DataModel::Nullable<CharSpan> mName;
6662
DataModel::Nullable<uint32_t> mStartDate;
63+
6764
DataModel::List<Structs::CalendarPeriodStruct::Type> mCalendarPeriods;
6865
DataModel::List<Structs::DayStruct::Type> mSpecialDays;
6966
DataModel::Nullable<Structs::PeakPeriodStruct::Type> mCurrentPeak;

examples/all-clusters-app/all-clusters-common/src/energy-calendar-instance.cpp

+5-16
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ chip::app::Clusters::EnergyCalendar::CalendarProviderInstance::~CalendarProvider
6565
{
6666
FreeMemoryCalendarPeriodStructList(mCalendarPeriods);
6767
FreeMemoryDayStructList(mSpecialDays);
68-
if (!mName.IsNull())
69-
{
70-
chip::Platform::MemoryFree((void *) mName.Value().data());
71-
mName.SetNull();
72-
}
7368
}
7469

7570
void CalendarProviderInstance::Init(void)
@@ -81,7 +76,7 @@ void CalendarProviderInstance::Init(void)
8176
void CalendarProviderInstance::SetDefault(void)
8277
{
8378
SetCalendarID(std::nullopt);
84-
SetName(std::nullopt);
79+
SetName(nullptr);
8580
SetProviderID(std::nullopt);
8681
SetEventID(std::nullopt);
8782

@@ -120,20 +115,14 @@ CHIP_ERROR CalendarProviderInstance::LoadJson(Json::Value & root)
120115
if (root.isMember("CalendarName"))
121116
{
122117
value = root.get("CalendarName", Json::Value());
123-
if (!mName.IsNull())
118+
if (value.isString())
124119
{
125-
chip::Platform::MemoryFree((void *) mName.Value().data());
126-
mName.SetNull();
120+
SetName(value.asCString());
127121
}
128-
if (value.isString())
122+
else
129123
{
130-
size_t len = value.asString().size();
131-
char * str = (char *) chip::Platform::MemoryAlloc(len);
132-
memcpy(str, value.asCString(), len);
133-
CharSpan nameString(str, len);
134-
mName = MakeNullable(static_cast<CharSpan>(nameString));
124+
SetName(nullptr);
135125
}
136-
SetName(mName);
137126
}
138127

139128
if (root.isMember("ProviderID"))

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void emberAfMeterIdentificationClusterInitCallback(chip::EndpointId endpointId)
3737
if (gMIDelegate)
3838
{
3939
gMIDelegate->Init();
40-
40+
4141
gMIInstance = std::make_unique<MeterIdentificationInstance>(endpointId, *gMIDelegate,
4242
BitMask<Feature, uint32_t>(Feature::kPowerThreshold));
4343

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

+18-15
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ using namespace chip::app::Clusters::MeterIdentification::Attributes;
3131
using chip::app::Clusters::MeterIdentification::MeterTypeEnum;
3232
using chip::app::Clusters::MeterIdentification::PowerThresholdSourceEnum;
3333

34+
constexpr size_t kUtilityNameSize = 16;
35+
constexpr size_t kPointOfDeliverySize = 16;
36+
3437
CHIP_ERROR MeterIdentificationInstance::Init()
3538
{
3639
return Instance::Init();
@@ -60,11 +63,11 @@ chip::app::Clusters::MeterIdentification::MeterIdentificationDelegate::~MeterIde
6063

6164
void MeterIdentificationDelegate::Init()
6265
{
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);
6871
}
6972

7073
CHIP_ERROR MeterIdentificationDelegate::LoadJson(Json::Value & root)
@@ -164,11 +167,11 @@ CHIP_ERROR MeterIdentificationDelegate::SetUtilityName(DataModel::Nullable<CharS
164167

165168
if (!newValue.IsNull())
166169
{
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));
172175
}
173176

174177
// if (!oldValue.data_equal(newValue))
@@ -191,11 +194,11 @@ CHIP_ERROR MeterIdentificationDelegate::SetPointOfDelivery(DataModel::Nullable<C
191194

192195
if (!newValue.IsNull())
193196
{
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));
199202
}
200203

201204
// if (!oldValue.data_equal(newValue))

0 commit comments

Comments
 (0)