Skip to content

Commit

Permalink
Simplifying example app and adding support for resource monitor list in
Browse files Browse the repository at this point in the history
the all clusters app
  • Loading branch information
cliffamzn committed Jul 20, 2023
1 parent 63c02b6 commit d9e6a9d
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 30 deletions.
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 @@ -37,10 +37,22 @@ constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast<uint32_t>(Featu
static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr;
static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr;

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

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

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

Expand Down Expand Up @@ -88,3 +101,17 @@ void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint)
DegradationDirectionEnum::kDown, true);
gHepaFilterInstance->Init();
}

CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::ReplacementProductStruct::Type & item)
{
ChipLogDetail(Zcl, "StaticReplacementProductListManager::Next()");

if (mReplacementProductListSize > mIndex)
{
item = mReplacementProductsList[mIndex];
mIndex++;
return CHIP_NO_ERROR;
}

return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,40 @@
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h>
#include <app/data-model/Nullable.h>
#include <app/util/config.h>
#include <app/util/endpoint-config-api.h>
#include <instances/ActivatedCarbonFilterMonitoring.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;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ActivatedCarbonFilterMonitoring;
using namespace chip::app::Clusters::ResourceMonitoring;
using chip::Protocols::InteractionModel::Status;

static ResourceMonitoring::Attributes::ReplacementProductStruct::Type
sActivatedCarbonFilterReplacementProductsList[ACTIVATED_CARBON_FILTER_REPLACEMENT_PRODUCT_LIST_SIZE];
StaticReplacementProductListManager
sActivatedCarbonFilterReplacementProductListManager(&sActivatedCarbonFilterReplacementProductsList[0],
ACTIVATED_CARBON_FILTER_REPLACEMENT_PRODUCT_LIST_SIZE);
static ResourceMonitoring::Attributes::ReplacementProductStruct::Type sActivatedCarbonFilterReplacementProductsList[] = {
{ .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kUpc,
.productIdentifierValue = CharSpan("upc12xcarbon") },
{ .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8,
.productIdentifierValue = CharSpan("gtin8xca") },
{ .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kEan,
.productIdentifierValue = CharSpan("ean13xacarbon") },
{ .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14,
.productIdentifierValue = CharSpan("gtin14xcarbonx") },
{ .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kOem,
.productIdentifierValue = CharSpan("oem20xcarbonxxxxxxxx") },
};
StaticReplacementProductListManager sActivatedCarbonFilterReplacementProductListManager(
&sActivatedCarbonFilterReplacementProductsList[0],
sizeof(sActivatedCarbonFilterReplacementProductsList) / sizeof(ResourceMonitoring::Attributes::ReplacementProductStruct::Type));

//-- 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,33 @@
#include <lib/core/CHIPError.h>
#include <lib/support/CodeUtils.h>
#include <protocols/interaction_model/StatusCode.h>
#include <system/SystemClock.h>
#include <zap-generated/gen_config.h>

#define HEPA_FILTER_REPLACEMENT_PRODUCT_LIST_SIZE 3

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

static ResourceMonitoring::Attributes::ReplacementProductStruct::Type
sHepaFilterReplacementProductsList[HEPA_FILTER_REPLACEMENT_PRODUCT_LIST_SIZE];
StaticReplacementProductListManager sHepaFilterReplacementProductListManager(&sHepaFilterReplacementProductsList[0],
HEPA_FILTER_REPLACEMENT_PRODUCT_LIST_SIZE);
static ResourceMonitoring::Attributes::ReplacementProductStruct::Type sHepaFilterReplacementProductsList[] = {
{ .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kUpc,
.productIdentifierValue = CharSpan("upc12xhepaxx") },
{ .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8,
.productIdentifierValue = CharSpan("gtin8xhe") },
{ .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kEan,
.productIdentifierValue = CharSpan("ean13xhepaxxx") },
{ .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14,
.productIdentifierValue = CharSpan("gtin14xhepaxxx") },
{ .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kOem,
.productIdentifierValue = CharSpan("oem20xhepaxxxxxxxxxx") },
};
StaticReplacementProductListManager sHepaFilterReplacementProductListManager(
&sHepaFilterReplacementProductsList[0],
sizeof(sHepaFilterReplacementProductsList) / sizeof(ResourceMonitoring::Attributes::ReplacementProductStruct::Type));

//-- Hepa filter Monitoring instance methods
CHIP_ERROR HepaFilterMonitoringInstance::AppInit()
{
ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()");

sHepaFilterReplacementProductsList[0].productIdentifierType = ProductIdentifierTypeEnum::kUpc;
sHepaFilterReplacementProductsList[0].productIdentifierValue = "upc12xhepaxx";
sHepaFilterReplacementProductsList[1].productIdentifierType = ProductIdentifierTypeEnum::kGtin8;
sHepaFilterReplacementProductsList[1].productIdentifierValue = "gtin8xhe";
sHepaFilterReplacementProductsList[2].productIdentifierType = ProductIdentifierTypeEnum::kEan;
sHepaFilterReplacementProductsList[2].productIdentifierValue = "ean13xhepaxxx";

SetReplacementProductListManagerInstance(&sHepaFilterReplacementProductListManager);

return CHIP_NO_ERROR;
Expand Down

0 comments on commit d9e6a9d

Please sign in to comment.