Skip to content

Commit

Permalink
Add ReplacementProductList to Resource Monitoring Cluster (#28095)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
cliffamzn and restyled-commits authored Jul 20, 2023
1 parent ddd5861 commit d2d4701
Show file tree
Hide file tree
Showing 32 changed files with 691 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,7 @@ server cluster HepaFilterMonitoring = 113 {
bitmap Feature : BITMAP32 {
kCondition = 0x1;
kWarning = 0x2;
kReplacementProductList = 0x3;
}

struct ReplacementProductStruct {
Expand All @@ -2764,6 +2765,7 @@ server cluster HepaFilterMonitoring = 113 {
readonly attribute ChangeIndicationEnum changeIndication = 2;
readonly attribute boolean inPlaceIndicator = 3;
attribute nullable epoch_s lastChangedTime = 4;
readonly attribute ReplacementProductStruct replacementProductList[] = 5;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
Expand Down Expand Up @@ -2798,6 +2800,7 @@ server cluster ActivatedCarbonFilterMonitoring = 114 {
bitmap Feature : BITMAP32 {
kCondition = 0x1;
kWarning = 0x2;
kReplacementProductList = 0x3;
}

struct ReplacementProductStruct {
Expand All @@ -2810,6 +2813,7 @@ server cluster ActivatedCarbonFilterMonitoring = 114 {
readonly attribute ChangeIndicationEnum changeIndication = 2;
readonly attribute boolean inPlaceIndicator = 3;
attribute nullable epoch_s lastChangedTime = 4;
readonly attribute ReplacementProductStruct replacementProductList[] = 5;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
Expand Down Expand Up @@ -6318,6 +6322,7 @@ endpoint 1 {
callback attribute changeIndication default = 0;
callback attribute inPlaceIndicator;
callback attribute lastChangedTime;
callback attribute replacementProductList;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
Expand All @@ -6332,6 +6337,7 @@ endpoint 1 {
callback attribute changeIndication default = 0;
callback attribute inPlaceIndicator;
callback attribute lastChangedTime;
callback attribute replacementProductList;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
Expand Down
38 changes: 35 additions & 3 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -15014,7 +15014,23 @@
"side": "server",
"type": "epoch_s",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "ReplacementProductList",
"code": 5,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
Expand Down Expand Up @@ -15252,7 +15268,23 @@
"side": "server",
"type": "epoch_s",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "ReplacementProductList",
"code": 5,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
Expand Down Expand Up @@ -31659,4 +31691,4 @@
}
],
"log": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,24 @@ class HepaFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitor
Instance(aEndpointId, chip::app::Clusters::HepaFilterMonitoring::Id, aFeature, aDegradationDirection,
aResetConditionCommandSupported){};
};

class StaticReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager
{
public:
uint8_t Size() override { return mReplacementProductListSize; };

CHIP_ERROR Next(chip::app::Clusters::ResourceMonitoring::Attributes::ReplacementProductStruct::Type & item) override;

~StaticReplacementProductListManager() {}
StaticReplacementProductListManager(
chip::app::Clusters::ResourceMonitoring::Attributes::ReplacementProductStruct::Type * aReplacementProductsList,
uint8_t aReplacementProductListSize)
{
mReplacementProductsList = aReplacementProductsList;
mReplacementProductListSize = aReplacementProductListSize;
}

private:
chip::app::Clusters::ResourceMonitoring::Attributes::ReplacementProductStruct::Type * mReplacementProductsList;
uint8_t mReplacementProductListSize;
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,34 @@ using namespace chip::app::Clusters::ResourceMonitoring;
using chip::Protocols::InteractionModel::Status;

constexpr std::bitset<4> gHepaFilterFeatureMap{ static_cast<uint32_t>(Feature::kCondition) |
static_cast<uint32_t>(Feature::kWarning) };
static_cast<uint32_t>(Feature::kWarning) |
static_cast<uint32_t>(Feature::kReplacementProductList) };
constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast<uint32_t>(Feature::kCondition) |
static_cast<uint32_t>(Feature::kWarning) };
static_cast<uint32_t>(Feature::kWarning) |
static_cast<uint32_t>(Feature::kReplacementProductList) };

static HepaFilterMonitoringInstance * gHepafilterInstance = nullptr;
static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr;
static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr;

static ResourceMonitoring::Attributes::ReplacementProductStruct::Type sReplacementProductsList[] = {
{ .productIdentifierType = ProductIdentifierTypeEnum::kUpc,
.productIdentifierValue = CharSpan::fromCharString("111112222233") },
{ .productIdentifierType = ProductIdentifierTypeEnum::kGtin8, .productIdentifierValue = CharSpan::fromCharString("gtin8xxx") },
{ .productIdentifierType = ProductIdentifierTypeEnum::kEan,
.productIdentifierValue = CharSpan::fromCharString("4444455555666") },
{ .productIdentifierType = ProductIdentifierTypeEnum::kGtin14,
.productIdentifierValue = CharSpan::fromCharString("gtin14xxxxxxxx") },
{ .productIdentifierType = ProductIdentifierTypeEnum::kOem,
.productIdentifierValue = CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx") },
};
StaticReplacementProductListManager sReplacementProductListManager(&sReplacementProductsList[0],
ArraySize(sReplacementProductsList));

//-- Activated Carbon Filter Monitoring Instance methods
CHIP_ERROR ActivatedCarbonFilterMonitoringInstance::AppInit()
{
ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::Init()");
SetReplacementProductListManagerInstance(&sReplacementProductListManager);
return CHIP_NO_ERROR;
}

Expand All @@ -58,6 +75,7 @@ Status ActivatedCarbonFilterMonitoringInstance::PostResetCondition()
CHIP_ERROR HepaFilterMonitoringInstance::AppInit()
{
ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()");
SetReplacementProductListManagerInstance(&sReplacementProductListManager);
return CHIP_NO_ERROR;
}

Expand All @@ -82,8 +100,19 @@ void emberAfActivatedCarbonFilterMonitoringClusterInitCallback(chip::EndpointId
}
void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint)
{
VerifyOrDie(gActivatedCarbonFilterInstance == nullptr);
gHepafilterInstance = new HepaFilterMonitoringInstance(endpoint, static_cast<uint32_t>(gHepaFilterFeatureMap.to_ulong()),
gHepaFilterInstance = new HepaFilterMonitoringInstance(endpoint, static_cast<uint32_t>(gHepaFilterFeatureMap.to_ulong()),
DegradationDirectionEnum::kDown, true);
gHepafilterInstance->Init();
gHepaFilterInstance->Init();
}

CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::ReplacementProductStruct::Type & item)
{
if (mIndex < mReplacementProductListSize)
{
item = mReplacementProductsList[mIndex];
mIndex++;
return CHIP_NO_ERROR;
}

return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}
3 changes: 2 additions & 1 deletion examples/resource-monitoring-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ config("includes") {

executable("chip-resource-monitoring-app") {
sources = [
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/StaticReplacementProductListManager.cpp",
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp",
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp",
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepaFilterMonitoring.cpp",
"include/CHIPProjectAppConfig.h",
"src/main.cpp",
]
Expand Down
7 changes: 5 additions & 2 deletions examples/resource-monitoring-app/linux/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include <AppMain.h>
#include <StaticReplacementProductListManager.h>
#include <app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h>
#include <bitset>
#include <instances/ActivatedCarbonFilterMonitoring.h>
Expand All @@ -29,9 +30,11 @@ using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ResourceMonitoring;

constexpr std::bitset<4> gHepaFilterFeatureMap{ static_cast<uint32_t>(Feature::kCondition) |
static_cast<uint32_t>(Feature::kWarning) };
static_cast<uint32_t>(Feature::kWarning) |
static_cast<uint32_t>(Feature::kReplacementProductList) };
constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast<uint32_t>(Feature::kCondition) |
static_cast<uint32_t>(Feature::kWarning) };
static_cast<uint32_t>(Feature::kWarning) |
static_cast<uint32_t>(Feature::kReplacementProductList) };

static HepaFilterMonitoringInstance gHepaFilterInstance(0x1, static_cast<uint32_t>(gHepaFilterFeatureMap.to_ulong()),
Clusters::ResourceMonitoring::DegradationDirectionEnum::kDown, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <app/clusters/resource-monitoring-server/replacement-product-list-manager.h>
#include <app/util/af.h>
#include <app/util/config.h>

namespace chip {
namespace app {
namespace Clusters {
namespace ResourceMonitoring {

/**
* This implementation statically defines the options.
*/

class StaticReplacementProductListManager : public ReplacementProductListManager
{
public:
uint8_t Size() override { return mReplacementProductListSize; };

CHIP_ERROR Next(Attributes::ReplacementProductStruct::Type & item) override;

~StaticReplacementProductListManager() {}
StaticReplacementProductListManager(Attributes::ReplacementProductStruct::Type * aReplacementProductsList,
uint8_t aReplacementProductListSize)
{
mReplacementProductsList = aReplacementProductsList;
mReplacementProductListSize = aReplacementProductListSize;
}

private:
Attributes::ReplacementProductStruct::Type * mReplacementProductsList;
uint8_t mReplacementProductListSize;
};

} // namespace ResourceMonitoring
} // namespace Clusters
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,7 @@ server cluster HepaFilterMonitoring = 113 {
bitmap Feature : BITMAP32 {
kCondition = 0x1;
kWarning = 0x2;
kReplacementProductList = 0x3;
}

struct ReplacementProductStruct {
Expand All @@ -1531,6 +1532,7 @@ server cluster HepaFilterMonitoring = 113 {
readonly attribute ChangeIndicationEnum changeIndication = 2;
readonly attribute boolean inPlaceIndicator = 3;
attribute nullable epoch_s lastChangedTime = 4;
readonly attribute ReplacementProductStruct replacementProductList[] = 5;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
Expand Down Expand Up @@ -1565,6 +1567,7 @@ server cluster ActivatedCarbonFilterMonitoring = 114 {
bitmap Feature : BITMAP32 {
kCondition = 0x1;
kWarning = 0x2;
kReplacementProductList = 0x3;
}

struct ReplacementProductStruct {
Expand All @@ -1577,6 +1580,7 @@ server cluster ActivatedCarbonFilterMonitoring = 114 {
readonly attribute ChangeIndicationEnum changeIndication = 2;
readonly attribute boolean inPlaceIndicator = 3;
attribute nullable epoch_s lastChangedTime = 4;
readonly attribute ReplacementProductStruct replacementProductList[] = 5;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
Expand Down Expand Up @@ -1984,6 +1988,7 @@ endpoint 1 {
callback attribute changeIndication default = 0;
callback attribute inPlaceIndicator;
callback attribute lastChangedTime;
callback attribute replacementProductList;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
Expand All @@ -1998,6 +2003,7 @@ endpoint 1 {
callback attribute changeIndication default = 0;
callback attribute inPlaceIndicator;
callback attribute lastChangedTime;
callback attribute replacementProductList;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6241,6 +6241,22 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "ReplacementProductList",
"code": 5,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
Expand Down Expand Up @@ -6479,6 +6495,22 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "ReplacementProductList",
"code": 5,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
Expand Down
Loading

0 comments on commit d2d4701

Please sign in to comment.