@@ -40,24 +40,51 @@ using namespace chip::app::Clusters::TestCluster;
40
40
using namespace chip ::app::Clusters::TestCluster::Commands;
41
41
using namespace chip ::app::Clusters::TestCluster::Attributes;
42
42
43
+ // The number of elements in the test attribute list
44
+ constexpr uint8_t kAttributeListLength = 4 ;
45
+
46
+ // The maximum length of the test attribute list element in bytes
47
+ constexpr uint8_t kAttributeEntryLength = 6 ;
48
+
43
49
namespace {
44
50
51
+ class OctetStringData
52
+ {
53
+ public:
54
+ uint8_t * Data () { return mDataBuf ; }
55
+ size_t Length () const { return mDataLen ; }
56
+ void SetLength (size_t size) { mDataLen = size; }
57
+
58
+ private:
59
+ uint8_t mDataBuf [kAttributeEntryLength ];
60
+ size_t mDataLen = 0 ;
61
+ };
62
+
45
63
class TestAttrAccess : public AttributeAccessInterface
46
64
{
47
65
public:
48
66
// Register for the Test Cluster cluster on all endpoints.
49
67
TestAttrAccess () : AttributeAccessInterface(Optional<EndpointId>::Missing(), TestCluster::Id) {}
50
68
51
69
CHIP_ERROR Read (const ConcreteAttributePath & aPath, AttributeValueEncoder & aEncoder) override ;
70
+ CHIP_ERROR Write (const ConcreteAttributePath & aPath, AttributeValueDecoder & aDecoder) override ;
52
71
53
72
private:
54
73
CHIP_ERROR ReadListInt8uAttribute (AttributeValueEncoder & aEncoder);
74
+ CHIP_ERROR WriteListInt8uAttribute (AttributeValueDecoder & aDecoder);
55
75
CHIP_ERROR ReadListOctetStringAttribute (AttributeValueEncoder & aEncoder);
76
+ CHIP_ERROR WriteListOctetStringAttribute (AttributeValueDecoder & aDecoder);
56
77
CHIP_ERROR ReadListStructOctetStringAttribute (AttributeValueEncoder & aEncoder);
78
+ CHIP_ERROR WriteListStructOctetStringAttribute (AttributeValueDecoder & aDecoder);
57
79
CHIP_ERROR ReadListNullablesAndOptionalsStructAttribute (AttributeValueEncoder & aEncoder);
80
+ CHIP_ERROR WriteListNullablesAndOptionalsStructAttribute (AttributeValueDecoder & aDecoder);
58
81
};
59
82
60
83
TestAttrAccess gAttrAccess ;
84
+ uint8_t gListUint8Data [kAttributeListLength ];
85
+ OctetStringData gListOctetStringData [kAttributeListLength ];
86
+ OctetStringData gListOperationalCert [kAttributeListLength ];
87
+ Structs::TestListStructOctet::Type listStructOctetStringData[kAttributeListLength ];
61
88
62
89
CHIP_ERROR TestAttrAccess::Read (const ConcreteAttributePath & aPath, AttributeValueEncoder & aEncoder)
63
90
{
@@ -83,54 +110,140 @@ CHIP_ERROR TestAttrAccess::Read(const ConcreteAttributePath & aPath, AttributeVa
83
110
return CHIP_NO_ERROR;
84
111
}
85
112
113
+ CHIP_ERROR TestAttrAccess::Write (const ConcreteAttributePath & aPath, AttributeValueDecoder & aDecoder)
114
+ {
115
+ switch (aPath.mAttributeId )
116
+ {
117
+ case ListInt8u::Id: {
118
+ return WriteListInt8uAttribute (aDecoder);
119
+ }
120
+ case ListOctetString::Id: {
121
+ return WriteListOctetStringAttribute (aDecoder);
122
+ }
123
+ case ListStructOctetString::Id: {
124
+ return WriteListStructOctetStringAttribute (aDecoder);
125
+ }
126
+ case ListNullablesAndOptionalsStruct::Id: {
127
+ return WriteListNullablesAndOptionalsStructAttribute (aDecoder);
128
+ }
129
+ default : {
130
+ break ;
131
+ }
132
+ }
133
+
134
+ return CHIP_NO_ERROR;
135
+ }
136
+
86
137
CHIP_ERROR TestAttrAccess::ReadListInt8uAttribute (AttributeValueEncoder & aEncoder)
87
138
{
88
139
return aEncoder.EncodeList ([](const TagBoundEncoder & encoder) -> CHIP_ERROR {
89
- constexpr uint8_t maxValue = 4 ;
90
- for (uint8_t value = 1 ; value <= maxValue; value++)
140
+ for (uint8_t index = 0 ; index < kAttributeListLength ; index ++)
91
141
{
92
- ReturnErrorOnFailure (encoder.Encode (value ));
142
+ ReturnErrorOnFailure (encoder.Encode (gListUint8Data [ index ] ));
93
143
}
94
144
return CHIP_NO_ERROR;
95
145
});
96
146
}
97
147
148
+ CHIP_ERROR TestAttrAccess::WriteListInt8uAttribute (AttributeValueDecoder & aDecoder)
149
+ {
150
+ ListInt8u::TypeInfo::DecodableType list;
151
+
152
+ ReturnErrorOnFailure (aDecoder.Decode (list));
153
+
154
+ uint8_t index = 0 ;
155
+ auto iter = list.begin ();
156
+ while (iter.Next ())
157
+ {
158
+ auto & entry = iter.GetValue ();
159
+
160
+ VerifyOrReturnError (index < kAttributeListLength , CHIP_ERROR_BUFFER_TOO_SMALL);
161
+ gListUint8Data [index ++] = entry;
162
+ }
163
+
164
+ return iter.GetStatus ();
165
+ }
166
+
98
167
CHIP_ERROR TestAttrAccess::ReadListOctetStringAttribute (AttributeValueEncoder & aEncoder)
99
168
{
100
169
return aEncoder.EncodeList ([](const TagBoundEncoder & encoder) -> CHIP_ERROR {
101
- constexpr uint16_t attributeCount = 4 ;
102
- char data[6 ] = { ' T' , ' e' , ' s' , ' t' , ' N' , ' \0 ' };
103
-
104
- for (uint8_t index = 0 ; index < attributeCount; index ++)
170
+ for (uint8_t index = 0 ; index < kAttributeListLength ; index ++)
105
171
{
106
- snprintf (data + strlen (data) - 1 , 2 , " %d" , index );
107
- ByteSpan span (Uint8::from_char (data), strlen (data));
172
+ ByteSpan span (gListOctetStringData [index ].Data (), gListOctetStringData [index ].Length ());
108
173
ReturnErrorOnFailure (encoder.Encode (span));
109
174
}
110
175
return CHIP_NO_ERROR;
111
176
});
112
177
}
113
178
179
+ CHIP_ERROR TestAttrAccess::WriteListOctetStringAttribute (AttributeValueDecoder & aDecoder)
180
+ {
181
+ ListOctetString::TypeInfo::DecodableType list;
182
+
183
+ ReturnErrorOnFailure (aDecoder.Decode (list));
184
+
185
+ uint8_t index = 0 ;
186
+ auto iter = list.begin ();
187
+ while (iter.Next ())
188
+ {
189
+ const auto & entry = iter.GetValue ();
190
+
191
+ VerifyOrReturnError (index < kAttributeListLength , CHIP_ERROR_BUFFER_TOO_SMALL);
192
+ VerifyOrReturnError (entry.size () <= kAttributeEntryLength , CHIP_ERROR_BUFFER_TOO_SMALL);
193
+ memcpy (gListOctetStringData [index ].Data (), entry.data (), entry.size ());
194
+ gListOctetStringData [index ].SetLength (entry.size ());
195
+ index ++;
196
+ }
197
+
198
+ return iter.GetStatus ();
199
+ }
200
+
114
201
CHIP_ERROR TestAttrAccess::ReadListStructOctetStringAttribute (AttributeValueEncoder & aEncoder)
115
202
{
116
203
return aEncoder.EncodeList ([](const TagBoundEncoder & encoder) -> CHIP_ERROR {
117
- constexpr uint16_t attributeCount = 4 ;
118
- char data[6 ] = { ' T' , ' e' , ' s' , ' t' , ' N' , ' \0 ' };
119
-
120
- for (uint8_t index = 0 ; index < attributeCount; index ++)
204
+ for (uint8_t index = 0 ; index < kAttributeListLength ; index ++)
121
205
{
122
- snprintf (data + strlen (data) - 1 , 2 , " %d" , index );
123
- ByteSpan span (Uint8::from_char (data), strlen (data));
124
-
125
206
Structs::TestListStructOctet::Type structOctet;
126
- structOctet.fabricIndex = index ;
127
- structOctet.operationalCert = span ;
207
+ structOctet.fabricIndex = listStructOctetStringData[ index ]. fabricIndex ;
208
+ structOctet.operationalCert = listStructOctetStringData[ index ]. operationalCert ;
128
209
ReturnErrorOnFailure (encoder.Encode (structOctet));
129
210
}
211
+
130
212
return CHIP_NO_ERROR;
131
213
});
132
214
}
133
215
216
+ CHIP_ERROR TestAttrAccess::WriteListStructOctetStringAttribute (AttributeValueDecoder & aDecoder)
217
+ {
218
+ ListStructOctetString::TypeInfo::DecodableType list;
219
+
220
+ ReturnErrorOnFailure (aDecoder.Decode (list));
221
+
222
+ uint8_t index = 0 ;
223
+ auto iter = list.begin ();
224
+ while (iter.Next ())
225
+ {
226
+ const auto & entry = iter.GetValue ();
227
+
228
+ VerifyOrReturnError (index < kAttributeListLength , CHIP_ERROR_BUFFER_TOO_SMALL);
229
+ VerifyOrReturnError (entry.operationalCert .size () <= kAttributeEntryLength , CHIP_ERROR_BUFFER_TOO_SMALL);
230
+ memcpy (gListOperationalCert [index ].Data (), entry.operationalCert .data (), entry.operationalCert .size ());
231
+ gListOperationalCert [index ].SetLength (entry.operationalCert .size ());
232
+
233
+ listStructOctetStringData[index ].fabricIndex = entry.fabricIndex ;
234
+ listStructOctetStringData[index ].operationalCert =
235
+ ByteSpan (gListOperationalCert [index ].Data (), gListOperationalCert [index ].Length ());
236
+ index ++;
237
+ }
238
+
239
+ if (iter.GetStatus () != CHIP_NO_ERROR)
240
+ {
241
+ return CHIP_ERROR_INVALID_DATA_LIST;
242
+ }
243
+
244
+ return CHIP_NO_ERROR;
245
+ }
246
+
134
247
CHIP_ERROR TestAttrAccess::ReadListNullablesAndOptionalsStructAttribute (AttributeValueEncoder & aEncoder)
135
248
{
136
249
return aEncoder.EncodeList ([](const TagBoundEncoder & encoder) -> CHIP_ERROR {
@@ -142,6 +255,11 @@ CHIP_ERROR TestAttrAccess::ReadListNullablesAndOptionalsStructAttribute(Attribut
142
255
});
143
256
}
144
257
258
+ CHIP_ERROR TestAttrAccess::WriteListNullablesAndOptionalsStructAttribute (AttributeValueDecoder & aDecoder)
259
+ {
260
+ // TODO Add yaml test case for NullablesAndOptionalsStruct list
261
+ return CHIP_NO_ERROR;
262
+ }
145
263
} // namespace
146
264
147
265
bool emberAfTestClusterClusterTestCallback (app::CommandHandler *, const app::ConcreteCommandPath & commandPath,
0 commit comments