Skip to content

Commit 640b8af

Browse files
authored
Merge branch 'master' into granbery/atomic_write
2 parents 031d33e + c55864b commit 640b8af

File tree

7 files changed

+327
-26
lines changed

7 files changed

+327
-26
lines changed

examples/all-clusters-app/all-clusters-common/all-clusters-app.matter

+8-4
Original file line numberDiff line numberDiff line change
@@ -8874,8 +8874,10 @@ endpoint 1 {
88748874
ram attribute occupancy;
88758875
ram attribute occupancySensorType;
88768876
ram attribute occupancySensorTypeBitmap;
8877-
ram attribute featureMap default = 0;
8878-
ram attribute clusterRevision default = 4;
8877+
ram attribute holdTime default = 10;
8878+
callback attribute holdTimeLimits;
8879+
ram attribute featureMap default = 0x01;
8880+
ram attribute clusterRevision default = 5;
88798881
}
88808882

88818883
server cluster CarbonMonoxideConcentrationMeasurement {
@@ -9343,8 +9345,10 @@ endpoint 2 {
93439345
ram attribute occupancy;
93449346
ram attribute occupancySensorType;
93459347
ram attribute occupancySensorTypeBitmap;
9346-
ram attribute featureMap default = 0;
9347-
ram attribute clusterRevision default = 4;
9348+
ram attribute holdTime default = 20;
9349+
callback attribute holdTimeLimits;
9350+
ram attribute featureMap default = 0x01;
9351+
ram attribute clusterRevision default = 5;
93489352
}
93499353
}
93509354
endpoint 3 {

examples/all-clusters-app/all-clusters-common/all-clusters-app.zap

+68-4
Original file line numberDiff line numberDiff line change
@@ -18952,6 +18952,38 @@
1895218952
"maxInterval": 65344,
1895318953
"reportableChange": 0
1895418954
},
18955+
{
18956+
"name": "HoldTime",
18957+
"code": 3,
18958+
"mfgCode": null,
18959+
"side": "server",
18960+
"type": "int16u",
18961+
"included": 1,
18962+
"storageOption": "RAM",
18963+
"singleton": 0,
18964+
"bounded": 0,
18965+
"defaultValue": "10",
18966+
"reportable": 1,
18967+
"minInterval": 1,
18968+
"maxInterval": 65534,
18969+
"reportableChange": 0
18970+
},
18971+
{
18972+
"name": "HoldTimeLimits",
18973+
"code": 4,
18974+
"mfgCode": null,
18975+
"side": "server",
18976+
"type": "HoldTimeLimitsStruct",
18977+
"included": 1,
18978+
"storageOption": "External",
18979+
"singleton": 0,
18980+
"bounded": 0,
18981+
"defaultValue": null,
18982+
"reportable": 1,
18983+
"minInterval": 1,
18984+
"maxInterval": 65534,
18985+
"reportableChange": 0
18986+
},
1895518987
{
1895618988
"name": "FeatureMap",
1895718989
"code": 65532,
@@ -18962,7 +18994,7 @@
1896218994
"storageOption": "RAM",
1896318995
"singleton": 0,
1896418996
"bounded": 0,
18965-
"defaultValue": "0",
18997+
"defaultValue": "0x01",
1896618998
"reportable": 1,
1896718999
"minInterval": 1,
1896819000
"maxInterval": 65534,
@@ -18978,7 +19010,7 @@
1897819010
"storageOption": "RAM",
1897919011
"singleton": 0,
1898019012
"bounded": 0,
18981-
"defaultValue": "4",
19013+
"defaultValue": "5",
1898219014
"reportable": 1,
1898319015
"minInterval": 0,
1898419016
"maxInterval": 65344,
@@ -24981,6 +25013,38 @@
2498125013
"maxInterval": 65344,
2498225014
"reportableChange": 0
2498325015
},
25016+
{
25017+
"name": "HoldTime",
25018+
"code": 3,
25019+
"mfgCode": null,
25020+
"side": "server",
25021+
"type": "int16u",
25022+
"included": 1,
25023+
"storageOption": "RAM",
25024+
"singleton": 0,
25025+
"bounded": 0,
25026+
"defaultValue": "20",
25027+
"reportable": 1,
25028+
"minInterval": 1,
25029+
"maxInterval": 65534,
25030+
"reportableChange": 0
25031+
},
25032+
{
25033+
"name": "HoldTimeLimits",
25034+
"code": 4,
25035+
"mfgCode": null,
25036+
"side": "server",
25037+
"type": "HoldTimeLimitsStruct",
25038+
"included": 1,
25039+
"storageOption": "External",
25040+
"singleton": 0,
25041+
"bounded": 0,
25042+
"defaultValue": null,
25043+
"reportable": 1,
25044+
"minInterval": 1,
25045+
"maxInterval": 65534,
25046+
"reportableChange": 0
25047+
},
2498425048
{
2498525049
"name": "FeatureMap",
2498625050
"code": 65532,
@@ -24991,7 +25055,7 @@
2499125055
"storageOption": "RAM",
2499225056
"singleton": 0,
2499325057
"bounded": 0,
24994-
"defaultValue": "0",
25058+
"defaultValue": "0x01",
2499525059
"reportable": 1,
2499625060
"minInterval": 1,
2499725061
"maxInterval": 65534,
@@ -25007,7 +25071,7 @@
2500725071
"storageOption": "RAM",
2500825072
"singleton": 0,
2500925073
"bounded": 0,
25010-
"defaultValue": "4",
25074+
"defaultValue": "5",
2501125075
"reportable": 1,
2501225076
"minInterval": 0,
2501325077
"maxInterval": 65344,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <app/CommandHandler.h>
19+
#include <app/clusters/occupancy-sensor-server/occupancy-hal.h>
20+
#include <app/clusters/occupancy-sensor-server/occupancy-sensor-server.h>
21+
#include <platform/CHIPDeviceLayer.h>
22+
23+
using namespace chip;
24+
using namespace chip::app::Clusters;
25+
using namespace chip::app::Clusters::OccupancySensing;
26+
using namespace chip::app::Clusters::OccupancySensing::Structs;
27+
using namespace chip::DeviceLayer;
28+
29+
using chip::Protocols::InteractionModel::Status;
30+
31+
static std::unique_ptr<OccupancySensingAttrAccess>
32+
gAttrAccess[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT];
33+
34+
void emberAfOccupancySensingClusterInitCallback(EndpointId endpointId)
35+
{
36+
VerifyOrDie(!gAttrAccess[endpointId]);
37+
38+
gAttrAccess[endpointId] = std::make_unique<OccupancySensingAttrAccess>(
39+
BitMask<OccupancySensing::Feature, uint32_t>(OccupancySensing::Feature::kOther));
40+
41+
OccupancySensing::Structs::HoldTimeLimitsStruct::Type holdTimeLimits = {
42+
.holdTimeMin = 1,
43+
.holdTimeMax = 300,
44+
.holdTimeDefault = 10,
45+
};
46+
47+
uint16_t holdTime = 10;
48+
49+
if (gAttrAccess[endpointId])
50+
{
51+
gAttrAccess[endpointId]->Init();
52+
53+
SetHoldTimeLimits(endpointId, holdTimeLimits);
54+
55+
SetHoldTime(endpointId, holdTime);
56+
}
57+
}

examples/all-clusters-app/linux/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ source_set("chip-all-clusters-common") {
4646
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/laundry-washer-controls-delegate-impl.cpp",
4747
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp",
4848
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/microwave-oven-mode.cpp",
49+
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/occupancy-sensing-stub.cpp",
4950
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/operational-state-delegate-impl.cpp",
5051
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/oven-modes.cpp",
5152
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/oven-operational-state-delegate.cpp",

src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp

+149-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright (c) 2020 Project CHIP Authors
3+
* Copyright (c) 2020-2024 Project CHIP Authors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -16,12 +16,158 @@
1616
*/
1717

1818
#include "occupancy-sensor-server.h"
19+
#include "occupancy-hal.h"
1920

20-
#include <app-common/zap-generated/attributes/Accessors.h>
21+
#include <app/AttributeAccessInterfaceRegistry.h>
22+
#include <app/EventLogging.h>
23+
#include <app/data-model/Encode.h>
24+
#include <app/reporting/reporting.h>
25+
#include <app/util/attribute-storage.h>
26+
#include <lib/core/CHIPError.h>
2127

22-
#include "occupancy-hal.h"
28+
using chip::Protocols::InteractionModel::Status;
29+
30+
namespace chip {
31+
namespace app {
32+
namespace Clusters {
33+
namespace OccupancySensing {
34+
35+
namespace {
36+
Structs::HoldTimeLimitsStruct::Type
37+
sHoldTimeLimitsStructs[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT];
38+
39+
uint16_t sHoldTime[MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT];
40+
} // namespace
41+
42+
CHIP_ERROR OccupancySensingAttrAccess::Init()
43+
{
44+
VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE);
45+
return CHIP_NO_ERROR;
46+
}
47+
48+
void OccupancySensingAttrAccess::Shutdown()
49+
{
50+
unregisterAttributeAccessOverride(this);
51+
}
52+
53+
CHIP_ERROR OccupancySensingAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
54+
{
55+
VerifyOrDie(aPath.mClusterId == app::Clusters::OccupancySensing::Id);
56+
57+
switch (aPath.mAttributeId)
58+
{
59+
case Attributes::FeatureMap::Id:
60+
ReturnErrorOnFailure(aEncoder.Encode(mFeature));
61+
break;
62+
case Attributes::HoldTime::Id: {
63+
64+
uint16_t * holdTime = GetHoldTimeForEndpoint(aPath.mEndpointId);
65+
66+
if (holdTime == nullptr)
67+
{
68+
return CHIP_ERROR_NOT_FOUND;
69+
}
70+
71+
return aEncoder.Encode(*holdTime);
72+
}
73+
case Attributes::HoldTimeLimits::Id: {
74+
75+
Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsStruct = GetHoldTimeLimitsForEndpoint(aPath.mEndpointId);
76+
77+
if (holdTimeLimitsStruct == nullptr)
78+
{
79+
return CHIP_ERROR_NOT_FOUND;
80+
}
81+
82+
return aEncoder.Encode(*holdTimeLimitsStruct);
83+
}
84+
default:
85+
return CHIP_NO_ERROR;
86+
}
87+
88+
return CHIP_NO_ERROR;
89+
}
90+
91+
bool OccupancySensingAttrAccess::HasFeature(Feature aFeature) const
92+
{
93+
return mFeature.Has(aFeature);
94+
}
95+
96+
Structs::HoldTimeLimitsStruct::Type * GetHoldTimeLimitsForEndpoint(EndpointId endpoint)
97+
{
98+
auto index = emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::OccupancySensing::Id,
99+
MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT);
100+
101+
if (index == kEmberInvalidEndpointIndex)
102+
{
103+
return nullptr;
104+
}
105+
106+
if (index >= ArraySize(sHoldTimeLimitsStructs))
107+
{
108+
ChipLogError(NotSpecified, "Internal error: invalid/unexpected hold time limits index.");
109+
return nullptr;
110+
}
111+
return &sHoldTimeLimitsStructs[index];
112+
}
113+
114+
CHIP_ERROR SetHoldTimeLimits(EndpointId endpointId, const Structs::HoldTimeLimitsStruct::Type & holdTimeLimits)
115+
{
116+
117+
VerifyOrReturnError(kInvalidEndpointId != endpointId, CHIP_ERROR_INVALID_ARGUMENT);
118+
119+
Structs::HoldTimeLimitsStruct::Type * holdTimeLimitsForEndpoint = GetHoldTimeLimitsForEndpoint(endpointId);
120+
VerifyOrReturnError(holdTimeLimitsForEndpoint != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
121+
122+
holdTimeLimitsForEndpoint->holdTimeMin = holdTimeLimits.holdTimeMin;
123+
holdTimeLimitsForEndpoint->holdTimeMax = holdTimeLimits.holdTimeMax;
124+
holdTimeLimitsForEndpoint->holdTimeDefault = holdTimeLimits.holdTimeDefault;
125+
126+
MatterReportingAttributeChangeCallback(endpointId, OccupancySensing::Id, Attributes::HoldTimeLimits::Id);
127+
128+
return CHIP_NO_ERROR;
129+
}
130+
131+
uint16_t * GetHoldTimeForEndpoint(EndpointId endpoint)
132+
{
133+
auto index = emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::OccupancySensing::Id,
134+
MATTER_DM_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT);
135+
136+
if (index == kEmberInvalidEndpointIndex)
137+
{
138+
return nullptr;
139+
}
140+
141+
if (index >= ArraySize(sHoldTimeLimitsStructs))
142+
{
143+
ChipLogError(NotSpecified, "Internal error: invalid/unexpected hold time index.");
144+
return nullptr;
145+
}
146+
return &sHoldTime[index];
147+
}
148+
149+
CHIP_ERROR SetHoldTime(EndpointId endpointId, const uint16_t & holdTime)
150+
{
151+
VerifyOrReturnError(kInvalidEndpointId != endpointId, CHIP_ERROR_INVALID_ARGUMENT);
152+
153+
uint16_t * holdTimeForEndpoint = GetHoldTimeForEndpoint(endpointId);
154+
VerifyOrReturnError(holdTimeForEndpoint != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
155+
156+
*holdTimeForEndpoint = holdTime;
157+
158+
MatterReportingAttributeChangeCallback(endpointId, OccupancySensing::Id, Attributes::HoldTime::Id);
159+
160+
return CHIP_NO_ERROR;
161+
}
162+
163+
} // namespace OccupancySensing
164+
} // namespace Clusters
165+
} // namespace app
166+
} // namespace chip
23167

24168
using namespace chip;
169+
using namespace chip::app;
170+
using namespace chip::app::Clusters;
25171
using namespace chip::app::Clusters::OccupancySensing;
26172

27173
//******************************************************************************
@@ -59,8 +205,6 @@ void emberAfOccupancySensingClusterServerInitCallback(EndpointId endpoint)
59205
break;
60206
}
61207
Attributes::OccupancySensorTypeBitmap::Set(endpoint, deviceTypeBitmap);
62-
63-
emberAfPluginOccupancyClusterServerPostInitCallback(endpoint);
64208
}
65209

66210
//******************************************************************************
@@ -82,8 +226,6 @@ void halOccupancyStateChangedCallback(EndpointId endpoint, HalOccupancyState occ
82226
Attributes::Occupancy::Set(endpoint, occupancyState);
83227
}
84228

85-
void emberAfPluginOccupancyClusterServerPostInitCallback(EndpointId endpoint) {}
86-
87229
HalOccupancySensorType __attribute__((weak)) halOccupancyGetSensorType(EndpointId endpoint)
88230
{
89231
return HAL_OCCUPANCY_SENSOR_TYPE_PIR;

0 commit comments

Comments
 (0)