From 9c53d0a48de5b0da204999d693bae7d5b212dcb3 Mon Sep 17 00:00:00 2001 From: Oliver Fan Date: Tue, 9 Jul 2024 00:21:16 -0700 Subject: [PATCH 01/15] [occupancy-sensing]Updated occupancy sensing cluster SDK & Sample app(all-clusters-app) implementation to Rev 5 (Matter 1.4) Signed-off-by: Oliver Fan --- .../all-clusters-app.matter | 12 +- .../all-clusters-common/all-clusters-app.zap | 100 +++++++++--- .../occupancy-sensor-server.cpp | 148 +++++++++++++++++- .../occupancy-sensor-server.h | 76 ++++++++- src/app/zap_cluster_list.json | 2 +- 5 files changed, 309 insertions(+), 29 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index f3b7b0d6b6e427..8ebb3d3f219051 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -8789,8 +8789,10 @@ endpoint 1 { ram attribute occupancy; ram attribute occupancySensorType; ram attribute occupancySensorTypeBitmap; - ram attribute featureMap default = 0; - ram attribute clusterRevision default = 4; + ram attribute holdTime default = 10; + callback attribute holdTimeLimits; + ram attribute featureMap default = 0x01; + ram attribute clusterRevision default = 5; } server cluster CarbonMonoxideConcentrationMeasurement { @@ -9258,8 +9260,10 @@ endpoint 2 { ram attribute occupancy; ram attribute occupancySensorType; ram attribute occupancySensorTypeBitmap; - ram attribute featureMap default = 0; - ram attribute clusterRevision default = 4; + ram attribute holdTime default = 20; + callback attribute holdTimeLimits; + ram attribute featureMap default = 0x01; + ram attribute clusterRevision default = 5; } } endpoint 65534 { diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index c547030731c6cf..823117db7cad17 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -18716,6 +18716,38 @@ "maxInterval": 65344, "reportableChange": 0 }, + { + "name": "HoldTime", + "code": 3, + "mfgCode": null, + "side": "server", + "type": "int16u", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "10", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "HoldTimeLimits", + "code": 4, + "mfgCode": null, + "side": "server", + "type": "HoldTimeLimitsStruct", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "FeatureMap", "code": 65532, @@ -18726,7 +18758,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "0", + "defaultValue": "0x01", "reportable": 1, "minInterval": 1, "maxInterval": 65534, @@ -18742,7 +18774,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "4", + "defaultValue": "5", "reportable": 1, "minInterval": 0, "maxInterval": 65344, @@ -21900,6 +21932,14 @@ "isIncoming": 1, "isEnabled": 1 }, + { + "name": "StringEchoResponse", + "code": 13, + "mfgCode": null, + "source": "server", + "isIncoming": 0, + "isEnabled": 1 + }, { "name": "TestEnumsRequest", "code": 14, @@ -21973,32 +22013,24 @@ "isEnabled": 1 }, { - "name": "TestDifferentVendorMeiRequest", - "code": 4294049962, + "name": "StringEchoRequest", + "code": 24, "mfgCode": null, "source": "client", "isIncoming": 1, "isEnabled": 1 }, { - "name": "TestDifferentVendorMeiResponse", - "code": 4294049979, - "mfgCode": null, - "source": "server", - "isIncoming": 0, - "isEnabled": 1 - }, - { - "name": "StringEchoRequest", - "code": 24, + "name": "TestDifferentVendorMeiRequest", + "code": 4294049962, "mfgCode": null, "source": "client", "isIncoming": 1, "isEnabled": 1 }, { - "name": "StringEchoResponse", - "code": 13, + "name": "TestDifferentVendorMeiResponse", + "code": 4294049979, "mfgCode": null, "source": "server", "isIncoming": 0, @@ -24745,6 +24777,38 @@ "maxInterval": 65344, "reportableChange": 0 }, + { + "name": "HoldTime", + "code": 3, + "mfgCode": null, + "side": "server", + "type": "int16u", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "20", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "HoldTimeLimits", + "code": 4, + "mfgCode": null, + "side": "server", + "type": "HoldTimeLimitsStruct", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "FeatureMap", "code": 65532, @@ -24755,7 +24819,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "0", + "defaultValue": "0x01", "reportable": 1, "minInterval": 1, "maxInterval": 65534, @@ -24771,7 +24835,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "4", + "defaultValue": "5", "reportable": 1, "minInterval": 0, "maxInterval": 65344, diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp index 50056387e3c359..90e58c827c39b0 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp @@ -1,6 +1,6 @@ /** * - * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2024 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. @@ -15,15 +15,147 @@ * limitations under the License. */ +#include "occupancy-hal.h" #include "occupancy-sensor-server.h" -#include +#include +#include +#include +#include +#include -#include "occupancy-hal.h" + + +using chip::Protocols::InteractionModel::Status; + +namespace chip { +namespace app { +namespace Clusters { +namespace OccupancySensing { + +Structs::HoldTimeLimitsStruct::Type * HoldTimeLimitsManager::HoldTimeLimits::GetHoldTimeLimitsStruct(EndpointId endpoint) +{ + size_t endpointIndex = 0; + Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = nullptr; + CHIP_ERROR status = FindHoldTimeLimitsIndex(endpoint, endpointIndex); + if (CHIP_NO_ERROR == status) + { + holdTimeLimitsStruct = &mHoldTimeLimitsStructs[endpointIndex]; + } + return holdTimeLimitsStruct; +} + + +CHIP_ERROR HoldTimeLimitsManager::HoldTimeLimits::SetHoldTimeLimitsStruct(EndpointId endpoint, + Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct) +{ + VerifyOrReturnError(kInvalidEndpointId != endpoint, CHIP_ERROR_INVALID_ARGUMENT); + + size_t endpointIndex = 0; + ReturnErrorOnFailure(FindHoldTimeLimitsIndex(endpoint, endpointIndex)); + + mHoldTimeLimitsStructs[endpointIndex] = holdTimeLimitsStruct; + + return CHIP_NO_ERROR; +} + +/// @brief Returns the index of the HoldTimeLimits associated to an endpoint +/// @param[in] endpoint target endpoint +/// @param[out] endpointIndex index of the corresponding HoldTimeLimits for an endpoint +/// @return CHIP_NO_ERROR or CHIP_ERROR_NOT_FOUND, CHIP_ERROR_INVALID_ARGUMENT if invalid endpoint +CHIP_ERROR HoldTimeLimitsManager::HoldTimeLimits::FindHoldTimeLimitsIndex(EndpointId endpoint, size_t & endpointIndex) +{ + VerifyOrReturnError(kInvalidEndpointId != endpoint, CHIP_ERROR_INVALID_ARGUMENT); + + uint16_t index = + emberAfGetClusterServerEndpointIndex(endpoint, OccupancySensing::Id, MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT); + + if (index < ArraySize(mHoldTimeLimitsStructs)) + { + endpointIndex = index; + return CHIP_NO_ERROR; + } + return CHIP_ERROR_NOT_FOUND; +} + +HoldTimeLimitsManager HoldTimeLimitsManager::mInstance; + +HoldTimeLimitsManager & HoldTimeLimitsManager::Instance() +{ + return mInstance; +} + +CHIP_ERROR HoldTimeLimitsManager::Init() +{ + // Prevents re-initializing + VerifyOrReturnError(!mIsInitialized, CHIP_ERROR_INCORRECT_STATE); + + for(size_t i = 0; i <= kOccupancySensingServerMaxEndpointCount; i++) + { + if(emberAfContainsServer(EndpointId(i), OccupancySensing::Id)) + { + Structs::HoldTimeLimitsStruct::Type holdTimeLimitsInit; + + // Set up some sane initial values for hold time limits structures + holdTimeLimitsInit.holdTimeMin = 1; + holdTimeLimitsInit.holdTimeMax = 300; + holdTimeLimitsInit.holdTimeDefault = 10; + + HoldTimeLimitsManager::Instance().SetHoldTimeLimitsStruct(EndpointId(i),holdTimeLimitsInit); + } + } + + VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); + + + mIsInitialized = true; + return CHIP_NO_ERROR; +} + +//AttributeAccessInterface +CHIP_ERROR HoldTimeLimitsManager::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +{ + switch (aPath.mAttributeId) + { + case Attributes::HoldTimeLimits::Id: { + + Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = HoldTimeLimitsManager::Instance().mHoldTimeLimits.GetHoldTimeLimitsStruct(aPath.mEndpointId); + Structs::HoldTimeLimitsStruct::Type res; + res.holdTimeMin = holdTimeLimitsStruct->holdTimeMin; + res.holdTimeMax = holdTimeLimitsStruct->holdTimeMax; + res.holdTimeDefault = holdTimeLimitsStruct->holdTimeDefault; + return aEncoder.Encode(res); + } + default: + return CHIP_NO_ERROR; + } +} + +Structs::HoldTimeLimitsStruct::Type * HoldTimeLimitsManager::GetHoldTimeLimitsStruct(EndpointId endpoint) +{ + Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = mHoldTimeLimits.GetHoldTimeLimitsStruct(endpoint); + return holdTimeLimitsStruct; +} + +CHIP_ERROR HoldTimeLimitsManager::SetHoldTimeLimitsStruct(EndpointId endpoint, + Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct) +{ + ReturnErrorOnFailure(mHoldTimeLimits.SetHoldTimeLimitsStruct(endpoint, holdTimeLimitsStruct)); + return CHIP_NO_ERROR; +} + +} // namespace OccupancySensing +} // namespace Clusters +} // namespace app +} // namespace chip using namespace chip; +using namespace chip::app; +using namespace chip::app::Clusters; using namespace chip::app::Clusters::OccupancySensing; +void chip::app::Clusters::OccupancySensing::emberAfPluginOccupancyClusterServerPostInitCallback(EndpointId endpoint) {} + //****************************************************************************** // Plugin init function //****************************************************************************** @@ -82,11 +214,17 @@ void halOccupancyStateChangedCallback(EndpointId endpoint, HalOccupancyState occ Attributes::Occupancy::Set(endpoint, occupancyState); } -void emberAfPluginOccupancyClusterServerPostInitCallback(EndpointId endpoint) {} HalOccupancySensorType __attribute__((weak)) halOccupancyGetSensorType(EndpointId endpoint) { return HAL_OCCUPANCY_SENSOR_TYPE_PIR; } -void MatterOccupancySensingPluginServerInitCallback() {} +void MatterOccupancySensingPluginServerInitCallback() +{ + CHIP_ERROR err = HoldTimeLimitsManager::Instance().Init(); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "HoldTimeLimitsManager::Instance().Init() error: %" CHIP_ERROR_FORMAT, err.Format()); + } +} diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h index 3ed762cbfb4013..fef5f55e7161f7 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2024 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. @@ -17,8 +17,77 @@ #pragma once +#include +#include +#include #include #include +#include +#include + + +namespace chip { +namespace app { +namespace Clusters { +namespace OccupancySensing { + +/** + * Interface to help manage the Hold Time Limits of the Occupancy Sensing Cluster. + */ +class HoldTimeLimitsManager : public AttributeAccessInterface +{ +public: + static constexpr size_t kOccupancySensingServerMaxEndpointCount = + MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; + static_assert(kOccupancySensingServerMaxEndpointCount <= kInvalidEndpointId, "Occupancy Sensing endpoint count error"); + + //HoldTimeLimits + class HoldTimeLimits + { + public: + Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsStruct(EndpointId endpoint); + CHIP_ERROR SetHoldTimeLimitsStruct(EndpointId endpoint, Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct); + + private: + /// @brief Returns the index of the HoldTimeLimits associated to an endpoint + /// @param[in] endpoint target endpoint + /// @param[out] endpointIndex index of the corresponding HoldTimeLimits for an endpoint + /// @return CHIP_NO_ERROR or CHIP_ERROR_NOT_FOUND, CHIP_ERROR_INVALID_ARGUMENT if invalid endpoint + CHIP_ERROR FindHoldTimeLimitsIndex(EndpointId endpoint, size_t & endpointIndex); + + Structs::HoldTimeLimitsStruct::Type mHoldTimeLimitsStructs[kOccupancySensingServerMaxEndpointCount]; + }; + + static HoldTimeLimitsManager & Instance(); + + CHIP_ERROR Init(); + + // AttributeAccessInterface + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; + + // HoldTimeLimitsStruct Accessors + Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsStruct(EndpointId endpoint); + CHIP_ERROR SetHoldTimeLimitsStruct(EndpointId endpoint, Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct); + +private: + HoldTimeLimitsManager() : AttributeAccessInterface(Optional(), Id) {} + ~HoldTimeLimitsManager() { } + + bool mIsInitialized = false; + + // HoldTimeLimits + HoldTimeLimits mHoldTimeLimits; + + // Instance + static HoldTimeLimitsManager mInstance; +}; + +inline bool HasFeature(EndpointId ep, Feature feature) +{ + uint32_t map; + bool success = (Attributes::FeatureMap::Get(ep, &map) == Protocols::InteractionModel::Status::Success); + return success ? (map & to_underlying(feature)) : false; +} /** @brief Occupancy Cluster Server Post Init * @@ -29,3 +98,8 @@ * @param endpoint Endpoint that is being initialized Ver.: always */ void emberAfPluginOccupancyClusterServerPostInitCallback(chip::EndpointId endpoint); + +} // namespace OccupancySensing +} // namespace Clusters +} // namespace app +} // namespace chip \ No newline at end of file diff --git a/src/app/zap_cluster_list.json b/src/app/zap_cluster_list.json index 4c7757224b1a7d..8513292c6491dc 100644 --- a/src/app/zap_cluster_list.json +++ b/src/app/zap_cluster_list.json @@ -70,7 +70,7 @@ "NETWORK_COMMISSIONING_CLUSTER": [], "SAMPLE_MEI_CLUSTER": [], "NITROGEN_DIOXIDE_CONCENTRATION_MEASUREMENT_CLUSTER": [], - "OCCUPANCY_SENSING_CLUSTER": ["occupancy-sensor-server"], + "OCCUPANCY_SENSING_CLUSTER": [], "ON_OFF_CLUSTER": [], "ON_OFF_SWITCH_CONFIGURATION_CLUSTER": [], "OPERATIONAL_CREDENTIALS_CLUSTER": [], From e5f97bae99dac322452ff67643ebb47f3d22b126 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 11 Jul 2024 05:33:22 +0000 Subject: [PATCH 02/15] Restyled by whitespace --- .../clusters/occupancy-sensor-server/occupancy-sensor-server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h index fef5f55e7161f7..2b8648a0cdf2f2 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h @@ -102,4 +102,4 @@ void emberAfPluginOccupancyClusterServerPostInitCallback(chip::EndpointId endpoi } // namespace OccupancySensing } // namespace Clusters } // namespace app -} // namespace chip \ No newline at end of file +} // namespace chip From adc3bc97e7aeb137ad74da597837f625650d87a6 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 11 Jul 2024 05:33:24 +0000 Subject: [PATCH 03/15] Restyled by clang-format --- .../occupancy-sensor-server.cpp | 67 +++++++++---------- .../occupancy-sensor-server.h | 23 +++---- 2 files changed, 43 insertions(+), 47 deletions(-) diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp index 90e58c827c39b0..8e875e7a472bb6 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp @@ -15,17 +15,15 @@ * limitations under the License. */ -#include "occupancy-hal.h" #include "occupancy-sensor-server.h" +#include "occupancy-hal.h" #include -#include #include +#include #include #include - - using chip::Protocols::InteractionModel::Status; namespace chip { @@ -35,19 +33,19 @@ namespace OccupancySensing { Structs::HoldTimeLimitsStruct::Type * HoldTimeLimitsManager::HoldTimeLimits::GetHoldTimeLimitsStruct(EndpointId endpoint) { - size_t endpointIndex = 0; - Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = nullptr; - CHIP_ERROR status = FindHoldTimeLimitsIndex(endpoint, endpointIndex); - if (CHIP_NO_ERROR == status) + size_t endpointIndex = 0; + Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = nullptr; + CHIP_ERROR status = FindHoldTimeLimitsIndex(endpoint, endpointIndex); + if (CHIP_NO_ERROR == status) { holdTimeLimitsStruct = &mHoldTimeLimitsStructs[endpointIndex]; } return holdTimeLimitsStruct; } - -CHIP_ERROR HoldTimeLimitsManager::HoldTimeLimits::SetHoldTimeLimitsStruct(EndpointId endpoint, - Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct) +CHIP_ERROR +HoldTimeLimitsManager::HoldTimeLimits::SetHoldTimeLimitsStruct(EndpointId endpoint, + Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct) { VerifyOrReturnError(kInvalidEndpointId != endpoint, CHIP_ERROR_INVALID_ARGUMENT); @@ -67,8 +65,8 @@ CHIP_ERROR HoldTimeLimitsManager::HoldTimeLimits::FindHoldTimeLimitsIndex(Endpoi { VerifyOrReturnError(kInvalidEndpointId != endpoint, CHIP_ERROR_INVALID_ARGUMENT); - uint16_t index = - emberAfGetClusterServerEndpointIndex(endpoint, OccupancySensing::Id, MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT); + uint16_t index = emberAfGetClusterServerEndpointIndex(endpoint, OccupancySensing::Id, + MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT); if (index < ArraySize(mHoldTimeLimitsStructs)) { @@ -90,41 +88,41 @@ CHIP_ERROR HoldTimeLimitsManager::Init() // Prevents re-initializing VerifyOrReturnError(!mIsInitialized, CHIP_ERROR_INCORRECT_STATE); - for(size_t i = 0; i <= kOccupancySensingServerMaxEndpointCount; i++) + for (size_t i = 0; i <= kOccupancySensingServerMaxEndpointCount; i++) { - if(emberAfContainsServer(EndpointId(i), OccupancySensing::Id)) - { - Structs::HoldTimeLimitsStruct::Type holdTimeLimitsInit; + if (emberAfContainsServer(EndpointId(i), OccupancySensing::Id)) + { + Structs::HoldTimeLimitsStruct::Type holdTimeLimitsInit; - // Set up some sane initial values for hold time limits structures - holdTimeLimitsInit.holdTimeMin = 1; - holdTimeLimitsInit.holdTimeMax = 300; - holdTimeLimitsInit.holdTimeDefault = 10; + // Set up some sane initial values for hold time limits structures + holdTimeLimitsInit.holdTimeMin = 1; + holdTimeLimitsInit.holdTimeMax = 300; + holdTimeLimitsInit.holdTimeDefault = 10; - HoldTimeLimitsManager::Instance().SetHoldTimeLimitsStruct(EndpointId(i),holdTimeLimitsInit); - } - } + HoldTimeLimitsManager::Instance().SetHoldTimeLimitsStruct(EndpointId(i), holdTimeLimitsInit); + } + } VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); - mIsInitialized = true; return CHIP_NO_ERROR; } -//AttributeAccessInterface +// AttributeAccessInterface CHIP_ERROR HoldTimeLimitsManager::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { switch (aPath.mAttributeId) { case Attributes::HoldTimeLimits::Id: { - Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = HoldTimeLimitsManager::Instance().mHoldTimeLimits.GetHoldTimeLimitsStruct(aPath.mEndpointId); - Structs::HoldTimeLimitsStruct::Type res; - res.holdTimeMin = holdTimeLimitsStruct->holdTimeMin; - res.holdTimeMax = holdTimeLimitsStruct->holdTimeMax; - res.holdTimeDefault = holdTimeLimitsStruct->holdTimeDefault; - return aEncoder.Encode(res); + Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = + HoldTimeLimitsManager::Instance().mHoldTimeLimits.GetHoldTimeLimitsStruct(aPath.mEndpointId); + Structs::HoldTimeLimitsStruct::Type res; + res.holdTimeMin = holdTimeLimitsStruct->holdTimeMin; + res.holdTimeMax = holdTimeLimitsStruct->holdTimeMax; + res.holdTimeDefault = holdTimeLimitsStruct->holdTimeDefault; + return aEncoder.Encode(res); } default: return CHIP_NO_ERROR; @@ -138,7 +136,7 @@ Structs::HoldTimeLimitsStruct::Type * HoldTimeLimitsManager::GetHoldTimeLimitsSt } CHIP_ERROR HoldTimeLimitsManager::SetHoldTimeLimitsStruct(EndpointId endpoint, - Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct) + Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct) { ReturnErrorOnFailure(mHoldTimeLimits.SetHoldTimeLimitsStruct(endpoint, holdTimeLimitsStruct)); return CHIP_NO_ERROR; @@ -214,7 +212,6 @@ void halOccupancyStateChangedCallback(EndpointId endpoint, HalOccupancyState occ Attributes::Occupancy::Set(endpoint, occupancyState); } - HalOccupancySensorType __attribute__((weak)) halOccupancyGetSensorType(EndpointId endpoint) { return HAL_OCCUPANCY_SENSOR_TYPE_PIR; @@ -222,7 +219,7 @@ HalOccupancySensorType __attribute__((weak)) halOccupancyGetSensorType(EndpointI void MatterOccupancySensingPluginServerInitCallback() { - CHIP_ERROR err = HoldTimeLimitsManager::Instance().Init(); + CHIP_ERROR err = HoldTimeLimitsManager::Instance().Init(); if (err != CHIP_NO_ERROR) { ChipLogError(Zcl, "HoldTimeLimitsManager::Instance().Init() error: %" CHIP_ERROR_FORMAT, err.Format()); diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h index 2b8648a0cdf2f2..12e77ade406ceb 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h @@ -25,7 +25,6 @@ #include #include - namespace chip { namespace app { namespace Clusters { @@ -37,19 +36,19 @@ namespace OccupancySensing { class HoldTimeLimitsManager : public AttributeAccessInterface { public: - static constexpr size_t kOccupancySensingServerMaxEndpointCount = + static constexpr size_t kOccupancySensingServerMaxEndpointCount = MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; static_assert(kOccupancySensingServerMaxEndpointCount <= kInvalidEndpointId, "Occupancy Sensing endpoint count error"); - //HoldTimeLimits + // HoldTimeLimits class HoldTimeLimits { public: - Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsStruct(EndpointId endpoint); + Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsStruct(EndpointId endpoint); CHIP_ERROR SetHoldTimeLimitsStruct(EndpointId endpoint, Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct); private: - /// @brief Returns the index of the HoldTimeLimits associated to an endpoint + /// @brief Returns the index of the HoldTimeLimits associated to an endpoint /// @param[in] endpoint target endpoint /// @param[out] endpointIndex index of the corresponding HoldTimeLimits for an endpoint /// @return CHIP_NO_ERROR or CHIP_ERROR_NOT_FOUND, CHIP_ERROR_INVALID_ARGUMENT if invalid endpoint @@ -58,27 +57,27 @@ class HoldTimeLimitsManager : public AttributeAccessInterface Structs::HoldTimeLimitsStruct::Type mHoldTimeLimitsStructs[kOccupancySensingServerMaxEndpointCount]; }; - static HoldTimeLimitsManager & Instance(); + static HoldTimeLimitsManager & Instance(); - CHIP_ERROR Init(); + CHIP_ERROR Init(); - // AttributeAccessInterface + // AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; - // HoldTimeLimitsStruct Accessors + // HoldTimeLimitsStruct Accessors Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsStruct(EndpointId endpoint); CHIP_ERROR SetHoldTimeLimitsStruct(EndpointId endpoint, Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct); private: HoldTimeLimitsManager() : AttributeAccessInterface(Optional(), Id) {} - ~HoldTimeLimitsManager() { } + ~HoldTimeLimitsManager() {} bool mIsInitialized = false; - // HoldTimeLimits + // HoldTimeLimits HoldTimeLimits mHoldTimeLimits; - // Instance + // Instance static HoldTimeLimitsManager mInstance; }; From 6cef67fc70a4301594a25a20f4f0118186379586 Mon Sep 17 00:00:00 2001 From: Oliver FAN <156269022+OliverFan1@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:35:56 +0800 Subject: [PATCH 04/15] Apply suggestions from code review Update Copyright suggestions Co-authored-by: Boris Zbarsky --- .../occupancy-sensor-server/occupancy-sensor-server.cpp | 2 +- .../clusters/occupancy-sensor-server/occupancy-sensor-server.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp index 8e875e7a472bb6..d17b138f851db0 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp @@ -1,6 +1,6 @@ /** * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2020-2024 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. diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h index 12e77ade406ceb..8acc57108b3414 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2020-2024 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. From eef78a558750ee775f989f749edf369bf9c8749c Mon Sep 17 00:00:00 2001 From: Oliver Fan Date: Fri, 12 Jul 2024 00:46:07 -0700 Subject: [PATCH 05/15] Apply suggestions from code review, remove some dead code. Signed-off-by: Oliver Fan --- .../occupancy-sensor-server/occupancy-sensor-server.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp index d17b138f851db0..f845cc8567be14 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp @@ -152,7 +152,6 @@ using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::OccupancySensing; -void chip::app::Clusters::OccupancySensing::emberAfPluginOccupancyClusterServerPostInitCallback(EndpointId endpoint) {} //****************************************************************************** // Plugin init function @@ -189,8 +188,6 @@ void emberAfOccupancySensingClusterServerInitCallback(EndpointId endpoint) break; } Attributes::OccupancySensorTypeBitmap::Set(endpoint, deviceTypeBitmap); - - emberAfPluginOccupancyClusterServerPostInitCallback(endpoint); } //****************************************************************************** From c98dba96d3788343eb5eb9ab9acdf7f54a3752ae Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 12 Jul 2024 07:47:17 +0000 Subject: [PATCH 06/15] Restyled by clang-format --- .../clusters/occupancy-sensor-server/occupancy-sensor-server.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp index f845cc8567be14..8596853323479f 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp @@ -152,7 +152,6 @@ using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::OccupancySensing; - //****************************************************************************** // Plugin init function //****************************************************************************** From 01b03ce691b2641a88f81dd0af64b8381f837ff1 Mon Sep 17 00:00:00 2001 From: Oliver Fan Date: Tue, 16 Jul 2024 19:20:40 -0700 Subject: [PATCH 07/15] Apply suggestions from code review * Avoid mixing code-backed and Attribute-store-backed attributes * Avoid global singletons to maintain state * Initialize the cluster from the application * Report features based on code, not on ZAP-configured values Signed-off-by: Oliver Fan --- .../src/occupancy-sensing-stub.cpp | 61 ++++++ examples/all-clusters-app/linux/BUILD.gn | 1 + .../occupancy-sensor-server.cpp | 175 ++++++++++-------- .../occupancy-sensor-server.h | 68 ++----- 4 files changed, 172 insertions(+), 133 deletions(-) create mode 100644 examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp diff --git a/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp b/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp new file mode 100644 index 00000000000000..f1652ecf7839c4 --- /dev/null +++ b/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp @@ -0,0 +1,61 @@ +/* + * + * Copyright (c) 2024 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 +#include +#include +#include + + +using namespace chip; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::OccupancySensing; +using namespace chip::app::Clusters::OccupancySensing::Structs; +using namespace chip::DeviceLayer; + +using chip::Protocols::InteractionModel::Status; + +static std::unique_ptr gAttrAccess[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; + + +void emberAfOccupancySensingClusterInitCallback(chip::EndpointId endpointId) +{ + + VerifyOrDie(!gAttrAccess[endpointId]); + + gAttrAccess[endpointId] = std::make_unique( + BitMask(OccupancySensing::Feature::kOther)); + + + OccupancySensing::Structs::HoldTimeLimitsStruct::Type holdTimeLimits = { + .holdTimeMin = 1, + .holdTimeMax = 300, + .holdTimeDefault = 10, + }; + + uint16_t holdTime = 10; + + if (gAttrAccess[endpointId]) + { + gAttrAccess[endpointId]->Init(); + + SetHoldTimeLimits(endpointId, holdTimeLimits); + + SetHoldTime(endpointId, holdTime); + } + +} diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index 3d52ef748de90d..7b0c70122217aa 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -46,6 +46,7 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/laundry-washer-controls-delegate-impl.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/microwave-oven-mode.cpp", + "${chip_root}/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/operational-state-delegate-impl.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/oven-modes.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/oven-operational-state-delegate.cpp", diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp index 8596853323479f..293232a46b5fa6 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -31,117 +32,133 @@ namespace app { namespace Clusters { namespace OccupancySensing { -Structs::HoldTimeLimitsStruct::Type * HoldTimeLimitsManager::HoldTimeLimits::GetHoldTimeLimitsStruct(EndpointId endpoint) -{ - size_t endpointIndex = 0; - Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = nullptr; - CHIP_ERROR status = FindHoldTimeLimitsIndex(endpoint, endpointIndex); - if (CHIP_NO_ERROR == status) - { - holdTimeLimitsStruct = &mHoldTimeLimitsStructs[endpointIndex]; - } - return holdTimeLimitsStruct; -} - -CHIP_ERROR -HoldTimeLimitsManager::HoldTimeLimits::SetHoldTimeLimitsStruct(EndpointId endpoint, - Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct) -{ - VerifyOrReturnError(kInvalidEndpointId != endpoint, CHIP_ERROR_INVALID_ARGUMENT); - - size_t endpointIndex = 0; - ReturnErrorOnFailure(FindHoldTimeLimitsIndex(endpoint, endpointIndex)); +Structs::HoldTimeLimitsStruct::Type mHoldTimeLimitsStructs[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; - mHoldTimeLimitsStructs[endpointIndex] = holdTimeLimitsStruct; +uint16_t mHoldTime[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; +CHIP_ERROR OccupancySensingAttrAccess::Init() +{ + VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); return CHIP_NO_ERROR; } -/// @brief Returns the index of the HoldTimeLimits associated to an endpoint -/// @param[in] endpoint target endpoint -/// @param[out] endpointIndex index of the corresponding HoldTimeLimits for an endpoint -/// @return CHIP_NO_ERROR or CHIP_ERROR_NOT_FOUND, CHIP_ERROR_INVALID_ARGUMENT if invalid endpoint -CHIP_ERROR HoldTimeLimitsManager::HoldTimeLimits::FindHoldTimeLimitsIndex(EndpointId endpoint, size_t & endpointIndex) +void OccupancySensingAttrAccess::Shutdown() { - VerifyOrReturnError(kInvalidEndpointId != endpoint, CHIP_ERROR_INVALID_ARGUMENT); + unregisterAttributeAccessOverride(this); +} - uint16_t index = emberAfGetClusterServerEndpointIndex(endpoint, OccupancySensing::Id, - MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT); - if (index < ArraySize(mHoldTimeLimitsStructs)) +CHIP_ERROR OccupancySensingAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +{ + VerifyOrDie(aPath.mClusterId == app::Clusters::OccupancySensing::Id); + + switch (aPath.mAttributeId) { - endpointIndex = index; + case Attributes::FeatureMap::Id: + ReturnErrorOnFailure(aEncoder.Encode(mFeature)); + break; + case Attributes::HoldTime::Id: { + + uint16_t * holdTime = GetHoldTimeForEndpoint(aPath.mEndpointId); + + if (holdTime == nullptr) + { + return CHIP_ERROR_NOT_FOUND; + } + + return aEncoder.Encode(*holdTime); + } + case Attributes::HoldTimeLimits::Id: { + + Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = GetHoldTimeLimitsForEndpoint(aPath.mEndpointId); + + if (holdTimeLimitsStruct == nullptr) + { + return CHIP_ERROR_NOT_FOUND; + } + + return aEncoder.Encode(*holdTimeLimitsStruct); + } + default: return CHIP_NO_ERROR; } - return CHIP_ERROR_NOT_FOUND; + + return CHIP_NO_ERROR; } -HoldTimeLimitsManager HoldTimeLimitsManager::mInstance; - -HoldTimeLimitsManager & HoldTimeLimitsManager::Instance() +bool OccupancySensingAttrAccess::HasFeature(Feature aFeature) const { - return mInstance; + return mFeature.Has(aFeature); } -CHIP_ERROR HoldTimeLimitsManager::Init() +Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsForEndpoint(EndpointId endpoint) { - // Prevents re-initializing - VerifyOrReturnError(!mIsInitialized, CHIP_ERROR_INCORRECT_STATE); + auto index = emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::OccupancySensing::Id, + MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT); + + if (index == kEmberInvalidEndpointIndex) + { + return nullptr; + } - for (size_t i = 0; i <= kOccupancySensingServerMaxEndpointCount; i++) + if (index >= ArraySize(mHoldTimeLimitsStructs)) { - if (emberAfContainsServer(EndpointId(i), OccupancySensing::Id)) - { - Structs::HoldTimeLimitsStruct::Type holdTimeLimitsInit; + ChipLogError(NotSpecified, "Internal error: invalid/unexpected hold time limits index."); + return nullptr; + } + return &mHoldTimeLimitsStructs[index]; +} - // Set up some sane initial values for hold time limits structures - holdTimeLimitsInit.holdTimeMin = 1; - holdTimeLimitsInit.holdTimeMax = 300; - holdTimeLimitsInit.holdTimeDefault = 10; +CHIP_ERROR SetHoldTimeLimits(EndpointId endpointId, const Structs::HoldTimeLimitsStruct::Type & holdTimeLimits) +{ - HoldTimeLimitsManager::Instance().SetHoldTimeLimitsStruct(EndpointId(i), holdTimeLimitsInit); - } - } + VerifyOrReturnError(kInvalidEndpointId != endpointId, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); + Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsForEndpoint = GetHoldTimeLimitsForEndpoint(endpointId); + VerifyOrReturnError(holdTimeLimitsForEndpoint != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + + holdTimeLimitsForEndpoint->holdTimeMin = holdTimeLimits.holdTimeMin; + holdTimeLimitsForEndpoint->holdTimeMax = holdTimeLimits.holdTimeMax; + holdTimeLimitsForEndpoint->holdTimeDefault = holdTimeLimits.holdTimeDefault; + + MatterReportingAttributeChangeCallback(endpointId, OccupancySensing::Id, Attributes::HoldTimeLimits::Id); - mIsInitialized = true; return CHIP_NO_ERROR; } -// AttributeAccessInterface -CHIP_ERROR HoldTimeLimitsManager::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +uint16_t * GetHoldTimeForEndpoint(EndpointId endpoint) { - switch (aPath.mAttributeId) + auto index = emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::OccupancySensing::Id, + MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT); + + if (index == kEmberInvalidEndpointIndex) { - case Attributes::HoldTimeLimits::Id: { - - Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = - HoldTimeLimitsManager::Instance().mHoldTimeLimits.GetHoldTimeLimitsStruct(aPath.mEndpointId); - Structs::HoldTimeLimitsStruct::Type res; - res.holdTimeMin = holdTimeLimitsStruct->holdTimeMin; - res.holdTimeMax = holdTimeLimitsStruct->holdTimeMax; - res.holdTimeDefault = holdTimeLimitsStruct->holdTimeDefault; - return aEncoder.Encode(res); + return nullptr; } - default: - return CHIP_NO_ERROR; + + if (index >= ArraySize(mHoldTimeLimitsStructs)) + { + ChipLogError(NotSpecified, "Internal error: invalid/unexpected hold time index."); + return nullptr; } + return &mHoldTime[index]; } -Structs::HoldTimeLimitsStruct::Type * HoldTimeLimitsManager::GetHoldTimeLimitsStruct(EndpointId endpoint) +CHIP_ERROR SetHoldTime(EndpointId endpointId, const uint16_t & holdTime) { - Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = mHoldTimeLimits.GetHoldTimeLimitsStruct(endpoint); - return holdTimeLimitsStruct; -} + VerifyOrReturnError(kInvalidEndpointId != endpointId, CHIP_ERROR_INVALID_ARGUMENT); + + uint16_t * holdTimeForEndpoint = GetHoldTimeForEndpoint(endpointId); + VerifyOrReturnError(holdTimeForEndpoint != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + + *holdTimeForEndpoint = holdTime; + + MatterReportingAttributeChangeCallback(endpointId, OccupancySensing::Id, Attributes::HoldTime::Id); -CHIP_ERROR HoldTimeLimitsManager::SetHoldTimeLimitsStruct(EndpointId endpoint, - Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct) -{ - ReturnErrorOnFailure(mHoldTimeLimits.SetHoldTimeLimitsStruct(endpoint, holdTimeLimitsStruct)); return CHIP_NO_ERROR; } + } // namespace OccupancySensing } // namespace Clusters } // namespace app @@ -213,11 +230,7 @@ HalOccupancySensorType __attribute__((weak)) halOccupancyGetSensorType(EndpointI return HAL_OCCUPANCY_SENSOR_TYPE_PIR; } + void MatterOccupancySensingPluginServerInitCallback() -{ - CHIP_ERROR err = HoldTimeLimitsManager::Instance().Init(); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "HoldTimeLimitsManager::Instance().Init() error: %" CHIP_ERROR_FORMAT, err.Format()); - } -} +{} + diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h index 8acc57108b3414..9d2ac08a7f736a 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h @@ -30,73 +30,37 @@ namespace app { namespace Clusters { namespace OccupancySensing { -/** - * Interface to help manage the Hold Time Limits of the Occupancy Sensing Cluster. - */ -class HoldTimeLimitsManager : public AttributeAccessInterface + +class OccupancySensingAttrAccess : public AttributeAccessInterface { public: - static constexpr size_t kOccupancySensingServerMaxEndpointCount = - MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; - static_assert(kOccupancySensingServerMaxEndpointCount <= kInvalidEndpointId, "Occupancy Sensing endpoint count error"); - - // HoldTimeLimits - class HoldTimeLimits - { - public: - Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsStruct(EndpointId endpoint); - CHIP_ERROR SetHoldTimeLimitsStruct(EndpointId endpoint, Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct); + OccupancySensingAttrAccess(BitMask aFeature) : + app::AttributeAccessInterface(Optional::Missing(), app::Clusters::OccupancySensing::Id), mFeature(aFeature) + {} + + ~OccupancySensingAttrAccess() { Shutdown(); } - private: - /// @brief Returns the index of the HoldTimeLimits associated to an endpoint - /// @param[in] endpoint target endpoint - /// @param[out] endpointIndex index of the corresponding HoldTimeLimits for an endpoint - /// @return CHIP_NO_ERROR or CHIP_ERROR_NOT_FOUND, CHIP_ERROR_INVALID_ARGUMENT if invalid endpoint - CHIP_ERROR FindHoldTimeLimitsIndex(EndpointId endpoint, size_t & endpointIndex); - - Structs::HoldTimeLimitsStruct::Type mHoldTimeLimitsStructs[kOccupancySensingServerMaxEndpointCount]; - }; - - static HoldTimeLimitsManager & Instance(); CHIP_ERROR Init(); + void Shutdown(); - // AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; - // HoldTimeLimitsStruct Accessors - Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsStruct(EndpointId endpoint); - CHIP_ERROR SetHoldTimeLimitsStruct(EndpointId endpoint, Structs::HoldTimeLimitsStruct::Type & holdTimeLimitsStruct); + bool HasFeature(Feature aFeature) const; private: - HoldTimeLimitsManager() : AttributeAccessInterface(Optional(), Id) {} - ~HoldTimeLimitsManager() {} + BitMask mFeature; + +}; - bool mIsInitialized = false; +CHIP_ERROR SetHoldTimeLimits(EndpointId endpointId, const Structs::HoldTimeLimitsStruct::Type & holdTimeLimits); - // HoldTimeLimits - HoldTimeLimits mHoldTimeLimits; +CHIP_ERROR SetHoldTime(EndpointId endpointId, const uint16_t & holdTime); - // Instance - static HoldTimeLimitsManager mInstance; -}; +Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsForEndpoint(EndpointId endpoint); -inline bool HasFeature(EndpointId ep, Feature feature) -{ - uint32_t map; - bool success = (Attributes::FeatureMap::Get(ep, &map) == Protocols::InteractionModel::Status::Success); - return success ? (map & to_underlying(feature)) : false; -} +uint16_t * GetHoldTimeForEndpoint(EndpointId endpoint); -/** @brief Occupancy Cluster Server Post Init - * - * Following resolution of the Occupancy state at startup for this endpoint, - * perform any additional initialization needed; e.g., synchronize hardware - * state. - * - * @param endpoint Endpoint that is being initialized Ver.: always - */ -void emberAfPluginOccupancyClusterServerPostInitCallback(chip::EndpointId endpoint); } // namespace OccupancySensing } // namespace Clusters From aa4b8e024f29d4c7bb4439d86296d8532f0e1d39 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 17 Jul 2024 02:48:00 +0000 Subject: [PATCH 08/15] Restyled by whitespace --- .../occupancy-sensor-server.cpp | 17 ++++++++--------- .../occupancy-sensor-server.h | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp index 293232a46b5fa6..849b3dfba5bc33 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp @@ -51,7 +51,7 @@ void OccupancySensingAttrAccess::Shutdown() CHIP_ERROR OccupancySensingAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { VerifyOrDie(aPath.mClusterId == app::Clusters::OccupancySensing::Id); - + switch (aPath.mAttributeId) { case Attributes::FeatureMap::Id: @@ -60,29 +60,29 @@ CHIP_ERROR OccupancySensingAttrAccess::Read(const ConcreteReadAttributePath & aP case Attributes::HoldTime::Id: { uint16_t * holdTime = GetHoldTimeForEndpoint(aPath.mEndpointId); - + if (holdTime == nullptr) { return CHIP_ERROR_NOT_FOUND; } - + return aEncoder.Encode(*holdTime); } case Attributes::HoldTimeLimits::Id: { Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = GetHoldTimeLimitsForEndpoint(aPath.mEndpointId); - + if (holdTimeLimitsStruct == nullptr) { return CHIP_ERROR_NOT_FOUND; } - + return aEncoder.Encode(*holdTimeLimitsStruct); } default: return CHIP_NO_ERROR; } - + return CHIP_NO_ERROR; } @@ -95,7 +95,7 @@ Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsForEndpoint(EndpointId en { auto index = emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::OccupancySensing::Id, MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT); - + if (index == kEmberInvalidEndpointIndex) { return nullptr; @@ -130,7 +130,7 @@ uint16_t * GetHoldTimeForEndpoint(EndpointId endpoint) { auto index = emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::OccupancySensing::Id, MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT); - + if (index == kEmberInvalidEndpointIndex) { return nullptr; @@ -233,4 +233,3 @@ HalOccupancySensorType __attribute__((weak)) halOccupancyGetSensorType(EndpointI void MatterOccupancySensingPluginServerInitCallback() {} - diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h index 9d2ac08a7f736a..321ae393639510 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h @@ -34,10 +34,10 @@ namespace OccupancySensing { class OccupancySensingAttrAccess : public AttributeAccessInterface { public: - OccupancySensingAttrAccess(BitMask aFeature) : + OccupancySensingAttrAccess(BitMask aFeature) : app::AttributeAccessInterface(Optional::Missing(), app::Clusters::OccupancySensing::Id), mFeature(aFeature) {} - + ~OccupancySensingAttrAccess() { Shutdown(); } From 62057bade586143315860f88fafbd8a2e1a3d1f9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 17 Jul 2024 02:48:01 +0000 Subject: [PATCH 09/15] Restyled by clang-format --- .../all-clusters-common/src/occupancy-sensing-stub.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp b/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp index f1652ecf7839c4..22d562ad459299 100644 --- a/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp @@ -15,9 +15,9 @@ * limitations under the License. */ -#include -#include #include +#include +#include #include From 0bb79871a0b9dea6a520c4e738428899b8286eb1 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 17 Jul 2024 02:54:32 +0000 Subject: [PATCH 10/15] Restyled by clang-format --- .../src/occupancy-sensing-stub.cpp | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp b/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp index 22d562ad459299..53ccb549a010ca 100644 --- a/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp @@ -20,7 +20,6 @@ #include #include - using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::OccupancySensing; @@ -29,33 +28,32 @@ using namespace chip::DeviceLayer; using chip::Protocols::InteractionModel::Status; -static std::unique_ptr gAttrAccess[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; +static std::unique_ptr + gAttrAccess[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; void emberAfOccupancySensingClusterInitCallback(chip::EndpointId endpointId) { - VerifyOrDie(!gAttrAccess[endpointId]); gAttrAccess[endpointId] = std::make_unique( BitMask(OccupancySensing::Feature::kOther)); - - OccupancySensing::Structs::HoldTimeLimitsStruct::Type holdTimeLimits = { + OccupancySensing::Structs::HoldTimeLimitsStruct::Type holdTimeLimits = { .holdTimeMin = 1, .holdTimeMax = 300, .holdTimeDefault = 10, }; - uint16_t holdTime = 10; + uint16_t holdTime = 10; if (gAttrAccess[endpointId]) { gAttrAccess[endpointId]->Init(); - - SetHoldTimeLimits(endpointId, holdTimeLimits); - - SetHoldTime(endpointId, holdTime); + + SetHoldTimeLimits(endpointId, holdTimeLimits); + + SetHoldTime(endpointId, holdTime); } - + } From 6037d9466ae027b5ab6595bd3750720636ca1d42 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 17 Jul 2024 09:16:42 +0000 Subject: [PATCH 11/15] Restyled by clang-format --- .../src/occupancy-sensing-stub.cpp | 2 - .../occupancy-sensor-server.cpp | 41 +++++++++---------- .../occupancy-sensor-server.h | 14 +++---- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp b/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp index 53ccb549a010ca..985d5866d0a929 100644 --- a/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp @@ -31,7 +31,6 @@ using chip::Protocols::InteractionModel::Status; static std::unique_ptr gAttrAccess[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; - void emberAfOccupancySensingClusterInitCallback(chip::EndpointId endpointId) { VerifyOrDie(!gAttrAccess[endpointId]); @@ -55,5 +54,4 @@ void emberAfOccupancySensingClusterInitCallback(chip::EndpointId endpointId) SetHoldTime(endpointId, holdTime); } - } diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp index 849b3dfba5bc33..1106280731d36f 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp @@ -32,7 +32,8 @@ namespace app { namespace Clusters { namespace OccupancySensing { -Structs::HoldTimeLimitsStruct::Type mHoldTimeLimitsStructs[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; +Structs::HoldTimeLimitsStruct::Type + mHoldTimeLimitsStructs[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; uint16_t mHoldTime[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; @@ -47,43 +48,42 @@ void OccupancySensingAttrAccess::Shutdown() unregisterAttributeAccessOverride(this); } - CHIP_ERROR OccupancySensingAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { - VerifyOrDie(aPath.mClusterId == app::Clusters::OccupancySensing::Id); + VerifyOrDie(aPath.mClusterId == app::Clusters::OccupancySensing::Id); - switch (aPath.mAttributeId) + switch (aPath.mAttributeId) { - case Attributes::FeatureMap::Id: + case Attributes::FeatureMap::Id: ReturnErrorOnFailure(aEncoder.Encode(mFeature)); break; case Attributes::HoldTime::Id: { uint16_t * holdTime = GetHoldTimeForEndpoint(aPath.mEndpointId); - if (holdTime == nullptr) + if (holdTime == nullptr) { return CHIP_ERROR_NOT_FOUND; } - return aEncoder.Encode(*holdTime); + return aEncoder.Encode(*holdTime); } - case Attributes::HoldTimeLimits::Id: { + case Attributes::HoldTimeLimits::Id: { Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = GetHoldTimeLimitsForEndpoint(aPath.mEndpointId); - if (holdTimeLimitsStruct == nullptr) + if (holdTimeLimitsStruct == nullptr) { return CHIP_ERROR_NOT_FOUND; } - return aEncoder.Encode(*holdTimeLimitsStruct); + return aEncoder.Encode(*holdTimeLimitsStruct); } default: return CHIP_NO_ERROR; } - return CHIP_NO_ERROR; + return CHIP_NO_ERROR; } bool OccupancySensingAttrAccess::HasFeature(Feature aFeature) const @@ -93,10 +93,10 @@ bool OccupancySensingAttrAccess::HasFeature(Feature aFeature) const Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsForEndpoint(EndpointId endpoint) { - auto index = emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::OccupancySensing::Id, + auto index = emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::OccupancySensing::Id, MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT); - if (index == kEmberInvalidEndpointIndex) + if (index == kEmberInvalidEndpointIndex) { return nullptr; } @@ -117,7 +117,7 @@ CHIP_ERROR SetHoldTimeLimits(EndpointId endpointId, const Structs::HoldTimeLimit Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsForEndpoint = GetHoldTimeLimitsForEndpoint(endpointId); VerifyOrReturnError(holdTimeLimitsForEndpoint != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - holdTimeLimitsForEndpoint->holdTimeMin = holdTimeLimits.holdTimeMin; + holdTimeLimitsForEndpoint->holdTimeMin = holdTimeLimits.holdTimeMin; holdTimeLimitsForEndpoint->holdTimeMax = holdTimeLimits.holdTimeMax; holdTimeLimitsForEndpoint->holdTimeDefault = holdTimeLimits.holdTimeDefault; @@ -128,10 +128,10 @@ CHIP_ERROR SetHoldTimeLimits(EndpointId endpointId, const Structs::HoldTimeLimit uint16_t * GetHoldTimeForEndpoint(EndpointId endpoint) { - auto index = emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::OccupancySensing::Id, + auto index = emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::OccupancySensing::Id, MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT); - if (index == kEmberInvalidEndpointIndex) + if (index == kEmberInvalidEndpointIndex) { return nullptr; } @@ -146,19 +146,18 @@ uint16_t * GetHoldTimeForEndpoint(EndpointId endpoint) CHIP_ERROR SetHoldTime(EndpointId endpointId, const uint16_t & holdTime) { - VerifyOrReturnError(kInvalidEndpointId != endpointId, CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(kInvalidEndpointId != endpointId, CHIP_ERROR_INVALID_ARGUMENT); uint16_t * holdTimeForEndpoint = GetHoldTimeForEndpoint(endpointId); VerifyOrReturnError(holdTimeForEndpoint != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - *holdTimeForEndpoint = holdTime; + *holdTimeForEndpoint = holdTime; MatterReportingAttributeChangeCallback(endpointId, OccupancySensing::Id, Attributes::HoldTime::Id); return CHIP_NO_ERROR; } - } // namespace OccupancySensing } // namespace Clusters } // namespace app @@ -230,6 +229,4 @@ HalOccupancySensorType __attribute__((weak)) halOccupancyGetSensorType(EndpointI return HAL_OCCUPANCY_SENSOR_TYPE_PIR; } - -void MatterOccupancySensingPluginServerInitCallback() -{} +void MatterOccupancySensingPluginServerInitCallback() {} diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h index 321ae393639510..6fdec4dd178509 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h @@ -30,27 +30,24 @@ namespace app { namespace Clusters { namespace OccupancySensing { - class OccupancySensingAttrAccess : public AttributeAccessInterface { public: - OccupancySensingAttrAccess(BitMask aFeature) : - app::AttributeAccessInterface(Optional::Missing(), app::Clusters::OccupancySensing::Id), mFeature(aFeature) - {} + OccupancySensingAttrAccess(BitMask aFeature) : + app::AttributeAccessInterface(Optional::Missing(), app::Clusters::OccupancySensing::Id), mFeature(aFeature) + {} ~OccupancySensingAttrAccess() { Shutdown(); } - CHIP_ERROR Init(); - void Shutdown(); + void Shutdown(); CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; - bool HasFeature(Feature aFeature) const; + bool HasFeature(Feature aFeature) const; private: BitMask mFeature; - }; CHIP_ERROR SetHoldTimeLimits(EndpointId endpointId, const Structs::HoldTimeLimitsStruct::Type & holdTimeLimits); @@ -61,7 +58,6 @@ Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsForEndpoint(EndpointId en uint16_t * GetHoldTimeForEndpoint(EndpointId endpoint); - } // namespace OccupancySensing } // namespace Clusters } // namespace app From 2342308e5e94d24568299373d3b02ea7d1ec3bcc Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 17 Jul 2024 09:29:49 +0000 Subject: [PATCH 12/15] Restyled by clang-format --- .../clusters/occupancy-sensor-server/occupancy-sensor-server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h index 6fdec4dd178509..f24c64f4dbfbb1 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h @@ -34,7 +34,7 @@ class OccupancySensingAttrAccess : public AttributeAccessInterface { public: OccupancySensingAttrAccess(BitMask aFeature) : - app::AttributeAccessInterface(Optional::Missing(), app::Clusters::OccupancySensing::Id), mFeature(aFeature) + app::AttributeAccessInterface(Optional::Missing(), app::Clusters::OccupancySensing::Id), mFeature(aFeature) {} ~OccupancySensingAttrAccess() { Shutdown(); } From 27003fefd8321803f890c96cca193ad17a1f09da Mon Sep 17 00:00:00 2001 From: Oliver FAN <156269022+OliverFan1@users.noreply.github.com> Date: Fri, 19 Jul 2024 09:53:34 +0800 Subject: [PATCH 13/15] Update examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp Co-authored-by: Boris Zbarsky --- .../all-clusters-common/src/occupancy-sensing-stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp b/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp index 985d5866d0a929..dcbb90ff659bcb 100644 --- a/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp @@ -31,7 +31,7 @@ using chip::Protocols::InteractionModel::Status; static std::unique_ptr gAttrAccess[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; -void emberAfOccupancySensingClusterInitCallback(chip::EndpointId endpointId) +void emberAfOccupancySensingClusterInitCallback(EndpointId endpointId) { VerifyOrDie(!gAttrAccess[endpointId]); From e2a290b55d9fd5aa79ab9279d26bee3b9c42cd63 Mon Sep 17 00:00:00 2001 From: Oliver Fan Date: Thu, 18 Jul 2024 22:40:20 -0700 Subject: [PATCH 14/15] Apply suggestions from code review change mHoldTimeLimitsStructs and mHoldTime to sHoldTimeLimitsStructs and sHoldTime put above two variables in an anonymous namespace Signed-off-by: Oliver Fan --- .../occupancy-sensor-server.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp index 1106280731d36f..bcc964b9aa2a7b 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp @@ -32,10 +32,12 @@ namespace app { namespace Clusters { namespace OccupancySensing { +namespace { Structs::HoldTimeLimitsStruct::Type - mHoldTimeLimitsStructs[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; + sHoldTimeLimitsStructs[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; -uint16_t mHoldTime[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; +uint16_t sHoldTime[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; +} CHIP_ERROR OccupancySensingAttrAccess::Init() { @@ -101,12 +103,12 @@ Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsForEndpoint(EndpointId en return nullptr; } - if (index >= ArraySize(mHoldTimeLimitsStructs)) + if (index >= ArraySize(sHoldTimeLimitsStructs)) { ChipLogError(NotSpecified, "Internal error: invalid/unexpected hold time limits index."); return nullptr; } - return &mHoldTimeLimitsStructs[index]; + return &sHoldTimeLimitsStructs[index]; } CHIP_ERROR SetHoldTimeLimits(EndpointId endpointId, const Structs::HoldTimeLimitsStruct::Type & holdTimeLimits) @@ -136,12 +138,12 @@ uint16_t * GetHoldTimeForEndpoint(EndpointId endpoint) return nullptr; } - if (index >= ArraySize(mHoldTimeLimitsStructs)) + if (index >= ArraySize(sHoldTimeLimitsStructs)) { ChipLogError(NotSpecified, "Internal error: invalid/unexpected hold time index."); return nullptr; } - return &mHoldTime[index]; + return &sHoldTime[index]; } CHIP_ERROR SetHoldTime(EndpointId endpointId, const uint16_t & holdTime) From 44f2723a4c4fe62043ac7381f8fa028330eda018 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 19 Jul 2024 05:40:56 +0000 Subject: [PATCH 15/15] Restyled by clang-format --- .../occupancy-sensor-server/occupancy-sensor-server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp index bcc964b9aa2a7b..4a3ba4103a0b0d 100644 --- a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp @@ -37,7 +37,7 @@ Structs::HoldTimeLimitsStruct::Type sHoldTimeLimitsStructs[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; uint16_t sHoldTime[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; -} +} // namespace CHIP_ERROR OccupancySensingAttrAccess::Init() {