|
21 | 21 | #include <app/util/af-types.h>
|
22 | 22 | #include <app/util/att-storage.h>
|
23 | 23 | #include <app/util/attribute-metadata.h>
|
| 24 | +#include <app/util/endpoint-config-defines.h> |
24 | 25 | #include <lib/support/CodeUtils.h>
|
25 | 26 |
|
26 | 27 | #include <app-common/zap-generated/cluster-objects.h>
|
| 28 | +#include <app-common/zap-generated/attribute-type.h> |
27 | 29 |
|
28 | 30 | static constexpr uint16_t kEmberInvalidEndpointIndex = 0xFFFF;
|
29 | 31 |
|
| 32 | +// If we have fixed number of endpoints, then max is the same. |
| 33 | +#ifdef FIXED_ENDPOINT_COUNT |
| 34 | +#define MAX_ENDPOINT_COUNT (FIXED_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT) |
| 35 | +#endif |
| 36 | + |
| 37 | +#define DECLARE_DYNAMIC_ENDPOINT(endpointName, clusterList) \ |
| 38 | + EmberAfEndpointType endpointName = { clusterList, ArraySize(clusterList), 0 } |
| 39 | + |
| 40 | +#define DECLARE_DYNAMIC_CLUSTER_LIST_BEGIN(clusterListName) EmberAfCluster clusterListName[] = { |
| 41 | + |
| 42 | +// The role argument should be used to determine whether cluster works as a server or a client. |
| 43 | +// It can be assigned with the ZAP_CLUSTER_MASK(SERVER) or ZAP_CLUSTER_MASK(CLUSTER) values. |
| 44 | +#define DECLARE_DYNAMIC_CLUSTER(clusterId, clusterAttrs, role, incomingCommands, outgoingCommands) \ |
| 45 | + { \ |
| 46 | + clusterId, clusterAttrs, ArraySize(clusterAttrs), 0, role, NULL, incomingCommands, outgoingCommands \ |
| 47 | + } |
| 48 | + |
| 49 | +#define DECLARE_DYNAMIC_CLUSTER_LIST_END } |
| 50 | + |
| 51 | +#define DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(attrListName) EmberAfAttributeMetadata attrListName[] = { |
| 52 | + |
| 53 | +#define DECLARE_DYNAMIC_ATTRIBUTE_LIST_END() \ |
| 54 | + { \ |
| 55 | + ZAP_EMPTY_DEFAULT(), 0xFFFD, 2, ZAP_TYPE(INT16U), ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) \ |
| 56 | + } /* cluster revision */ \ |
| 57 | + } |
| 58 | + |
| 59 | +#define DECLARE_DYNAMIC_ATTRIBUTE(attId, attType, attSizeBytes, attrMask) \ |
| 60 | + { \ |
| 61 | + ZAP_EMPTY_DEFAULT(), attId, attSizeBytes, ZAP_TYPE(attType), attrMask | ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) \ |
| 62 | + } |
| 63 | + |
| 64 | + |
30 | 65 | /**
|
31 | 66 | * @brief locate attribute metadata
|
32 | 67 | *
|
@@ -210,6 +245,34 @@ const EmberAfCluster * emberAfFindClusterInType(const EmberAfEndpointType * endp
|
210 | 245 | // Initial configuration
|
211 | 246 | void emberAfEndpointConfigure();
|
212 | 247 |
|
| 248 | + |
| 249 | +// Register a dynamic endpoint. This involves registering descriptors that describe |
| 250 | +// the composition of the endpoint (encapsulated in the 'ep' argument) as well as providing |
| 251 | +// storage for data versions. |
| 252 | +// |
| 253 | +// dataVersionStorage.size() needs to be at least as large as the number of |
| 254 | +// server clusters on this endpoint. If it's not, the endpoint will not be able |
| 255 | +// to store data versions, which may break consumers. |
| 256 | +// |
| 257 | +// The memory backing dataVersionStorage needs to remain allocated until this dynamic |
| 258 | +// endpoint is cleared. |
| 259 | +// |
| 260 | +// An optional device type list can be passed in as well. If provided, the memory |
| 261 | +// backing the list needs to remain allocated until this dynamic endpoint is cleared. |
| 262 | +// |
| 263 | +// An optional parent endpoint id should be passed for child endpoints of composed device. |
| 264 | +// |
| 265 | +// Returns CHIP_NO_ERROR No error. |
| 266 | +// CHIP_ERROR_NO_MEMORY MAX_ENDPOINT_COUNT is reached or when no storage is left for clusters |
| 267 | +// CHIP_ERROR_INVALID_ARGUMENT The EndpointId value passed is kInvalidEndpointId |
| 268 | +// CHIP_ERROR_ENDPOINT_EXISTS If the EndpointId value passed already exists |
| 269 | +// |
| 270 | +CHIP_ERROR emberAfSetDynamicEndpoint(uint16_t index, chip::EndpointId id, const EmberAfEndpointType * ep, |
| 271 | + const chip::Span<chip::DataVersion> & dataVersionStorage, |
| 272 | + chip::Span<const EmberAfDeviceType> deviceTypeList = {}, |
| 273 | + chip::EndpointId parentEndpointId = chip::kInvalidEndpointId); |
| 274 | +chip::EndpointId emberAfClearDynamicEndpoint(uint16_t index); |
| 275 | +uint16_t emberAfGetDynamicIndexFromEndpoint(chip::EndpointId id); |
213 | 276 | /**
|
214 | 277 | * @brief Loads attribute defaults and any non-volatile attributes stored
|
215 | 278 | *
|
|
0 commit comments