Skip to content

Commit

Permalink
Make Scenes name support dependent on FeatureMap attribute (project-c…
Browse files Browse the repository at this point in the history
…hip#18667)

* Make Scenes name support dependent on FeatureMap attribute

* Fix CI
  • Loading branch information
jepenven-silabs authored May 22, 2022
1 parent b36b8eb commit 7afd352
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 32 deletions.
3 changes: 1 addition & 2 deletions src/app/clusters/scenes/scenes-tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
// Define the actual token storage information here

DEFINE_BASIC_TOKEN(SCENES_NUM_ENTRIES, uint8_t, 0x00)
DEFINE_INDEXED_TOKEN(SCENES_TABLE, EmberAfSceneTableEntry, EMBER_AF_PLUGIN_SCENES_TABLE_SIZE,
{ EMBER_AF_SCENE_TABLE_UNUSED_ENDPOINT_ID })
DEFINE_INDEXED_TOKEN(SCENES_TABLE, EmberAfSceneTableEntry, MATTER_SCENES_TABLE_SIZE, { EMBER_AF_SCENE_TABLE_UNUSED_ENDPOINT_ID })
#endif // DEFINETOKENS

#endif // EMBER_AF_PLUGIN_SCENES_USE_TOKENS
44 changes: 22 additions & 22 deletions src/app/clusters/scenes/scenes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ using namespace chip::app::Clusters::Scenes;

uint8_t emberAfPluginScenesServerEntriesInUse = 0;
#if !defined(EMBER_AF_PLUGIN_SCENES_USE_TOKENS) || defined(EZSP_HOST)
EmberAfSceneTableEntry emberAfPluginScenesServerSceneTable[EMBER_AF_PLUGIN_SCENES_TABLE_SIZE];
EmberAfSceneTableEntry emberAfPluginScenesServerSceneTable[MATTER_SCENES_TABLE_SIZE];
#endif

static bool readServerAttribute(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId, const char * name,
Expand Down Expand Up @@ -107,7 +107,7 @@ bool isEndpointInGroup(chip::FabricIndex fabricIndex, EndpointId endpoint, Group

void emberAfScenesClusterServerInitCallback(EndpointId endpoint)
{
#ifdef EMBER_AF_PLUGIN_SCENES_NAME_SUPPORT
#if defined(MATTER_CLUSTER_SCENE_NAME_SUPPORT) && MATTER_CLUSTER_SCENE_NAME_SUPPORT
{
// The high bit of Name Support indicates whether scene names are supported.
uint8_t nameSupport = EMBER_BIT(7);
Expand All @@ -118,7 +118,7 @@ void emberAfScenesClusterServerInitCallback(EndpointId endpoint)
#if !defined(EMBER_AF_PLUGIN_SCENES_USE_TOKENS) || defined(EZSP_HOST)
{
uint8_t i;
for (i = 0; i < EMBER_AF_PLUGIN_SCENES_TABLE_SIZE; i++)
for (i = 0; i < MATTER_SCENES_TABLE_SIZE; i++)
{
EmberAfSceneTableEntry entry;
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
Expand Down Expand Up @@ -175,16 +175,16 @@ void emAfPluginScenesServerPrintInfo(void)
uint8_t i;
EmberAfSceneTableEntry entry;
emberAfCorePrintln("using 0x%x out of 0x%x table slots", emberAfPluginScenesServerNumSceneEntriesInUse(),
EMBER_AF_PLUGIN_SCENES_TABLE_SIZE);
for (i = 0; i < EMBER_AF_PLUGIN_SCENES_TABLE_SIZE; i++)
MATTER_SCENES_TABLE_SIZE);
for (i = 0; i < MATTER_SCENES_TABLE_SIZE; i++)
{
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
emberAfCorePrint("%x: ", i);
if (entry.endpoint != EMBER_AF_SCENE_TABLE_UNUSED_ENDPOINT_ID)
{
emberAfCorePrint("ep %x grp %2x scene %x tt %d", entry.endpoint, entry.groupId, entry.sceneId, entry.transitionTime);
emberAfCorePrint(".%d", entry.transitionTime100ms);
#ifdef EMBER_AF_PLUGIN_SCENES_NAME_SUPPORT
#if defined(MATTER_CLUSTER_SCENE_NAME_SUPPORT) && MATTER_CLUSTER_SCENE_NAME_SUPPORT
emberAfCorePrint(" name(%x)\"", emberAfStringLength(entry.name));
emberAfCorePrintString(entry.name);
emberAfCorePrint("\"");
Expand Down Expand Up @@ -261,7 +261,7 @@ bool emberAfScenesClusterRemoveSceneCallback(app::CommandHandler * commandObj, c
else
{
uint8_t i;
for (i = 0; i < EMBER_AF_PLUGIN_SCENES_TABLE_SIZE; i++)
for (i = 0; i < MATTER_SCENES_TABLE_SIZE; i++)
{
EmberAfSceneTableEntry entry;
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
Expand Down Expand Up @@ -316,7 +316,7 @@ bool emberAfScenesClusterRemoveAllScenesCallback(app::CommandHandler * commandOb
{
uint8_t i;
status = EMBER_ZCL_STATUS_SUCCESS;
for (i = 0; i < EMBER_AF_PLUGIN_SCENES_TABLE_SIZE; i++)
for (i = 0; i < MATTER_SCENES_TABLE_SIZE; i++)
{
EmberAfSceneTableEntry entry;
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
Expand Down Expand Up @@ -436,7 +436,7 @@ bool emberAfScenesClusterGetSceneMembershipCallback(app::CommandHandler * comman
CHIP_ERROR err = CHIP_NO_ERROR;
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
uint8_t sceneCount = 0;
uint8_t sceneList[EMBER_AF_PLUGIN_SCENES_TABLE_SIZE];
uint8_t sceneList[MATTER_SCENES_TABLE_SIZE];

emberAfScenesClusterPrintln("RX: GetSceneMembership 0x%2x", groupId);

Expand All @@ -448,7 +448,7 @@ bool emberAfScenesClusterGetSceneMembershipCallback(app::CommandHandler * comman
if (status == EMBER_ZCL_STATUS_SUCCESS)
{
uint8_t i;
for (i = 0; i < EMBER_AF_PLUGIN_SCENES_TABLE_SIZE; i++)
for (i = 0; i < MATTER_SCENES_TABLE_SIZE; i++)
{
EmberAfSceneTableEntry entry;
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
Expand All @@ -472,9 +472,9 @@ bool emberAfScenesClusterGetSceneMembershipCallback(app::CommandHandler * comman
SuccessOrExit(err = commandObj->PrepareCommand(path));
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status));
SuccessOrExit(err = writer->Put(TLV::ContextTag(1),
static_cast<uint8_t>(EMBER_AF_PLUGIN_SCENES_TABLE_SIZE -
emberAfPluginScenesServerNumSceneEntriesInUse())));
SuccessOrExit(
err = writer->Put(TLV::ContextTag(1),
static_cast<uint8_t>(MATTER_SCENES_TABLE_SIZE - emberAfPluginScenesServerNumSceneEntriesInUse())));
SuccessOrExit(err = writer->Put(TLV::ContextTag(2), groupId));
SuccessOrExit(err = writer->Put(TLV::ContextTag(3), sceneCount));
SuccessOrExit(err = writer->Put(TLV::ContextTag(4), ByteSpan(sceneList, sceneCount)));
Expand All @@ -500,7 +500,7 @@ EmberAfStatus emberAfScenesClusterStoreCurrentSceneCallback(chip::FabricIndex fa
return EMBER_ZCL_STATUS_INVALID_FIELD;
}

for (i = 0; i < EMBER_AF_PLUGIN_SCENES_TABLE_SIZE; i++)
for (i = 0; i < MATTER_SCENES_TABLE_SIZE; i++)
{
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
if (entry.endpoint == endpoint && entry.groupId == groupId && entry.sceneId == sceneId)
Expand Down Expand Up @@ -599,7 +599,7 @@ EmberAfStatus emberAfScenesClusterStoreCurrentSceneCallback(chip::FabricIndex fa
entry.endpoint = endpoint;
entry.groupId = groupId;
entry.sceneId = sceneId;
#ifdef EMBER_AF_PLUGIN_SCENES_NAME_SUPPORT
#if defined(MATTER_CLUSTER_SCENE_NAME_SUPPORT) && MATTER_CLUSTER_SCENE_NAME_SUPPORT
entry.name[0] = 0;
#endif
entry.transitionTime = 0;
Expand All @@ -624,7 +624,7 @@ EmberAfStatus emberAfScenesClusterRecallSavedSceneCallback(chip::FabricIndex fab
}

uint8_t i;
for (i = 0; i < EMBER_AF_PLUGIN_SCENES_TABLE_SIZE; i++)
for (i = 0; i < MATTER_SCENES_TABLE_SIZE; i++)
{
EmberAfSceneTableEntry entry;
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
Expand Down Expand Up @@ -772,7 +772,7 @@ bool emberAfPluginScenesServerParseAddScene(
goto kickout;
}

for (i = 0; i < EMBER_AF_PLUGIN_SCENES_TABLE_SIZE; i++)
for (i = 0; i < MATTER_SCENES_TABLE_SIZE; i++)
{
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
if (entry.endpoint == endpoint && entry.groupId == groupId && entry.sceneId == sceneId)
Expand Down Expand Up @@ -808,7 +808,7 @@ bool emberAfPluginScenesServerParseAddScene(
entry.transitionTime100ms = 0;
}

#ifdef EMBER_AF_PLUGIN_SCENES_NAME_SUPPORT
#if defined(MATTER_CLUSTER_SCENE_NAME_SUPPORT) && MATTER_CLUSTER_SCENE_NAME_SUPPORT
emberAfCopyString(entry.name, sceneName, ZCL_SCENES_CLUSTER_MAXIMUM_NAME_LENGTH);
#endif

Expand Down Expand Up @@ -1106,7 +1106,7 @@ bool emberAfPluginScenesServerParseViewScene(app::CommandHandler * commandObj, c
else
{
uint8_t i;
for (i = 0; i < EMBER_AF_PLUGIN_SCENES_TABLE_SIZE; i++)
for (i = 0; i < MATTER_SCENES_TABLE_SIZE; i++)
{
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
if (entry.endpoint == endpoint && entry.groupId == groupId && entry.sceneId == sceneId)
Expand Down Expand Up @@ -1134,7 +1134,7 @@ bool emberAfPluginScenesServerParseViewScene(app::CommandHandler * commandObj, c
SuccessOrExit(err = writer->Put(TLV::ContextTag(3),
static_cast<uint16_t>(enhanced ? entry.transitionTime * 10 + entry.transitionTime100ms
: entry.transitionTime)));
#ifdef EMBER_AF_PLUGIN_SCENES_NAME_SUPPORT
#if defined(MATTER_CLUSTER_SCENE_NAME_SUPPORT) && MATTER_CLUSTER_SCENE_NAME_SUPPORT
SuccessOrExit(err = writer->Put(TLV::ContextTag(4), entry.name));
#else
SuccessOrExit(err = writer->PutString(TLV::ContextTag(4), ""));
Expand All @@ -1150,7 +1150,7 @@ bool emberAfPluginScenesServerParseViewScene(app::CommandHandler * commandObj, c
// command and tenths of a second in the enhanced version.
emberAfPutInt16uInResp(
static_cast<uint16_t>(enhanced ? entry.transitionTime * 10 + entry.transitionTime100ms : entry.transitionTime));
#ifdef EMBER_AF_PLUGIN_SCENES_NAME_SUPPORT
#if defined(MATTER_CLUSTER_SCENE_NAME_SUPPORT) && MATTER_CLUSTER_SCENE_NAME_SUPPORT
emberAfPutStringInResp(entry.name);
#else
emberAfPutInt8uInResp(0); // name length
Expand Down Expand Up @@ -1301,7 +1301,7 @@ bool emberAfPluginScenesServerParseViewScene(app::CommandHandler * commandObj, c
void emberAfScenesClusterRemoveScenesInGroupCallback(EndpointId endpoint, GroupId groupId)
{
uint8_t i;
for (i = 0; i < EMBER_AF_PLUGIN_SCENES_TABLE_SIZE; i++)
for (i = 0; i < MATTER_SCENES_TABLE_SIZE; i++)
{
EmberAfSceneTableEntry entry;
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ typedef struct
chip::EndpointId endpoint; // 0x00 when this record is not in use
chip::GroupId groupId; // 0x0000 if not associated with a group
uint8_t sceneId;
#ifdef EMBER_AF_PLUGIN_SCENES_NAME_SUPPORT
#if defined(MATTER_CLUSTER_SCENE_NAME_SUPPORT) && MATTER_CLUSTER_SCENE_NAME_SUPPORT
uint8_t name[ZCL_SCENES_CLUSTER_MAXIMUM_NAME_LENGTH + 1];
#endif
uint16_t transitionTime; // in seconds
Expand Down
19 changes: 18 additions & 1 deletion src/app/zap-templates/templates/app/gen_config.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,24 @@
{{else if (isStrEqual name "Scenes")}}
{{#if (isServer side)}}
// User options for {{side}} plugin {{name}}
#define EMBER_AF_PLUGIN_SCENES_TABLE_SIZE 3
// Cluster spec 1.4.8.2
#ifdef CHIP_CONFIG_MAX_SCENES_PER_FABRIC
#define MATTER_SCENES_TABLE_SIZE CHIP_CONFIG_MAX_SCENES_PER_FABRIC
#else
#define MATTER_SCENES_TABLE_SIZE 16
#endif
{{/if}}
{{#all_user_cluster_generated_attributes}}
{{#if (isStrEqual ../name clusterName)}}
{{#if (isStrEqual name "FeatureMap")}}

// Scenes FeatureMap Attribute Toggle Scenes Name feature
// App cluster specs 1.4.4
#define MATTER_CLUSTER_SCENE_NAME_SUPPORT_MASK 0x0001
#define MATTER_CLUSTER_SCENE_NAME_SUPPORT ({{asHex defaultValue 4}} & MATTER_CLUSTER_SCENE_NAME_SUPPORT_MASK)
{{/if}}
{{/if}}
{{/all_user_cluster_generated_attributes}}
{{/if}}

{{/all_user_clusters}}
7 changes: 6 additions & 1 deletion zzz_generated/all-clusters-app/zap-generated/gen_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion zzz_generated/placeholder/app1/zap-generated/gen_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion zzz_generated/placeholder/app2/zap-generated/gen_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion zzz_generated/pump-app/zap-generated/gen_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion zzz_generated/thermostat/zap-generated/gen_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion zzz_generated/tv-casting-app/zap-generated/gen_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7afd352

Please sign in to comment.