Skip to content

Commit

Permalink
[Scenes] Scene Bytes Size Config (project-chip#30628)
Browse files Browse the repository at this point in the history
* Create a config to allow increasing the SceneTableImpl's scene buffer size in the event the number of clusters per scene would be increased

* Added detail about scene size calculation
  • Loading branch information
lpbeliveau-silabs authored Nov 27, 2023
1 parent d20a10a commit 514e2c9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/app/clusters/scenes-server/SceneTableImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct EndpointSceneCount : public PersistentData<kPersistentBufferSceneCountByt
// when using the OnOff, Level Control and Color Control as well as the maximal name length of 16 bytes. Putting 256 gives some
// slack in case different clusters are used. Value obtained by using writer.GetLengthWritten at the end of the SceneTableData
// Serialize method.
static constexpr size_t kPersistentSceneBufferMax = 256;
static constexpr size_t kPersistentSceneBufferMax = CHIP_CONFIG_SCENES_MAX_SERIALIZED_SCENE_SIZE_BYTES;

struct SceneTableData : public SceneTableEntry, PersistentData<kPersistentSceneBufferMax>
{
Expand Down
56 changes: 56 additions & 0 deletions src/lib/core/CHIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,62 @@ extern const char CHIP_NON_PRODUCTION_MARKER[];
#define CHIP_CONFIG_SCENES_MAX_EXTENSION_FIELDSET_SIZE_PER_CLUSTER 128
#endif

/**
* @brief The maximum number bytes taken by a scene. This needs to be increased if the number of clusters per scene is increased.
* @note The default number (256) is based on the assumption that the maximum number of clusters per scene is 3 and that those
* clusers are onOff, level control and color control cluster.
* @warning Changing this value will not only affect the RAM usage of a scene but also the size of the scene table in the flash.
* A scene's size can be calculated based on the following structure:
* Scene TLV (struct)
* {
* 2 bytes GroupID,
* 1 byte SceneID,
* 0 - 16 bytes SceneName,
* 4 bytes Transition time in miliseconds,
*
* Extension field sets TLV (array)
* [
* EFS TLV (struct)
* {
* 4 bytes for the cluster ID,
* Attribute Value List TLV (array)
* [
* AttributeValue Pair TLV (struct)
* {
* Attribute ID
* 4 bytes attributeID,
* AttributeValue
* 1 - 8 bytes AttributeValue,
* },
* .
* .
* .
*
* ],
*
* },
* .
* .
* .
* ],
* }
*
* Including all the TLV fields, the following values can help estimate the needed size for a scenes given a number of clusters:
* Empty EFS Scene Max name size: 33bytes
* Scene Max name size + OnOff : 51 bytes
* Scene Max name size + LevelControl : 60 bytes
* Scene Max name size + ColorControl : 126 bytes
* Scene Max name size + OnOff + LevelControl + ColoControl : 171 bytes
*
* Cluster Sizes:
* OnOff Cluster Max Size: 18 bytes
* LevelControl Cluster Max Size: 27 bytes
* Color Control Cluster Max Size: 93 bytes
* */
#ifndef CHIP_CONFIG_SCENES_MAX_SERIALIZED_SCENE_SIZE_BYTES
#define CHIP_CONFIG_SCENES_MAX_SERIALIZED_SCENE_SIZE_BYTES 256
#endif

/**
* @def CHIP_CONFIG_MAX_SCENES_CONCURRENT_ITERATORS
*
Expand Down

0 comments on commit 514e2c9

Please sign in to comment.