Skip to content

Commit

Permalink
Modifying the placeholder app to have example output
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffamzn committed Jul 26, 2023
1 parent a20f485 commit c626d5b
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 30 deletions.
1 change: 1 addition & 0 deletions examples/placeholder/linux/apps/app1/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ source_set("app1") {
]

sources = [
"../../resource-monitoring-instances.cpp",
"../../src/bridged-actions-stub.cpp",
"../../static-supported-modes-manager.cpp",
]
Expand Down
1 change: 1 addition & 0 deletions examples/placeholder/linux/apps/app2/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ source_set("app2") {
]

sources = [
"../../resource-monitoring-instances.cpp",
"../../src/bridged-actions-stub.cpp",
"../../static-supported-modes-manager.cpp",
]
Expand Down
115 changes: 115 additions & 0 deletions examples/placeholder/linux/resource-monitoring-instances.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
*
* 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.
*/

#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h>
#include <app/clusters/resource-monitoring-server/resource-monitoring-server.h>
#include <resource-monitoring-instances.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
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::kReplacementProductList) };
constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast<uint32_t>(Feature::kCondition) |
static_cast<uint32_t>(Feature::kWarning) |
static_cast<uint32_t>(Feature::kReplacementProductList) };

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

static ResourceMonitoring::Attributes::GenericType sReplacementProductsList[] = {
{ ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233") },
{ ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xxx") },
{ ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666") },
{ ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xxxxxxxx") },
{ ProductIdentifierTypeEnum::kOem, 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;
}

Status ActivatedCarbonFilterMonitoringInstance::PreResetCondition()
{
ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringInstance::PreResetCondition()");
return Status::Success;
}

Status ActivatedCarbonFilterMonitoringInstance::PostResetCondition()
{
ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringInstance::PostResetCondition()");
return Status::Success;
}

//-- Hepa Filter Monitoring instance methods
CHIP_ERROR HepaFilterMonitoringInstance::AppInit()
{
ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()");
SetReplacementProductListManagerInstance(&sReplacementProductListManager);
return CHIP_NO_ERROR;
}

Status HepaFilterMonitoringInstance::PreResetCondition()
{
ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::PreResetCondition()");
return Status::Success;
}

Status HepaFilterMonitoringInstance::PostResetCondition()
{
ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::PostResetCondition()");
return Status::Success;
}

void emberAfActivatedCarbonFilterMonitoringClusterInitCallback(chip::EndpointId endpoint)
{
VerifyOrDie(gActivatedCarbonFilterInstance == nullptr);
gActivatedCarbonFilterInstance = new ActivatedCarbonFilterMonitoringInstance(
endpoint, static_cast<uint32_t>(gActivatedCarbonFeatureMap.to_ulong()), DegradationDirectionEnum::kDown, true);
gActivatedCarbonFilterInstance->Init();
}
void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint)
{
VerifyOrDie(gHepaFilterInstance == nullptr);
gHepaFilterInstance = new HepaFilterMonitoringInstance(endpoint, static_cast<uint32_t>(gHepaFilterFeatureMap.to_ulong()),
DegradationDirectionEnum::kDown, true);
gHepaFilterInstance->Init();
}

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

return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}
27 changes: 22 additions & 5 deletions src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ config:
nodeId: 0x12344321
cluster: "Activated Carbon Filter Monitoring"
endpoint: 1
ReplacementProductList:
type: "ReplacementProductStruct"
defaultValue:
[{ ProductIdentifierType: 1, ProductIdentifierValue: "gtin8xac" }]

tests:
- label: "Wait for the commissioned device to be retrieved"
Expand All @@ -37,4 +33,25 @@ tests:
attribute: "ReplacementProductList"
response:
value:
[{ ProductIdentifierType: 1, ProductIdentifierValue: "gtin8xac" }]
[
{
ProductIdentifierType: 0,
ProductIdentifierValue: "111112222233",
},
{
ProductIdentifierType: 1,
ProductIdentifierValue: "gtin8xxx",
},
{
ProductIdentifierType: 2,
ProductIdentifierValue: "4444455555666",
},
{
ProductIdentifierType: 3,
ProductIdentifierValue: "gtin14xxxxxxxx",
},
{
ProductIdentifierType: 4,
ProductIdentifierValue: "oem20xxxxxxxxxxxxxxx",
},
]
25 changes: 0 additions & 25 deletions src/app/tests/suites/TestHepaFilterMonitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,6 @@ config:
nodeId: 0x12344321
cluster: "HEPA Filter Monitoring"
endpoint: 1
ReplacementProductList:
type: "ReplacementProductStruct"
defaultValue:
[
{
ProductIdentifierType: 0,
ProductIdentifierValue: "111112222233",
},
{
ProductIdentifierType: 1,
ProductIdentifierValue: "gtin8xxx",
},
{
ProductIdentifierType: 2,
ProductIdentifierValue: "4444455555666",
},
{
ProductIdentifierType: 3,
ProductIdentifierValue: "gtin14xxxxxxxx",
},
{
ProductIdentifierType: 4,
ProductIdentifierValue: "oem20xxxxxxxxxxxxxxx",
},
]

tests:
- label: "Wait for the commissioned device to be retrieved"
Expand Down

0 comments on commit c626d5b

Please sign in to comment.