34
34
#include < app/util/attribute-storage-null-handling.h>
35
35
#include < app/util/attribute-storage.h>
36
36
#include < app/util/ember-global-attribute-access-interface.h>
37
+ #include < app/util/ember-io-storage.h>
37
38
#include < app/util/endpoint-config-api.h>
38
39
#include < app/util/odd-sized-integers.h>
39
40
#include < lib/core/CHIPError.h>
@@ -45,99 +46,7 @@ namespace chip {
45
46
namespace app {
46
47
namespace CodegenDataModel {
47
48
namespace {
48
- // On some apps, ATTRIBUTE_LARGEST can as small as 3, making compiler unhappy since data[kAttributeReadBufferSize] cannot hold
49
- // uint64_t. Make kAttributeReadBufferSize at least 8 so it can fit all basic types.
50
- constexpr size_t kAttributeReadBufferSize = (ATTRIBUTE_LARGEST >= 8 ? ATTRIBUTE_LARGEST : 8 );
51
- uint8_t attributeReadBufferSpace[kAttributeReadBufferSize ];
52
-
53
- // BasicType maps the type to basic int(8|16|32|64)(s|u) types.
54
- // TODO: this code should be SHARED!
55
- EmberAfAttributeType BaseType (EmberAfAttributeType type)
56
- {
57
- switch (type)
58
- {
59
- case ZCL_ACTION_ID_ATTRIBUTE_TYPE: // Action Id
60
- case ZCL_FABRIC_IDX_ATTRIBUTE_TYPE: // Fabric Index
61
- case ZCL_BITMAP8_ATTRIBUTE_TYPE: // 8-bit bitmap
62
- case ZCL_ENUM8_ATTRIBUTE_TYPE: // 8-bit enumeration
63
- case ZCL_STATUS_ATTRIBUTE_TYPE: // Status Code
64
- case ZCL_PERCENT_ATTRIBUTE_TYPE: // Percentage
65
- static_assert (std::is_same<chip::Percent, uint8_t >::value,
66
- " chip::Percent is expected to be uint8_t, change this when necessary" );
67
- return ZCL_INT8U_ATTRIBUTE_TYPE;
68
-
69
- case ZCL_ENDPOINT_NO_ATTRIBUTE_TYPE: // Endpoint Number
70
- case ZCL_GROUP_ID_ATTRIBUTE_TYPE: // Group Id
71
- case ZCL_VENDOR_ID_ATTRIBUTE_TYPE: // Vendor Id
72
- case ZCL_ENUM16_ATTRIBUTE_TYPE: // 16-bit enumeration
73
- case ZCL_BITMAP16_ATTRIBUTE_TYPE: // 16-bit bitmap
74
- case ZCL_PERCENT100THS_ATTRIBUTE_TYPE: // 100ths of a percent
75
- static_assert (std::is_same<chip::EndpointId, uint16_t >::value,
76
- " chip::EndpointId is expected to be uint16_t, change this when necessary" );
77
- static_assert (std::is_same<chip::GroupId, uint16_t >::value,
78
- " chip::GroupId is expected to be uint16_t, change this when necessary" );
79
- static_assert (std::is_same<chip::Percent100ths, uint16_t >::value,
80
- " chip::Percent100ths is expected to be uint16_t, change this when necessary" );
81
- return ZCL_INT16U_ATTRIBUTE_TYPE;
82
-
83
- case ZCL_CLUSTER_ID_ATTRIBUTE_TYPE: // Cluster Id
84
- case ZCL_ATTRIB_ID_ATTRIBUTE_TYPE: // Attribute Id
85
- case ZCL_FIELD_ID_ATTRIBUTE_TYPE: // Field Id
86
- case ZCL_EVENT_ID_ATTRIBUTE_TYPE: // Event Id
87
- case ZCL_COMMAND_ID_ATTRIBUTE_TYPE: // Command Id
88
- case ZCL_TRANS_ID_ATTRIBUTE_TYPE: // Transaction Id
89
- case ZCL_DEVTYPE_ID_ATTRIBUTE_TYPE: // Device Type Id
90
- case ZCL_DATA_VER_ATTRIBUTE_TYPE: // Data Version
91
- case ZCL_BITMAP32_ATTRIBUTE_TYPE: // 32-bit bitmap
92
- case ZCL_EPOCH_S_ATTRIBUTE_TYPE: // Epoch Seconds
93
- case ZCL_ELAPSED_S_ATTRIBUTE_TYPE: // Elapsed Seconds
94
- static_assert (std::is_same<chip::ClusterId, uint32_t >::value,
95
- " chip::Cluster is expected to be uint32_t, change this when necessary" );
96
- static_assert (std::is_same<chip::AttributeId, uint32_t >::value,
97
- " chip::AttributeId is expected to be uint32_t, change this when necessary" );
98
- static_assert (std::is_same<chip::AttributeId, uint32_t >::value,
99
- " chip::AttributeId is expected to be uint32_t, change this when necessary" );
100
- static_assert (std::is_same<chip::EventId, uint32_t >::value,
101
- " chip::EventId is expected to be uint32_t, change this when necessary" );
102
- static_assert (std::is_same<chip::CommandId, uint32_t >::value,
103
- " chip::CommandId is expected to be uint32_t, change this when necessary" );
104
- static_assert (std::is_same<chip::TransactionId, uint32_t >::value,
105
- " chip::TransactionId is expected to be uint32_t, change this when necessary" );
106
- static_assert (std::is_same<chip::DeviceTypeId, uint32_t >::value,
107
- " chip::DeviceTypeId is expected to be uint32_t, change this when necessary" );
108
- static_assert (std::is_same<chip::DataVersion, uint32_t >::value,
109
- " chip::DataVersion is expected to be uint32_t, change this when necessary" );
110
- return ZCL_INT32U_ATTRIBUTE_TYPE;
111
-
112
- case ZCL_AMPERAGE_MA_ATTRIBUTE_TYPE: // Amperage milliamps
113
- case ZCL_ENERGY_MWH_ATTRIBUTE_TYPE: // Energy milliwatt-hours
114
- case ZCL_POWER_MW_ATTRIBUTE_TYPE: // Power milliwatts
115
- case ZCL_VOLTAGE_MV_ATTRIBUTE_TYPE: // Voltage millivolts
116
- return ZCL_INT64S_ATTRIBUTE_TYPE;
117
-
118
- case ZCL_EVENT_NO_ATTRIBUTE_TYPE: // Event Number
119
- case ZCL_FABRIC_ID_ATTRIBUTE_TYPE: // Fabric Id
120
- case ZCL_NODE_ID_ATTRIBUTE_TYPE: // Node Id
121
- case ZCL_BITMAP64_ATTRIBUTE_TYPE: // 64-bit bitmap
122
- case ZCL_EPOCH_US_ATTRIBUTE_TYPE: // Epoch Microseconds
123
- case ZCL_POSIX_MS_ATTRIBUTE_TYPE: // POSIX Milliseconds
124
- case ZCL_SYSTIME_MS_ATTRIBUTE_TYPE: // System time Milliseconds
125
- case ZCL_SYSTIME_US_ATTRIBUTE_TYPE: // System time Microseconds
126
- static_assert (std::is_same<chip::EventNumber, uint64_t >::value,
127
- " chip::EventNumber is expected to be uint64_t, change this when necessary" );
128
- static_assert (std::is_same<chip::FabricId, uint64_t >::value,
129
- " chip::FabricId is expected to be uint64_t, change this when necessary" );
130
- static_assert (std::is_same<chip::NodeId, uint64_t >::value,
131
- " chip::NodeId is expected to be uint64_t, change this when necessary" );
132
- return ZCL_INT64U_ATTRIBUTE_TYPE;
133
-
134
- case ZCL_TEMPERATURE_ATTRIBUTE_TYPE: // Temperature
135
- return ZCL_INT16S_ATTRIBUTE_TYPE;
136
-
137
- default :
138
- return type;
139
- }
140
- }
49
+ using namespace chip ::app::Compatibility::Internal;
141
50
142
51
// Fetch the source for the given attribute path: either a cluster (for global ones) or attribute
143
52
// path.
@@ -311,7 +220,7 @@ CHIP_ERROR EncodeEmberValue(ByteSpan data, const EmberAfAttributeMetadata * meta
311
220
312
221
const bool isNullable = metadata->IsNullable ();
313
222
314
- switch (BaseType (metadata->attributeType ))
223
+ switch (AttributeBaseType (metadata->attributeType ))
315
224
{
316
225
case ZCL_NO_DATA_ATTRIBUTE_TYPE: // No data
317
226
return encoder.EncodeNull ();
@@ -417,19 +326,19 @@ CHIP_ERROR Model::ReadAttribute(const InteractionModel::ReadAttributeRequest & r
417
326
418
327
// At this point, we have to use ember directly to read the data.
419
328
EmberAfAttributeSearchRecord record;
420
- record.endpoint = request.path .mEndpointId ;
421
- record.clusterId = request.path .mClusterId ;
422
- record.attributeId = request.path .mAttributeId ;
423
- Protocols::InteractionModel::Status status =
424
- emAfReadOrWriteAttribute ( &record, &attributeMetadata, attributeReadBufferSpace, sizeof (attributeReadBufferSpace ),
425
- /* write = */ false );
329
+ record.endpoint = request.path .mEndpointId ;
330
+ record.clusterId = request.path .mClusterId ;
331
+ record.attributeId = request.path .mAttributeId ;
332
+ Protocols::InteractionModel::Status status = emAfReadOrWriteAttribute (
333
+ &record, &attributeMetadata, gEmberAttributeIOBufferSpan . data (), gEmberAttributeIOBufferSpan . size ( ),
334
+ /* write = */ false );
426
335
427
336
if (status != Protocols::InteractionModel::Status::Success)
428
337
{
429
338
return ChipError (ChipError::SdkPart::kIMGlobalStatus , to_underlying (status), __FILE__, __LINE__);
430
339
}
431
340
432
- return EncodeEmberValue (ByteSpan (attributeReadBufferSpace) , attributeMetadata, encoder);
341
+ return EncodeEmberValue (gEmberAttributeIOBufferSpan , attributeMetadata, encoder);
433
342
}
434
343
435
344
} // namespace CodegenDataModel
0 commit comments