|
| 1 | +/** |
| 2 | + * |
| 3 | + * Copyright (c) 2020 Project CHIP Authors |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#pragma once |
| 19 | + |
| 20 | +#include <app/AttributeAccessInterface.h> |
| 21 | +#include <app/ConcreteAttributePath.h> |
| 22 | +#include <app/util/config.h> |
| 23 | +#include <app/util/endpoint-config-api.h> |
| 24 | +#include <lib/support/CodeUtils.h> |
| 25 | + |
| 26 | +#include <app/util/att-storage.h> |
| 27 | +#include <app/util/attribute-metadata.h> |
| 28 | +#include <zap-generated/endpoint_config.h> |
| 29 | + |
| 30 | +#include <protocols/interaction_model/StatusCode.h> |
| 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 | +#include <app-common/zap-generated/attribute-type.h> |
| 38 | + |
| 39 | +#define DECLARE_DYNAMIC_ENDPOINT(endpointName, clusterList) \ |
| 40 | + EmberAfEndpointType endpointName = { clusterList, ArraySize(clusterList), 0 } |
| 41 | + |
| 42 | +#define DECLARE_DYNAMIC_CLUSTER_LIST_BEGIN(clusterListName) EmberAfCluster clusterListName[] = { |
| 43 | + |
| 44 | +// The role argument should be used to determine whether cluster works as a server or a client. |
| 45 | +// It can be assigned with the ZAP_CLUSTER_MASK(SERVER) or ZAP_CLUSTER_MASK(CLUSTER) values. |
| 46 | +#define DECLARE_DYNAMIC_CLUSTER(clusterId, clusterAttrs, role, incomingCommands, outgoingCommands) \ |
| 47 | + { \ |
| 48 | + clusterId, clusterAttrs, ArraySize(clusterAttrs), 0, role, NULL, incomingCommands, outgoingCommands \ |
| 49 | + } |
| 50 | + |
| 51 | +#define DECLARE_DYNAMIC_CLUSTER_LIST_END } |
| 52 | + |
| 53 | +#define DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(attrListName) EmberAfAttributeMetadata attrListName[] = { |
| 54 | + |
| 55 | +#define DECLARE_DYNAMIC_ATTRIBUTE_LIST_END() \ |
| 56 | + { \ |
| 57 | + ZAP_EMPTY_DEFAULT(), 0xFFFD, 2, ZAP_TYPE(INT16U), ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) \ |
| 58 | + } /* cluster revision */ \ |
| 59 | + } |
| 60 | + |
| 61 | +#define DECLARE_DYNAMIC_ATTRIBUTE(attId, attType, attSizeBytes, attrMask) \ |
| 62 | + { \ |
| 63 | + ZAP_EMPTY_DEFAULT(), attId, attSizeBytes, ZAP_TYPE(attType), attrMask | ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) \ |
| 64 | + } |
| 65 | + |
| 66 | +extern uint8_t attributeData[]; // main storage bucket for all attributes |
| 67 | + |
| 68 | +void emAfCallInits(); |
| 69 | + |
| 70 | +chip::Protocols::InteractionModel::Status emAfReadOrWriteAttribute(const EmberAfAttributeSearchRecord * attRecord, |
| 71 | + const EmberAfAttributeMetadata ** metadata, uint8_t * buffer, |
| 72 | + uint16_t readLength, bool write); |
| 73 | + |
| 74 | +// |
| 75 | +// Given a cluster ID, endpoint ID and a cluster mask, finds a matching cluster within that endpoint |
| 76 | +// with a matching mask. If one is found, the relative index of that cluster within the list of clusters on that |
| 77 | +// endpoint is returned. Otherwise, 0xFF is returned. |
| 78 | +// |
| 79 | +uint8_t emberAfClusterIndex(chip::EndpointId endpoint, chip::ClusterId clusterId, EmberAfClusterMask mask); |
| 80 | + |
| 81 | +// Returns the clusterId of Nth server or client cluster, |
| 82 | +// depending on server toggle. |
| 83 | +// Returns Optional<ClusterId>::Missing if cluster does not exist. |
| 84 | +chip::Optional<chip::ClusterId> emberAfGetNthClusterId(chip::EndpointId endpoint, uint8_t n, bool server); |
| 85 | + |
| 86 | +// Returns cluster within the endpoint; Does not ignore disabled endpoints |
| 87 | +const EmberAfCluster * emberAfFindClusterIncludingDisabledEndpoints(chip::EndpointId endpoint, chip::ClusterId clusterId, |
| 88 | + EmberAfClusterMask mask); |
| 89 | + |
| 90 | +// Function mask must contain one of the CLUSTER_MASK function macros, |
| 91 | +// then this method either returns the function pointer or null if |
| 92 | +// function doesn't exist. Before you call the function, you must |
| 93 | +// cast it. |
| 94 | +EmberAfGenericClusterFunction emberAfFindClusterFunction(const EmberAfCluster * cluster, EmberAfClusterMask functionMask); |
| 95 | + |
| 96 | +// After the RAM value has changed, code should call this function. If this |
| 97 | +// attribute has been tagged as non-volatile, its value will be stored. |
| 98 | +void emAfSaveAttributeToStorageIfNeeded(uint8_t * data, chip::EndpointId endpoint, chip::ClusterId clusterId, |
| 99 | + const EmberAfAttributeMetadata * metadata); |
| 100 | + |
| 101 | +// Calls the attribute changed callback |
| 102 | +void emAfClusterAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath); |
| 103 | + |
| 104 | +// Calls the attribute changed callback for a specific cluster. |
| 105 | +chip::Protocols::InteractionModel::Status |
| 106 | +emAfClusterPreAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath, EmberAfAttributeType attributeType, |
| 107 | + uint16_t size, uint8_t * value); |
| 108 | + |
| 109 | +// Register a dynamic endpoint. This involves registering descriptors that describe |
| 110 | +// the composition of the endpoint (encapsulated in the 'ep' argument) as well as providing |
| 111 | +// storage for data versions. |
| 112 | +// |
| 113 | +// dataVersionStorage.size() needs to be at least as large as the number of |
| 114 | +// server clusters on this endpoint. If it's not, the endpoint will not be able |
| 115 | +// to store data versions, which may break consumers. |
| 116 | +// |
| 117 | +// The memory backing dataVersionStorage needs to remain allocated until this dynamic |
| 118 | +// endpoint is cleared. |
| 119 | +// |
| 120 | +// An optional device type list can be passed in as well. If provided, the memory |
| 121 | +// backing the list needs to remain allocated until this dynamic endpoint is cleared. |
| 122 | +// |
| 123 | +// An optional parent endpoint id should be passed for child endpoints of composed device. |
| 124 | +// |
| 125 | +// Returns CHIP_NO_ERROR No error. |
| 126 | +// CHIP_ERROR_NO_MEMORY MAX_ENDPOINT_COUNT is reached or when no storage is left for clusters |
| 127 | +// CHIP_ERROR_INVALID_ARGUMENT The EndpointId value passed is kInvalidEndpointId |
| 128 | +// CHIP_ERROR_ENDPOINT_EXISTS If the EndpointId value passed already exists |
| 129 | +// |
| 130 | +CHIP_ERROR emberAfSetDynamicEndpoint(uint16_t index, chip::EndpointId id, const EmberAfEndpointType * ep, |
| 131 | + const chip::Span<chip::DataVersion> & dataVersionStorage, |
| 132 | + chip::Span<const EmberAfDeviceType> deviceTypeList = {}, |
| 133 | + chip::EndpointId parentEndpointId = chip::kInvalidEndpointId); |
| 134 | +chip::EndpointId emberAfClearDynamicEndpoint(uint16_t index); |
| 135 | +uint16_t emberAfGetDynamicIndexFromEndpoint(chip::EndpointId id); |
| 136 | + |
| 137 | +// Get the number of attributes of the specific cluster under the endpoint. |
| 138 | +// Returns 0 if the cluster does not exist. |
| 139 | +uint16_t emberAfGetServerAttributeCount(chip::EndpointId endpoint, chip::ClusterId cluster); |
| 140 | + |
| 141 | +// Get the index of the given attribute of the specific cluster under the endpoint. |
| 142 | +// Returns UINT16_MAX if the attribute does not exist. |
| 143 | +uint16_t emberAfGetServerAttributeIndexByAttributeId(chip::EndpointId endpoint, chip::ClusterId cluster, |
| 144 | + chip::AttributeId attributeId); |
| 145 | + |
| 146 | +// Get the attribute id at the attributeIndex of the cluster under the endpoint. This function is useful for iterating over the |
| 147 | +// attributes. |
| 148 | +// Returns Optional<chip::AttributeId>::Missing() if the attribute does not exist. |
| 149 | +chip::Optional<chip::AttributeId> emberAfGetServerAttributeIdByIndex(chip::EndpointId endpoint, chip::ClusterId cluster, |
| 150 | + uint16_t attributeIndex); |
| 151 | + |
0 commit comments