From 21a2fee847db856d486a9bc7b4e8bf2dc105b4b1 Mon Sep 17 00:00:00 2001 From: Evgeni Margolis Date: Mon, 30 Jan 2023 10:51:40 -0800 Subject: [PATCH 01/17] Global Event List Support: All Manually Updated Files --- src/app/GlobalAttributes.h | 3 ++- src/app/util/af-types.h | 11 ++++++++++ src/app/util/attribute-storage.cpp | 6 +++++- .../util/ember-compatibility-functions.cpp | 18 +++++++++++------ .../templates/app/endpoint_config.zapt | 7 +++++++ .../zcl/data-model/chip/global-attributes.xml | 6 +++--- src/controller/tests/TestEventChunking.cpp | 8 ++++++-- src/controller/tests/TestReadChunking.cpp | 20 +++++++++++-------- 8 files changed, 58 insertions(+), 21 deletions(-) diff --git a/src/app/GlobalAttributes.h b/src/app/GlobalAttributes.h index 82980a798d2072..8f35d2e93e9ee1 100644 --- a/src/app/GlobalAttributes.h +++ b/src/app/GlobalAttributes.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Project CHIP Authors + * Copyright (c) 2022-2023 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,6 +31,7 @@ namespace app { constexpr AttributeId GlobalAttributesNotInMetadata[] = { Clusters::Globals::Attributes::GeneratedCommandList::Id, Clusters::Globals::Attributes::AcceptedCommandList::Id, + Clusters::Globals::Attributes::EventList::Id, Clusters::Globals::Attributes::AttributeList::Id, }; diff --git a/src/app/util/af-types.h b/src/app/util/af-types.h index 74a7dd426dd611..d284d93961dd0d 100644 --- a/src/app/util/af-types.h +++ b/src/app/util/af-types.h @@ -108,6 +108,17 @@ typedef struct * is a response to client command request. Can be nullptr or terminated by 0xFFFF_FFFF. */ const chip::CommandId * generatedCommandList; + + /** + * Pointer to an array of event IDs of the events supported by the cluster instance. + * Can be nullptr. + */ + const chip::EventId * eventList; + + /** + * Total number of events supported by the cluster instance (in eventList array). + */ + uint16_t eventCount; } EmberAfCluster; /** diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index 3c9fac5a09a5b6..5ef8420025026b 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -1,6 +1,6 @@ /** * - * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2020-2023 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -82,6 +82,10 @@ GENERATED_FUNCTION_ARRAYS constexpr const chip::CommandId generatedCommands[] = GENERATED_COMMANDS; #endif // GENERATED_COMMANDS +#ifdef GENERATED_EVENTS +constexpr const chip::EventId generatedEvents[] = GENERATED_EVENTS; +#endif // GENERATED_EVENTS + constexpr const EmberAfAttributeMetadata generatedAttributes[] = GENERATED_ATTRIBUTES; constexpr const EmberAfCluster generatedClusters[] = GENERATED_CLUSTERS; constexpr const EmberAfEndpointType generatedEmberAfEndpointTypes[] = GENERATED_ENDPOINT_TYPES; diff --git a/src/app/util/ember-compatibility-functions.cpp b/src/app/util/ember-compatibility-functions.cpp index b4852caa022429..35a4662ef99003 100644 --- a/src/app/util/ember-compatibility-functions.cpp +++ b/src/app/util/ember-compatibility-functions.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021-2023 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -383,11 +383,8 @@ CHIP_ERROR GlobalAttributeReader::Read(const ConcreteReadAttributePath & aPath, AttributeId id = mCluster->attributes[i].attributeId; constexpr auto lastGlobalId = GlobalAttributesNotInMetadata[ArraySize(GlobalAttributesNotInMetadata) - 1]; // We are relying on GlobalAttributesNotInMetadata not having - // any gaps in their ids here, but for now they do because we - // have no EventList support. So this assert is not quite - // right. There should be a "- 1" on the right-hand side of the - // equals sign. - static_assert(lastGlobalId - GlobalAttributesNotInMetadata[0] == ArraySize(GlobalAttributesNotInMetadata), + // any gaps in their ids here. + static_assert(lastGlobalId - GlobalAttributesNotInMetadata[0] == ArraySize(GlobalAttributesNotInMetadata) - 1, "Ids in GlobalAttributesNotInMetadata not consecutive (except EventList)"); if (!addedExtraGlobals && id > lastGlobalId) { @@ -408,6 +405,15 @@ CHIP_ERROR GlobalAttributeReader::Read(const ConcreteReadAttributePath & aPath, } return CHIP_NO_ERROR; }); + case EventList::Id: + return aEncoder.EncodeList([this](const auto & encoder) { + for (size_t i = 0; i < mCluster->eventCount; ++i) + { + ReturnErrorOnFailure(encoder.Encode(mCluster->eventList[i])); + } + return CHIP_NO_ERROR; + }); + return CHIP_NO_ERROR; case AcceptedCommandList::Id: return EncodeCommandList(aPath, aEncoder, &CommandHandlerInterface::EnumerateAcceptedCommands, mCluster->acceptedCommandList); diff --git a/src/app/zap-templates/templates/app/endpoint_config.zapt b/src/app/zap-templates/templates/app/endpoint_config.zapt index 3f8938766fcba2..92574b71fa912e 100644 --- a/src/app/zap-templates/templates/app/endpoint_config.zapt +++ b/src/app/zap-templates/templates/app/endpoint_config.zapt @@ -39,6 +39,13 @@ #define ZAP_GENERATED_COMMANDS_INDEX(index) (&generatedCommands[index]) +// clang-format off +#define GENERATED_EVENT_COUNT {{ chip_endpoint_generated_event_count }} +#define GENERATED_EVENTS {{ chip_endpoint_generated_event_list }} +// clang-format on + +#define ZAP_GENERATED_EVENTS_INDEX(index) (&generatedEvents[index]) + // Cluster function static arrays #define GENERATED_FUNCTION_ARRAYS {{chip_endpoint_generated_functions}} diff --git a/src/app/zap-templates/zcl/data-model/chip/global-attributes.xml b/src/app/zap-templates/zcl/data-model/chip/global-attributes.xml index 9705e4bdb235bb..4b473a8ea26037 100644 --- a/src/app/zap-templates/zcl/data-model/chip/global-attributes.xml +++ b/src/app/zap-templates/zcl/data-model/chip/global-attributes.xml @@ -1,6 +1,6 @@