16
16
*/
17
17
18
18
#include < app/clusters/scenes-server/SceneHandlerImpl.h>
19
+ #include < app/util/ember-io-storage.h>
19
20
#include < app/util/endpoint-config-api.h>
20
21
#include < app/util/odd-sized-integers.h>
21
22
@@ -37,7 +38,7 @@ template <typename Type>
37
38
typename app::NumericAttributeTraits<Type>::WorkingType
38
39
ConvertDefaultValueToWorkingValue (const EmberAfDefaultAttributeValue & defaultValue)
39
40
{
40
- if (sizeof (typename app::NumericAttributeTraits<Type>::WorkingType) <= 2 )
41
+ if constexpr (sizeof (typename app::NumericAttributeTraits<Type>::WorkingType) <= 2 )
41
42
{
42
43
return static_cast <typename app::NumericAttributeTraits<Type>::WorkingType>(defaultValue.defaultValue );
43
44
}
@@ -47,11 +48,11 @@ ConvertDefaultValueToWorkingValue(const EmberAfDefaultAttributeValue & defaultVa
47
48
return app::NumericAttributeTraits<Type>::StorageToWorking (sValue );
48
49
}
49
50
50
- // / IsOnlyOneValuePopulated
51
- // / @brief Helper function to verify if only one value is populated in a given AttributeValuePairType
51
+ // / IsExactlyOneValuePopulated
52
+ // / @brief Helper function to verify that exactly one value is populated in a given AttributeValuePairType
52
53
// / @param AttributeValuePairType & type AttributeValuePairType to verify
53
54
// / @return bool true if only one value is populated, false otherwise
54
- bool IsOnlyOneValuePopulated (const AttributeValuePairType & type)
55
+ bool IsExactlyOneValuePopulated (const AttributeValuePairType & type)
55
56
{
56
57
int count = 0 ;
57
58
if (type.valueUnsigned8 .HasValue ())
@@ -73,14 +74,14 @@ bool IsOnlyOneValuePopulated(const AttributeValuePairType & type)
73
74
return count == 1 ;
74
75
}
75
76
76
- // / CapAttributeID
77
+ // / CapAttributeValue
77
78
// / Cap the attribute value based on the attribute's min and max if they are defined,
78
79
// / or based on the attribute's size if they are not.
79
80
// / @param[in] aVPair AttributeValuePairType
80
81
// / @param[in] metadata EmberAfAttributeMetadata
81
82
// /
82
83
template <typename Type>
83
- void CapAttributeID (typename app::NumericAttributeTraits<Type>::WorkingType & Value , const EmberAfAttributeMetadata * metadata)
84
+ void CapAttributeValue (typename app::NumericAttributeTraits<Type>::WorkingType & value , const EmberAfAttributeMetadata * metadata)
84
85
{
85
86
using IntType = app::NumericAttributeTraits<Type>;
86
87
using WorkingType = typename IntType::WorkingType;
@@ -89,7 +90,7 @@ void CapAttributeID(typename app::NumericAttributeTraits<Type>::WorkingType & Va
89
90
WorkingType minValue;
90
91
uint16_t bitWidth = static_cast <uint16_t >(emberAfAttributeSize (metadata) * 8 );
91
92
92
- // Min/Max Value capps for the OddSize integers
93
+ // Min/Max Value caps for the OddSize integers
93
94
if (metadata->IsSignedIntegerAttribute ())
94
95
{
95
96
// We use emberAfAttributeSize for cases like INT24S, INT40S, INT48S, INT56S where numeric_limits<WorkingType>::max()
@@ -118,7 +119,7 @@ void CapAttributeID(typename app::NumericAttributeTraits<Type>::WorkingType & Va
118
119
if (metadata->IsBoolean ())
119
120
{
120
121
// Caping the value to 1 in case values greater than 1 are set
121
- Value = Value ? 1 : 0 ;
122
+ value = value ? 1 : 0 ;
122
123
return ;
123
124
}
124
125
@@ -130,13 +131,20 @@ void CapAttributeID(typename app::NumericAttributeTraits<Type>::WorkingType & Va
130
131
maxValue = ConvertDefaultValueToWorkingValue<Type>(minMaxValue->maxValue );
131
132
}
132
133
133
- if (minValue > Value )
134
+ if (metadata-> IsNullable () && ( minValue > value || maxValue < value) )
134
135
{
135
- Value = minValue;
136
+ // If the attribute is nullable, the value can be set to NULL
137
+ app::NumericAttributeTraits<WorkingType>::SetNull (value);
138
+ return ;
139
+ }
140
+
141
+ if (minValue > value)
142
+ {
143
+ value = minValue;
136
144
}
137
- else if (maxValue < Value )
145
+ else if (maxValue < value )
138
146
{
139
- Value = maxValue;
147
+ value = maxValue;
140
148
}
141
149
}
142
150
@@ -159,72 +167,80 @@ CHIP_ERROR ValidateAttributePath(EndpointId endpoint, ClusterId cluster, Attribu
159
167
}
160
168
161
169
// There should never be more than one populated value in an ExtensionFieldSet
162
- VerifyOrReturnError (IsOnlyOneValuePopulated (aVPair), CHIP_ERROR_INVALID_ARGUMENT);
170
+ VerifyOrReturnError (IsExactlyOneValuePopulated (aVPair), CHIP_ERROR_INVALID_ARGUMENT);
163
171
164
- switch (metadata->attributeType )
172
+ switch (app::Compatibility::Internal::AttributeBaseType ( metadata->attributeType ) )
165
173
{
166
174
case ZCL_BOOLEAN_ATTRIBUTE_TYPE:
167
175
case ZCL_BITMAP8_ATTRIBUTE_TYPE:
168
176
case ZCL_ENUM8_ATTRIBUTE_TYPE:
169
177
case ZCL_INT8U_ATTRIBUTE_TYPE:
170
178
VerifyOrReturnError (aVPair.valueUnsigned8 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
171
- CapAttributeID <uint8_t >(aVPair.valueUnsigned8 .Value (), metadata);
179
+ CapAttributeValue <uint8_t >(aVPair.valueUnsigned8 .Value (), metadata);
172
180
break ;
173
181
case ZCL_BITMAP16_ATTRIBUTE_TYPE:
174
182
case ZCL_ENUM16_ATTRIBUTE_TYPE:
175
183
case ZCL_INT16U_ATTRIBUTE_TYPE:
176
184
VerifyOrReturnError (aVPair.valueUnsigned16 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
177
- CapAttributeID <uint16_t >(aVPair.valueUnsigned16 .Value (), metadata);
185
+ CapAttributeValue <uint16_t >(aVPair.valueUnsigned16 .Value (), metadata);
178
186
break ;
179
187
case ZCL_INT24U_ATTRIBUTE_TYPE:
180
188
VerifyOrReturnError (aVPair.valueUnsigned32 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
181
- CapAttributeID <OddSizedInteger<3 , false >>(aVPair.valueUnsigned32 .Value (), metadata);
189
+ CapAttributeValue <OddSizedInteger<3 , false >>(aVPair.valueUnsigned32 .Value (), metadata);
182
190
break ;
183
191
case ZCL_BITMAP32_ATTRIBUTE_TYPE:
184
192
case ZCL_INT32U_ATTRIBUTE_TYPE:
185
193
VerifyOrReturnError (aVPair.valueUnsigned32 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
186
- CapAttributeID<uint32_t >(aVPair.valueUnsigned32 .Value (), metadata);
194
+ CapAttributeValue<uint32_t >(aVPair.valueUnsigned32 .Value (), metadata);
195
+ break ;
196
+ case ZCL_INT40U_ATTRIBUTE_TYPE:
197
+ VerifyOrReturnError (aVPair.valueUnsigned64 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
198
+ CapAttributeValue<OddSizedInteger<5 , false >>(aVPair.valueUnsigned64 .Value (), metadata);
187
199
break ;
188
200
case ZCL_INT48U_ATTRIBUTE_TYPE:
189
201
VerifyOrReturnError (aVPair.valueUnsigned64 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
190
- CapAttributeID <OddSizedInteger<6 , false >>(aVPair.valueUnsigned64 .Value (), metadata);
202
+ CapAttributeValue <OddSizedInteger<6 , false >>(aVPair.valueUnsigned64 .Value (), metadata);
191
203
break ;
192
204
case ZCL_INT56U_ATTRIBUTE_TYPE:
193
205
VerifyOrReturnError (aVPair.valueUnsigned64 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
194
- CapAttributeID <OddSizedInteger<7 , false >>(aVPair.valueUnsigned64 .Value (), metadata);
206
+ CapAttributeValue <OddSizedInteger<7 , false >>(aVPair.valueUnsigned64 .Value (), metadata);
195
207
break ;
196
208
case ZCL_BITMAP64_ATTRIBUTE_TYPE:
197
209
case ZCL_INT64U_ATTRIBUTE_TYPE:
198
210
VerifyOrReturnError (aVPair.valueUnsigned64 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
199
- CapAttributeID <uint64_t >(aVPair.valueUnsigned64 .Value (), metadata);
211
+ CapAttributeValue <uint64_t >(aVPair.valueUnsigned64 .Value (), metadata);
200
212
break ;
201
213
case ZCL_INT8S_ATTRIBUTE_TYPE:
202
214
VerifyOrReturnError (aVPair.valueSigned8 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
203
- CapAttributeID <int8_t >(aVPair.valueSigned8 .Value (), metadata);
215
+ CapAttributeValue <int8_t >(aVPair.valueSigned8 .Value (), metadata);
204
216
break ;
205
217
case ZCL_INT16S_ATTRIBUTE_TYPE:
206
218
VerifyOrReturnError (aVPair.valueSigned16 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
207
- CapAttributeID <int16_t >(aVPair.valueSigned16 .Value (), metadata);
219
+ CapAttributeValue <int16_t >(aVPair.valueSigned16 .Value (), metadata);
208
220
break ;
209
221
case ZCL_INT24S_ATTRIBUTE_TYPE:
210
222
VerifyOrReturnError (aVPair.valueSigned32 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
211
- CapAttributeID <OddSizedInteger<3 , true >>(aVPair.valueSigned32 .Value (), metadata);
223
+ CapAttributeValue <OddSizedInteger<3 , true >>(aVPair.valueSigned32 .Value (), metadata);
212
224
break ;
213
225
case ZCL_INT32S_ATTRIBUTE_TYPE:
214
226
VerifyOrReturnError (aVPair.valueSigned32 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
215
- CapAttributeID<int32_t >(aVPair.valueSigned32 .Value (), metadata);
227
+ CapAttributeValue<int32_t >(aVPair.valueSigned32 .Value (), metadata);
228
+ break ;
229
+ case ZCL_INT40S_ATTRIBUTE_TYPE:
230
+ VerifyOrReturnError (aVPair.valueSigned64 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
231
+ CapAttributeValue<OddSizedInteger<5 , true >>(aVPair.valueSigned64 .Value (), metadata);
216
232
break ;
217
233
case ZCL_INT48S_ATTRIBUTE_TYPE:
218
234
VerifyOrReturnError (aVPair.valueSigned64 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
219
- CapAttributeID <OddSizedInteger<6 , true >>(aVPair.valueSigned64 .Value (), metadata);
235
+ CapAttributeValue <OddSizedInteger<6 , true >>(aVPair.valueSigned64 .Value (), metadata);
220
236
break ;
221
237
case ZCL_INT56S_ATTRIBUTE_TYPE:
222
238
VerifyOrReturnError (aVPair.valueSigned64 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
223
- CapAttributeID <OddSizedInteger<7 , true >>(aVPair.valueSigned64 .Value (), metadata);
239
+ CapAttributeValue <OddSizedInteger<7 , true >>(aVPair.valueSigned64 .Value (), metadata);
224
240
break ;
225
241
case ZCL_INT64S_ATTRIBUTE_TYPE:
226
242
VerifyOrReturnError (aVPair.valueSigned64 .HasValue (), CHIP_ERROR_INVALID_ARGUMENT);
227
- CapAttributeID <int64_t >(aVPair.valueSigned64 .Value (), metadata);
243
+ CapAttributeValue <int64_t >(aVPair.valueSigned64 .Value (), metadata);
228
244
break ;
229
245
default :
230
246
return CHIP_IM_GLOBAL_STATUS (UnsupportedAttribute);
0 commit comments