Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lpbeliveau-silabs committed Oct 11, 2023
1 parent b19454e commit 22f282b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 39 deletions.
6 changes: 4 additions & 2 deletions src/app/clusters/scenes-server/SceneTableImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
#include <lib/support/CommonIterator.h>
#include <lib/support/PersistentData.h>
#include <lib/support/Pool.h>
#include <zap-generated/gen_config.h>


namespace chip {
namespace scenes {

static constexpr uint16_t kMaxScenesPerFabric = CHIP_CONFIG_SCENES_MAX_PER_FABRIC;
static constexpr uint16_t kMaxScenesPerEndpoint = CHIP_CONFIG_MAX_SCENES_PER_ENDPOINT;
static constexpr uint16_t kMaxScenesPerFabric = MATTER_SCENES_TABLE_SIZE / 2;
static constexpr uint16_t kMaxScenesPerEndpoint = MATTER_SCENES_TABLE_SIZE;

using clusterId = chip::ClusterId;

Expand Down
30 changes: 29 additions & 1 deletion src/app/tests/TestSceneTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1695,11 +1695,39 @@ void TestOTAChanges(nlTestSuite * aSuite, void * aContext)
NL_TEST_ASSERT(aSuite, CHIP_ERROR_NOT_FOUND == sceneTable->GetSceneTableEntry(kFabric1, sceneId8, scene));
NL_TEST_ASSERT(aSuite, CHIP_ERROR_NOT_FOUND == sceneTable->GetSceneTableEntry(kFabric2, sceneId8, scene));
// The Remaining capacity in the original scene table therefore have been modified as well
// Fabric 2 should still be at capacity
// Fabric 2 should still be almost at capacity
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity));
NL_TEST_ASSERT(aSuite, 3 == fabric_capacity);
uint8_t scene_table_fabric1_capacity = fabric_capacity;
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity));
uint8_t scene_table_fabric2_capacity = fabric_capacity;
NL_TEST_ASSERT(aSuite, 1 == fabric_capacity);

// Create a scene table with a greater capacity than the original one
uint8_t endpoint_added_capacity = 8;
uint8_t fabric_added_capacity = endpoint_added_capacity / 2;
TestSceneTableImpl ExpandedSceneTable(scenes::kMaxScenesPerFabric + fabric_added_capacity,
scenes::kMaxScenesPerEndpoint + endpoint_added_capacity);
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == ExpandedSceneTable.Init(&testStorage));
ExpandedSceneTable.SetEndpoint(kTestEndpoint1);

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == ExpandedSceneTable.GetRemainingCapacity(kFabric1, fabric_capacity));
NL_TEST_ASSERT(aSuite, scene_table_fabric1_capacity + fabric_added_capacity == fabric_capacity);
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == ExpandedSceneTable.GetRemainingCapacity(kFabric2, fabric_capacity));
NL_TEST_ASSERT(aSuite, scene_table_fabric2_capacity + fabric_added_capacity == fabric_capacity);

// We should be able to insert 5 scenes into fabric 2
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == ExpandedSceneTable.SetSceneTableEntry(kFabric2, scene8));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == ExpandedSceneTable.SetSceneTableEntry(kFabric2, scene9));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == ExpandedSceneTable.SetSceneTableEntry(kFabric2, scene10));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == ExpandedSceneTable.SetSceneTableEntry(kFabric2, scene11));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == ExpandedSceneTable.GetRemainingCapacity(kFabric2, fabric_capacity));
NL_TEST_ASSERT(aSuite, 1 == fabric_capacity);
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == ExpandedSceneTable.SetSceneTableEntry(kFabric2, scene12));

// Fabric 1's capacity should have remain unchanged
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == ExpandedSceneTable.GetRemainingCapacity(kFabric1, fabric_capacity));
NL_TEST_ASSERT(aSuite, scene_table_fabric2_capacity + fabric_added_capacity == fabric_capacity);
}

} // namespace TestScenes
Expand Down
1 change: 1 addition & 0 deletions src/app/util/mock/include/zap-generated/gen_config.h

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

45 changes: 23 additions & 22 deletions src/app/zap-templates/templates/app/gen_config.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,58 @@

/**** Cluster endpoint counts ****/
{{#all_user_clusters}}
#define EMBER_AF_{{asDelimitedMacro define}}_{{asDelimitedMacro side}}_ENDPOINT_COUNT ({{user_endpoint_count_by_cluster id side}})
#define EMBER_AF_{{as_delimited_macro define}}_{{as_delimited_macro side}}_ENDPOINT_COUNT ({{user_endpoint_count_by_cluster id side}})
{{/all_user_clusters}}

/**** Cluster Plugins ****/
{{#all_user_clusters}}

// Use this macro to check if the {{side}} side of the {{name}} cluster is included
#define ZCL_USING_{{asDelimitedMacro define}}_{{asDelimitedMacro side}}
#define EMBER_AF_PLUGIN_{{asDelimitedMacro name}}_{{asDelimitedMacro side}}
{{#if (isServer side)}}
#define EMBER_AF_PLUGIN_{{asDelimitedMacro name}}
#define ZCL_USING_{{as_delimited_macro define}}_{{as_delimited_macro side}}
#define EMBER_AF_PLUGIN_{{as_delimited_macro name}}_{{as_delimited_macro side}}
{{#if (is_server side)}}
#define EMBER_AF_PLUGIN_{{as_delimited_macro name}}
{{/if}}
{{#if (isStrEqual name "Color Control")}}
{{#if (isServer side)}}
{{#if (is_str_equal name "Color Control")}}
{{#if (is_server side)}}
// User options for {{side}} plugin {{name}}
#define EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_XY
#define EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP
#define EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_HSV
{{/if}}
{{else if (isStrEqual name "IAS Zone")}}
{{else if (is_str_equal name "IAS Zone")}}
// User options for {{side}} plugin {{name}}
{{#if (isServer side)}}
{{#if (is_server side)}}
#define EMBER_AF_PLUGIN_IAS_ZONE_SERVER_ZONE_TYPE 541
{{else}}
#define EMBER_AF_PLUGIN_IAS_ZONE_CLIENT_MAX_DEVICES 10
{{/if}}
{{else if (isStrEqual name "Level Control")}}
{{#if (isServer side)}}
{{else if (is_str_equal name "Level Control")}}
{{#if (is_server side)}}
// User options for {{side}} plugin {{name}}
#define EMBER_AF_PLUGIN_LEVEL_CONTROL_MAXIMUM_LEVEL 254
#define EMBER_AF_PLUGIN_LEVEL_CONTROL_MINIMUM_LEVEL 0
#define EMBER_AF_PLUGIN_LEVEL_CONTROL_RATE 0
{{/if}}
{{else if (isStrEqual name "Scenes")}}
{{#if (isServer side)}}
{{else if (is_str_equal name "Scenes")}}
{{#if (is_server side)}}
// User options for {{side}} plugin {{name}}
// 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")}}

{{#if (is_str_equal ../name clusterName)}}
{{#if (is_str_equal 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)
// Scenes FeatureMap Table Size feature used for the MATTER_SCENES_TABLE_SIZE define
// App cluster specs 1.4.4.2
#define MATTER_CLUSTER_TABLE_SIZE_SUPPORT_MASK 0x0001
#define MATTER_CLUSTER_TABLE_SIZE_SUPPORT ({{asHex defaultValue 4}} & MATTER_CLUSTER_TABLE_SIZE_SUPPORT_MASK)
{{/if}}
{{#if (is_str_equal name "SceneTableSize")}}
// Cluster spec 1.4.8.7
#define MATTER_SCENES_TABLE_SIZE {{defaultValue}}
{{/if}}
{{/if}}
{{/all_user_cluster_generated_attributes}}
Expand Down
14 changes: 0 additions & 14 deletions src/lib/core/CHIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -1403,27 +1403,13 @@ extern const char CHIP_NON_PRODUCTION_MARKER[];
#define CHIP_CONFIG_MAX_SUBSCRIPTION_RESUMPTION_STORAGE_CONCURRENT_ITERATORS 2
#endif

/**
* @brief The minimum number of scenes to support according to spec
*/
#ifndef CHIP_CONFIG_MAX_SCENES_PER_ENDPOINT
#define CHIP_CONFIG_MAX_SCENES_PER_ENDPOINT 16
#endif

/**
* @brief Maximum length of Scene names
*/
#ifndef CHIP_CONFIG_SCENES_CLUSTER_MAXIMUM_NAME_LENGTH
#define CHIP_CONFIG_SCENES_CLUSTER_MAXIMUM_NAME_LENGTH 16
#endif

/**
* @brief The maximum number of scenes allowed on a single fabric
*/
#ifndef CHIP_CONFIG_SCENES_MAX_PER_FABRIC
#define CHIP_CONFIG_SCENES_MAX_PER_FABRIC (CHIP_CONFIG_MAX_SCENES_PER_ENDPOINT / 2)
#endif

/**
* @brief The maximum number of attribute value pairs in an extension field set.
*/
Expand Down

0 comments on commit 22f282b

Please sign in to comment.