From b157fa5ffb9ed2361f5c7248136e3cc8ca1f8dfd Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Sep 2024 13:02:15 -0400 Subject: [PATCH] Stop hardcoding the list of signed integer attribute types. ZAP has this information. We should just use that instead of duplicating it. Fixes https://github.com/project-chip/connectedhomeip/issues/35147 --- src/app/util/attribute-metadata.h | 6 +-- .../templates/app/attribute-type.zapt | 20 +++++++++ .../app-common/zap-generated/attribute-type.h | 41 +++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/app/util/attribute-metadata.h b/src/app/util/attribute-metadata.h index 1a2b2fd04ed447..5be6916438d48a 100644 --- a/src/app/util/attribute-metadata.h +++ b/src/app/util/attribute-metadata.h @@ -166,11 +166,7 @@ struct EmberAfAttributeMetadata /** * Check wether this attribute is signed based on its type according to the spec. */ - bool IsSignedIntegerAttribute() const - { - return (attributeType >= ZCL_INT8S_ATTRIBUTE_TYPE && attributeType <= ZCL_INT64S_ATTRIBUTE_TYPE) || - attributeType == ZCL_TEMPERATURE_ATTRIBUTE_TYPE; - } + bool IsSignedIntegerAttribute() const { return chip::app::IsSignedAttributeType(attributeType); } /** * Check whether this attribute has a define min and max. diff --git a/src/app/zap-templates/templates/app/attribute-type.zapt b/src/app/zap-templates/templates/app/attribute-type.zapt index bc0e3fb7d2bee2..233cf0a1e46b2a 100644 --- a/src/app/zap-templates/templates/app/attribute-type.zapt +++ b/src/app/zap-templates/templates/app/attribute-type.zapt @@ -3,9 +3,29 @@ // Prevent multiple inclusion #pragma once +#include + // ZCL attribute types enum { {{#zcl_atomics}} {{ident}}ZCL_{{asDelimitedMacro name}}_ATTRIBUTE_TYPE = {{asHex atomicId 2}}, // {{description}} {{/zcl_atomics}} }; + +namespace chip { +namespace app { +inline bool IsSignedAttributeType(uint8_t attributeType) +{ + switch (attributeType) { + {{#zcl_atomics}} + {{#if isSigned}} + case ZCL_{{asDelimitedMacro name}}_ATTRIBUTE_TYPE: + return true; + {{/if}} + {{/zcl_atomics}} + default: + return false; + } +} +} // namespace app +} // namespace chip diff --git a/zzz_generated/app-common/app-common/zap-generated/attribute-type.h b/zzz_generated/app-common/app-common/zap-generated/attribute-type.h index 6f4c3bc90208e2..ae493673fc03f2 100644 --- a/zzz_generated/app-common/app-common/zap-generated/attribute-type.h +++ b/zzz_generated/app-common/app-common/zap-generated/attribute-type.h @@ -20,6 +20,8 @@ // Prevent multiple inclusion #pragma once +#include + // ZCL attribute types enum { @@ -99,3 +101,42 @@ enum ZCL_HWADR_ATTRIBUTE_TYPE = 0xF6, // Hardware Address ZCL_UNKNOWN_ATTRIBUTE_TYPE = 0xFF, // Unknown }; + +namespace chip { +namespace app { +inline bool IsSignedAttributeType(uint8_t attributeType) +{ + switch (attributeType) + { + case ZCL_INT8S_ATTRIBUTE_TYPE: + return true; + case ZCL_INT16S_ATTRIBUTE_TYPE: + return true; + case ZCL_INT24S_ATTRIBUTE_TYPE: + return true; + case ZCL_INT32S_ATTRIBUTE_TYPE: + return true; + case ZCL_INT40S_ATTRIBUTE_TYPE: + return true; + case ZCL_INT48S_ATTRIBUTE_TYPE: + return true; + case ZCL_INT56S_ATTRIBUTE_TYPE: + return true; + case ZCL_INT64S_ATTRIBUTE_TYPE: + return true; + case ZCL_TEMPERATURE_ATTRIBUTE_TYPE: + return true; + case ZCL_POWER_MW_ATTRIBUTE_TYPE: + return true; + case ZCL_AMPERAGE_MA_ATTRIBUTE_TYPE: + return true; + case ZCL_VOLTAGE_MV_ATTRIBUTE_TYPE: + return true; + case ZCL_ENERGY_MWH_ATTRIBUTE_TYPE: + return true; + default: + return false; + } +} +} // namespace app +} // namespace chip