Skip to content

Commit 5965601

Browse files
cliffamznrestyled-commits
authored andcommitted
Add ReplacementProductList to Resource Monitoring Cluster (#28095)
* Add ReplacementProductList to Resource Monitoring Cluster This adds the implementation to fetch the replacement product list from the aliased resource-monitoring-cluster. It adds support for Hepa and Activated Carbon filter examples. Closes out issues #27802, #27801, #27577 ### Testing I tested this using the all-clusters-app and the resource-monitoring-example-app ``` >>>> hepafiltermonitoring read replacement-product-list 0x1 0x1 DataVersion = 0xd31d0b60, AttributePathIB = { Endpoint = 0x1, Cluster = 0x71, Attribute = 0x0000_0005, } Data = [ { 0x0 = 0, 0x1 = "upc12xhepaxx" (13 chars), }, { 0x0 = 1, 0x1 = "gtin8xhe" (9 chars), }, { 0x0 = 2, 0x1 = "ean13xhepaxxx" (14 chars), }, ], >>>> activatedcarbonfiltermonitoring read replacement-product-list 0x1 0x1 DataVersion = 0xfd145260, AttributePathIB = { Endpoint = 0x1, Cluster = 0x72, Attribute = 0x0000_0005, } Data = [ { 0x0 = 0, 0x1 = "upc12xcarbon" (13 chars), }, { 0x0 = 1, 0x1 = "gtin8xca" (9 chars), }, { 0x0 = 2, 0x1 = "ean13xacarbon" (14 chars), }, ], ``` * Addressing @tobiasgraf's comments * Addressing @tcarmelveilleux's comments and restyled * Simplifying example app and adding support for resource monitor list in the all clusters app * Addressing @tcarmelveilleux's suggestions * Restyled by whitespace * Restyled by clang-format --------- Co-authored-by: Restyled.io <[email protected]>
1 parent c3f2374 commit 5965601

32 files changed

+691
-74
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -2752,6 +2752,7 @@ server cluster HepaFilterMonitoring = 113 {
27522752
bitmap Feature : BITMAP32 {
27532753
kCondition = 0x1;
27542754
kWarning = 0x2;
2755+
kReplacementProductList = 0x3;
27552756
}
27562757

27572758
struct ReplacementProductStruct {
@@ -2764,6 +2765,7 @@ server cluster HepaFilterMonitoring = 113 {
27642765
readonly attribute ChangeIndicationEnum changeIndication = 2;
27652766
readonly attribute boolean inPlaceIndicator = 3;
27662767
attribute nullable epoch_s lastChangedTime = 4;
2768+
readonly attribute ReplacementProductStruct replacementProductList[] = 5;
27672769
readonly attribute command_id generatedCommandList[] = 65528;
27682770
readonly attribute command_id acceptedCommandList[] = 65529;
27692771
readonly attribute event_id eventList[] = 65530;
@@ -2798,6 +2800,7 @@ server cluster ActivatedCarbonFilterMonitoring = 114 {
27982800
bitmap Feature : BITMAP32 {
27992801
kCondition = 0x1;
28002802
kWarning = 0x2;
2803+
kReplacementProductList = 0x3;
28012804
}
28022805

28032806
struct ReplacementProductStruct {
@@ -2810,6 +2813,7 @@ server cluster ActivatedCarbonFilterMonitoring = 114 {
28102813
readonly attribute ChangeIndicationEnum changeIndication = 2;
28112814
readonly attribute boolean inPlaceIndicator = 3;
28122815
attribute nullable epoch_s lastChangedTime = 4;
2816+
readonly attribute ReplacementProductStruct replacementProductList[] = 5;
28132817
readonly attribute command_id generatedCommandList[] = 65528;
28142818
readonly attribute command_id acceptedCommandList[] = 65529;
28152819
readonly attribute event_id eventList[] = 65530;
@@ -6318,6 +6322,7 @@ endpoint 1 {
63186322
callback attribute changeIndication default = 0;
63196323
callback attribute inPlaceIndicator;
63206324
callback attribute lastChangedTime;
6325+
callback attribute replacementProductList;
63216326
callback attribute generatedCommandList;
63226327
callback attribute acceptedCommandList;
63236328
callback attribute eventList;
@@ -6332,6 +6337,7 @@ endpoint 1 {
63326337
callback attribute changeIndication default = 0;
63336338
callback attribute inPlaceIndicator;
63346339
callback attribute lastChangedTime;
6340+
callback attribute replacementProductList;
63356341
callback attribute generatedCommandList;
63366342
callback attribute acceptedCommandList;
63376343
callback attribute eventList;

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

+35-3
Original file line numberDiff line numberDiff line change
@@ -15014,7 +15014,23 @@
1501415014
"side": "server",
1501515015
"type": "epoch_s",
1501615016
"included": 1,
15017-
"storageOption": "RAM",
15017+
"storageOption": "External",
15018+
"singleton": 0,
15019+
"bounded": 0,
15020+
"defaultValue": null,
15021+
"reportable": 1,
15022+
"minInterval": 1,
15023+
"maxInterval": 65534,
15024+
"reportableChange": 0
15025+
},
15026+
{
15027+
"name": "ReplacementProductList",
15028+
"code": 5,
15029+
"mfgCode": null,
15030+
"side": "server",
15031+
"type": "array",
15032+
"included": 1,
15033+
"storageOption": "External",
1501815034
"singleton": 0,
1501915035
"bounded": 0,
1502015036
"defaultValue": null,
@@ -15252,7 +15268,23 @@
1525215268
"side": "server",
1525315269
"type": "epoch_s",
1525415270
"included": 1,
15255-
"storageOption": "RAM",
15271+
"storageOption": "External",
15272+
"singleton": 0,
15273+
"bounded": 0,
15274+
"defaultValue": null,
15275+
"reportable": 1,
15276+
"minInterval": 1,
15277+
"maxInterval": 65534,
15278+
"reportableChange": 0
15279+
},
15280+
{
15281+
"name": "ReplacementProductList",
15282+
"code": 5,
15283+
"mfgCode": null,
15284+
"side": "server",
15285+
"type": "array",
15286+
"included": 1,
15287+
"storageOption": "External",
1525615288
"singleton": 0,
1525715289
"bounded": 0,
1525815290
"defaultValue": null,
@@ -31659,4 +31691,4 @@
3165931691
}
3166031692
],
3166131693
"log": []
31662-
}
31694+
}

examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h

+21
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,24 @@ class HepaFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitor
5454
Instance(aEndpointId, chip::app::Clusters::HepaFilterMonitoring::Id, aFeature, aDegradationDirection,
5555
aResetConditionCommandSupported){};
5656
};
57+
58+
class StaticReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager
59+
{
60+
public:
61+
uint8_t Size() override { return mReplacementProductListSize; };
62+
63+
CHIP_ERROR Next(chip::app::Clusters::ResourceMonitoring::Attributes::ReplacementProductStruct::Type & item) override;
64+
65+
~StaticReplacementProductListManager() {}
66+
StaticReplacementProductListManager(
67+
chip::app::Clusters::ResourceMonitoring::Attributes::ReplacementProductStruct::Type * aReplacementProductsList,
68+
uint8_t aReplacementProductListSize)
69+
{
70+
mReplacementProductsList = aReplacementProductsList;
71+
mReplacementProductListSize = aReplacementProductListSize;
72+
}
73+
74+
private:
75+
chip::app::Clusters::ResourceMonitoring::Attributes::ReplacementProductStruct::Type * mReplacementProductsList;
76+
uint8_t mReplacementProductListSize;
77+
};

examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp

+35-6
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,34 @@ using namespace chip::app::Clusters::ResourceMonitoring;
2828
using chip::Protocols::InteractionModel::Status;
2929

3030
constexpr std::bitset<4> gHepaFilterFeatureMap{ static_cast<uint32_t>(Feature::kCondition) |
31-
static_cast<uint32_t>(Feature::kWarning) };
31+
static_cast<uint32_t>(Feature::kWarning) |
32+
static_cast<uint32_t>(Feature::kReplacementProductList) };
3233
constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast<uint32_t>(Feature::kCondition) |
33-
static_cast<uint32_t>(Feature::kWarning) };
34+
static_cast<uint32_t>(Feature::kWarning) |
35+
static_cast<uint32_t>(Feature::kReplacementProductList) };
3436

35-
static HepaFilterMonitoringInstance * gHepafilterInstance = nullptr;
37+
static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr;
3638
static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr;
3739

40+
static ResourceMonitoring::Attributes::ReplacementProductStruct::Type sReplacementProductsList[] = {
41+
{ .productIdentifierType = ProductIdentifierTypeEnum::kUpc,
42+
.productIdentifierValue = CharSpan::fromCharString("111112222233") },
43+
{ .productIdentifierType = ProductIdentifierTypeEnum::kGtin8, .productIdentifierValue = CharSpan::fromCharString("gtin8xxx") },
44+
{ .productIdentifierType = ProductIdentifierTypeEnum::kEan,
45+
.productIdentifierValue = CharSpan::fromCharString("4444455555666") },
46+
{ .productIdentifierType = ProductIdentifierTypeEnum::kGtin14,
47+
.productIdentifierValue = CharSpan::fromCharString("gtin14xxxxxxxx") },
48+
{ .productIdentifierType = ProductIdentifierTypeEnum::kOem,
49+
.productIdentifierValue = CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx") },
50+
};
51+
StaticReplacementProductListManager sReplacementProductListManager(&sReplacementProductsList[0],
52+
ArraySize(sReplacementProductsList));
53+
3854
//-- Activated Carbon Filter Monitoring Instance methods
3955
CHIP_ERROR ActivatedCarbonFilterMonitoringInstance::AppInit()
4056
{
4157
ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::Init()");
58+
SetReplacementProductListManagerInstance(&sReplacementProductListManager);
4259
return CHIP_NO_ERROR;
4360
}
4461

@@ -58,6 +75,7 @@ Status ActivatedCarbonFilterMonitoringInstance::PostResetCondition()
5875
CHIP_ERROR HepaFilterMonitoringInstance::AppInit()
5976
{
6077
ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()");
78+
SetReplacementProductListManagerInstance(&sReplacementProductListManager);
6179
return CHIP_NO_ERROR;
6280
}
6381

@@ -82,8 +100,19 @@ void emberAfActivatedCarbonFilterMonitoringClusterInitCallback(chip::EndpointId
82100
}
83101
void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint)
84102
{
85-
VerifyOrDie(gActivatedCarbonFilterInstance == nullptr);
86-
gHepafilterInstance = new HepaFilterMonitoringInstance(endpoint, static_cast<uint32_t>(gHepaFilterFeatureMap.to_ulong()),
103+
gHepaFilterInstance = new HepaFilterMonitoringInstance(endpoint, static_cast<uint32_t>(gHepaFilterFeatureMap.to_ulong()),
87104
DegradationDirectionEnum::kDown, true);
88-
gHepafilterInstance->Init();
105+
gHepaFilterInstance->Init();
106+
}
107+
108+
CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::ReplacementProductStruct::Type & item)
109+
{
110+
if (mIndex < mReplacementProductListSize)
111+
{
112+
item = mReplacementProductsList[mIndex];
113+
mIndex++;
114+
return CHIP_NO_ERROR;
115+
}
116+
117+
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
89118
}

examples/resource-monitoring-app/linux/BUILD.gn

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ config("includes") {
3030

3131
executable("chip-resource-monitoring-app") {
3232
sources = [
33+
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/StaticReplacementProductListManager.cpp",
3334
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp",
34-
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp",
35+
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepaFilterMonitoring.cpp",
3536
"include/CHIPProjectAppConfig.h",
3637
"src/main.cpp",
3738
]

examples/resource-monitoring-app/linux/src/main.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include <AppMain.h>
20+
#include <StaticReplacementProductListManager.h>
2021
#include <app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h>
2122
#include <bitset>
2223
#include <instances/ActivatedCarbonFilterMonitoring.h>
@@ -29,9 +30,11 @@ using namespace chip::app::Clusters;
2930
using namespace chip::app::Clusters::ResourceMonitoring;
3031

3132
constexpr std::bitset<4> gHepaFilterFeatureMap{ static_cast<uint32_t>(Feature::kCondition) |
32-
static_cast<uint32_t>(Feature::kWarning) };
33+
static_cast<uint32_t>(Feature::kWarning) |
34+
static_cast<uint32_t>(Feature::kReplacementProductList) };
3335
constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast<uint32_t>(Feature::kCondition) |
34-
static_cast<uint32_t>(Feature::kWarning) };
36+
static_cast<uint32_t>(Feature::kWarning) |
37+
static_cast<uint32_t>(Feature::kReplacementProductList) };
3538

3639
static HepaFilterMonitoringInstance gHepaFilterInstance(0x1, static_cast<uint32_t>(gHepaFilterFeatureMap.to_ulong()),
3740
Clusters::ResourceMonitoring::DegradationDirectionEnum::kDown, true);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <app/clusters/resource-monitoring-server/replacement-product-list-manager.h>
22+
#include <app/util/af.h>
23+
#include <app/util/config.h>
24+
25+
namespace chip {
26+
namespace app {
27+
namespace Clusters {
28+
namespace ResourceMonitoring {
29+
30+
/**
31+
* This implementation statically defines the options.
32+
*/
33+
34+
class StaticReplacementProductListManager : public ReplacementProductListManager
35+
{
36+
public:
37+
uint8_t Size() override { return mReplacementProductListSize; };
38+
39+
CHIP_ERROR Next(Attributes::ReplacementProductStruct::Type & item) override;
40+
41+
~StaticReplacementProductListManager() {}
42+
StaticReplacementProductListManager(Attributes::ReplacementProductStruct::Type * aReplacementProductsList,
43+
uint8_t aReplacementProductListSize)
44+
{
45+
mReplacementProductsList = aReplacementProductsList;
46+
mReplacementProductListSize = aReplacementProductListSize;
47+
}
48+
49+
private:
50+
Attributes::ReplacementProductStruct::Type * mReplacementProductsList;
51+
uint8_t mReplacementProductListSize;
52+
};
53+
54+
} // namespace ResourceMonitoring
55+
} // namespace Clusters
56+
} // namespace app
57+
} // namespace chip

examples/resource-monitoring-app/resource-monitoring-common/resource-monitoring-app.matter

+6
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,7 @@ server cluster HepaFilterMonitoring = 113 {
15191519
bitmap Feature : BITMAP32 {
15201520
kCondition = 0x1;
15211521
kWarning = 0x2;
1522+
kReplacementProductList = 0x3;
15221523
}
15231524

15241525
struct ReplacementProductStruct {
@@ -1531,6 +1532,7 @@ server cluster HepaFilterMonitoring = 113 {
15311532
readonly attribute ChangeIndicationEnum changeIndication = 2;
15321533
readonly attribute boolean inPlaceIndicator = 3;
15331534
attribute nullable epoch_s lastChangedTime = 4;
1535+
readonly attribute ReplacementProductStruct replacementProductList[] = 5;
15341536
readonly attribute command_id generatedCommandList[] = 65528;
15351537
readonly attribute command_id acceptedCommandList[] = 65529;
15361538
readonly attribute event_id eventList[] = 65530;
@@ -1565,6 +1567,7 @@ server cluster ActivatedCarbonFilterMonitoring = 114 {
15651567
bitmap Feature : BITMAP32 {
15661568
kCondition = 0x1;
15671569
kWarning = 0x2;
1570+
kReplacementProductList = 0x3;
15681571
}
15691572

15701573
struct ReplacementProductStruct {
@@ -1577,6 +1580,7 @@ server cluster ActivatedCarbonFilterMonitoring = 114 {
15771580
readonly attribute ChangeIndicationEnum changeIndication = 2;
15781581
readonly attribute boolean inPlaceIndicator = 3;
15791582
attribute nullable epoch_s lastChangedTime = 4;
1583+
readonly attribute ReplacementProductStruct replacementProductList[] = 5;
15801584
readonly attribute command_id generatedCommandList[] = 65528;
15811585
readonly attribute command_id acceptedCommandList[] = 65529;
15821586
readonly attribute event_id eventList[] = 65530;
@@ -1984,6 +1988,7 @@ endpoint 1 {
19841988
callback attribute changeIndication default = 0;
19851989
callback attribute inPlaceIndicator;
19861990
callback attribute lastChangedTime;
1991+
callback attribute replacementProductList;
19871992
callback attribute generatedCommandList;
19881993
callback attribute acceptedCommandList;
19891994
callback attribute eventList;
@@ -1998,6 +2003,7 @@ endpoint 1 {
19982003
callback attribute changeIndication default = 0;
19992004
callback attribute inPlaceIndicator;
20002005
callback attribute lastChangedTime;
2006+
callback attribute replacementProductList;
20012007
callback attribute generatedCommandList;
20022008
callback attribute acceptedCommandList;
20032009
callback attribute eventList;

examples/resource-monitoring-app/resource-monitoring-common/resource-monitoring-app.zap

+32
Original file line numberDiff line numberDiff line change
@@ -6241,6 +6241,22 @@
62416241
"maxInterval": 65534,
62426242
"reportableChange": 0
62436243
},
6244+
{
6245+
"name": "ReplacementProductList",
6246+
"code": 5,
6247+
"mfgCode": null,
6248+
"side": "server",
6249+
"type": "array",
6250+
"included": 1,
6251+
"storageOption": "External",
6252+
"singleton": 0,
6253+
"bounded": 0,
6254+
"defaultValue": null,
6255+
"reportable": 1,
6256+
"minInterval": 1,
6257+
"maxInterval": 65534,
6258+
"reportableChange": 0
6259+
},
62446260
{
62456261
"name": "GeneratedCommandList",
62466262
"code": 65528,
@@ -6479,6 +6495,22 @@
64796495
"maxInterval": 65534,
64806496
"reportableChange": 0
64816497
},
6498+
{
6499+
"name": "ReplacementProductList",
6500+
"code": 5,
6501+
"mfgCode": null,
6502+
"side": "server",
6503+
"type": "array",
6504+
"included": 1,
6505+
"storageOption": "External",
6506+
"singleton": 0,
6507+
"bounded": 0,
6508+
"defaultValue": null,
6509+
"reportable": 1,
6510+
"minInterval": 1,
6511+
"maxInterval": 65534,
6512+
"reportableChange": 0
6513+
},
64826514
{
64836515
"name": "GeneratedCommandList",
64846516
"code": 65528,

0 commit comments

Comments
 (0)