Skip to content

Commit

Permalink
Implementation of persistant storage of scene table along with test.
Browse files Browse the repository at this point in the history
  • Loading branch information
lpbeliveau-silabs authored and pull[bot] committed Jan 8, 2024
1 parent 573ec19 commit 33569c9
Show file tree
Hide file tree
Showing 11 changed files with 1,248 additions and 2 deletions.
11 changes: 10 additions & 1 deletion scripts/examples/gn_efr32_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ else
shift
while [ $# -gt 0 ]; do
case $1 in
--clean)
DIR_CLEAN=true
shift
;;
--wifi)
if [ -z "$2" ]; then
echo "--wifi requires rs9116 or SiWx917 or wf200"
Expand All @@ -154,7 +158,7 @@ else
elif [ "$2" = "SiWx917" ]; then
optArgs+="use_SiWx917=true "
elif [ "$2" = "wf200" ]; then
optArgs+="use_wf200=true "
optArgs+="use_wf200=true"
else
echo "Wifi usage: --wifi rs9116|SiWx917|wf200"
exit 1
Expand Down Expand Up @@ -242,6 +246,11 @@ else

BUILD_DIR=$OUTDIR/$SILABS_BOARD
echo BUILD_DIR="$BUILD_DIR"

if [ "$DIR_CLEAN" == true ]; then
rm -rf "$BUILD_DIR"
fi

if [ "$USE_WIFI" == true ]; then
# wifi build
# NCP mode EFR32 + wifi module
Expand Down
5 changes: 5 additions & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ 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/SceneTable.h",
"${_app_root}/clusters/scenes/SceneTableImpl.cpp",
"${_app_root}/clusters/scenes/SceneTableImpl.h",
"${_app_root}/clusters/scenes/scenes-tokens.h",
"${_app_root}/clusters/scenes/scenes.h",
"${_app_root}/util/ClientMonitoringRegistrationTable.cpp",
Expand Down
95 changes: 95 additions & 0 deletions src/app/clusters/scenes/ExtensionFieldsSets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
*
* 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 "ExtensionFieldsSets.h"

namespace chip {
namespace scenes {

ExtensionFieldsSets::ExtensionFieldsSets()
{
// check if any of the clusters with scene attributes are enabled
if (this->kExentesionFieldsSetsSize == 1)
{
// a size of 1 byte indicates an empty struct, or a struct that only contains :
// the on-off cluster
// the Mode select cluster
// the door lock cluster
#ifdef ZCL_USING_ON_OFF_CLUSTER_SERVER
this->enabledFieldSets.onOff = false;

#elif defined(ZCL_USING_MODE_SELECT_CLUSTER_SERVER)
this->enabledFieldSets.currentMode = 0;
#elif defined(ZCL_USING_DOOR_LOCK_CLUSTER_SERVER)
this->enabledFieldSets.lockState = 0;
#else
this->empty = true;
#endif
}
else if (this->kExentesionFieldsSetsSize > 1)
{
memset(&this->enabledFieldSets, 0, kExentesionFieldsSetsSize);
}
}

CHIP_ERROR ExtensionFieldsSets::Serialize(TLV::TLVWriter & writer) const
{
if (!this->empty)
{
TLV::TLVType container;
ReturnErrorOnFailure(writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_Structure, container));

ReturnErrorOnFailure(
writer.PutBytes(TagEnabledFielsSets(), (uint8_t *) &this->enabledFieldSets, kExentesionFieldsSetsSize));

return writer.EndContainer(container);
}
else
{
return CHIP_NO_ERROR;
}
}

CHIP_ERROR ExtensionFieldsSets::Deserialize(TLV::TLVReader & reader)
{
if (!this->empty)
{
TLV::TLVType container;
ReturnErrorOnFailure(reader.Next(TLV::kTLVType_Structure, TLV::ContextTag(1)));
ReturnErrorOnFailure(reader.EnterContainer(container));

ReturnErrorOnFailure(reader.Next(TagEnabledFielsSets()));
ReturnErrorOnFailure(reader.GetBytes((uint8_t *) &this->enabledFieldSets, kExentesionFieldsSetsSize));

return reader.ExitContainer(container);
}
else
{
return CHIP_NO_ERROR;
}
}
void ExtensionFieldsSets::clear()
{
if (!this->empty)
{
memset(&this->enabledFieldSets, 0, sizeof(this->enabledFieldSets));
}
}

} // namespace scenes

} // namespace chip
100 changes: 100 additions & 0 deletions src/app/clusters/scenes/ExtensionFieldsSets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
*
* 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.
*/

#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 fieldSets_s
{
#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_t;

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

ExtensionFieldsSets();
virtual ~ExtensionFieldsSets() = default;

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, kExentesionFieldsSetsSize));
}

void operator=(const ExtensionFieldsSets & other)
{
memcpy(&this->enabledFieldSets, &other.enabledFieldSets, kExentesionFieldsSetsSize);
}
};
} // namespace scenes
} // namespace chip
Loading

0 comments on commit 33569c9

Please sign in to comment.