Skip to content

Commit

Permalink
Support writing Attributes in RVC clusters
Browse files Browse the repository at this point in the history
Support writing CurrentMode in RvcRunMode Cluser
Support writing OperationState in RvcOperationalState Cluser
Enable Start/Stop in RvcOperationalState Cluster
  • Loading branch information
erwinpan1 committed Feb 3, 2024
1 parent a11704d commit f7af441
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 8 deletions.
97 changes: 91 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,14 @@
#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 +107,60 @@ 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));
new ModeBase::Instance(gRvcRunModeDelegate, endpointId, 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 +241,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 +292,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
16 changes: 16 additions & 0 deletions examples/chef/common/chef-rvc-mode-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,19 @@ 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
55 changes: 54 additions & 1 deletion 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 @@ -155,6 +155,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 Down
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 @@ -155,3 +155,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

23 changes: 23 additions & 0 deletions examples/chef/common/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
defined(EMBER_AF_PLUGIN_RADON_CONCENTRATION_MEASUREMENT_SERVER)
#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;

Expand All @@ -27,6 +34,7 @@ EmberAfStatus emberAfExternalAttributeReadCallback(EndpointId endpoint, ClusterI
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer,
uint16_t maxReadLength)
{

switch (clusterId)
{
#ifdef EMBER_AF_PLUGIN_AIR_QUALITY_SERVER
Expand Down Expand Up @@ -101,6 +109,21 @@ EmberAfStatus emberAfExternalAttributeWriteCallback(EndpointId endpoint, Cluster
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
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,8 @@ server cluster RvcOperationalState = 97 {
}

command Pause(): OperationalCommandResponse = 0;
command Stop(): OperationalCommandResponse = 1;
command Start(): OperationalCommandResponse = 2;
command Resume(): OperationalCommandResponse = 3;
}

Expand Down Expand Up @@ -1328,6 +1330,8 @@ endpoint 1 {
ram attribute clusterRevision default = 1;

handle command Pause;
handle command Stop;
handle command Start;
handle command Resume;
handle command OperationalCommandResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@
"code": 2,
"mfgCode": null,
"side": "server",
"type": "int16u",
"type": "vendor_id",
"included": 1,
"storageOption": "External",
"singleton": 0,
Expand Down Expand Up @@ -2789,6 +2789,22 @@
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "Stop",
"code": 1,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "Start",
"code": 2,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "Resume",
"code": 3,
Expand Down

0 comments on commit f7af441

Please sign in to comment.