blob: 7bc5f999827c20365afc5b6b7fbb3f503f6294a9 [file] [log] [blame]
/*
*
* Copyright (c) 2021 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
*
* 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.
*/
// THIS FILE IS GENERATED BY ZAP
#include "CHIPClusters.h"
#include <cstdint>
#include <support/BufferWriter.h>
#include <support/SafeInt.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemPacketBuffer.h>
#include <app/chip-zcl-zpro-codec.h>
#include <app/common/gen/ids/Attributes.h>
#include <app/util/basic-types.h>
#include <app/InteractionModelEngine.h>
#include <gen/CHIPClientCallbacks.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/SafeInt.h>
#define COMMAND_HEADER(name, clusterId) \
const char * kName = name; \
uint8_t seqNum = mDevice->GetNextSequenceNumber(); \
\
PacketBufferWriter buf(System::PacketBufferHandle::New(kMaxBufferSize)); \
if (buf.IsNull()) \
{ \
ChipLogError(Zcl, "Could not allocate packet buffer while trying to encode %s command", kName); \
return CHIP_ERROR_INTERNAL; \
} \
\
if (doEncodeApsFrame(buf, clusterId, kSourceEndpoint, mEndpoint, 0, 0, 0, 0, false)) \
{
#define COMMAND_FOOTER() \
} \
if (!buf.Fit()) \
{ \
ChipLogError(Zcl, "Command %s can't fit in the allocated buffer", kName); \
} \
return SendCommand(seqNum, buf.Finalize(), onSuccessCallback, onFailureCallback);
namespace {
// TODO: Find a way to calculate maximum message length for clusters
// https://github.com/project-chip/connectedhomeip/issues/965
constexpr uint16_t kMaxBufferSize = 1024;
// This is a global command, so the low bits are 0b00. The command is
// standard, so does not need a manufacturer code, and we're sending client
// to server, so all the remaining bits are 0.
constexpr uint8_t kFrameControlGlobalCommand = 0x00;
// Pick source endpoint as 1 for now
constexpr chip::EndpointId kSourceEndpoint = 1;
const uint8_t kReportingDirectionReported = 0x00;
} // namespace
using namespace chip::app::Clusters;
using namespace chip::System;
using namespace chip::Encoding::LittleEndian;
namespace chip {
namespace Controller {
// TODO(#4502): onCompletion is not used by IM for now.
// TODO(#4503): length should be passed to commands when byte string is in argument list.
// TODO(#4503): Commands should take group id as an argument.
// FlowMeasurement Cluster Commands
// FlowMeasurement Cluster Attributes
CHIP_ERROR FlowMeasurementCluster::DiscoverAttributes(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
COMMAND_HEADER("DiscoverFlowMeasurementAttributes", FlowMeasurement::Id);
buf.Put8(kFrameControlGlobalCommand).Put8(seqNum).Put32(Globals::Commands::Ids::DiscoverAttributes).Put32(0x0000).Put8(0xFF);
COMMAND_FOOTER();
}
CHIP_ERROR FlowMeasurementCluster::ReadAttributeMeasuredValue(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000000;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16sAttributeCallback>);
}
CHIP_ERROR FlowMeasurementCluster::ConfigureAttributeMeasuredValue(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, uint16_t minInterval,
uint16_t maxInterval, int16_t change)
{
COMMAND_HEADER("ReportFlowMeasurementMeasuredValue", FlowMeasurement::Id);
buf.Put8(kFrameControlGlobalCommand)
.Put8(seqNum)
.Put32(Globals::Commands::Ids::ConfigureReporting)
.Put8(kReportingDirectionReported)
.Put32(FlowMeasurement::Attributes::Ids::MeasuredValue)
.Put8(41)
.Put16(minInterval)
.Put16(maxInterval);
buf.Put16(static_cast<uint16_t>(change));
COMMAND_FOOTER();
}
CHIP_ERROR FlowMeasurementCluster::ReportAttributeMeasuredValue(Callback::Cancelable * onReportCallback)
{
return RequestAttributeReporting(0x0000, onReportCallback);
}
CHIP_ERROR FlowMeasurementCluster::ReadAttributeMinMeasuredValue(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000001;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16sAttributeCallback>);
}
CHIP_ERROR FlowMeasurementCluster::ReadAttributeMaxMeasuredValue(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000002;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16sAttributeCallback>);
}
CHIP_ERROR FlowMeasurementCluster::ReadAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x0000FFFD;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
// LevelControl Cluster Commands
CHIP_ERROR LevelControlCluster::Move(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback,
uint8_t moveMode, uint8_t rate, uint8_t optionMask, uint8_t optionOverride)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::CommandSender * sender = nullptr;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, LevelControl::Commands::Ids::Move,
(chip::app::CommandPathFlags::kEndpointIdValid) };
SuccessOrExit(err = chip::app::InteractionModelEngine::GetInstance()->NewCommandSender(&sender));
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataElementTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// moveMode: moveMode
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), moveMode));
// rate: int8u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), rate));
// optionMask: bitmap8
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), optionMask));
// optionOverride: bitmap8
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), optionOverride));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender, onSuccessCallback, onFailureCallback);
err = mDevice->SendCommands(sender);
exit:
// On error, we are responsible to close the sender.
if (err != CHIP_NO_ERROR && sender != nullptr)
{
sender->Shutdown();
}
return err;
}
CHIP_ERROR LevelControlCluster::MoveToLevel(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback,
uint8_t level, uint16_t transitionTime, uint8_t optionMask, uint8_t optionOverride)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::CommandSender * sender = nullptr;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, LevelControl::Commands::Ids::MoveToLevel,
(chip::app::CommandPathFlags::kEndpointIdValid) };
SuccessOrExit(err = chip::app::InteractionModelEngine::GetInstance()->NewCommandSender(&sender));
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataElementTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// level: int8u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), level));
// transitionTime: int16u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), transitionTime));
// optionMask: bitmap8
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), optionMask));
// optionOverride: bitmap8
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), optionOverride));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender, onSuccessCallback, onFailureCallback);
err = mDevice->SendCommands(sender);
exit:
// On error, we are responsible to close the sender.
if (err != CHIP_NO_ERROR && sender != nullptr)
{
sender->Shutdown();
}
return err;
}
CHIP_ERROR LevelControlCluster::MoveToLevelWithOnOff(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, uint8_t level,
uint16_t transitionTime)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::CommandSender * sender = nullptr;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, LevelControl::Commands::Ids::MoveToLevelWithOnOff,
(chip::app::CommandPathFlags::kEndpointIdValid) };
SuccessOrExit(err = chip::app::InteractionModelEngine::GetInstance()->NewCommandSender(&sender));
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataElementTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// level: int8u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), level));
// transitionTime: int16u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), transitionTime));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender, onSuccessCallback, onFailureCallback);
err = mDevice->SendCommands(sender);
exit:
// On error, we are responsible to close the sender.
if (err != CHIP_NO_ERROR && sender != nullptr)
{
sender->Shutdown();
}
return err;
}
CHIP_ERROR LevelControlCluster::MoveWithOnOff(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback,
uint8_t moveMode, uint8_t rate)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::CommandSender * sender = nullptr;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, LevelControl::Commands::Ids::MoveWithOnOff,
(chip::app::CommandPathFlags::kEndpointIdValid) };
SuccessOrExit(err = chip::app::InteractionModelEngine::GetInstance()->NewCommandSender(&sender));
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataElementTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// moveMode: moveMode
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), moveMode));
// rate: int8u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), rate));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender, onSuccessCallback, onFailureCallback);
err = mDevice->SendCommands(sender);
exit:
// On error, we are responsible to close the sender.
if (err != CHIP_NO_ERROR && sender != nullptr)
{
sender->Shutdown();
}
return err;
}
CHIP_ERROR LevelControlCluster::Step(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback,
uint8_t stepMode, uint8_t stepSize, uint16_t transitionTime, uint8_t optionMask,
uint8_t optionOverride)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::CommandSender * sender = nullptr;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, LevelControl::Commands::Ids::Step,
(chip::app::CommandPathFlags::kEndpointIdValid) };
SuccessOrExit(err = chip::app::InteractionModelEngine::GetInstance()->NewCommandSender(&sender));
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataElementTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// stepMode: stepMode
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), stepMode));
// stepSize: int8u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), stepSize));
// transitionTime: int16u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), transitionTime));
// optionMask: bitmap8
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), optionMask));
// optionOverride: bitmap8
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), optionOverride));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender, onSuccessCallback, onFailureCallback);
err = mDevice->SendCommands(sender);
exit:
// On error, we are responsible to close the sender.
if (err != CHIP_NO_ERROR && sender != nullptr)
{
sender->Shutdown();
}
return err;
}
CHIP_ERROR LevelControlCluster::StepWithOnOff(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback,
uint8_t stepMode, uint8_t stepSize, uint16_t transitionTime)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::CommandSender * sender = nullptr;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, LevelControl::Commands::Ids::StepWithOnOff,
(chip::app::CommandPathFlags::kEndpointIdValid) };
SuccessOrExit(err = chip::app::InteractionModelEngine::GetInstance()->NewCommandSender(&sender));
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataElementTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// stepMode: stepMode
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), stepMode));
// stepSize: int8u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), stepSize));
// transitionTime: int16u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), transitionTime));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender, onSuccessCallback, onFailureCallback);
err = mDevice->SendCommands(sender);
exit:
// On error, we are responsible to close the sender.
if (err != CHIP_NO_ERROR && sender != nullptr)
{
sender->Shutdown();
}
return err;
}
CHIP_ERROR LevelControlCluster::Stop(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback,
uint8_t optionMask, uint8_t optionOverride)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::CommandSender * sender = nullptr;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, LevelControl::Commands::Ids::Stop,
(chip::app::CommandPathFlags::kEndpointIdValid) };
SuccessOrExit(err = chip::app::InteractionModelEngine::GetInstance()->NewCommandSender(&sender));
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataElementTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// optionMask: bitmap8
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), optionMask));
// optionOverride: bitmap8
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), optionOverride));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender, onSuccessCallback, onFailureCallback);
err = mDevice->SendCommands(sender);
exit:
// On error, we are responsible to close the sender.
if (err != CHIP_NO_ERROR && sender != nullptr)
{
sender->Shutdown();
}
return err;
}
CHIP_ERROR LevelControlCluster::StopWithOnOff(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::CommandSender * sender = nullptr;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, LevelControl::Commands::Ids::StopWithOnOff,
(chip::app::CommandPathFlags::kEndpointIdValid) };
SuccessOrExit(err = chip::app::InteractionModelEngine::GetInstance()->NewCommandSender(&sender));
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
// Command takes no arguments.
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender, onSuccessCallback, onFailureCallback);
err = mDevice->SendCommands(sender);
exit:
// On error, we are responsible to close the sender.
if (err != CHIP_NO_ERROR && sender != nullptr)
{
sender->Shutdown();
}
return err;
}
// LevelControl Cluster Attributes
CHIP_ERROR LevelControlCluster::DiscoverAttributes(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
COMMAND_HEADER("DiscoverLevelControlAttributes", LevelControl::Id);
buf.Put8(kFrameControlGlobalCommand).Put8(seqNum).Put32(Globals::Commands::Ids::DiscoverAttributes).Put32(0x0000).Put8(0xFF);
COMMAND_FOOTER();
}
CHIP_ERROR LevelControlCluster::ReadAttributeCurrentLevel(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000000;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR LevelControlCluster::ConfigureAttributeCurrentLevel(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, uint16_t minInterval,
uint16_t maxInterval, uint8_t change)
{
COMMAND_HEADER("ReportLevelControlCurrentLevel", LevelControl::Id);
buf.Put8(kFrameControlGlobalCommand)
.Put8(seqNum)
.Put32(Globals::Commands::Ids::ConfigureReporting)
.Put8(kReportingDirectionReported)
.Put32(LevelControl::Attributes::Ids::CurrentLevel)
.Put8(32)
.Put16(minInterval)
.Put16(maxInterval);
buf.Put8(static_cast<uint8_t>(change));
COMMAND_FOOTER();
}
CHIP_ERROR LevelControlCluster::ReportAttributeCurrentLevel(Callback::Cancelable * onReportCallback)
{
return RequestAttributeReporting(0x0000, onReportCallback);
}
CHIP_ERROR LevelControlCluster::ReadAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x0000FFFD;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
// OnOff Cluster Commands
CHIP_ERROR OnOffCluster::Off(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::CommandSender * sender = nullptr;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, OnOff::Commands::Ids::Off,
(chip::app::CommandPathFlags::kEndpointIdValid) };
SuccessOrExit(err = chip::app::InteractionModelEngine::GetInstance()->NewCommandSender(&sender));
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
// Command takes no arguments.
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender, onSuccessCallback, onFailureCallback);
err = mDevice->SendCommands(sender);
exit:
// On error, we are responsible to close the sender.
if (err != CHIP_NO_ERROR && sender != nullptr)
{
sender->Shutdown();
}
return err;
}
CHIP_ERROR OnOffCluster::On(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::CommandSender * sender = nullptr;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, OnOff::Commands::Ids::On,
(chip::app::CommandPathFlags::kEndpointIdValid) };
SuccessOrExit(err = chip::app::InteractionModelEngine::GetInstance()->NewCommandSender(&sender));
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
// Command takes no arguments.
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender, onSuccessCallback, onFailureCallback);
err = mDevice->SendCommands(sender);
exit:
// On error, we are responsible to close the sender.
if (err != CHIP_NO_ERROR && sender != nullptr)
{
sender->Shutdown();
}
return err;
}
CHIP_ERROR OnOffCluster::Toggle(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::CommandSender * sender = nullptr;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, OnOff::Commands::Ids::Toggle,
(chip::app::CommandPathFlags::kEndpointIdValid) };
SuccessOrExit(err = chip::app::InteractionModelEngine::GetInstance()->NewCommandSender(&sender));
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
// Command takes no arguments.
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender, onSuccessCallback, onFailureCallback);
err = mDevice->SendCommands(sender);
exit:
// On error, we are responsible to close the sender.
if (err != CHIP_NO_ERROR && sender != nullptr)
{
sender->Shutdown();
}
return err;
}
// OnOff Cluster Attributes
CHIP_ERROR OnOffCluster::DiscoverAttributes(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
{
COMMAND_HEADER("DiscoverOnOffAttributes", OnOff::Id);
buf.Put8(kFrameControlGlobalCommand).Put8(seqNum).Put32(Globals::Commands::Ids::DiscoverAttributes).Put32(0x0000).Put8(0xFF);
COMMAND_FOOTER();
}
CHIP_ERROR OnOffCluster::ReadAttributeOnOff(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000000;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<BooleanAttributeCallback>);
}
CHIP_ERROR OnOffCluster::ReadAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x0000FFFD;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
// PressureMeasurement Cluster Commands
// PressureMeasurement Cluster Attributes
CHIP_ERROR PressureMeasurementCluster::DiscoverAttributes(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
COMMAND_HEADER("DiscoverPressureMeasurementAttributes", PressureMeasurement::Id);
buf.Put8(kFrameControlGlobalCommand).Put8(seqNum).Put32(Globals::Commands::Ids::DiscoverAttributes).Put32(0x0000).Put8(0xFF);
COMMAND_FOOTER();
}
CHIP_ERROR PressureMeasurementCluster::ReadAttributeMeasuredValue(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000000;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16sAttributeCallback>);
}
CHIP_ERROR PressureMeasurementCluster::ConfigureAttributeMeasuredValue(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback,
uint16_t minInterval, uint16_t maxInterval, int16_t change)
{
COMMAND_HEADER("ReportPressureMeasurementMeasuredValue", PressureMeasurement::Id);
buf.Put8(kFrameControlGlobalCommand)
.Put8(seqNum)
.Put32(Globals::Commands::Ids::ConfigureReporting)
.Put8(kReportingDirectionReported)
.Put32(PressureMeasurement::Attributes::Ids::MeasuredValue)
.Put8(41)
.Put16(minInterval)
.Put16(maxInterval);
buf.Put16(static_cast<uint16_t>(change));
COMMAND_FOOTER();
}
CHIP_ERROR PressureMeasurementCluster::ReportAttributeMeasuredValue(Callback::Cancelable * onReportCallback)
{
return RequestAttributeReporting(0x0000, onReportCallback);
}
CHIP_ERROR PressureMeasurementCluster::ReadAttributeMinMeasuredValue(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000001;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16sAttributeCallback>);
}
CHIP_ERROR PressureMeasurementCluster::ReadAttributeMaxMeasuredValue(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000002;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16sAttributeCallback>);
}
CHIP_ERROR PressureMeasurementCluster::ReadAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x0000FFFD;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
// PumpConfigurationAndControl Cluster Commands
// PumpConfigurationAndControl Cluster Attributes
CHIP_ERROR PumpConfigurationAndControlCluster::DiscoverAttributes(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
COMMAND_HEADER("DiscoverPumpConfigurationAndControlAttributes", PumpConfigurationAndControl::Id);
buf.Put8(kFrameControlGlobalCommand).Put8(seqNum).Put32(Globals::Commands::Ids::DiscoverAttributes).Put32(0x0000).Put8(0xFF);
COMMAND_FOOTER();
}
CHIP_ERROR PumpConfigurationAndControlCluster::ReadAttributeMaxPressure(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000000;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16sAttributeCallback>);
}
CHIP_ERROR PumpConfigurationAndControlCluster::ReadAttributeMaxSpeed(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000001;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
CHIP_ERROR PumpConfigurationAndControlCluster::ReadAttributeMaxFlow(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000002;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
CHIP_ERROR PumpConfigurationAndControlCluster::ReadAttributeEffectiveOperationMode(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000011;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR PumpConfigurationAndControlCluster::ReadAttributeEffectiveControlMode(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000012;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR PumpConfigurationAndControlCluster::ReadAttributeCapacity(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000013;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16sAttributeCallback>);
}
CHIP_ERROR PumpConfigurationAndControlCluster::ConfigureAttributeCapacity(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback,
uint16_t minInterval, uint16_t maxInterval,
int16_t change)
{
COMMAND_HEADER("ReportPumpConfigurationAndControlCapacity", PumpConfigurationAndControl::Id);
buf.Put8(kFrameControlGlobalCommand)
.Put8(seqNum)
.Put32(Globals::Commands::Ids::ConfigureReporting)
.Put8(kReportingDirectionReported)
.Put32(PumpConfigurationAndControl::Attributes::Ids::Capacity)
.Put8(41)
.Put16(minInterval)
.Put16(maxInterval);
buf.Put16(static_cast<uint16_t>(change));
COMMAND_FOOTER();
}
CHIP_ERROR PumpConfigurationAndControlCluster::ReportAttributeCapacity(Callback::Cancelable * onReportCallback)
{
return RequestAttributeReporting(0x0013, onReportCallback);
}
CHIP_ERROR PumpConfigurationAndControlCluster::ReadAttributeOperationMode(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000020;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR PumpConfigurationAndControlCluster::WriteAttributeOperationMode(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, uint8_t value)
{
app::WriteClientHandle handle;
chip::app::AttributePathParams attributePath;
attributePath.mNodeId = mDevice->GetDeviceId();
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000020;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
ReturnErrorOnFailure(app::InteractionModelEngine::GetInstance()->NewWriteClient(handle));
ReturnErrorOnFailure(handle.EncodeScalarAttributeWritePayload(attributePath, value));
return mDevice->SendWriteAttributeRequest(std::move(handle), onSuccessCallback, onFailureCallback);
}
CHIP_ERROR PumpConfigurationAndControlCluster::ReadAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x0000FFFD;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
// TemperatureMeasurement Cluster Commands
// TemperatureMeasurement Cluster Attributes
CHIP_ERROR TemperatureMeasurementCluster::DiscoverAttributes(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
COMMAND_HEADER("DiscoverTemperatureMeasurementAttributes", TemperatureMeasurement::Id);
buf.Put8(kFrameControlGlobalCommand).Put8(seqNum).Put32(Globals::Commands::Ids::DiscoverAttributes).Put32(0x0000).Put8(0xFF);
COMMAND_FOOTER();
}
CHIP_ERROR TemperatureMeasurementCluster::ReadAttributeMeasuredValue(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000000;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16sAttributeCallback>);
}
CHIP_ERROR TemperatureMeasurementCluster::ConfigureAttributeMeasuredValue(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback,
uint16_t minInterval, uint16_t maxInterval,
int16_t change)
{
COMMAND_HEADER("ReportTemperatureMeasurementMeasuredValue", TemperatureMeasurement::Id);
buf.Put8(kFrameControlGlobalCommand)
.Put8(seqNum)
.Put32(Globals::Commands::Ids::ConfigureReporting)
.Put8(kReportingDirectionReported)
.Put32(TemperatureMeasurement::Attributes::Ids::MeasuredValue)
.Put8(41)
.Put16(minInterval)
.Put16(maxInterval);
buf.Put16(static_cast<uint16_t>(change));
COMMAND_FOOTER();
}
CHIP_ERROR TemperatureMeasurementCluster::ReportAttributeMeasuredValue(Callback::Cancelable * onReportCallback)
{
return RequestAttributeReporting(0x0000, onReportCallback);
}
CHIP_ERROR TemperatureMeasurementCluster::ReadAttributeMinMeasuredValue(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000001;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16sAttributeCallback>);
}
CHIP_ERROR TemperatureMeasurementCluster::ReadAttributeMaxMeasuredValue(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x00000002;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16sAttributeCallback>);
}
CHIP_ERROR TemperatureMeasurementCluster::ReadAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = 0x0000FFFD;
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
} // namespace Controller
} // namespace chip