From 7efced21f363bfdb77ab09635d2e785af84e4a63 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 15 Nov 2022 12:48:47 -0500 Subject: [PATCH 1/5] Move all non-codegen callbacks into a separate header file. Compilation still needs to be fixed --- src/app/util/generic-callbacks.h | 196 ++++++++++++++++++ .../zap-templates/templates/app/callback.zapt | 167 --------------- .../app-common/zap-generated/callback.h | 166 --------------- 3 files changed, 196 insertions(+), 333 deletions(-) create mode 100644 src/app/util/generic-callbacks.h diff --git a/src/app/util/generic-callbacks.h b/src/app/util/generic-callbacks.h new file mode 100644 index 00000000000000..7fbc0297e82c6e --- /dev/null +++ b/src/app/util/generic-callbacks.h @@ -0,0 +1,196 @@ +/* + * + * Copyright (c) 2022 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/** @brief Cluster Init + * + * This function is called when a specific cluster is initialized. It gives the + * application an opportunity to take care of cluster initialization procedures. + * It is called exactly once for each endpoint where cluster is present. + * + * @param endpoint Ver.: always + * @param clusterId Ver.: always + */ +void emberAfClusterInitCallback(chip::EndpointId endpoint, chip::ClusterId clusterId); + +/** @brief Allow Network Write Attribute + * + * This function is called by the application framework before it writes an + * attribute in response to a write attribute request from an external device. + * The value passed into this callback is the value to which the attribute is to + * be set by the framework. + Example: In mirroring simple metering data + * on an Energy Services Interface (ESI) (formerly called Energy Service Portal + * (ESP) in SE 1.0).), a mirrored simple meter needs to write read-only + * attributes on its mirror. The-meter-mirror sample application, located in + * app/framework/sample-apps, uses this callback to allow the mirrored device to + * write simple metering attributes on the mirror regardless of the fact that + * most simple metering attributes are defined as read-only by the ZigBee + * specification. + Note: The ZCL specification does not (as of this + * writing) specify any permission-level security for writing writeable + * attributes. As far as the ZCL specification is concerned, if an attribute is + * writeable, any device that has a link key for the device should be able to + * write that attribute. Furthermore if an attribute is read only, it should not + * be written over the air. Thus, if you implement permissions for writing + * attributes as a feature, you MAY be operating outside the specification. This + * is unlikely to be a problem for writing read-only attributes, but it may be a + * problem for attributes that are writeable according to the specification but + * restricted by the application implementing this callback. + */ +EmberAfAttributeWritePermission emberAfAllowNetworkWriteAttributeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + chip::AttributeId attributeId, uint8_t * value, + uint8_t type); + +/** @brief Attribute Read Access + * + * This function is called whenever the Application Framework needs to check + * access permission for an attribute read. + */ +bool emberAfAttributeReadAccessCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId); + +/** @brief Attribute Write Access + * + * This function is called whenever the Application Framework needs to check + * access permission for an attribute write. + */ +bool emberAfAttributeWriteAccessCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId); + +/** @brief External Attribute Read + * + * Like emberAfExternalAttributeWriteCallback above, this function is called + * when the framework needs to read an attribute that is not stored within the + * Application Framework's data structures. + All of the important + * information about the attribute itself is passed as a pointer to an + * EmberAfAttributeMetadata struct, which is stored within the application and + * used to manage the attribute. A complete description of the + * EmberAfAttributeMetadata struct is provided in + * app/framework/include/af-types.h + This function assumes that the + * application is able to read the attribute, write it into the passed buffer, + * and return immediately. Any attributes that require a state machine for + * reading and writing are not really candidates for externalization at the + * present time. The Application Framework does not currently include a state + * machine for reading or writing attributes that must take place across a + * series of application ticks. Attributes that cannot be read in a timely + * manner should be stored within the Application Framework and updated + * occasionally by the application code from within the + * emberAfMainTickCallback. + If the application was successfully able to + * read the attribute and write it into the passed buffer, it should return a + * value of EMBER_ZCL_STATUS_SUCCESS. Ensure that the size of the externally + * managed attribute value is smaller than what the buffer can hold. In the case + * of a buffer overflow throw an appropriate error such as + * EMBER_ZCL_STATUS_INSUFFICIENT_SPACE. Any other return value indicates the + * application was not able to read the attribute. + */ +EmberAfStatus emberAfExternalAttributeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, + uint16_t maxReadLength); + +/** @brief External Attribute Write + * + * This function is called whenever the Application Framework needs to write an + * attribute which is not stored within the data structures of the Application + * Framework itself. One of the new features in Version 2 is the ability to + * store attributes outside the Framework. This is particularly useful for + * attributes that do not need to be stored because they can be read off the + * hardware when they are needed, or are stored in some central location used by + * many modules within the system. In this case, you can indicate that the + * attribute is stored externally. When the framework needs to write an external + * attribute, it makes a call to this callback. + This callback is very + * useful for host micros which need to store attributes in persistent memory. + * Because each host micro (used with an Ember NCP) has its own type of + * persistent memory storage, the Application Framework does not include the + * ability to mark attributes as stored in flash the way that it does for Ember + * SoCs like the EM35x. On a host micro, any attributes that need to be stored + * in persistent memory should be marked as external and accessed through the + * external read and write callbacks. Any host code associated with the + * persistent storage should be implemented within this callback. + All of + * the important information about the attribute itself is passed as a pointer + * to an EmberAfAttributeMetadata struct, which is stored within the application + * and used to manage the attribute. A complete description of the + * EmberAfAttributeMetadata struct is provided in + * app/framework/include/af-types.h. + This function assumes that the + * application is able to write the attribute and return immediately. Any + * attributes that require a state machine for reading and writing are not + * candidates for externalization at the present time. The Application Framework + * does not currently include a state machine for reading or writing attributes + * that must take place across a series of application ticks. Attributes that + * cannot be written immediately should be stored within the Application + * Framework and updated occasionally by the application code from within the + * emberAfMainTickCallback. + If the application was successfully able to + * write the attribute, it returns a value of EMBER_ZCL_STATUS_SUCCESS. Any + * other return value indicates the application was not able to write the + * attribute. + */ +EmberAfStatus emberAfExternalAttributeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); + +/** @brief Registration Abort + * + * This callback is called when the device should abort the registration + * process. + * + */ +void emberAfRegistrationAbortCallback(); + +/** @brief Start Move + * + * This function is called to initiate the process for a device to move (rejoin) + * to a new parent. + * + */ +bool emberAfStartMoveCallback(); + +/** @brief Pre Attribute Change + * + * This function is called by the application framework before it changes an + * attribute value. The value passed into this callback is the value to which + * the attribute is to be set by the framework. The application should return + * chip::Protocols::InteractionModel::Status::Success to permit the change or + * any other code to reject it. + */ +chip::Protocols::InteractionModel::Status MatterPreAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, + uint8_t type, uint16_t size, uint8_t * value); + +/** @brief Post Attribute Change + * + * This function is called by the application framework after it changes an + * attribute value. The value passed into this callback is the value to which + * the attribute was set by the framework. + */ +void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, + uint8_t * value); diff --git a/src/app/zap-templates/templates/app/callback.zapt b/src/app/zap-templates/templates/app/callback.zapt index 0d68cb6bac9786..307214d9d12cd7 100644 --- a/src/app/zap-templates/templates/app/callback.zapt +++ b/src/app/zap-templates/templates/app/callback.zapt @@ -15,17 +15,6 @@ #include #include -/** @brief Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * @param clusterId Ver.: always - */ -void emberAfClusterInitCallback(chip::EndpointId endpoint, chip::ClusterId clusterId); - // Cluster Init Functions {{#zcl_clusters}} @@ -154,159 +143,3 @@ bool emberAf{{asUpperCamelCase parent.label}}Cluster{{asUpperCamelCase name}}Cal {{/if}} {{/zcl_commands}} {{/zcl_clusters}} - -/** @brief Allow Network Write Attribute - * - * This function is called by the application framework before it writes an - * attribute in response to a write attribute request from an external device. - * The value passed into this callback is the value to which the attribute is to - * be set by the framework. - Example: In mirroring simple metering data - * on an Energy Services Interface (ESI) (formerly called Energy Service Portal - * (ESP) in SE 1.0).), a mirrored simple meter needs to write read-only - * attributes on its mirror. The-meter-mirror sample application, located in - * app/framework/sample-apps, uses this callback to allow the mirrored device to - * write simple metering attributes on the mirror regardless of the fact that - * most simple metering attributes are defined as read-only by the ZigBee - * specification. - Note: The ZCL specification does not (as of this - * writing) specify any permission-level security for writing writeable - * attributes. As far as the ZCL specification is concerned, if an attribute is - * writeable, any device that has a link key for the device should be able to - * write that attribute. Furthermore if an attribute is read only, it should not - * be written over the air. Thus, if you implement permissions for writing - * attributes as a feature, you MAY be operating outside the specification. This - * is unlikely to be a problem for writing read-only attributes, but it may be a - * problem for attributes that are writeable according to the specification but - * restricted by the application implementing this callback. - */ -EmberAfAttributeWritePermission emberAfAllowNetworkWriteAttributeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - chip::AttributeId attributeId, - uint8_t * value, uint8_t type); - -/** @brief Attribute Read Access - * - * This function is called whenever the Application Framework needs to check - * access permission for an attribute read. - */ -bool emberAfAttributeReadAccessCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId); - -/** @brief Attribute Write Access - * - * This function is called whenever the Application Framework needs to check - * access permission for an attribute write. - */ -bool emberAfAttributeWriteAccessCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId); - -/** @brief External Attribute Read - * - * Like emberAfExternalAttributeWriteCallback above, this function is called - * when the framework needs to read an attribute that is not stored within the - * Application Framework's data structures. - All of the important - * information about the attribute itself is passed as a pointer to an - * EmberAfAttributeMetadata struct, which is stored within the application and - * used to manage the attribute. A complete description of the - * EmberAfAttributeMetadata struct is provided in - * app/framework/include/af-types.h - This function assumes that the - * application is able to read the attribute, write it into the passed buffer, - * and return immediately. Any attributes that require a state machine for - * reading and writing are not really candidates for externalization at the - * present time. The Application Framework does not currently include a state - * machine for reading or writing attributes that must take place across a - * series of application ticks. Attributes that cannot be read in a timely - * manner should be stored within the Application Framework and updated - * occasionally by the application code from within the - * emberAfMainTickCallback. - If the application was successfully able to - * read the attribute and write it into the passed buffer, it should return a - * value of EMBER_ZCL_STATUS_SUCCESS. Ensure that the size of the externally - * managed attribute value is smaller than what the buffer can hold. In the case - * of a buffer overflow throw an appropriate error such as - * EMBER_ZCL_STATUS_INSUFFICIENT_SPACE. Any other return value indicates the - * application was not able to read the attribute. - */ -EmberAfStatus emberAfExternalAttributeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, - uint8_t * buffer, uint16_t maxReadLength); - -/** @brief External Attribute Write - * - * This function is called whenever the Application Framework needs to write an - * attribute which is not stored within the data structures of the Application - * Framework itself. One of the new features in Version 2 is the ability to - * store attributes outside the Framework. This is particularly useful for - * attributes that do not need to be stored because they can be read off the - * hardware when they are needed, or are stored in some central location used by - * many modules within the system. In this case, you can indicate that the - * attribute is stored externally. When the framework needs to write an external - * attribute, it makes a call to this callback. - This callback is very - * useful for host micros which need to store attributes in persistent memory. - * Because each host micro (used with an Ember NCP) has its own type of - * persistent memory storage, the Application Framework does not include the - * ability to mark attributes as stored in flash the way that it does for Ember - * SoCs like the EM35x. On a host micro, any attributes that need to be stored - * in persistent memory should be marked as external and accessed through the - * external read and write callbacks. Any host code associated with the - * persistent storage should be implemented within this callback. - All of - * the important information about the attribute itself is passed as a pointer - * to an EmberAfAttributeMetadata struct, which is stored within the application - * and used to manage the attribute. A complete description of the - * EmberAfAttributeMetadata struct is provided in - * app/framework/include/af-types.h. - This function assumes that the - * application is able to write the attribute and return immediately. Any - * attributes that require a state machine for reading and writing are not - * candidates for externalization at the present time. The Application Framework - * does not currently include a state machine for reading or writing attributes - * that must take place across a series of application ticks. Attributes that - * cannot be written immediately should be stored within the Application - * Framework and updated occasionally by the application code from within the - * emberAfMainTickCallback. - If the application was successfully able to - * write the attribute, it returns a value of EMBER_ZCL_STATUS_SUCCESS. Any - * other return value indicates the application was not able to write the - * attribute. - */ -EmberAfStatus emberAfExternalAttributeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, - uint8_t * buffer); - -/** @brief Registration Abort - * - * This callback is called when the device should abort the registration - * process. - * - */ -void emberAfRegistrationAbortCallback(); - -/** @brief Start Move - * - * This function is called to initiate the process for a device to move (rejoin) - * to a new parent. - * - */ -bool emberAfStartMoveCallback(); - -/** @brief Pre Attribute Change - * - * This function is called by the application framework before it changes an - * attribute value. The value passed into this callback is the value to which - * the attribute is to be set by the framework. The application should return - * chip::Protocols::InteractionModel::Status::Success to permit the change or - * any other code to reject it. - */ -chip::Protocols::InteractionModel::Status MatterPreAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, - uint8_t type, uint16_t size, uint8_t * value); - -/** @brief Post Attribute Change - * - * This function is called by the application framework after it changes an - * attribute value. The value passed into this callback is the value to which - * the attribute was set by the framework. - */ -void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, - uint8_t type, uint16_t size, uint8_t * value); diff --git a/zzz_generated/app-common/app-common/zap-generated/callback.h b/zzz_generated/app-common/app-common/zap-generated/callback.h index b10f7a4a86c432..6669d106cd3da8 100644 --- a/zzz_generated/app-common/app-common/zap-generated/callback.h +++ b/zzz_generated/app-common/app-common/zap-generated/callback.h @@ -32,17 +32,6 @@ #include #include -/** @brief Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * @param clusterId Ver.: always - */ -void emberAfClusterInitCallback(chip::EndpointId endpoint, chip::ClusterId clusterId); - // Cluster Init Functions /** @brief Identify Cluster Init @@ -8925,158 +8914,3 @@ bool emberAfFaultInjectionClusterFailAtFaultCallback( bool emberAfFaultInjectionClusterFailRandomlyAtFaultCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::FaultInjection::Commands::FailRandomlyAtFault::DecodableType & commandData); - -/** @brief Allow Network Write Attribute - * - * This function is called by the application framework before it writes an - * attribute in response to a write attribute request from an external device. - * The value passed into this callback is the value to which the attribute is to - * be set by the framework. - Example: In mirroring simple metering data - * on an Energy Services Interface (ESI) (formerly called Energy Service Portal - * (ESP) in SE 1.0).), a mirrored simple meter needs to write read-only - * attributes on its mirror. The-meter-mirror sample application, located in - * app/framework/sample-apps, uses this callback to allow the mirrored device to - * write simple metering attributes on the mirror regardless of the fact that - * most simple metering attributes are defined as read-only by the ZigBee - * specification. - Note: The ZCL specification does not (as of this - * writing) specify any permission-level security for writing writeable - * attributes. As far as the ZCL specification is concerned, if an attribute is - * writeable, any device that has a link key for the device should be able to - * write that attribute. Furthermore if an attribute is read only, it should not - * be written over the air. Thus, if you implement permissions for writing - * attributes as a feature, you MAY be operating outside the specification. This - * is unlikely to be a problem for writing read-only attributes, but it may be a - * problem for attributes that are writeable according to the specification but - * restricted by the application implementing this callback. - */ -EmberAfAttributeWritePermission emberAfAllowNetworkWriteAttributeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - chip::AttributeId attributeId, uint8_t * value, - uint8_t type); - -/** @brief Attribute Read Access - * - * This function is called whenever the Application Framework needs to check - * access permission for an attribute read. - */ -bool emberAfAttributeReadAccessCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId); - -/** @brief Attribute Write Access - * - * This function is called whenever the Application Framework needs to check - * access permission for an attribute write. - */ -bool emberAfAttributeWriteAccessCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId); - -/** @brief External Attribute Read - * - * Like emberAfExternalAttributeWriteCallback above, this function is called - * when the framework needs to read an attribute that is not stored within the - * Application Framework's data structures. - All of the important - * information about the attribute itself is passed as a pointer to an - * EmberAfAttributeMetadata struct, which is stored within the application and - * used to manage the attribute. A complete description of the - * EmberAfAttributeMetadata struct is provided in - * app/framework/include/af-types.h - This function assumes that the - * application is able to read the attribute, write it into the passed buffer, - * and return immediately. Any attributes that require a state machine for - * reading and writing are not really candidates for externalization at the - * present time. The Application Framework does not currently include a state - * machine for reading or writing attributes that must take place across a - * series of application ticks. Attributes that cannot be read in a timely - * manner should be stored within the Application Framework and updated - * occasionally by the application code from within the - * emberAfMainTickCallback. - If the application was successfully able to - * read the attribute and write it into the passed buffer, it should return a - * value of EMBER_ZCL_STATUS_SUCCESS. Ensure that the size of the externally - * managed attribute value is smaller than what the buffer can hold. In the case - * of a buffer overflow throw an appropriate error such as - * EMBER_ZCL_STATUS_INSUFFICIENT_SPACE. Any other return value indicates the - * application was not able to read the attribute. - */ -EmberAfStatus emberAfExternalAttributeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, - uint16_t maxReadLength); - -/** @brief External Attribute Write - * - * This function is called whenever the Application Framework needs to write an - * attribute which is not stored within the data structures of the Application - * Framework itself. One of the new features in Version 2 is the ability to - * store attributes outside the Framework. This is particularly useful for - * attributes that do not need to be stored because they can be read off the - * hardware when they are needed, or are stored in some central location used by - * many modules within the system. In this case, you can indicate that the - * attribute is stored externally. When the framework needs to write an external - * attribute, it makes a call to this callback. - This callback is very - * useful for host micros which need to store attributes in persistent memory. - * Because each host micro (used with an Ember NCP) has its own type of - * persistent memory storage, the Application Framework does not include the - * ability to mark attributes as stored in flash the way that it does for Ember - * SoCs like the EM35x. On a host micro, any attributes that need to be stored - * in persistent memory should be marked as external and accessed through the - * external read and write callbacks. Any host code associated with the - * persistent storage should be implemented within this callback. - All of - * the important information about the attribute itself is passed as a pointer - * to an EmberAfAttributeMetadata struct, which is stored within the application - * and used to manage the attribute. A complete description of the - * EmberAfAttributeMetadata struct is provided in - * app/framework/include/af-types.h. - This function assumes that the - * application is able to write the attribute and return immediately. Any - * attributes that require a state machine for reading and writing are not - * candidates for externalization at the present time. The Application Framework - * does not currently include a state machine for reading or writing attributes - * that must take place across a series of application ticks. Attributes that - * cannot be written immediately should be stored within the Application - * Framework and updated occasionally by the application code from within the - * emberAfMainTickCallback. - If the application was successfully able to - * write the attribute, it returns a value of EMBER_ZCL_STATUS_SUCCESS. Any - * other return value indicates the application was not able to write the - * attribute. - */ -EmberAfStatus emberAfExternalAttributeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); - -/** @brief Registration Abort - * - * This callback is called when the device should abort the registration - * process. - * - */ -void emberAfRegistrationAbortCallback(); - -/** @brief Start Move - * - * This function is called to initiate the process for a device to move (rejoin) - * to a new parent. - * - */ -bool emberAfStartMoveCallback(); - -/** @brief Pre Attribute Change - * - * This function is called by the application framework before it changes an - * attribute value. The value passed into this callback is the value to which - * the attribute is to be set by the framework. The application should return - * chip::Protocols::InteractionModel::Status::Success to permit the change or - * any other code to reject it. - */ -chip::Protocols::InteractionModel::Status MatterPreAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, - uint8_t type, uint16_t size, uint8_t * value); - -/** @brief Post Attribute Change - * - * This function is called by the application framework after it changes an - * attribute value. The value passed into this callback is the value to which - * the attribute was set by the framework. - */ -void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, - uint8_t * value); From 68b8099c7b25ebbf1e23e117c1bed7d6b1a48e90 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 15 Nov 2022 12:50:56 -0500 Subject: [PATCH 2/5] Update some ember files so that at least chip-tool compiles. Only generic callbacks are required --- src/app/util/attribute-storage.cpp | 6 +++--- src/app/util/attribute-table.cpp | 4 ++-- src/app/util/util.cpp | 23 +++++++++++------------ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index 38708a52dbac0a..95d4a260815445 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -21,12 +21,12 @@ #include #include #include +#include #include #include #include #include -#include #include using namespace chip; @@ -322,8 +322,8 @@ EmberAfStatus emAfClusterPreAttributeChangedCallback(const app::ConcreteAttribut EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; // Casting and calling a function pointer on the same line results in ignoring the return // of the call on gcc-arm-none-eabi-9-2019-q4-major - EmberAfClusterPreAttributeChangedCallback f = (EmberAfClusterPreAttributeChangedCallback)( - emberAfFindClusterFunction(cluster, CLUSTER_MASK_PRE_ATTRIBUTE_CHANGED_FUNCTION)); + EmberAfClusterPreAttributeChangedCallback f = (EmberAfClusterPreAttributeChangedCallback) (emberAfFindClusterFunction( + cluster, CLUSTER_MASK_PRE_ATTRIBUTE_CHANGED_FUNCTION)); if (f != nullptr) { status = f(attributePath, attributeType, size, value); diff --git a/src/app/util/attribute-table.cpp b/src/app/util/attribute-table.cpp index 2a86c16fec77fe..9a7c34c769e47d 100644 --- a/src/app/util/attribute-table.cpp +++ b/src/app/util/attribute-table.cpp @@ -21,8 +21,8 @@ // for pulling in defines dealing with EITHER server or client #include "app/util/common.h" -#include #include +#include #include #include @@ -394,7 +394,7 @@ EmberAfStatus emAfReadAttribute(EndpointId endpoint, ClusterId cluster, Attribut record.clusterId = cluster; record.attributeId = attributeID; status = emAfReadOrWriteAttribute(&record, &metadata, dataPtr, readLength, - false); // write? + false); // write? if (status == EMBER_ZCL_STATUS_SUCCESS) { diff --git a/src/app/util/util.cpp b/src/app/util/util.cpp index c00d36bdcc4750..2ce498a074d323 100644 --- a/src/app/util/util.cpp +++ b/src/app/util/util.cpp @@ -18,13 +18,13 @@ #include "app/util/common.h" #include #include -#include #include #include #include #include #include #include +#include // TODO: figure out a clear path for compile-time codegen #include @@ -380,23 +380,23 @@ EmberStatus emberAfSendDefaultResponse(const EmberAfClusterCommand * cmd, EmberA void emberAfCopyInt16u(uint8_t * data, uint16_t index, uint16_t x) { - data[index] = (uint8_t)(((x)) & 0xFF); - data[index + 1] = (uint8_t)(((x) >> 8) & 0xFF); + data[index] = (uint8_t) (((x)) & 0xFF); + data[index + 1] = (uint8_t) (((x) >> 8) & 0xFF); } void emberAfCopyInt24u(uint8_t * data, uint16_t index, uint32_t x) { - data[index] = (uint8_t)(((x)) & 0xFF); - data[index + 1] = (uint8_t)(((x) >> 8) & 0xFF); - data[index + 2] = (uint8_t)(((x) >> 16) & 0xFF); + data[index] = (uint8_t) (((x)) & 0xFF); + data[index + 1] = (uint8_t) (((x) >> 8) & 0xFF); + data[index + 2] = (uint8_t) (((x) >> 16) & 0xFF); } void emberAfCopyInt32u(uint8_t * data, uint16_t index, uint32_t x) { - data[index] = (uint8_t)(((x)) & 0xFF); - data[index + 1] = (uint8_t)(((x) >> 8) & 0xFF); - data[index + 2] = (uint8_t)(((x) >> 16) & 0xFF); - data[index + 3] = (uint8_t)(((x) >> 24) & 0xFF); + data[index] = (uint8_t) (((x)) & 0xFF); + data[index + 1] = (uint8_t) (((x) >> 8) & 0xFF); + data[index + 2] = (uint8_t) (((x) >> 16) & 0xFF); + data[index + 3] = (uint8_t) (((x) >> 24) & 0xFF); } void emberAfCopyString(uint8_t * dest, const uint8_t * src, size_t size) @@ -621,8 +621,7 @@ void slabAssert(const char * file, int line) (void) line; // Unused parameter // Wait forever until the watchdog fires while (true) - { - } + {} } #define ENCODED_8BIT_CHANPG_PAGE_MASK 0xE0 // top 3 bits From 5b6134f246825fb8f1302af08612099b7ca9fe57 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 15 Nov 2022 13:08:35 -0500 Subject: [PATCH 3/5] Add back callbacks.h to the attribute storage header --- src/app/util/attribute-storage.cpp | 11 +++++++++-- src/app/util/generic-callbacks.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index 95d4a260815445..90a2fedc399033 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -26,8 +26,15 @@ #include #include -#include -#include +// Attribute storage depends on knowing the current layout/setup of attributes +// and corresponding callbacks. Specifically: +// - zap-generated/callback.h is needed because endpoint_config will call the +// corresponding callbacks and the include for it is: +// util/common.h +// -> util/af.h +// -> util/config.h +// -> zap-generated/endpoint_config.h +#include using namespace chip; diff --git a/src/app/util/generic-callbacks.h b/src/app/util/generic-callbacks.h index 7fbc0297e82c6e..f690732081cc44 100644 --- a/src/app/util/generic-callbacks.h +++ b/src/app/util/generic-callbacks.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include From 6506ddca4c167957b82339af394b839146bffed8 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 15 Nov 2022 13:11:04 -0500 Subject: [PATCH 4/5] Minor comment update --- src/app/util/attribute-storage.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index 90a2fedc399033..193767dac002fd 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -29,7 +29,8 @@ // Attribute storage depends on knowing the current layout/setup of attributes // and corresponding callbacks. Specifically: // - zap-generated/callback.h is needed because endpoint_config will call the -// corresponding callbacks and the include for it is: +// corresponding callbacks (via GENERATED_FUNCTION_ARRAYS) and the include +// for it is: // util/common.h // -> util/af.h // -> util/config.h From 48bf32d9cf515e3d503aa4d4de0fc379bcdd22c9 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 15 Nov 2022 13:11:17 -0500 Subject: [PATCH 5/5] Restyle --- src/app/util/attribute-storage.cpp | 4 ++-- src/app/util/attribute-table.cpp | 2 +- src/app/util/util.cpp | 21 +++++++++++---------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index 193767dac002fd..7eab17cdef45ea 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -330,8 +330,8 @@ EmberAfStatus emAfClusterPreAttributeChangedCallback(const app::ConcreteAttribut EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; // Casting and calling a function pointer on the same line results in ignoring the return // of the call on gcc-arm-none-eabi-9-2019-q4-major - EmberAfClusterPreAttributeChangedCallback f = (EmberAfClusterPreAttributeChangedCallback) (emberAfFindClusterFunction( - cluster, CLUSTER_MASK_PRE_ATTRIBUTE_CHANGED_FUNCTION)); + EmberAfClusterPreAttributeChangedCallback f = (EmberAfClusterPreAttributeChangedCallback)( + emberAfFindClusterFunction(cluster, CLUSTER_MASK_PRE_ATTRIBUTE_CHANGED_FUNCTION)); if (f != nullptr) { status = f(attributePath, attributeType, size, value); diff --git a/src/app/util/attribute-table.cpp b/src/app/util/attribute-table.cpp index 9a7c34c769e47d..8af0222348881f 100644 --- a/src/app/util/attribute-table.cpp +++ b/src/app/util/attribute-table.cpp @@ -394,7 +394,7 @@ EmberAfStatus emAfReadAttribute(EndpointId endpoint, ClusterId cluster, Attribut record.clusterId = cluster; record.attributeId = attributeID; status = emAfReadOrWriteAttribute(&record, &metadata, dataPtr, readLength, - false); // write? + false); // write? if (status == EMBER_ZCL_STATUS_SUCCESS) { diff --git a/src/app/util/util.cpp b/src/app/util/util.cpp index 2ce498a074d323..a9dcb7a735eac1 100644 --- a/src/app/util/util.cpp +++ b/src/app/util/util.cpp @@ -380,23 +380,23 @@ EmberStatus emberAfSendDefaultResponse(const EmberAfClusterCommand * cmd, EmberA void emberAfCopyInt16u(uint8_t * data, uint16_t index, uint16_t x) { - data[index] = (uint8_t) (((x)) & 0xFF); - data[index + 1] = (uint8_t) (((x) >> 8) & 0xFF); + data[index] = (uint8_t)(((x)) & 0xFF); + data[index + 1] = (uint8_t)(((x) >> 8) & 0xFF); } void emberAfCopyInt24u(uint8_t * data, uint16_t index, uint32_t x) { - data[index] = (uint8_t) (((x)) & 0xFF); - data[index + 1] = (uint8_t) (((x) >> 8) & 0xFF); - data[index + 2] = (uint8_t) (((x) >> 16) & 0xFF); + data[index] = (uint8_t)(((x)) & 0xFF); + data[index + 1] = (uint8_t)(((x) >> 8) & 0xFF); + data[index + 2] = (uint8_t)(((x) >> 16) & 0xFF); } void emberAfCopyInt32u(uint8_t * data, uint16_t index, uint32_t x) { - data[index] = (uint8_t) (((x)) & 0xFF); - data[index + 1] = (uint8_t) (((x) >> 8) & 0xFF); - data[index + 2] = (uint8_t) (((x) >> 16) & 0xFF); - data[index + 3] = (uint8_t) (((x) >> 24) & 0xFF); + data[index] = (uint8_t)(((x)) & 0xFF); + data[index + 1] = (uint8_t)(((x) >> 8) & 0xFF); + data[index + 2] = (uint8_t)(((x) >> 16) & 0xFF); + data[index + 3] = (uint8_t)(((x) >> 24) & 0xFF); } void emberAfCopyString(uint8_t * dest, const uint8_t * src, size_t size) @@ -621,7 +621,8 @@ void slabAssert(const char * file, int line) (void) line; // Unused parameter // Wait forever until the watchdog fires while (true) - {} + { + } } #define ENCODED_8BIT_CHANPG_PAGE_MASK 0xE0 // top 3 bits