Skip to content

Commit

Permalink
implemented and tested EFSs handlers for the scene table
Browse files Browse the repository at this point in the history
  • Loading branch information
lpbeliveau-silabs authored and pull[bot] committed Oct 11, 2023
1 parent d40a0d6 commit 1d24463
Show file tree
Hide file tree
Showing 11 changed files with 690 additions and 185 deletions.
3 changes: 2 additions & 1 deletion src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ template("chip_data_model") {
"${_app_root}/clusters/identify-server/identify-server.h",
"${_app_root}/clusters/level-control/level-control.h",
"${_app_root}/clusters/on-off-server/on-off-server.h",
"${_app_root}/clusters/scenes/ExtensionFieldsSets.cpp",
"${_app_root}/clusters/scenes/ExtensionFieldsSets.h",
"${_app_root}/clusters/scenes/ExtensionFieldsSetsImpl.cpp",
"${_app_root}/clusters/scenes/ExtensionFieldsSetsImpl.h",
"${_app_root}/clusters/scenes/SceneTable.h",
"${_app_root}/clusters/scenes/SceneTableImpl.cpp",
"${_app_root}/clusters/scenes/SceneTableImpl.h",
Expand Down
94 changes: 0 additions & 94 deletions src/app/clusters/scenes/ExtensionFieldsSets.cpp

This file was deleted.

77 changes: 7 additions & 70 deletions src/app/clusters/scenes/ExtensionFieldsSets.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,85 +17,22 @@

#pragma once

#include <app/util/config.h>
#include <lib/core/CHIPError.h>
#include <lib/core/DataModelTypes.h>
#include <lib/core/TLV.h>

namespace chip {
namespace scenes {

typedef struct
{

#ifdef ZCL_USING_ON_OFF_CLUSTER_SERVER
bool onOff;
#endif

#ifdef ZCL_USING_LEVEL_CONTROL_CLUSTER_SERVER
uint8_t currentLevel;
uint16_t currentFrequency;
#endif

#ifdef ZCL_USING_MODE_SELECT_CLUSTER_SERVER
uint8_t currentMode;
#endif

#ifdef ZCL_USING_COLOR_CONTROL_CLUSTER_SERVER
uint8_t currentSaturation;
uint16_t currentX;
uint16_t currentY;
uint16_t colorTemperatureMireds;
uint16_t enhancedCurrentHue;
uint8_t enhancedColorMode;
uint8_t colorLoopActive;
uint8_t colorLoopDirection;
uint16_t colorLoopTime;
#endif

#ifdef ZCL_USING_THERMOSTAT_CLUSTER_SERVER
uint16_t occupiedCoolingSetpoint;
uint16_t occupiedHeatingSetpoint;
uint8_t systemMode;
#endif

#ifdef ZCL_USING_DOOR_LOCK_CLUSTER_SERVER
uint8_t lockState;
#endif

#ifdef ZCL_USING_WINDOW_COVERING_CLUSTER_SERVER
uint8_t currentPositionLiftPercentage;
uint8_t currentPositionTiltPercentage;
uint8_t targetPositionLiftPercent100ths;
uint8_t targetPositionTiltPercent100ths;
#endif
} FieldSets;

class ExtensionFieldsSets
{
public:
static constexpr size_t kExtensionFieldsSetsSize = sizeof(FieldSets);
static constexpr TLV::Tag TagEnabledFielsSets() { return TLV::ContextTag(1); }
FieldSets enabledFieldSets;
bool empty = false;

ExtensionFieldsSets();
~ExtensionFieldsSets(){};

CHIP_ERROR Serialize(TLV::TLVWriter & writer) const;
CHIP_ERROR Deserialize(TLV::TLVReader & reader);

void Clear();

bool operator==(const ExtensionFieldsSets & other)
{
return (!memcmp(&this->enabledFieldSets, &other.enabledFieldSets, kExtensionFieldsSetsSize));
}
ExtensionFieldsSets(){};
virtual ~ExtensionFieldsSets() = default;

void operator=(const ExtensionFieldsSets & other)
{
memcpy(&this->enabledFieldSets, &other.enabledFieldSets, kExtensionFieldsSetsSize);
}
virtual CHIP_ERROR Serialize(TLV::TLVWriter & writer) const = 0;
virtual CHIP_ERROR Deserialize(TLV::TLVReader & reader) = 0;
virtual void Clear() = 0;
virtual bool is_empty() const = 0;
};
} // namespace scenes
} // namespace chip
} // namespace chip
152 changes: 152 additions & 0 deletions src/app/clusters/scenes/ExtensionFieldsSetsImpl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://urldefense.com/v3/__http://www.apache.org/licenses/LICENSE-2.0__;!!N30Cs7Jr!UgbMbEQ59BIK-1Xslc7QXYm0lQBh92qA3ElecRe1CF_9YhXxbwPOZa6j4plru7B7kCJ7bKQgHxgQrket3-Dnk268sIdA7Qb8$
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <app/clusters/scenes/ExtensionFieldsSetsImpl.h>

namespace chip {
namespace scenes {

ExtensionFieldsSetsImpl::ExtensionFieldsSetsImpl() : ExtensionFieldsSets() {}

CHIP_ERROR ExtensionFieldsSetsImpl::Serialize(TLV::TLVWriter & writer) const
{
TLV::TLVType container;
ReturnErrorOnFailure(writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_Structure, container));
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++)
{
if (!this->EFS[i].is_empty())
{
LogErrorOnFailure(this->EFS[i].Serialize(writer));
}
}
}

return writer.EndContainer(container);
}

CHIP_ERROR ExtensionFieldsSetsImpl::Deserialize(TLV::TLVReader & reader)
{
TLV::TLVType container;
ReturnErrorOnFailure(reader.Next(TLV::kTLVType_Structure, TLV::ContextTag(1)));
ReturnErrorOnFailure(reader.EnterContainer(container));

ReturnErrorOnFailure(reader.Next(TagFieldNum()));
ReturnErrorOnFailure(reader.Get(this->fieldNum));

if (!this->is_empty())
{
for (uint8_t i = 0; i < this->fieldNum; i++)
{
ReturnErrorOnFailure(this->EFS[i].Deserialize(reader));
}
}

return reader.ExitContainer(container);
}
void ExtensionFieldsSetsImpl::Clear()
{
if (!this->is_empty())
{
for (uint8_t i = 0; i < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES; i++)
{
this->EFS[i].Clear();
}
}
this->fieldNum = 0;
}

bool ExtensionFieldsSetsImpl::is_empty() const
{
return (this->fieldNum <= 0);
}

/// @brief Inserts a field set into the array of extension field sets for a scene entry if the same ID is present in the EFS array,
/// it will overwrite it
/// @param field field set to be inserted
/// @return CHIP_NO_ERROR if insertion worked, CHIP_ERROR_BUFFER_TOO_SMALL if the array is already full
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++)
{
if (this->EFS[i].ID == field.ID)
{
idPosition = i;
break;
}

if (this->EFS[i].is_empty() && fisrtEmptyPosition == 0xFF)
{
fisrtEmptyPosition = i;
}
}

// if found, insert at found position, otherwise at first free possition, otherwise return error
if (idPosition < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES)
{
ReturnErrorOnFailure(this->EFS[idPosition] = field);
return CHIP_NO_ERROR;
}
else if (fisrtEmptyPosition < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES)
{
ReturnErrorOnFailure(this->EFS[fisrtEmptyPosition] = field);
this->fieldNum++;
return CHIP_NO_ERROR;
}
else
{
return CHIP_ERROR_BUFFER_TOO_SMALL;
}
}

CHIP_ERROR ExtensionFieldsSetsImpl::getFieldAtPosition(ExtensionFieldsSet & field, uint8_t position)
{
if (position < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES)
{
ReturnErrorOnFailure(field = this->EFS[position]);
}

return CHIP_NO_ERROR;
}

CHIP_ERROR ExtensionFieldsSetsImpl::removeFieldAtPosition(uint8_t position)
{
if (!this->is_empty())
{
if (position < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES)
{
if (!this->EFS[position].is_empty())
{
this->EFS[position].Clear();
this->fieldNum--;
}
}
else
{
return CHIP_ERROR_ACCESS_DENIED;
}
}

return CHIP_NO_ERROR;
}

} // namespace scenes

} // namespace chip
Loading

0 comments on commit 1d24463

Please sign in to comment.