Skip to content

Commit

Permalink
1. enable rvc write attributes 2. enable power source cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
stingchang committed Apr 25, 2024
1 parent 22188b6 commit b70604a
Show file tree
Hide file tree
Showing 8 changed files with 710 additions and 69 deletions.
100 changes: 94 additions & 6 deletions examples/chef/common/chef-rvc-mode-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
#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 EMBER_AF_PLUGIN_RVC_RUN_MODE_SERVER
#include <chef-rvc-mode-delegate.h>
using namespace chip::app::Clusters::RvcRunMode;
static RvcRunModeDelegate * gRvcRunModeDelegate = nullptr;
Expand Down Expand Up @@ -106,17 +108,62 @@ void RvcRunMode::Shutdown()
}
}

EmberAfStatus chefRvcRunModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer)
{
EmberAfStatus ret = EMBER_ZCL_STATUS_SUCCESS;

VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gRvcRunModeInstance != nullptr);

ModeBase::Instance * clusterInstance = gRvcRunModeInstance;
chip::AttributeId attributeId = attributeMetadata->attributeId;

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

return ret;
}

EmberAfStatus chefRvcRunModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer,
uint16_t maxReadLength)
{
EmberAfStatus ret = EMBER_ZCL_STATUS_SUCCESS;

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));
gRvcRunModeInstance =
new ModeBase::Instance(gRvcRunModeDelegate, endpointId, RvcRunMode::Id, chip::to_underlying(RvcRunMode::Feature::kOnOff));
// gRvcRunModeInstance =
// new ModeBase::Instance(gRvcRunModeDelegate, 0x1, RvcRunMode::Id, chip::to_underlying(RvcRunMode::Feature::kOnOff));
gRvcRunModeInstance->Init();
}
#endif // EMBER_AF_PLUGIN_RVC_RUN_MODE_SERVER

#ifdef ZCL_USING_RVC_CLEAN_MODE_CLUSTER_SERVER
#ifdef EMBER_AF_PLUGIN_RVC_CLEAN_MODE_SERVER
#include <chef-rvc-mode-delegate.h>
using namespace chip::app::Clusters::RvcCleanMode;
static RvcCleanModeDelegate * gRvcCleanModeDelegate = nullptr;
Expand Down Expand Up @@ -197,6 +244,48 @@ void RvcCleanMode::Shutdown()
}
}

EmberAfStatus chefRvcCleanModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer)
{
EmberAfStatus ret = EMBER_ZCL_STATUS_SUCCESS;

VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gRvcCleanModeInstance != nullptr);

ModeBase::Instance * clusterInstance = gRvcCleanModeInstance;
chip::AttributeId attributeId = attributeMetadata->attributeId;

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

return ret;
}

EmberAfStatus chefRvcCleanModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer,
uint16_t maxReadLength)
{
EmberAfStatus ret = EMBER_ZCL_STATUS_SUCCESS;

return ret;
}

void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
Expand All @@ -206,5 +295,4 @@ void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId)
new ModeBase::Instance(gRvcCleanModeDelegate, 0x1, RvcCleanMode::Id, chip::to_underlying(RvcCleanMode::Feature::kOnOff));
gRvcCleanModeInstance->Init();
}
#endif // ZCL_USING_RVC_CLEAN_MODE_CLUSTER_SERVER
#endif // ZCL_USING_RVC_RUN_MODE_CLUSTER_SERVER
#endif // EMBER_AF_PLUGIN_RVC_CLEAN_MODE_SERVER
17 changes: 17 additions & 0 deletions examples/chef/common/chef-rvc-mode-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,20 @@ void Shutdown();
} // namespace Clusters
} // namespace app
} // namespace chip


#ifdef EMBER_AF_PLUGIN_RVC_RUN_MODE_SERVER
EmberAfStatus chefRvcRunModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer);
EmberAfStatus chefRvcRunModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer,
uint16_t maxReadLength);
#endif

#ifdef EMBER_AF_PLUGIN_RVC_CLEAN_MODE_SERVER
EmberAfStatus chefRvcCleanModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer);
EmberAfStatus chefRvcCleanModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer,
uint16_t maxReadLength);
#endif // EMBER_AF_PLUGIN_RVC_RUN_MODE_SERVER
57 changes: 55 additions & 2 deletions examples/chef/common/chef-rvc-operational-state-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/util/config.h>

#ifdef ZCL_USING_OPERATIONAL_STATE_RVC_CLUSTER_SERVER
#ifdef EMBER_AF_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
#include <chef-rvc-operational-state-delegate.h>

using namespace chip;
Expand Down Expand Up @@ -154,6 +154,59 @@ void RvcOperationalState::Shutdown()
}
}

EmberAfStatus chefRvcOperationalStateWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer)
{
EmberAfStatus ret = EMBER_ZCL_STATUS_SUCCESS;

VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gRvcOperationalStateInstance != nullptr);

chip::AttributeId attributeId = attributeMetadata->attributeId;

switch (attributeId)
{
case chip::app::Clusters::RvcOperationalState::Attributes::CurrentPhase::Id: {
uint8_t m = static_cast<uint8_t>(buffer[0]);
DataModel::Nullable<uint8_t> aPhase(m);
CHIP_ERROR err = gRvcOperationalStateInstance->SetCurrentPhase(aPhase);
if (CHIP_NO_ERROR == err)
{
break;
}
ret = EMBER_ZCL_STATUS_UNSUPPORTED_WRITE;
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %" CHIP_ERROR_FORMAT, err.Format());
}
break;
case chip::app::Clusters::RvcOperationalState::Attributes::OperationalState::Id: {
uint8_t m = static_cast<uint8_t>(buffer[0]);
CHIP_ERROR err = gRvcOperationalStateInstance->SetOperationalState(m);
if (CHIP_NO_ERROR == err)
{
break;
}
ret = EMBER_ZCL_STATUS_UNSUPPORTED_WRITE;
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %" CHIP_ERROR_FORMAT, err.Format());
}
break;
default:
ret = EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE;
ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast<int>(attributeId));
break;
}

return ret;
}

EmberAfStatus chefRvcOperationalStateReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer,
uint16_t maxReadLength)
{
EmberAfStatus ret = EMBER_ZCL_STATUS_SUCCESS;

return ret;
}

void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
Expand All @@ -167,4 +220,4 @@ void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId)

gRvcOperationalStateInstance->Init();
}
#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
#endif // EMBER_AF_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
9 changes: 9 additions & 0 deletions examples/chef/common/chef-rvc-operational-state-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,12 @@ void Shutdown();
} // namespace Clusters
} // namespace app
} // namespace chip


#ifdef EMBER_AF_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
EmberAfStatus chefRvcOperationalStateWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer);
EmberAfStatus chefRvcOperationalStateReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer,
uint16_t maxReadLength);
#endif // EMBER_AF_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
23 changes: 23 additions & 0 deletions examples/chef/common/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
#include "chef-concentration-measurement.h"
#endif

#if defined(EMBER_AF_PLUGIN_RVC_RUN_MODE_SERVER) || \
defined(EMBER_AF_PLUGIN_RVC_CLEAN_MODE_SERVER)
#include "chef-rvc-mode-delegate.h"
#endif
#ifdef EMBER_AF_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
#include "chef-rvc-operational-state-delegate.h"
#endif

using chip::app::DataModel::Nullable;

using namespace chip;
Expand Down Expand Up @@ -104,6 +112,21 @@ Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(Endpoi
case chip::app::Clusters::RadonConcentrationMeasurement::Id:
case chip::app::Clusters::TotalVolatileOrganicCompoundsConcentrationMeasurement::Id:
return chefConcentrationMeasurementWriteCallback(endpoint, clusterId, attributeMetadata, buffer);
#endif
#ifdef EMBER_AF_PLUGIN_RVC_RUN_MODE_SERVER
case chip::app::Clusters::RvcRunMode::Id:
return chefRvcRunModeWriteCallback(endpoint, clusterId, attributeMetadata, buffer);
break;
#endif
#ifdef EMBER_AF_PLUGIN_RVC_CLEAN_MODE_SERVER
case chip::app::Clusters::RvcCleanMode::Id:
return chefRvcCleanModeWriteCallback(endpoint, clusterId, attributeMetadata, buffer);
break;
#endif
#ifdef EMBER_AF_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
case chip::app::Clusters::RvcOperationalState::Id:
return chefRvcOperationalStateWriteCallback(endpoint, clusterId, attributeMetadata, buffer);
break;
#endif
default:
break;
Expand Down
Loading

0 comments on commit b70604a

Please sign in to comment.