Skip to content

Commit

Permalink
Add Resource Monitoring Cluster Implementation (#27798)
Browse files Browse the repository at this point in the history
* Add Basic Resource Monitoring Server Implementation

* Add Basic Working Resource Monitoring Example App

* Improve log output

* Replace some HepafilterMonitoring specifics with more general ResourceMonitoring defines

- using `using`
- and adding by hand

* Apply clang-format

* More Hepa to ResourceMonitoring replacement

* Add ActivatedCarbonFilterMonitoring Cluster

* Rename ActivatedCarbonFilterMonitoring.cpp to ActivatedCarbonFilterMonitoringDelegate.cpp

* Split delegate definitions into separate files

* Cleanup some Headers

* Rename member variables

* Refactoring: Rename Delegate to Instance

Add cluster-objects.h / cpp instead of defining it inside the server.h / cpp

* Refactoring: Implement Read and Write function

- have External Attribute Storage inside Instances
- implement getters and Setters for Attributes

* Refactoring: reorder methods to math the order in the .h file

* Run Clang-Format

* Add Getter for DegradationDirection Attribute

- also clean up some namespaces

* Add Construction Option To Set OnResetCondition To Supported

Also add basic OnResetCondition implementation.

* Add Default Values

* Modified the AttributePersistenceProvider ReadValue function signiture to take the required attribute information directly rather than as a EmberAfAttributeMetadata structure.

* Force External Storage for All Resource Monitoring Clusters

* Force External Storage for All Resource Monitoring Clusters

Regenerated Code

* Expanded AttributePersistanceProvider API to include reading and wirting of uint8 and nullable uint8

* Add LastChangedTime to Attributes For ResourceMonitoring Clusters

* Add LastChangedTime to Attributes For ResourceMonitoring Clusters

Regenerated Code

* Add `LastChangedTime` to Forced External Storage List For Resource Monitoring

* Add LastChangedTime To Resource-Monitoring Server Implementation

* Templated the AttributePersistanceProvider read and wiret function to work for all uint types.

* Fixed AttributePersistanceProvider accepted types. Added read helper for type bool.

* Restyled by clang-format

* Formatting and some comments

* Make OnResetCondition Pure Virtual

And remove implementation from resource-monitor-server.cpp.
It's not allowed to use the resource-monitoring-server::instance without deriving it yourself.

* Set LastChangedTime In the OnResetCondition Handler

* Fixed mismatched size return error of DefaultAttributePersistenceProvider

* Add All Missing Aliased Clusters

- CeramicFilterMonitoring
- ElectrostaticFilterMonitoring
- FuelTankMonitoring
- InkCartridgeMonitoring
- IonizingFilterMonitoring
- OzoneFilterMonitoring
- TonerCartridgeMonitoring
- UvFilterMonitoring
- WaterTankMonitoring
- ZeoliteFilterMonitoring

* Started work on tests for the AttributePersistenceProvider.

* Add Missing Instances to resourceMonitoring Test App

* Add Persistent Storage To LastChangedTime

* Add README.md

* Remove `ResourceMonitoringAliasesInstanceMap` as it wasn't really needed

* Update Description Of Init()

* Update Description of AppInit() and OnResetCondition()

* Added unit tests for AttributePersistenceProvider testing the storage and retrival of all unsigned types and their nullable veriaties, bool and ByteSpan. Tested for small buffer errors.

* Changed the type of aSize in ReadValue to size_t

* Removed the dependancy on generated code in the AttributePersistencezprovider.h

* Added static funtctions to get the KVS null representation for different types.

* Fix Errors after Merge

* Some Changes From Comments From The ModeBase PR

* Added functions to read and write nullable bools and accompanying tests.

* Incorporated boolean tests in the scalar test.

* Added failure before init test

* Restyled by clang-format

* Move Headers To Resource-Monitoring-Common

* Move Cpp files To resource-monitor-common

* Remove All Unused Aliases For The Resource-Monitoring-Cluster

this was decided in the AirQuality Call on 06.07.2023

* Fixed after merge.

* Removed the failure on init test as it may have been causing seg faults in some tests.

* Renamed GetNull -> GetNullValueForNullableType

* Added the initialisation of valueReadBack and added a new templated function for nullable types to avoid the error: The left operand of '==' is a garbage value, on some platforms.

* Added handline of signed ints and accompanying tests.

* Added handline of nullable signed ints and accompanying tests.

* Type cast null.

* Restyled by clang-format

* Changed shift bit to be af the same type are the return val.

* Added tests got GetNull functions

* Remove Aliased Clusters From Resource Monitoring Clusters except Hepa and ActivatedCarbon

enable LastChangedTime for Hepa and ActivatedCarbon

* Add Resource Monitoring Aliased Clusters Server implementation To Linux All-Clusters-App

* Remove Todo

* Remove Aliased Clusters From Resource Monitoring Clusters except Hepa and ActivatedCarbon

* Remove Redundant Check

apparently it's not necessary / allow to check this

* Apply Restyled patch

* Remove Tests For Removed Aliased Clusters

- all except Hepa and ActivatedCarbon

* Fix Spelling

* Remove Unused / disallowed #include <maps>

* Remove resource-monitoring-instances.h

* Remove Unneeded Destructors

* Use Default Descructor and Make Class Non copyable or moveable

* Change IsAliascluster to IsValidAliasCluster

* Fix Typo

* Reset ChangeIndication Attribute On ResetCondition Command

Spec requires this to be reset as well

* Set FeatureMap To 3

For testing with Warning Feature enabled

* Rename mFeature To mFeatureMap

* Rewrite Some Comments From "function" to "method"

* Remove Const

* Update Comment Of Init() Method

added the exact CHIP_ERROR_XXX that this can return.

* Remove Commented Code

* Added TODO For REP Feature

* Change From "Next value" To "UINT8_MAX"

* Use ChipLogDetail Instead Of ChipLogError

* Fix Log on Some Platforms

On some platforms (e.g. ASR) uint32_t seems to be a long and will produce a error if %u is used. So cast it to unsinged long on all platforms and use %lu.

* Update README.md For Linux Resource-Monitoring-Example-App

* Remove Aliased Clusters From Resource Monitoring Clusters except Hepa and ActivatedCarbon

* Regen Code

* Apply Restylerd Patch

* Update Wordlist

- Add HEPA

* Remove PICS values For Resource Monitoring Clusters That Were Removed

* Remove PICS For Resource Monitoring Clusters from PICS.yaml

* Add Resource Monitoring README.md To docs/examples/index.md

* Remove redundant chip::app:: prefixes

* Use Bitset Instead Of Just a Number For FeatureMap

* Remove Options from CHIPProjectAppConfig.h

not needed or wrong

* Remove network commissioning bits

As of earlier today that's handled by AppInit. Which is good, because the bits here are buggy.

* Make Hepa And ActivateCarbon Filter Monitoring Instances Static

* Remove ClusterId From Specialized Hepa and Activated Carbon Construtors

They should know their cluster ids, and now they do!

* Add Getter for Endpoint

* Remove Nonsense Comment

* Remove Aliased Cluster IDs That Got Removed

* Fix Typo

* Simplify HandleResetCondition Method

* Add Copyright

* Sort out Includes

Add what is needed using "include what you use" tool

* Make Methods To Private

and move private section to bottom instead of in between

* Initialize All The Member Varaibles With Initializer List

also updated the comment with the new parameters

* Explicit Delete Move Constructors

* Make More Methods To Private

* Update Comment For OnResetCondition Command Handler

* Add FeatureMap To Zcl*.json Files

* Apply restyled Patch

* Remove ResetCondtion::Type And Encode

they are only needed for sending the command, it does not send the command.

* Remove While Loop's Body

is a very complicated no-op. Keep the while itself, it basically check if this is not malformed TLV

* Move OnResetCondition Handling to Cluster Implementation

- add PreResetCondition and PostResetCondition() methods to be overwritten

fixes #27986

* Apply Restyled Patch

* Fix Typo

* Remove Init For Resource Monitoring Clusters From main-common.cpp

And put it in resource-monitoring-helper.cpp.
This will use the ClusterInitCallbacks to initialize the instance objects.

This removes the need to have the init code in every example app, just include the helper.cpp file.

* Apply Restyled Patch

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

Co-authored-by: Cliff Chung <[email protected]>

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

Co-authored-by: Cliff Chung <[email protected]>

* Fix Some Typos

* Disable Removed Test Cases

* Apply Restylerd Patch

* Apply Restyled Patch

* Add Resource-Monitoring-Server To ESP32 All Clusters Example

* Remove Test Scripts For Aliased Clusters

* Revert "Disable Removed Test Cases"

This reverts commit 34e6355.

* Add VerifyOrDie() When More Than 1 EP gets Initialized For Hepa Or Activated Carbon Filter Monitoring

* Add Resource-Monitoring Clusters To ESP32 Minimal App

* Apply Restyled Patch

* Move Resource-Monitoring Instances/Delegates To All-Clusters-Common

to avoid having to include multiple directories and source code from another example app.

* Apply Restyled Patch

* Update Code Gen

* Fix Zap After Merge + CodeGen

---------

Co-authored-by: William Hicklin <[email protected]>
Co-authored-by: William <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Cliff Chung <[email protected]>
Co-authored-by: Cliff Chung <[email protected]>
  • Loading branch information
6 people authored and pull[bot] committed Oct 24, 2023
1 parent b68939a commit 1311044
Show file tree
Hide file tree
Showing 41 changed files with 12,965 additions and 465 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ HomePods
hostapd
hostname
href
HEPA
HTTPS
HW
hwadr
Expand Down
9 changes: 9 additions & 0 deletions docs/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,12 @@ tv-casting-app/**/README
window-app/**/README
```

## Resource monitoring example

```{toctree}
:glob:
:maxdepth: 1
resource-monitoring-app/**/README
```
Original file line number Diff line number Diff line change
Expand Up @@ -2773,12 +2773,15 @@ server cluster HepaFilterMonitoring = 113 {
readonly attribute DegradationDirectionEnum degradationDirection = 1;
readonly attribute ChangeIndicationEnum changeIndication = 2;
readonly attribute boolean inPlaceIndicator = 3;
attribute nullable epoch_s lastChangedTime = 4;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

command ResetCondition(): DefaultSuccess = 0;
}

/** Attributes and commands for monitoring activated carbon filters in a device */
Expand Down Expand Up @@ -2816,12 +2819,15 @@ server cluster ActivatedCarbonFilterMonitoring = 114 {
readonly attribute DegradationDirectionEnum degradationDirection = 1;
readonly attribute ChangeIndicationEnum changeIndication = 2;
readonly attribute boolean inPlaceIndicator = 3;
attribute nullable epoch_s lastChangedTime = 4;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

command ResetCondition(): DefaultSuccess = 0;
}

/** An interface to a generic way to secure a door */
Expand Down Expand Up @@ -6321,10 +6327,11 @@ endpoint 1 {
}

server cluster HepaFilterMonitoring {
ram attribute condition;
ram attribute degradationDirection;
ram attribute changeIndication default = 0;
ram attribute inPlaceIndicator;
callback attribute condition;
callback attribute degradationDirection;
callback attribute changeIndication default = 0;
callback attribute inPlaceIndicator;
callback attribute lastChangedTime;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
Expand All @@ -6334,10 +6341,11 @@ endpoint 1 {
}

server cluster ActivatedCarbonFilterMonitoring {
ram attribute condition;
ram attribute degradationDirection;
ram attribute changeIndication default = 0;
ram attribute inPlaceIndicator;
callback attribute condition;
callback attribute degradationDirection;
callback attribute changeIndication default = 0;
callback attribute inPlaceIndicator;
callback attribute lastChangedTime;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
Expand Down
90 changes: 71 additions & 19 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -6794,7 +6794,7 @@
"side": "server",
"type": "int32u",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "500",
Expand All @@ -6810,7 +6810,7 @@
"side": "server",
"type": "int32u",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "300",
Expand All @@ -6826,7 +6826,7 @@
"side": "server",
"type": "int16u",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "300",
Expand Down Expand Up @@ -6858,7 +6858,7 @@
"side": "server",
"type": "int32u",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
Expand All @@ -6874,7 +6874,7 @@
"side": "server",
"type": "int16u",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "2",
Expand Down Expand Up @@ -13668,7 +13668,7 @@
"side": "server",
"type": "array",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -13684,7 +13684,7 @@
"side": "server",
"type": "array",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -13700,7 +13700,7 @@
"side": "server",
"type": "array",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -13716,7 +13716,7 @@
"side": "server",
"type": "array",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -13732,7 +13732,7 @@
"side": "server",
"type": "array",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand Down Expand Up @@ -14710,7 +14710,7 @@
"code": 4,
"mfgCode": null,
"side": "server",
"type": "OperationalStateStruct",
"type": "OperationalStateEnum",
"included": 1,
"storageOption": "External",
"singleton": 0,
Expand Down Expand Up @@ -14858,6 +14858,16 @@
"define": "HEPA_FILTER_MONITORING_CLUSTER",
"side": "client",
"enabled": 0,
"commands": [
{
"name": "ResetCondition",
"code": 0,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
}
],
"attributes": [
{
"name": "FeatureMap",
Expand Down Expand Up @@ -14908,7 +14918,7 @@
"side": "server",
"type": "percent",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -14924,7 +14934,7 @@
"side": "server",
"type": "DegradationDirectionEnum",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -14940,7 +14950,7 @@
"side": "server",
"type": "ChangeIndicationEnum",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
Expand All @@ -14956,7 +14966,7 @@
"side": "server",
"type": "boolean",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -14965,6 +14975,22 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "LastChangedTime",
"code": 4,
"mfgCode": null,
"side": "server",
"type": "epoch_s",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
Expand Down Expand Up @@ -15070,6 +15096,16 @@
"define": "ACTIVATED_CARBON_FILTER_MONITORING_CLUSTER",
"side": "client",
"enabled": 0,
"commands": [
{
"name": "ResetCondition",
"code": 0,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
}
],
"attributes": [
{
"name": "FeatureMap",
Expand Down Expand Up @@ -15120,7 +15156,7 @@
"side": "server",
"type": "percent",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -15136,7 +15172,7 @@
"side": "server",
"type": "DegradationDirectionEnum",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -15152,7 +15188,7 @@
"side": "server",
"type": "ChangeIndicationEnum",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
Expand All @@ -15168,7 +15204,7 @@
"side": "server",
"type": "boolean",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -15177,6 +15213,22 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "LastChangedTime",
"code": 4,
"mfgCode": null,
"side": "server",
"type": "epoch_s",
"included": 1,
"storageOption": "RAM",
"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
@@ -0,0 +1,56 @@
/*
*
* 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>

/// This is an application level Instance to handle ActivatedCarbonfilterMonitoringInstance commands according to the specific
/// business logic.
class ActivatedCarbonFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitoring::Instance
{
private:
CHIP_ERROR AppInit() override;
chip::Protocols::InteractionModel::Status PreResetCondition() override;
chip::Protocols::InteractionModel::Status PostResetCondition() override;

public:
ActivatedCarbonFilterMonitoringInstance(
chip::EndpointId aEndpointId, uint32_t aFeature,
chip::app::Clusters::ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection,
bool aResetConditionCommandSupported) :
Instance(aEndpointId, chip::app::Clusters::ActivatedCarbonFilterMonitoring::Id, aFeature, aDegradationDirection,
aResetConditionCommandSupported){};
};

/// This is an application level instance to handle HepaFilterMonitoringInstance commands according to the specific business logic.
class HepaFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitoring::Instance
{
private:
CHIP_ERROR AppInit() override;
chip::Protocols::InteractionModel::Status PreResetCondition() override;
chip::Protocols::InteractionModel::Status PostResetCondition() override;

public:
HepaFilterMonitoringInstance(
chip::EndpointId aEndpointId, uint32_t aFeature,
chip::app::Clusters::ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection,
bool aResetConditionCommandSupported) :
Instance(aEndpointId, chip::app::Clusters::HepaFilterMonitoring::Id, aFeature, aDegradationDirection,
aResetConditionCommandSupported){};
};
Loading

0 comments on commit 1311044

Please sign in to comment.