Skip to content

Commit

Permalink
Reduced the number of loads necessary when accessing scenes stored in…
Browse files Browse the repository at this point in the history
… nvm by loading an array of storage IDs when loading the fabric scene data
  • Loading branch information
lpbeliveau-silabs authored and pull[bot] committed Jun 28, 2023
1 parent b2e4ace commit 2360809
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 197 deletions.
3 changes: 3 additions & 0 deletions src/app/clusters/scenes/ExtensionFieldsSets.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
namespace chip {
namespace scenes {

static constexpr uint8_t kMaxClusterPerScenes = CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES;
static constexpr uint8_t kMaxFieldsPerCluster = CHIP_CONFIG_SCENES_MAX_EXTENSION_FIELDSET_SIZE_PER_CLUSTER;

class ExtensionFieldsSets
{
public:
Expand Down
14 changes: 7 additions & 7 deletions src/app/clusters/scenes/ExtensionFieldsSetsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ CHIP_ERROR ExtensionFieldsSetsImpl::Serialize(TLV::TLVWriter & writer) const
ReturnErrorOnFailure(writer.Put(TagFieldNum(), static_cast<uint8_t>(this->fieldNum)));
if (!this->is_empty())
{
for (uint8_t i = 0; i < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES; i++)
for (uint8_t i = 0; i < kMaxClusterPerScenes; i++)
{
if (!this->EFS[i].is_empty())
{
Expand Down Expand Up @@ -64,7 +64,7 @@ void ExtensionFieldsSetsImpl::Clear()
{
if (!this->is_empty())
{
for (uint8_t i = 0; i < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES; i++)
for (uint8_t i = 0; i < kMaxClusterPerScenes; i++)
{
this->EFS[i].Clear();
}
Expand All @@ -84,7 +84,7 @@ bool ExtensionFieldsSetsImpl::is_empty() const
CHIP_ERROR ExtensionFieldsSetsImpl::insertField(ExtensionFieldsSet & field)
{
uint8_t idPosition = 0xff, fisrtEmptyPosition = 0xff;
for (uint8_t i = 0; i < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES; i++)
for (uint8_t i = 0; i < kMaxClusterPerScenes; i++)
{
if (this->EFS[i].ID == field.ID)
{
Expand All @@ -99,12 +99,12 @@ CHIP_ERROR ExtensionFieldsSetsImpl::insertField(ExtensionFieldsSet & field)
}

// if found, insert at found position, otherwise at first free possition, otherwise return error
if (idPosition < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES)
if (idPosition < kMaxClusterPerScenes)
{
ReturnErrorOnFailure(this->EFS[idPosition] = field);
return CHIP_NO_ERROR;
}
else if (fisrtEmptyPosition < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES)
else if (fisrtEmptyPosition < kMaxClusterPerScenes)
{
ReturnErrorOnFailure(this->EFS[fisrtEmptyPosition] = field);
this->fieldNum++;
Expand All @@ -118,7 +118,7 @@ CHIP_ERROR ExtensionFieldsSetsImpl::insertField(ExtensionFieldsSet & field)

CHIP_ERROR ExtensionFieldsSetsImpl::getFieldAtPosition(ExtensionFieldsSet & field, uint8_t position)
{
if (position < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES)
if (position < kMaxClusterPerScenes)
{
ReturnErrorOnFailure(field = this->EFS[position]);
}
Expand All @@ -130,7 +130,7 @@ CHIP_ERROR ExtensionFieldsSetsImpl::removeFieldAtPosition(uint8_t position)
{
if (!this->is_empty())
{
if (position < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES)
if (position < kMaxClusterPerScenes)
{
if (!this->EFS[position].is_empty())
{
Expand Down
23 changes: 11 additions & 12 deletions src/app/clusters/scenes/ExtensionFieldsSetsImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ struct ExtensionFieldsSet
{
static constexpr TLV::Tag TagClusterId() { return TLV::ContextTag(1); }
static constexpr TLV::Tag TagEFS() { return TLV::ContextTag(2); }
clusterId ID = kInvalidClusterId;
uint8_t bytesBuffer[CHIP_CONFIG_SCENES_MAX_EXTENSION_FIELDSET_SIZE_PER_CLUSTER] = { 0 };
uint8_t usedBytes = 0;
clusterId ID = kInvalidClusterId;
uint8_t bytesBuffer[kMaxFieldsPerCluster] = { 0 };
uint8_t usedBytes = 0;

ExtensionFieldsSet() = default;
ExtensionFieldsSet(clusterId cID, uint8_t * data, uint8_t dataSize) : ID(cID), usedBytes(dataSize)
{
if (dataSize <= CHIP_CONFIG_SCENES_MAX_EXTENSION_FIELDSET_SIZE_PER_CLUSTER)
if (dataSize <= kMaxFieldsPerCluster)
{
memcpy(bytesBuffer, data, usedBytes);
}
Expand Down Expand Up @@ -65,24 +65,23 @@ struct ExtensionFieldsSet

ReturnErrorOnFailure(reader.Next(TagEFS()));
ReturnErrorOnFailure(reader.Get(buffer));
if (buffer.size() > CHIP_CONFIG_SCENES_MAX_EXTENSION_FIELDSET_SIZE_PER_CLUSTER)
if (buffer.size() > kMaxFieldsPerCluster)
{
this->usedBytes = CHIP_CONFIG_SCENES_MAX_EXTENSION_FIELDSET_SIZE_PER_CLUSTER;
this->usedBytes = kMaxFieldsPerCluster;
}
else
{
this->usedBytes = static_cast<uint8_t>(buffer.size());
}
memcpy(this->bytesBuffer, buffer.data(), this->usedBytes);
// ReturnErrorOnFailure(reader.GetBytes(bytesBuffer, CHIP_CONFIG_SCENES_MAX_EXTENSION_FIELDSET_SIZE_PER_CLUSTER));

return reader.ExitContainer(container);
}

void Clear()
{
this->ID = kInvalidClusterId;
memset(this->bytesBuffer, 0, CHIP_CONFIG_SCENES_MAX_EXTENSION_FIELDSET_SIZE_PER_CLUSTER);
memset(this->bytesBuffer, 0, kMaxFieldsPerCluster);
this->usedBytes = 0;
}

Expand All @@ -96,7 +95,7 @@ struct ExtensionFieldsSet

CHIP_ERROR operator=(const ExtensionFieldsSet & other)
{
if (other.usedBytes <= CHIP_CONFIG_SCENES_MAX_EXTENSION_FIELDSET_SIZE_PER_CLUSTER)
if (other.usedBytes <= kMaxFieldsPerCluster)
{
memcpy(this->bytesBuffer, other.bytesBuffer, other.usedBytes);
}
Expand Down Expand Up @@ -130,7 +129,7 @@ class ExtensionFieldsSetsImpl : public ExtensionFieldsSets

bool operator==(const ExtensionFieldsSetsImpl & other)
{
for (uint8_t i = 0; i < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES; i++)
for (uint8_t i = 0; i < kMaxClusterPerScenes; i++)
{
if (!(this->EFS[i] == other.EFS[i]))
{
Expand All @@ -142,7 +141,7 @@ class ExtensionFieldsSetsImpl : public ExtensionFieldsSets

CHIP_ERROR operator=(const ExtensionFieldsSetsImpl & other)
{
for (uint8_t i = 0; i < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES; i++)
for (uint8_t i = 0; i < kMaxClusterPerScenes; i++)
{
ReturnErrorOnFailure(this->EFS[i] = other.EFS[i]);
}
Expand All @@ -153,7 +152,7 @@ class ExtensionFieldsSetsImpl : public ExtensionFieldsSets

protected:
static constexpr TLV::Tag TagFieldNum() { return TLV::ContextTag(1); }
ExtensionFieldsSet EFS[CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES];
ExtensionFieldsSet EFS[kMaxClusterPerScenes];
uint8_t fieldNum = 0;
};
} // namespace scenes
Expand Down
7 changes: 4 additions & 3 deletions src/app/clusters/scenes/SceneTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ namespace scenes {
typedef uint16_t SceneTransitionTime;
typedef uint8_t TransitionTime100ms;

static constexpr uint8_t kMaxScenePerFabric = CHIP_CONFIG_SCENES_MAX_PER_FABRIC;

class SceneTable
{
public:
static constexpr size_t kIteratorsMax = CHIP_CONFIG_MAX_GROUP_CONCURRENT_ITERATORS;
static constexpr size_t kSceneNameMax = CHIP_CONFIG_SCENES_CLUSTER_MAXIMUM_NAME_LENGTH;
static constexpr uint8_t kMaxScenePerFabric = CHIP_CONFIG_SCENES_MAX_PER_FABRIC;
static constexpr size_t kIteratorsMax = CHIP_CONFIG_MAX_GROUP_CONCURRENT_ITERATORS;
static constexpr size_t kSceneNameMax = CHIP_CONFIG_SCENES_CLUSTER_MAXIMUM_NAME_LENGTH;

/// @brief struct used to identify a scene in storage by 3 ids, endpoint, group and scene
struct SceneStorageId
Expand Down
Loading

0 comments on commit 2360809

Please sign in to comment.