Skip to content

Commit

Permalink
Update ZAP to version that generates min/max information. (#12325)
Browse files Browse the repository at this point in the history
* Update ZAP to version that generates min/max information.

The XML updates are based on examining the all-clusters app codegen
and removing spurious min-max constraints that just restate the value
range of the type (e.g. setting max to 0xFFFF for an int16u).  A few
attributes were made nullable in the process to remove an unnecessary
constraint like max="0xFFFE" when the spec says range is all but the
attribute is nullable.

* Make generatedAttributes (and generatedDefaults, minMaxDefaults) constexpr.

This should ensure that it does not accidentally end up in .data
instead of .rodata.

The main fix here is adding the constexpr constructor for
EmberAfDefaultOrMinMaxAttributeValue that takes a
EmberAfAttributeMinMaxValue*, which lets us remove the non-constexpr
reinterpret_cast (coming from the C-style cast) to uint8_t* in
ZAP_MIN_MAX_DEFAULTS_INDEX.

The other fixes are just fixing long-standing const-correctness
issues; this allows us to remove the implicit const_cast from
ZAP_LONG_DEFAULTS_INDEX.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Dec 8, 2021
1 parent 6e6c6f9 commit 1043660
Show file tree
Hide file tree
Showing 52 changed files with 1,641 additions and 634 deletions.
2 changes: 1 addition & 1 deletion examples/bridge-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void HandleDeviceStatusChanged(Device * dev, Device::Changed_t itemChangedMask)
uint8_t buffer[kFixedLabelAttributeArraySize];
EmberAfAttributeMetadata am = { .attributeId = ZCL_LABEL_LIST_ATTRIBUTE_ID,
.size = kFixedLabelAttributeArraySize,
.defaultValue = nullptr };
.defaultValue = static_cast<uint16_t>(0) };

EncodeFixedLabel("room", dev->GetLocation(), buffer, sizeof(buffer), &am);

Expand Down
2 changes: 1 addition & 1 deletion examples/bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void HandleDeviceStatusChanged(Device * dev, Device::Changed_t itemChangedMask)
uint8_t buffer[kFixedLabelAttributeArraySize];
EmberAfAttributeMetadata am = { .attributeId = ZCL_LABEL_LIST_ATTRIBUTE_ID,
.size = kFixedLabelAttributeArraySize,
.defaultValue = nullptr };
.defaultValue = static_cast<uint16_t>(0) };

EncodeFixedLabel("room", dev->GetLocation(), buffer, sizeof(buffer), &am);

Expand Down
10 changes: 5 additions & 5 deletions src/app/clusters/level-control/level-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,22 +700,22 @@ static void moveHandler(CommandId commandId, uint8_t moveMode, uint8_t rate, uin
// Otherwise, move as fast as possible
if (rate == 0xFF)
{
uint8_t defaultMoveRate;
status = Attributes::DefaultMoveRate::Get(endpoint, &defaultMoveRate);
if (status != EMBER_ZCL_STATUS_SUCCESS)
app::DataModel::Nullable<uint8_t> defaultMoveRate;
status = Attributes::DefaultMoveRate::Get(endpoint, defaultMoveRate);
if (status != EMBER_ZCL_STATUS_SUCCESS || defaultMoveRate.IsNull())
{
emberAfLevelControlClusterPrintln("ERR: reading default move rate %x", status);
state->eventDurationMs = FASTEST_TRANSITION_TIME_MS;
}
else
{
// nonsensical case, means "don't move", so we're done
if (defaultMoveRate == 0)
if (defaultMoveRate.Value() == 0)
{
status = EMBER_ZCL_STATUS_SUCCESS;
goto send_default_response;
}
state->eventDurationMs = MILLISECOND_TICKS_PER_SECOND / defaultMoveRate;
state->eventDurationMs = MILLISECOND_TICKS_PER_SECOND / defaultMoveRate.Value();
}
}
else
Expand Down
11 changes: 6 additions & 5 deletions src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ typedef void (*EmberAfGenericClusterFunction)(void);
*/
union EmberAfDefaultAttributeValue
{
constexpr EmberAfDefaultAttributeValue(uint8_t * ptr) : ptrToDefaultValue(ptr) {}
constexpr EmberAfDefaultAttributeValue(const uint8_t * ptr) : ptrToDefaultValue(ptr) {}
constexpr EmberAfDefaultAttributeValue(uint16_t val) : defaultValue(val) {}

/**
* Points to data if size is more than 2 bytes.
* If size is more than 2 bytes, and this value is NULL,
* then the default value is all zeroes.
*/
uint8_t * ptrToDefaultValue;
const uint8_t * ptrToDefaultValue;

/**
* Actual default value if the attribute size is 2 bytes or less.
Expand Down Expand Up @@ -144,15 +144,16 @@ typedef struct
*/
union EmberAfDefaultOrMinMaxAttributeValue
{
constexpr EmberAfDefaultOrMinMaxAttributeValue(uint8_t * ptr) : ptrToDefaultValue(ptr) {}
constexpr EmberAfDefaultOrMinMaxAttributeValue(const uint8_t * ptr) : ptrToDefaultValue(ptr) {}
constexpr EmberAfDefaultOrMinMaxAttributeValue(uint16_t val) : defaultValue(val) {}
constexpr EmberAfDefaultOrMinMaxAttributeValue(const EmberAfAttributeMinMaxValue * ptr) : ptrToMinMaxValue(ptr) {}

/**
* Points to data if size is more than 2 bytes.
* If size is more than 2 bytes, and this value is NULL,
* then the default value is all zeroes.
*/
uint8_t * ptrToDefaultValue;
const uint8_t * ptrToDefaultValue;
/**
* Actual default value if the attribute size is 2 bytes or less.
*/
Expand All @@ -161,7 +162,7 @@ union EmberAfDefaultOrMinMaxAttributeValue
* Points to the min max attribute value structure, if min/max is
* supported for this attribute.
*/
EmberAfAttributeMinMaxValue * ptrToMinMaxValue;
const EmberAfAttributeMinMaxValue * ptrToMinMaxValue;
};

// Attribute masks modify how attributes are used by the framework
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ uint8_t emberAfGetLastSequenceNumber(void);
* greater than 4 is being compared
* 1, if val2 is smaller.
*/
int8_t emberAfCompareValues(uint8_t * val1, uint8_t * val2, uint16_t len, bool signedNumber);
int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t len, bool signedNumber);

/**
* @brief populates the passed EUI64 with the local EUI64 MAC address.
Expand Down
21 changes: 11 additions & 10 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ EmberAfDefinedEndpoint emAfEndpoints[MAX_ENDPOINT_COUNT];

uint8_t attributeData[ACTUAL_ATTRIBUTE_SIZE];

namespace {

#if (!defined(ATTRIBUTE_SINGLETONS_SIZE)) || (ATTRIBUTE_SINGLETONS_SIZE == 0)
#define ACTUAL_SINGLETONS_SIZE 1
#else
Expand All @@ -80,25 +82,25 @@ uint16_t emberEndpointCount = 0;
// If we have attributes that are more than 2 bytes, then
// we need this data block for the defaults
#if (defined(GENERATED_DEFAULTS) && GENERATED_DEFAULTS_COUNT)
const uint8_t generatedDefaults[] = GENERATED_DEFAULTS;
constexpr const uint8_t generatedDefaults[] = GENERATED_DEFAULTS;
#endif // GENERATED_DEFAULTS

#if (defined(GENERATED_MIN_MAX_DEFAULTS) && GENERATED_MIN_MAX_DEFAULT_COUNT)
const EmberAfAttributeMinMaxValue minMaxDefaults[] = GENERATED_MIN_MAX_DEFAULTS;
constexpr const EmberAfAttributeMinMaxValue minMaxDefaults[] = GENERATED_MIN_MAX_DEFAULTS;
#endif // GENERATED_MIN_MAX_DEFAULTS

#ifdef GENERATED_FUNCTION_ARRAYS
GENERATED_FUNCTION_ARRAYS
#endif

const EmberAfAttributeMetadata generatedAttributes[] = GENERATED_ATTRIBUTES;
const EmberAfCluster generatedClusters[] = GENERATED_CLUSTERS;
const EmberAfEndpointType generatedEmberAfEndpointTypes[] = GENERATED_ENDPOINT_TYPES;
constexpr const EmberAfAttributeMetadata generatedAttributes[] = GENERATED_ATTRIBUTES;
constexpr const EmberAfCluster generatedClusters[] = GENERATED_CLUSTERS;
constexpr const EmberAfEndpointType generatedEmberAfEndpointTypes[] = GENERATED_ENDPOINT_TYPES;

const EmberAfManufacturerCodeEntry clusterManufacturerCodes[] = GENERATED_CLUSTER_MANUFACTURER_CODES;
const uint16_t clusterManufacturerCodeCount = GENERATED_CLUSTER_MANUFACTURER_CODE_COUNT;
const EmberAfManufacturerCodeEntry attributeManufacturerCodes[] = GENERATED_ATTRIBUTE_MANUFACTURER_CODES;
const uint16_t attributeManufacturerCodeCount = GENERATED_ATTRIBUTE_MANUFACTURER_CODE_COUNT;
constexpr const EmberAfManufacturerCodeEntry clusterManufacturerCodes[] = GENERATED_CLUSTER_MANUFACTURER_CODES;
constexpr const uint16_t clusterManufacturerCodeCount = GENERATED_CLUSTER_MANUFACTURER_CODE_COUNT;
constexpr const EmberAfManufacturerCodeEntry attributeManufacturerCodes[] = GENERATED_ATTRIBUTE_MANUFACTURER_CODES;
constexpr const uint16_t attributeManufacturerCodeCount = GENERATED_ATTRIBUTE_MANUFACTURER_CODE_COUNT;

#if !defined(EMBER_SCRIPTED_TEST)
#define endpointNumber(x) fixedEndpoints[x]
Expand All @@ -109,7 +111,6 @@ const uint16_t attributeManufacturerCodeCount = GENERATED_ATTR
#define endpointNetworkIndex(x) fixedNetworks[x]
#endif

namespace {
app::AttributeAccessInterface * gAttributeAccessOverrides = nullptr;
} // anonymous namespace

Expand Down
2 changes: 1 addition & 1 deletion src/app/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ void emberAfCopyLongString(uint8_t * dest, const uint8_t * src, size_t size)
// You can pass in val1 as NULL, which will assume that it is
// pointing to an array of all zeroes. This is used so that
// default value of NULL is treated as all zeroes.
int8_t emberAfCompareValues(uint8_t * val1, uint8_t * val2, uint16_t len, bool signedNumber)
int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t len, bool signedNumber)
{
uint8_t i, j, k;
if (signedNumber)
Expand Down
4 changes: 2 additions & 2 deletions src/app/zap-templates/templates/app/endpoint_config.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#define GENERATED_DEFAULTS_COUNT ({{endpoint_attribute_long_defaults_count}})

#define ZAP_TYPE(type) ZCL_ ## type ## _ATTRIBUTE_TYPE
#define ZAP_LONG_DEFAULTS_INDEX(index) {(uint8_t*)(&generatedDefaults[index])}
#define ZAP_MIN_MAX_DEFAULTS_INDEX(index) {(uint8_t*)(&minMaxDefault[index])}
#define ZAP_LONG_DEFAULTS_INDEX(index) { &generatedDefaults[index] }
#define ZAP_MIN_MAX_DEFAULTS_INDEX(index) { &minMaxDefaults[index] }
#define ZAP_EMPTY_DEFAULT() {(uint16_t) 0}
#define ZAP_SIMPLE_DEFAULT(x) {(uint16_t) x}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ limitations under the License.
<code>0x0030</code>
<define>GENERAL_COMMISSIONING_CLUSTER</define>
<description>This cluster is used to set, remove and update fabric information on a commissionee.</description>
<attribute side="server" code="0x00" define="BREADCRUMB" type="INT64U" min="0x0000000000000000" max="0xFFFFFFFFFFFFFFFF" writable="true" default="0x0000000000000000" optional="false">Breadcrumb</attribute>
<attribute side="server" code="0x00" define="BREADCRUMB" type="INT64U" writable="true" default="0x0000000000000000" optional="false">Breadcrumb</attribute>
<attribute side="server" code="0x01" define="BASICCOMMISSIONINGINFO_LIST" type="ARRAY" entryType="BasicCommissioningInfoType" length="254" writable="false" optional="false">BasicCommissioningInfoList</attribute>
<attribute side="server" code="0x02" define="REGULATORYCONFIG" type="ENUM8" writable="false" optional="true">RegulatoryConfig</attribute>
<attribute side="server" code="0x03" define="LOCATIONCAPABILITY" type="ENUM8" writable="false" optional="true">LocationCapability</attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ limitations under the License.
<attribute side="server" code="0x0012" define="EFFECTIVE_CONTROL_MODE" type="ENUM8" min="0x00" max="0xFE" writable="false" optional="false">EffectiveControlMode</attribute>
<attribute side="server" code="0x0013" define="CAPACITY" type="INT16S" min="0x0000" max="0x7FFF" writable="false" reportable="true" optional="false">Capacity</attribute>
<attribute side="server" code="0x0014" define="SPEED" type="INT16U" min="0x0000" max="0xFFFE" writable="false" optional="true">Speed</attribute>
<attribute side="server" code="0x0015" define="LIFETIME_RUNNING_HOURS" type="INT24U" min="0x000000" max="0xFFFFFE" writable="true" default="0x000000" optional="true">LifetimeRunningHours</attribute>
<attribute side="server" code="0x0016" define="PUMP_POWER" type="INT24U" min="0x000000" max="0xFFFFFE" writable="true" optional="true">Power</attribute>
<attribute side="server" code="0x0017" define="LIFETIME_ENERGY_CONSUMED" type="INT32U" min="0x00000000" max="0xFFFFFFFE" writable="false" default="0x00000000" optional="true">LifetimeEnergyConsumed</attribute>
<attribute side="server" code="0x0015" define="LIFETIME_RUNNING_HOURS" type="INT24U" isNullable="true" writable="true" default="0x000000" optional="true">LifetimeRunningHours</attribute>
<attribute side="server" code="0x0016" define="PUMP_POWER" type="INT24U" min="0x000000" max="0xFFFFFE" writable="false" optional="true">Power</attribute>
<attribute side="server" code="0x0017" define="LIFETIME_ENERGY_CONSUMED" type="INT32U" isNullable="true" writable="true" default="0x00000000" optional="true">LifetimeEnergyConsumed</attribute>
<attribute side="server" code="0x0020" define="OPERATION_MODE" type="ENUM8" min="0x00" max="0xFE" writable="true" default="0x00" optional="false">OperationMode</attribute>
<attribute side="server" code="0x0021" define="CONTROL_MODE" type="ENUM8" min="0x00" max="0xFE" writable="true" default="0x00" optional="true">ControlMode</attribute>
<attribute side="server" code="0x0022" define="PUMP_ALARM_MASK" type="BITMAP16" writable="false" optional="true">AlarmMask</attribute>
Expand Down
12 changes: 6 additions & 6 deletions src/app/zap-templates/zcl/data-model/silabs/general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,13 @@ limitations under the License.
<attribute side="server" code="0x0005" define="MIN_FREQUENCY" type="INT16U" min="0x0000" max="0xFFFF" writable="false" default="0x0000" optional="true">min frequency</attribute>
<attribute side="server" code="0x0006" define="MAX_FREQUENCY" type="INT16U" min="0x0000" max="0xFFFF" writable="false" default="0x0000" optional="true">max frequency</attribute>

<attribute side="server" code="0x0010" define="ON_OFF_TRANSITION_TIME" type="INT16U" min="0x0000" max="0xFFFF" writable="true" default="0x0000" optional="true">on off transition time</attribute>
<attribute side="server" code="0x0011" define="ON_LEVEL" type="INT8U" min="0x00" max="0xFF" writable="true" default="0xFE" optional="true">on level</attribute>
<attribute side="server" code="0x0012" define="ON_TRANSITION_TIME" type="INT16U" min="0x0000" max="0xFFFE" writable="true" optional="true" introducedIn="ha-1.2-05-3520-29">on transition time</attribute>
<attribute side="server" code="0x0013" define="OFF_TRANSITION_TIME" type="INT16U" min="0x0000" max="0xFFFE" writable="true" optional="true" introducedIn="ha-1.2-05-3520-29">off transition time</attribute>
<attribute side="server" code="0x0014" define="DEFAULT_MOVE_RATE" type="INT8U" min="0x00" max="0xFE" writable="true" optional="true" introducedIn="ha-1.2-05-3520-29">default move rate</attribute>
<attribute side="server" code="0x0010" define="ON_OFF_TRANSITION_TIME" type="INT16U" writable="true" default="0x0000" optional="true">on off transition time</attribute>
<attribute side="server" code="0x0011" define="ON_LEVEL" type="INT8U" isNullable="true" writable="true" default="0xFE" optional="true">on level</attribute>
<attribute side="server" code="0x0012" define="ON_TRANSITION_TIME" type="INT16U" isNullable="true" writable="true" optional="true" introducedIn="ha-1.2-05-3520-29">on transition time</attribute>
<attribute side="server" code="0x0013" define="OFF_TRANSITION_TIME" type="INT16U" isNullable="true" writable="true" optional="true" introducedIn="ha-1.2-05-3520-29">off transition time</attribute>
<attribute side="server" code="0x0014" define="DEFAULT_MOVE_RATE" type="INT8U" isNullable="true" writable="true" optional="true" introducedIn="ha-1.2-05-3520-29">default move rate</attribute>
<attribute side="server" code="0x000F" define="OPTIONS" type="BITMAP8" min="0x00" max="0x03" writable="true" default="0x00" optional="true" introducedIn="l&amp;o-1.0-15-0014-04">options</attribute>
<attribute side="server" code="0x4000" define="START_UP_CURRENT_LEVEL" type="INT8U" min="0x01" max="0xFF" writable="true" optional="true" introducedIn="l&amp;o-1.0-15-0014-04">start up current level</attribute>
<attribute side="server" code="0x4000" define="START_UP_CURRENT_LEVEL" type="INT8U" writable="true" optional="true" introducedIn="l&amp;o-1.0-15-0014-04">start up current level</attribute>
<command source="client" code="0x00" name="MoveToLevel" optional="false" cli="zcl level-control mv-to-level">
<description>
Command description for MoveToLevel
Expand Down
10 changes: 5 additions & 5 deletions src/app/zap-templates/zcl/data-model/silabs/ha.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ limitations under the License.
<!-- COLOR_TEMPERATURE -->
<attribute side="server" code="0x0008" define="COLOR_CONTROL_COLOR_MODE" type="ENUM8" min="0x00" max="0x02" writable="false" default="0x01" optional="true">color mode</attribute>
<!-- COLOR_MODE -->
<attribute side="server" code="0x000F" define="COLOR_CONTROL_OPTIONS" type="BITMAP8" min="0x00" max="0xFF" writable="true" default="0x00" optional="false" introducedIn="zcl-6.0-15-02017-001">color control options</attribute>
<attribute side="server" code="0x000F" define="COLOR_CONTROL_OPTIONS" type="BITMAP8" writable="true" default="0x00" optional="false" introducedIn="zcl-6.0-15-02017-001">color control options</attribute>
<!-- COLOR_CONTROL_OPTIONS -->
<attribute side="server" code="0x0010" define="COLOR_CONTROL_NUMBER_OF_PRIMARIES" type="INT8U" min="0x00" max="0x06" writable="false" optional="true">number of primaries</attribute>
<!-- NUMBER_OF_PRIMARIES -->
Expand Down Expand Up @@ -270,22 +270,22 @@ limitations under the License.
<!-- COLOR_POINT_R_X -->
<attribute side="server" code="0x0033" define="COLOR_CONTROL_COLOR_POINT_R_Y" type="INT16U" min="0x0000" max="0xFEFF" writable="true" optional="true">color point r y</attribute>
<!-- COLOR_POINT_R_Y -->
<attribute side="server" code="0x0034" define="COLOR_CONTROL_COLOR_POINT_R_INTENSITY" type="INT8U" min="0x00" max="0xFF" writable="true" optional="true">color point r intensity</attribute>
<attribute side="server" code="0x0034" define="COLOR_CONTROL_COLOR_POINT_R_INTENSITY" type="INT8U" writable="true" optional="true">color point r intensity</attribute>
<!-- COLOR_POINT_R_INTENSITY -->
<attribute side="server" code="0x0036" define="COLOR_CONTROL_COLOR_POINT_G_X" type="INT16U" min="0x0000" max="0xFEFF" writable="true" optional="true">color point g x</attribute>
<!-- COLOR_POINT_G_X -->
<attribute side="server" code="0x0037" define="COLOR_CONTROL_COLOR_POINT_G_Y" type="INT16U" min="0x0000" max="0xFEFF" writable="true" optional="true">color point g y</attribute>
<!-- COLOR_POINT_G_Y -->
<attribute side="server" code="0x0038" define="COLOR_CONTROL_COLOR_POINT_G_INTENSITY" type="INT8U" min="0x00" max="0xFF" writable="true" optional="true">color point g intensity</attribute>
<attribute side="server" code="0x0038" define="COLOR_CONTROL_COLOR_POINT_G_INTENSITY" type="INT8U" writable="true" optional="true">color point g intensity</attribute>
<!-- COLOR_POINT_G_INTENSITY -->
<attribute side="server" code="0x003A" define="COLOR_CONTROL_COLOR_POINT_B_X" type="INT16U" min="0x0000" max="0xFEFF" writable="true" optional="true">color point b x</attribute>
<!-- COLOR_POINT_B_X -->
<attribute side="server" code="0x003B" define="COLOR_CONTROL_COLOR_POINT_B_Y" type="INT16U" min="0x0000" max="0xFEFF" writable="true" optional="true">color point b y</attribute>
<!-- COLOR_POINT_B_Y -->
<attribute side="server" code="0x003C" define="COLOR_CONTROL_COLOR_POINT_B_INTENSITY" type="INT8U" min="0x00" max="0xFF" writable="true" optional="true">color point b intensity</attribute>
<attribute side="server" code="0x003C" define="COLOR_CONTROL_COLOR_POINT_B_INTENSITY" type="INT8U" writable="true" optional="true">color point b intensity</attribute>
<!-- COLOR_POINT_B_INTENSITY -->
<attribute side="server" code="0x400D" define="COLOR_CONTROL_TEMPERATURE_LEVEL_MIN_MIREDS" type="INT16U" min="0x0000" max="0xFFFF" writable="false" optional="false" introducedIn="l&amp;o-1.0-15-0014-04">couple color temp to level min-mireds</attribute>
<attribute side="server" code="0x4010" define="START_UP_COLOR_TEMPERATURE_MIREDS" type="INT16U" min="0x0000" max="0xFFFF" writable="true" optional="false" introducedIn="l&amp;o-1.0-15-0014-04">start up color temperature mireds</attribute>
<attribute side="server" code="0x4010" define="START_UP_COLOR_TEMPERATURE_MIREDS" type="INT16U" min="0x0000" max="0xFEFF" writable="true" optional="false" introducedIn="l&amp;o-1.0-15-0014-04">start up color temperature mireds</attribute>
<command source="client" code="0x00" name="MoveToHue" optional="true" cli="zcl color-control movetohue">
<description>
Move to specified hue.
Expand Down
Loading

0 comments on commit 1043660

Please sign in to comment.