1
1
/* *
2
2
*
3
- * Copyright (c) 2020 Project CHIP Authors
3
+ * Copyright (c) 2020-2024 Project CHIP Authors
4
4
*
5
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
6
* you may not use this file except in compliance with the License.
16
16
*/
17
17
18
18
#include " occupancy-sensor-server.h"
19
+ #include " occupancy-hal.h"
19
20
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>
21
27
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
23
167
24
168
using namespace chip ;
169
+ using namespace chip ::app;
170
+ using namespace chip ::app::Clusters;
25
171
using namespace chip ::app::Clusters::OccupancySensing;
26
172
27
173
// ******************************************************************************
@@ -59,8 +205,6 @@ void emberAfOccupancySensingClusterServerInitCallback(EndpointId endpoint)
59
205
break ;
60
206
}
61
207
Attributes::OccupancySensorTypeBitmap::Set (endpoint, deviceTypeBitmap);
62
-
63
- emberAfPluginOccupancyClusterServerPostInitCallback (endpoint);
64
208
}
65
209
66
210
// ******************************************************************************
@@ -82,8 +226,6 @@ void halOccupancyStateChangedCallback(EndpointId endpoint, HalOccupancyState occ
82
226
Attributes::Occupancy::Set (endpoint, occupancyState);
83
227
}
84
228
85
- void emberAfPluginOccupancyClusterServerPostInitCallback (EndpointId endpoint) {}
86
-
87
229
HalOccupancySensorType __attribute__ ((weak)) halOccupancyGetSensorType(EndpointId endpoint)
88
230
{
89
231
return HAL_OCCUPANCY_SENSOR_TYPE_PIR;
0 commit comments