Skip to content

Commit

Permalink
Enable chef robotic vacuum cleaner device (#33258)
Browse files Browse the repository at this point in the history
* Enable chef robotic vacuum cleaner device

* Restyled by whitespace

* Restyled by clang-format

* remove old rvc feature

* Restyled by clang-format

* update return status

* Restyled by whitespace

* Restyled by clang-format

* add back ifdef; remove old feature flag

* Restyled by clang-format

* write read attributes into buffer

* Restyled by clang-format

* update readCallback write buffer

* Restyled by whitespace

* update buffer read in read call back

* Restyled by clang-format

* use static instance

* Restyled by clang-format

* write attribute into buffer in callback

* use unique_ptr

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
stingchang and restyled-commits authored Jun 6, 2024
1 parent be94090 commit d15f6c1
Show file tree
Hide file tree
Showing 8 changed files with 862 additions and 147 deletions.
155 changes: 121 additions & 34 deletions examples/chef/common/chef-rvc-mode-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/util/config.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using chip::Protocols::InteractionModel::Status;
template <typename T>
using List = chip::app::DataModel::List<T>;
using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::Type;

#ifdef ZCL_USING_RVC_RUN_MODE_CLUSTER_SERVER
#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
#include <chef-rvc-mode-delegate.h>
using namespace chip::app::Clusters::RvcRunMode;
static RvcRunModeDelegate * gRvcRunModeDelegate = nullptr;
static ModeBase::Instance * gRvcRunModeInstance = nullptr;

static std::unique_ptr<RvcRunModeDelegate> gRvcRunModeDelegate;
static std::unique_ptr<ModeBase::Instance> gRvcRunModeInstance;

CHIP_ERROR RvcRunModeDelegate::Init()
{
Expand Down Expand Up @@ -87,40 +90,82 @@ CHIP_ERROR RvcRunModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<ModeTa
return CHIP_NO_ERROR;
}

ModeBase::Instance * RvcRunMode::Instance()
void RvcRunMode::Shutdown()
{
return gRvcRunModeInstance;
gRvcRunModeInstance.reset();
gRvcRunModeDelegate.reset();
}

void RvcRunMode::Shutdown()
chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer)
{
if (gRvcRunModeInstance != nullptr)
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1
VerifyOrDie(gRvcRunModeInstance != nullptr);
chip::Protocols::InteractionModel::Status ret;
chip::AttributeId attributeId = attributeMetadata->attributeId;

switch (attributeId)
{
delete gRvcRunModeInstance;
gRvcRunModeInstance = nullptr;
case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: {
uint8_t m = static_cast<uint8_t>(buffer[0]);
ret = gRvcRunModeInstance->UpdateCurrentMode(m);
if (chip::Protocols::InteractionModel::Status::Success != ret)
{
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast<int>(ret));
}
}
if (gRvcRunModeDelegate != nullptr)
break;
default:
ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite;
ChipLogError(DeviceLayer, "Unsupported Writng Attribute ID: %d", static_cast<int>(attributeId));
break;
}

return ret;
}

chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength)
{
chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success;
chip::AttributeId attributeId = attributeMetadata->attributeId;

switch (attributeId)
{
delete gRvcRunModeDelegate;
gRvcRunModeDelegate = nullptr;
case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: {
*buffer = gRvcRunModeInstance->GetCurrentMode();
ChipLogDetail(DeviceLayer, "Reading RunMode CurrentMode : %d", static_cast<int>(attributeId));
}
break;
default:
ret = chip::Protocols::InteractionModel::Status::UnsupportedRead;
ChipLogDetail(DeviceLayer, "Unsupported attributeId %d from reading RvcRunMode", static_cast<int>(attributeId));
break;
}

return ret;
}

void emberAfRvcRunModeClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gRvcRunModeDelegate == nullptr && gRvcRunModeInstance == nullptr);
gRvcRunModeDelegate = new RvcRunMode::RvcRunModeDelegate;
gRvcRunModeInstance =
new ModeBase::Instance(gRvcRunModeDelegate, 0x1, RvcRunMode::Id, chip::to_underlying(RvcRunMode::Feature::kOnOff));
VerifyOrDie(!gRvcRunModeDelegate && !gRvcRunModeInstance);

gRvcRunModeDelegate = std::make_unique<RvcRunModeDelegate>();
gRvcRunModeInstance = std::make_unique<ModeBase::Instance>(gRvcRunModeDelegate.get(), endpointId, RvcRunMode::Id,
chip::to_underlying(RvcRunMode::Feature::kNoFeatures));
gRvcRunModeInstance->Init();
}

#ifdef ZCL_USING_RVC_CLEAN_MODE_CLUSTER_SERVER
#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER

#ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER
#include <chef-rvc-mode-delegate.h>
using namespace chip::app::Clusters::RvcCleanMode;
static RvcCleanModeDelegate * gRvcCleanModeDelegate = nullptr;
static ModeBase::Instance * gRvcCleanModeInstance = nullptr;
static std::unique_ptr<RvcCleanModeDelegate> gRvcCleanModeDelegate;
static std::unique_ptr<ModeBase::Instance> gRvcCleanModeInstance;

CHIP_ERROR RvcCleanModeDelegate::Init()
{
Expand Down Expand Up @@ -178,33 +223,75 @@ CHIP_ERROR RvcCleanModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<Mode
return CHIP_NO_ERROR;
}

ModeBase::Instance * RvcCleanMode::Instance()
void RvcCleanMode::Shutdown()
{
return gRvcCleanModeInstance;
gRvcCleanModeInstance.reset();
gRvcCleanModeDelegate.reset();
}

void RvcCleanMode::Shutdown()
chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer)
{
if (gRvcCleanModeInstance != nullptr)
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1
VerifyOrDie(gRvcCleanModeInstance != nullptr);
chip::Protocols::InteractionModel::Status ret;
chip::AttributeId attributeId = attributeMetadata->attributeId;

switch (attributeId)
{
delete gRvcCleanModeInstance;
gRvcCleanModeInstance = nullptr;
case chip::app::Clusters::RvcCleanMode::Attributes::CurrentMode::Id: {
uint8_t m = static_cast<uint8_t>(buffer[0]);
ret = gRvcCleanModeInstance->UpdateCurrentMode(m);
if (chip::Protocols::InteractionModel::Status::Success != ret)
{
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast<int>(ret));
}
}
break;
default:
ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite;
ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast<int>(attributeId));
break;
}
if (gRvcCleanModeDelegate != nullptr)

return ret;
}

chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength)
{
VerifyOrReturnValue(maxReadLength > 0, chip::Protocols::InteractionModel::Status::ResourceExhausted);
buffer[0] = gRvcCleanModeInstance->GetCurrentMode();

chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success;
chip::AttributeId attributeId = attributeMetadata->attributeId;

switch (attributeId)
{
delete gRvcCleanModeDelegate;
gRvcCleanModeDelegate = nullptr;
case chip::app::Clusters::RvcCleanMode::Attributes::CurrentMode::Id: {
*buffer = gRvcCleanModeInstance->GetCurrentMode();
ChipLogDetail(DeviceLayer, "Reading CleanMode CurrentMode : %d", static_cast<int>(attributeId));
}
break;
default:
ret = chip::Protocols::InteractionModel::Status::UnsupportedRead;
ChipLogDetail(DeviceLayer, "Unsupported attributeId %d from reading RvcCleanMode", static_cast<int>(attributeId));
break;
}

return ret;
}

void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gRvcCleanModeDelegate == nullptr && gRvcCleanModeInstance == nullptr);
gRvcCleanModeDelegate = new RvcCleanMode::RvcCleanModeDelegate;
gRvcCleanModeInstance =
new ModeBase::Instance(gRvcCleanModeDelegate, 0x1, RvcCleanMode::Id, chip::to_underlying(RvcCleanMode::Feature::kOnOff));
VerifyOrDie(!gRvcCleanModeDelegate && !gRvcCleanModeInstance);

gRvcCleanModeDelegate = std::make_unique<RvcCleanModeDelegate>();
gRvcCleanModeInstance = std::make_unique<ModeBase::Instance>(gRvcCleanModeDelegate.get(), endpointId, RvcCleanMode::Id,
chip::to_underlying(RvcCleanMode::Feature::kNoFeatures));
gRvcCleanModeInstance->Init();
}
#endif // ZCL_USING_RVC_CLEAN_MODE_CLUSTER_SERVER
#endif // ZCL_USING_RVC_RUN_MODE_CLUSTER_SERVER
#endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER
20 changes: 20 additions & 0 deletions examples/chef/common/chef-rvc-mode-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <cstring>
#include <utility>

using chip::Protocols::InteractionModel::Status;

namespace chip {
namespace app {
namespace Clusters {
Expand Down Expand Up @@ -118,3 +120,21 @@ void Shutdown();
} // namespace Clusters
} // namespace app
} // namespace chip

#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer);
chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength);
#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER

#ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER
chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer);
chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength);
#endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER
Loading

0 comments on commit d15f6c1

Please sign in to comment.