Skip to content

Commit 34cd75f

Browse files
bzbarsky-appleshgutte
authored andcommitted
Stop hardcoding the list of signed integer attribute types. (project-chip#35412)
ZAP has this information. We should just use that instead of duplicating it. Fixes project-chip#35147
1 parent c27d380 commit 34cd75f

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

src/app/util/attribute-metadata.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,7 @@ struct EmberAfAttributeMetadata
166166
/**
167167
* Check wether this attribute is signed based on its type according to the spec.
168168
*/
169-
bool IsSignedIntegerAttribute() const
170-
{
171-
return (attributeType >= ZCL_INT8S_ATTRIBUTE_TYPE && attributeType <= ZCL_INT64S_ATTRIBUTE_TYPE) ||
172-
attributeType == ZCL_TEMPERATURE_ATTRIBUTE_TYPE;
173-
}
169+
bool IsSignedIntegerAttribute() const { return chip::app::IsSignedAttributeType(attributeType); }
174170

175171
/**
176172
* Check whether this attribute has a define min and max.

src/app/zap-templates/templates/app/attribute-type.zapt

+20
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,29 @@
33
// Prevent multiple inclusion
44
#pragma once
55

6+
#include <cstdint>
7+
68
// ZCL attribute types
79
enum {
810
{{#zcl_atomics}}
911
{{ident}}ZCL_{{asDelimitedMacro name}}_ATTRIBUTE_TYPE = {{asHex atomicId 2}}, // {{description}}
1012
{{/zcl_atomics}}
1113
};
14+
15+
namespace chip {
16+
namespace app {
17+
inline bool IsSignedAttributeType(uint8_t attributeType)
18+
{
19+
switch (attributeType) {
20+
{{#zcl_atomics}}
21+
{{#if isSigned}}
22+
case ZCL_{{asDelimitedMacro name}}_ATTRIBUTE_TYPE:
23+
return true;
24+
{{/if}}
25+
{{/zcl_atomics}}
26+
default:
27+
return false;
28+
}
29+
}
30+
} // namespace app
31+
} // namespace chip

zzz_generated/app-common/app-common/zap-generated/attribute-type.h

+41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)