Skip to content

Commit c4c04f2

Browse files
Using clusters in all-clusters-app
1 parent 865bba6 commit c4c04f2

File tree

9 files changed

+237
-133
lines changed

9 files changed

+237
-133
lines changed

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

+84
Original file line numberDiff line numberDiff line change
@@ -14232,6 +14232,48 @@
1423214232
}
1423314233
]
1423414234
},
14235+
{
14236+
"name": "Energy Calendar",
14237+
"code": 154,
14238+
"mfgCode": null,
14239+
"define": "ENERGY_CALENDAR_CLUSTER",
14240+
"side": "server",
14241+
"enabled": 1,
14242+
"attributes": [
14243+
{
14244+
"name": "FeatureMap",
14245+
"code": 65532,
14246+
"mfgCode": null,
14247+
"side": "server",
14248+
"type": "bitmap32",
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": 0
14258+
},
14259+
{
14260+
"name": "ClusterRevision",
14261+
"code": 65533,
14262+
"mfgCode": null,
14263+
"side": "server",
14264+
"type": "int16u",
14265+
"included": 1,
14266+
"storageOption": "RAM",
14267+
"singleton": 0,
14268+
"bounded": 0,
14269+
"defaultValue": "1",
14270+
"reportable": 1,
14271+
"minInterval": 1,
14272+
"maxInterval": 65534,
14273+
"reportableChange": 0
14274+
}
14275+
]
14276+
},
1423514277
{
1423614278
"name": "Energy Preference",
1423714279
"code": 155,
@@ -21739,6 +21781,48 @@
2173921781
}
2174021782
]
2174121783
},
21784+
{
21785+
"name": "Meter Identification",
21786+
"code": 2822,
21787+
"mfgCode": null,
21788+
"define": "METER_IDENTIFICATION_CLUSTER",
21789+
"side": "server",
21790+
"enabled": 1,
21791+
"attributes": [
21792+
{
21793+
"name": "FeatureMap",
21794+
"code": 65532,
21795+
"mfgCode": null,
21796+
"side": "server",
21797+
"type": "bitmap32",
21798+
"included": 1,
21799+
"storageOption": "External",
21800+
"singleton": 0,
21801+
"bounded": 0,
21802+
"defaultValue": null,
21803+
"reportable": 1,
21804+
"minInterval": 1,
21805+
"maxInterval": 65534,
21806+
"reportableChange": 0
21807+
},
21808+
{
21809+
"name": "ClusterRevision",
21810+
"code": 65533,
21811+
"mfgCode": null,
21812+
"side": "server",
21813+
"type": "int16u",
21814+
"included": 1,
21815+
"storageOption": "RAM",
21816+
"singleton": 0,
21817+
"bounded": 0,
21818+
"defaultValue": "1",
21819+
"reportable": 1,
21820+
"minInterval": 1,
21821+
"maxInterval": 65534,
21822+
"reportableChange": 0
21823+
}
21824+
]
21825+
},
2174221826
{
2174321827
"name": "Unit Testing",
2174421828
"code": 4294048773,

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ class CalendarProviderInstance : public CalendarProvider
5858

5959
private:
6060
uint32_t mDate;
61-
uint32_t time;
61+
uint32_t mTime;
6262

6363
// Attributes contaners allocated memory
64+
DataModel::Nullable<CharSpan> mName;
6465
DataModel::List<Structs::CalendarPeriodStruct::Type> mCalendarPeriods;
6566
DataModel::List<Structs::DayStruct::Type> mSpecialDays;
6667
Structs::DayStruct::Type mCurrentDay;

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

+54-37
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ using namespace chip::app::DataModel;
2828
using namespace chip::app::Clusters;
2929
using namespace chip::app::Clusters::EnergyCalendar;
3030
using namespace chip::app::Clusters::EnergyCalendar::Attributes;
31-
using chip::Protocols::InteractionModel::Status;
3231

3332
constexpr uint32_t kOneDay = 24 * 60 * 60;
3433

@@ -55,6 +54,11 @@ chip::app::Clusters::EnergyCalendar::CalendarProviderInstance::~CalendarProvider
5554
FreeMemoryDayStructList(mSpecialDays);
5655
FreeMemoryDayStruct(mCurrentDay);
5756
FreeMemoryDayStruct(mNextDay);
57+
if (!mName.IsNull())
58+
{
59+
chip::Platform::MemoryFree((void*)mName.Value().data());
60+
mName.SetNull();
61+
}
5862
}
5963

6064
void CalendarProviderInstance::Init(void)
@@ -85,82 +89,95 @@ void CalendarProviderInstance::SetDefault(void)
8589

8690
Structs::PeakPeriodStruct::Type peak = { .severity = PeakPeriodSeverityEnum::kHigh, .peakPeriod = 100, .startTime = 2000, .endTime = 2200 };
8791

88-
DataModel::List<Structs::CalendarPeriodStruct::Type> calendarPeriods = {};
89-
DataModel::List<Structs::DayStruct::Type> specialDays = {};
92+
//DataModel::List<Structs::CalendarPeriodStruct::Type> calendarPeriods = {};
93+
//DataModel::List<Structs::DayStruct::Type> specialDays = {};
94+
95+
char *str = (char*)chip::Platform::MemoryAlloc(5);
96+
memcpy(str, "Test", 5);
97+
CharSpan nameString(str, 5);
98+
mName = MakeNullable(static_cast<CharSpan>(nameString));
9099

91-
SetCommonAttributes(1, "Test", 123, 1);
92-
SetCalendarPeriod(date, calendarPeriods);
93-
SetSpecialDays(specialDays);
100+
SetCommonAttributes(1, mName, 123, 1);
101+
SetCalendarPeriod(date, mCalendarPeriods);
102+
SetSpecialDays(mSpecialDays);
94103
SetCurrentAndNextDays(DataModel::MakeNullable(day), DataModel::MakeNullable(day));
95104
SetPeakPeriods(DataModel::MakeNullable(peak), DataModel::MakeNullable(peak));
96105
}
97106

98107
CHIP_ERROR CalendarProviderInstance::LoadJson(Json::Value & root)
99108
{
100109
DataModel::Nullable<uint32_t> calendarID;
101-
DataModel::Nullable<std::string> name;
102110
DataModel::Nullable<uint32_t> providerID;
103111
DataModel::Nullable<uint32_t> eventID;
104112
DataModel::Nullable<uint32_t> startDate;
105113
Structs::PeakPeriodStruct::Type currentPeak;
106114
Structs::PeakPeriodStruct::Type nextPeak;
107115

108-
auto value = root.get("CalendarID", Json::Value());
116+
Json::Value value = root.get("CalendarID", Json::Value());
109117
if (!value.empty() && value.isInt())
110118
{
111119
calendarID.SetNonNull(value.asInt());
112120
}
113121

114-
auto value = root.get("Name", Json::Value());
122+
value = root.get("Name", Json::Value());
123+
if (!mName.IsNull())
124+
{
125+
chip::Platform::MemoryFree((void*)mName.Value().data());
126+
mName.SetNull();
127+
}
115128
if (!value.empty() && value.isString())
116129
{
117-
name.SetNonNull(value.asString());
130+
size_t len = value.asString().size()+1;
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));
118135
}
119136

120-
auto value = root.get("ProviderID", Json::Value());
137+
value = root.get("ProviderID", Json::Value());
121138
if (!value.empty() && value.isInt())
122139
{
123140
providerID.SetNonNull(value.asInt());
124141
}
125142

126-
auto value = root.get("EventID", Json::Value());
143+
value = root.get("EventID", Json::Value());
127144
if (!value.empty() && value.isInt())
128145
{
129146
eventID.SetNonNull(value.asInt());
130147
}
131148

132-
SetCommonAttributes(calendarID, name, providerID, eventID);
149+
SetCommonAttributes(calendarID, mName, providerID, eventID);
133150

134-
auto value = root.get("StartDate", Json::Value());
151+
value = root.get("StartDate", Json::Value());
135152
if (!value.empty() && value.isInt())
136153
{
137154
startDate.SetNonNull(value.asInt());
138155
}
139156

140-
auto value = root.get("CalendarPeriods", Json::Value());
157+
value = root.get("CalendarPeriods", Json::Value());
141158
FreeMemoryCalendarPeriodStructList(mCalendarPeriods);
142159
if (!value.empty() && value.isArray())
143160
{
144161
JsonToCalendarPeriodStructList(value, mCalendarPeriods);
145162
}
146163
SetCalendarPeriod(startDate, mCalendarPeriods);
147164

148-
auto value = root.get("SpecialDays", Json::Value());
165+
value = root.get("SpecialDays", Json::Value());
149166
FreeMemoryDayStructList(mSpecialDays);
150167
if (!value.empty() && value.isArray())
151168
{
152169
JsonToDayStructList(value, mSpecialDays);
153170
}
154171
SetSpecialDays(mSpecialDays);
155172

156-
auto value = root.get("CurrentDay", Json::Value());
173+
value = root.get("CurrentDay", Json::Value());
157174
FreeMemoryDayStruct(mCurrentDay);
158175
if (!value.empty())
159176
{
160177
JsonToDayStruct(value, mCurrentDay);
161178
}
162179

163-
auto value = root.get("NextDay", Json::Value());
180+
value = root.get("NextDay", Json::Value());
164181
FreeMemoryDayStruct(mNextDay);
165182
if (!value.empty())
166183
{
@@ -169,13 +186,13 @@ CHIP_ERROR CalendarProviderInstance::LoadJson(Json::Value & root)
169186

170187
SetCurrentAndNextDays(mCurrentDay, mNextDay);
171188

172-
auto value = root.get("CurrentPeak", Json::Value());
189+
value = root.get("CurrentPeak", Json::Value());
173190
if (!value.empty())
174191
{
175192
JsonToPeakPeriodStruct(value, currentPeak);
176193
}
177194

178-
auto value = root.get("NextPeak", Json::Value());
195+
value = root.get("NextPeak", Json::Value());
179196
if (!value.empty())
180197
{
181198
JsonToPeakPeriodStruct(value, nextPeak);
@@ -348,13 +365,13 @@ bool CalendarProviderInstance::CheckDay(const Structs::DayStruct::Type &day)
348365

349366
void CalendarProviderInstance::JsonToCalendarPeriodStruct(Json::Value & root, Structs::CalendarPeriodStruct::Type & value)
350367
{
351-
auto t = root.get("startDate", Json::Value());
368+
Json::Value t = root.get("startDate", Json::Value());
352369
if (!t.empty() && t.isInt())
353370
{
354371
value.startDate.SetNonNull(t.asInt());
355372
}
356373

357-
auto t = root.get("days", Json::Value());
374+
t = root.get("days", Json::Value());
358375
if (!t.empty() && t.isArray())
359376
{
360377
DataModel::List<Structs::DayStruct::Type> *days = (DataModel::List<Structs::DayStruct::Type>*)&value.days;
@@ -364,26 +381,26 @@ void CalendarProviderInstance::JsonToCalendarPeriodStruct(Json::Value & root, St
364381

365382
void CalendarProviderInstance::JsonToDayStruct(Json::Value & root, Structs::DayStruct::Type & value)
366383
{
367-
auto t = root.get("date", Json::Value());
384+
Json::Value t = root.get("date", Json::Value());
368385
if (!t.empty() && t.isInt())
369386
{
370387
value.date.SetValue(t.asInt());
371388
}
372389

373-
auto t = root.get("daysOfWeek", Json::Value());
390+
t = root.get("daysOfWeek", Json::Value());
374391
if (!t.empty() && t.isInt())
375392
{
376-
value.daysOfWeek.SetValue((chip::BitMask<TransitionDayOfWeekBitmap>)(t.asInt()));
393+
value.daysOfWeek.SetValue(chip::BitMask<TransitionDayOfWeekBitmap>((uint8_t)t.asInt()));
377394
}
378395

379-
auto t = root.get("transitions", Json::Value());
396+
t = root.get("transitions", Json::Value());
380397
if (!t.empty() && t.isArray())
381398
{
382399
DataModel::List<Structs::TransitionStruct::Type> *transitions = (DataModel::List<Structs::TransitionStruct::Type>*)&value.transitions;
383400
JsonToTransitionStructList(t, *transitions);
384401
}
385402

386-
auto t = root.get("calendarID", Json::Value());
403+
t = root.get("calendarID", Json::Value());
387404
if (!t.empty() && t.isInt())
388405
{
389406
value.calendarID.SetValue(t.asInt());
@@ -392,25 +409,25 @@ void CalendarProviderInstance::JsonToDayStruct(Json::Value & root, Structs::DayS
392409

393410
void CalendarProviderInstance::JsonToPeakPeriodStruct(Json::Value & root, Structs::PeakPeriodStruct::Type & value)
394411
{
395-
auto t = root.get("severity", Json::Value());
412+
Json::Value t = root.get("severity", Json::Value());
396413
if (!t.empty() && t.isInt())
397414
{
398415
value.severity = static_cast<PeakPeriodSeverityEnum>(t.asInt());
399416
}
400417

401-
auto t = root.get("peakPeriod", Json::Value());
418+
t = root.get("peakPeriod", Json::Value());
402419
if (!t.empty() && t.isInt())
403420
{
404421
value.peakPeriod = static_cast<uint16_t>(t.asInt());
405422
}
406423

407-
auto t = root.get("startTime", Json::Value());
424+
t = root.get("startTime", Json::Value());
408425
if (!t.empty() && t.isInt())
409426
{
410427
value.startTime.SetNonNull(t.asInt());
411428
}
412429

413-
auto t = root.get("endTime", Json::Value());
430+
t = root.get("endTime", Json::Value());
414431
if (!t.empty() && t.isInt())
415432
{
416433
value.endTime.SetNonNull(t.asInt());
@@ -455,28 +472,28 @@ void CalendarProviderInstance::JsonToTransitionStructList(Json::Value & root,
455472
{
456473
Json::Value v = root[i];
457474

458-
auto t = v.get("transitionTime", Json::Value());
475+
Json::Value t = v.get("transitionTime", Json::Value());
459476
if (!t.empty() && t.isInt())
460477
{
461-
value[i].transitionTime = t.asInt();
478+
value[i].transitionTime = static_cast<uint16_t>(t.asInt());
462479
}
463480

464-
auto t = v.get("priceTier", Json::Value());
481+
t = v.get("priceTier", Json::Value());
465482
if (!t.empty() && t.isInt())
466483
{
467484
value[i].priceTier.SetValue(t.asInt());
468485
}
469486

470-
auto t = v.get("friendlyCredit", Json::Value());
487+
t = v.get("friendlyCredit", Json::Value());
471488
if (!t.empty() && t.isBool())
472489
{
473490
value[i].friendlyCredit.SetValue(t.asBool());
474491
}
475492

476-
auto t = v.get("auxiliaryLoad", Json::Value());
493+
t = v.get("auxiliaryLoad", Json::Value());
477494
if (!t.empty() && t.isInt())
478495
{
479-
value[i].auxiliaryLoad.SetValue((chip::BitMask<AuxiliaryLoadBitmap>)(t.asInt()));
496+
value[i].auxiliaryLoad.SetValue(chip::BitMask<AuxiliaryLoadBitmap>((uint8_t)t.asInt()));
480497
}
481498
}
482499
}

examples/all-clusters-app/linux/BUILD.gn

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ source_set("chip-all-clusters-common") {
5757
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp",
5858
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp",
5959
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp",
60+
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/energy-calendar-instance.cpp",
61+
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/meter-identification-stub.cpp",
6062
"${chip_root}/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp",
6163
"${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp",
6264
"${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp",
@@ -65,6 +67,7 @@ source_set("chip-all-clusters-common") {
6567
"${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp",
6668
"${chip_root}/examples/energy-management-app/energy-management-common/src/device-energy-management-mode.cpp",
6769
"${chip_root}/examples/energy-management-app/energy-management-common/src/energy-evse-mode.cpp",
70+
"${chip_root}/examples/energy-management-app/energy-management-common/src/MeterIdentificationDelegate.cpp",
6871
"AllClustersCommandDelegate.cpp",
6972
"AppOptions.cpp",
7073
"ValveControlDelegate.cpp",

src/app/chip_data_model.gni

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ template("chip_data_model") {
215215
]
216216
}
217217

218+
print(invoker.zap_file)
218219
if (defined(invoker.zap_file)) {
219220
_zap_file = rebase_path(invoker.zap_file, root_build_dir)
220221
_script_args = [

0 commit comments

Comments
 (0)