Skip to content

Commit

Permalink
Add ReplacementProductList to Resource Monitoring Cluster
Browse files Browse the repository at this point in the history
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 project-chip#27802, project-chip#27801, project-chip#27577

### Testing

I tested this using 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),
        },
],
```
  • Loading branch information
cliffamzn committed Jul 20, 2023
1 parent 78c62b0 commit 63ea77b
Show file tree
Hide file tree
Showing 39 changed files with 866 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2762,6 +2762,7 @@ server cluster HepaFilterMonitoring = 113 {
bitmap Feature : BITMAP32 {
kCondition = 0x1;
kWarning = 0x2;
kReplacementProductList = 0x3;
}

struct ReplacementProductStruct {
Expand All @@ -2774,6 +2775,7 @@ server cluster HepaFilterMonitoring = 113 {
readonly attribute ChangeIndicationEnum changeIndication = 2;
readonly attribute boolean inPlaceIndicator = 3;
attribute nullable epoch_s lastChangedTime = 4;
readonly attribute nullable 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 @@ -2808,6 +2810,7 @@ server cluster ActivatedCarbonFilterMonitoring = 114 {
bitmap Feature : BITMAP32 {
kCondition = 0x1;
kWarning = 0x2;
kReplacementProductList = 0x3;
}

struct ReplacementProductStruct {
Expand All @@ -2820,6 +2823,7 @@ server cluster ActivatedCarbonFilterMonitoring = 114 {
readonly attribute ChangeIndicationEnum changeIndication = 2;
readonly attribute boolean inPlaceIndicator = 3;
attribute nullable epoch_s lastChangedTime = 4;
readonly attribute nullable 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 @@ -6332,6 +6336,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 @@ -6346,6 +6351,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 @@ -14982,7 +14982,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 @@ -15220,7 +15236,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 @@ -31611,4 +31643,4 @@
}
],
"log": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ 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;

//-- Activated Carbon Filter Monitoring Instance methods
Expand Down Expand Up @@ -82,8 +84,7 @@ 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();
}
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 @@ -31,7 +31,8 @@ config("includes") {
executable("chip-resource-monitoring-app") {
sources = [
"${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",
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/instances/StaticReplacementProductListManager.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 @@ -21,6 +21,7 @@
#include <bitset>
#include <instances/ActivatedCarbonFilterMonitoring.h>
#include <instances/HepaFilterMonitoring.h>
#include <instances/StaticReplacementProductListManager.h>
#include <stdint.h>

using namespace chip;
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 nullable 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 nullable 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,39 @@
#include <app/data-model/Nullable.h>
#include <app/util/endpoint-config-api.h>
#include <instances/ActivatedCarbonFilterMonitoring.h>
#include <instances/StaticReplacementProductListManager.h>
#include <lib/core/CHIPError.h>
#include <lib/support/CodeUtils.h>
#include <protocols/interaction_model/StatusCode.h>
#include <system/SystemClock.h>

#define ACTIVATED_CARBON_FILTER_REPLACEMENT_PRODUCT_LIST_SIZE 3

using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ActivatedCarbonFilterMonitoring;
using namespace chip::app::Clusters::ResourceMonitoring;
using chip::Protocols::InteractionModel::Status;

//-- Hepa filter Monitoring Instance methods
static ResourceMonitoring::Attributes::ReplacementProductStruct::Type
sActivatedCarbonFilterReplacementProductsList[ACTIVATED_CARBON_FILTER_REPLACEMENT_PRODUCT_LIST_SIZE];
StaticReplacementProductListManager
sActivatedCarbonFilterReplacementProductListManager(&sActivatedCarbonFilterReplacementProductsList[0],
ACTIVATED_CARBON_FILTER_REPLACEMENT_PRODUCT_LIST_SIZE);

//-- Activated carbon filter Monitoring Instance methods
CHIP_ERROR ActivatedCarbonFilterMonitoringInstance::AppInit()
{
ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::Init()");

sActivatedCarbonFilterReplacementProductsList[0].productIdentifierType = ProductIdentifierTypeEnum::kUpc;
sActivatedCarbonFilterReplacementProductsList[0].productIdentifierValue = "upc12xcarbon";
sActivatedCarbonFilterReplacementProductsList[1].productIdentifierType = ProductIdentifierTypeEnum::kGtin8;
sActivatedCarbonFilterReplacementProductsList[1].productIdentifierValue = "gtin8xca";
sActivatedCarbonFilterReplacementProductsList[2].productIdentifierType = ProductIdentifierTypeEnum::kEan;
sActivatedCarbonFilterReplacementProductsList[2].productIdentifierValue = "ean13xacarbon";

SetReplacementProductListManagerInstance(&sActivatedCarbonFilterReplacementProductListManager);

return CHIP_NO_ERROR;
}

Expand Down
Loading

0 comments on commit 63ea77b

Please sign in to comment.