Skip to content

Commit

Permalink
Create iterator to iterate over the supported-temperature-levels
Browse files Browse the repository at this point in the history
  • Loading branch information
jadhavrohit924 committed Jul 11, 2023
1 parent 941ad24 commit 3103409
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,31 @@ namespace TemperatureControl {
class StaticSupportedTemperatureLevelsManager : public SupportedTemperatureLevelsManager
{
using TemperatureLevelStructType = Structs::TemperatureLevelStruct::Type;
using storage_value_type = const TemperatureLevelStructType;
using storage_value_type = TemperatureLevelStructType;

struct EndpointSpanPair
struct EndpointPair
{
const EndpointId mEndpointId;
const Span<storage_value_type> mSpan;
EndpointId mEndpointId;
TemperatureLevelStructType * mData;
int mSize;

EndpointSpanPair(const EndpointId aEndpointId, const Span<storage_value_type> && aSpan) :
mEndpointId(aEndpointId), mSpan(aSpan)
EndpointPair(EndpointId aEndpointId, TemperatureLevelStructType * aData, int aSize) :
mEndpointId(aEndpointId), mData(aData), mSize(aSize)
{}

EndpointSpanPair() : mEndpointId(0), mSpan(Span<storage_value_type>()) {}
};

static storage_value_type temperatureLevelOptions[];
static const EndpointSpanPair supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT];

public:
static const StaticSupportedTemperatureLevelsManager instance;
static const EndpointPair supportedOptionsByEndpoints[EMBER_AF_TEMPERATURE_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT];

SupportedTemperatureLevelsManager::TemperatureLevelOptionsProvider
GetTemperatureLevelOptionsProvider(EndpointId endpointId) const override;
static TemperatureLevelStructType * data;

~StaticSupportedTemperatureLevelsManager(){};

StaticSupportedTemperatureLevelsManager() {}

static inline const StaticSupportedTemperatureLevelsManager & GetStaticSupportedTemperatureLevelsManagerInstance()
{
return instance;
}
};

const SupportedTemperatureLevelsManager * GetSupportedTemperatureLevelsManager();

} // namespace TemperatureControl
} // namespace Clusters
} // namespace app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using namespace chip::app::Clusters::TemperatureControl;
using chip::Protocols::InteractionModel::Status;

using TemperatureLevelStructType = Structs::TemperatureLevelStruct::Type;
using storage_value_type = const TemperatureLevelStructType;
using storage_value_type = TemperatureLevelStructType;
namespace {
Structs::TemperatureLevelStruct::Type buildTemperatureLevelStruct(const char * label, uint8_t temperatureLevel)
{
Expand All @@ -42,29 +42,24 @@ storage_value_type StaticSupportedTemperatureLevelsManager::temperatureLevelOpti
buildTemperatureLevelStruct("wash Temperature", 1), buildTemperatureLevelStruct("rinse Temperature", 2),
buildTemperatureLevelStruct("dry Temperature", 3)
};
const StaticSupportedTemperatureLevelsManager::EndpointSpanPair
StaticSupportedTemperatureLevelsManager::supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT] = {
EndpointSpanPair(
1, Span<storage_value_type>(StaticSupportedTemperatureLevelsManager::temperatureLevelOptions)) // Options for Endpoint 1
const StaticSupportedTemperatureLevelsManager::EndpointPair StaticSupportedTemperatureLevelsManager::supportedOptionsByEndpoints
[EMBER_AF_TEMPERATURE_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT] = {
EndpointPair(1, StaticSupportedTemperatureLevelsManager::temperatureLevelOptions, 3) // Options for Endpoint 1
};

const StaticSupportedTemperatureLevelsManager StaticSupportedTemperatureLevelsManager::instance =
StaticSupportedTemperatureLevelsManager();

StaticSupportedTemperatureLevelsManager::TemperatureLevelOptionsProvider
StaticSupportedTemperatureLevelsManager::GetTemperatureLevelOptionsProvider(EndpointId endpointId) const
bool StaticSupportedTemperatureLevelsManager::SupportedTemperatureLevelsManager::Iterator::Next(TemperatureLevelStructType & item)
{
for (auto & endpointSpanPair : supportedOptionsByEndpoints)
for (auto & endpointPair : StaticSupportedTemperatureLevelsManager::supportedOptionsByEndpoints)
{
if (endpointSpanPair.mEndpointId == endpointId)
if (endpointPair.mEndpointId == mEndpoint)
{
return TemperatureLevelOptionsProvider(endpointSpanPair.mSpan.data(), endpointSpanPair.mSpan.end());
if (endpointPair.mSize > mIndex)
{
item = endpointPair.mData[mIndex];
mIndex++;
return true;
}
}
}
return TemperatureLevelOptionsProvider(nullptr, nullptr);
}

const TemperatureControl::SupportedTemperatureLevelsManager * TemperatureControl::GetSupportedTemperatureLevelsManager()
{
return &StaticSupportedTemperatureLevelsManager::instance;
return false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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/clusters/temperature-control-server/supported-temperature-levels-manager.h>
#include <app/util/af.h>
#include <app/util/config.h>
#include <cstring>

namespace chip {
namespace app {
namespace Clusters {
namespace TemperatureControl {

/**
* This implementation statically defines the options.
*/

class StaticSupportedTemperatureLevelsManager : public SupportedTemperatureLevelsManager
{
using TemperatureLevelStructType = Structs::TemperatureLevelStruct::Type;
using storage_value_type = TemperatureLevelStructType;

struct EndpointPair
{
EndpointId mEndpointId;
TemperatureLevelStructType * mData;
int mSize;

EndpointPair(EndpointId aEndpointId, TemperatureLevelStructType * aData, int aSize) :
mEndpointId(aEndpointId), mData(aData), mSize(aSize)
{}
};

static storage_value_type temperatureLevelOptions[];

public:
static const EndpointPair supportedOptionsByEndpoints[EMBER_AF_TEMPERATURE_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT];

static TemperatureLevelStructType * data;

~StaticSupportedTemperatureLevelsManager(){};

StaticSupportedTemperatureLevelsManager() {}
};

} // namespace TemperatureControl
} // namespace Clusters
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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/util/config.h>
#include <static-supported-temperature-levels-manager.h>

using namespace std;
using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::TemperatureControl;
using chip::Protocols::InteractionModel::Status;

using TemperatureLevelStructType = Structs::TemperatureLevelStruct::Type;
using storage_value_type = TemperatureLevelStructType;
namespace {
Structs::TemperatureLevelStruct::Type buildTemperatureLevelStruct(const char * label, uint8_t temperatureLevel)
{
Structs::TemperatureLevelStruct::Type option;
option.label = CharSpan::fromCharString(label);
option.temperatureLevel = temperatureLevel;
return option;
}
} // namespace

// TODO: Configure your options for each endpoint
storage_value_type StaticSupportedTemperatureLevelsManager::temperatureLevelOptions[] = {
buildTemperatureLevelStruct("wash Temperature", 1), buildTemperatureLevelStruct("rinse Temperature", 2),
buildTemperatureLevelStruct("dry Temperature", 3)
};
const StaticSupportedTemperatureLevelsManager::EndpointPair StaticSupportedTemperatureLevelsManager::supportedOptionsByEndpoints
[EMBER_AF_TEMPERATURE_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT] = {
EndpointPair(1, StaticSupportedTemperatureLevelsManager::temperatureLevelOptions, 3) // Options for Endpoint 1
};

bool StaticSupportedTemperatureLevelsManager::SupportedTemperatureLevelsManager::Iterator::Next(TemperatureLevelStructType & item)
{
for (auto & endpointPair : StaticSupportedTemperatureLevelsManager::supportedOptionsByEndpoints)
{
if (endpointPair.mEndpointId == mEndpoint)
{
if (endpointPair.mSize > mIndex)
{
item = endpointPair.mData[mIndex];
mIndex++;
return true;
}
}
}
return false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ bool emberAfTemperatureControlClusterSetTemperatureCallback(app::CommandHandler
{
status = Status::InvalidCommand;
}
else
{
status = Status::InvalidCommand;
}
}
exit:
commandObj->AddStatus(commandPath, status);
Expand Down

0 comments on commit 3103409

Please sign in to comment.