Reading 8- or 16-bit attributes from big-endian device returns 0 (#6166) #6685
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When reading an 8- or 16-bit attribute from a big endian device the value is 0, despite that defaults other than 0 are defined.
The defaults of these attributes are defined in a zap-file and from that a header file is generated (endpoint_config.h).
This header file contains structures that are used by the software to read cluster information and the attributes of these clusters.
The value of these attributes are stored in a union that also contains 2 pointers:
typedef union { uint8_t * ptrToDefaultValue; uint16_t defaultValue; EmberAfAttributeMinMaxValue * ptrToMinMaxValue; } EmberAfDefaultOrMinMaxAttributeValue;
A generated default value is compiled into that union using an explicit type cast to a pointer.
Example:
{ (uint8_t *) 3 } }
In a 32-bit little-endian the memory layout will be:
03 00 00 00
The 16-bit defaultValue (the first 2 bytes) will have the value 3, which is correct.
In a 32-bit big-endian system the layout will be:
00 00 00 03
The 16-bit defaultValue (the first 2 bytes) will have the value 0, which is not correct.
Summary of Changes
Redefinitions of the unions and update of the zap file.
Fixes #6166