Skip to content

Commit

Permalink
Handle the RvcOperationalState GoHome command (#31289)
Browse files Browse the repository at this point in the history
* Added the RvcOpearationalState specific command GoHome to the XML.

* Regenerated files from XMLs.

* Added a virtual method to the base operational state class that allows derived clusters to handle the invocation of their specific commands. This method is called by the operational state cluster if the received command is not a known base cluster command.

* Added a mechanism by which the OperationalState cluster can call derived cluster methods to handle commands intended for them.

* Implemented a default implementation of the RvcOperationalState::Delegate's HandleGoHomeCommandCallback method since the GoHome command is optional. Use the correct delegate type of in the rvc-app example.

* Restyled by clang-format

* Regenerated files from XMLs after merging changes in master.

* Separated the RVC OpState delegate implementation in the all-clusters-app and implemented its GoHome command handle.

* Enabled the GoHome command in the all-clusters-app zap file.

* Enabled the GoHome command in the rvc-pp zap file.

* Restyled by clang-format

* Restyled by gn

* Java file regen

* Removed definition of the RvcOperationalState class as it was mistake in the previous merge.

* Fixed the RvcOpState delegate in the all-clusters-app since the GenericOperationalPhase class was removed when main was merget.

* Added functions to get the OpratioalState and RvcOperationalState instances in the all-clusters-app. Replaced the custom implementation of the OperationalState and RvcOperationalState delegates for the ameba platform with the common implementations.

* Restyled by clang-format

* Regenerated zap files.

* Added missing license to an all-clusters-app src file.

* Restyled by clang-format

* Removed question comment.

---------

Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Matthew Hazley <Matthew.Hazley@dyson.com>
  • Loading branch information
3 people authored Jan 18, 2024
1 parent 1e6e62b commit 4ac4a7f
Show file tree
Hide file tree
Showing 15 changed files with 183 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7789,6 +7789,7 @@ endpoint 1 {
handle command Pause;
handle command Resume;
handle command OperationalCommandResponse;
handle command GoHome;
}

server cluster ScenesManagement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11262,6 +11262,14 @@
"source": "server",
"isIncoming": 0,
"isEnabled": 1
},
{
"name": "GoHome",
"code": 128,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
}
],
"attributes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,38 +111,11 @@ class OperationalStateDelegate : public GenericOperationalStateDelegateImpl
}
};

void Shutdown();

} // namespace OperationalState

namespace RvcOperationalState {

// This is an application level delegate to handle operational state commands according to the specific business logic.
class RvcOperationalStateDelegate : public OperationalState::GenericOperationalStateDelegateImpl
{
private:
const OperationalState::GenericOperationalState rvcOpStateList[7] = {
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kError)),
OperationalState::GenericOperationalState(
to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kSeekingCharger)),
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kCharging)),
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kDocked)),
};

public:
RvcOperationalStateDelegate()
{
GenericOperationalStateDelegateImpl::mOperationalStateList =
Span<const OperationalState::GenericOperationalState>(rvcOpStateList);
}
};
Instance * GetOperationalStateInstance();

void Shutdown();

} // namespace RvcOperationalState
} // namespace OperationalState
} // namespace Clusters
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,34 @@
#include <app/util/af-enums.h>
#include <protocols/interaction_model/StatusCode.h>

void getOperationalStateSet(u8 state);

namespace chip {
namespace app {
namespace Clusters {

namespace OperationalState {

Instance * GetOperationalStateInstance();
namespace RvcOperationalState {

// This is an application level delegate to handle operational state commands according to the specific business logic.
class GenericOperationalStateDelegateImpl : public Delegate
class RvcOperationalStateDelegate : public Delegate
{
private:
const Clusters::OperationalState::GenericOperationalState rvcOpStateList[7] = {
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kError)),
OperationalState::GenericOperationalState(
to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kSeekingCharger)),
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kCharging)),
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kDocked)),
};

Span<const OperationalState::GenericOperationalState> mOperationalStateList =
Span<const OperationalState::GenericOperationalState>(rvcOpStateList);
Span<const CharSpan> mOperationalPhaseList;

public:
RvcOperationalStateDelegate() {}

/**
* Get the countdown time. This attribute is not used in this application.
* @return The current countdown time.
Expand All @@ -51,19 +65,15 @@ class GenericOperationalStateDelegateImpl : public Delegate
* @param index The index of the state, with 0 representing the first state.
* @param operationalState The GenericOperationalState is filled.
*/
CHIP_ERROR GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState) override;
CHIP_ERROR GetOperationalStateAtIndex(size_t index, OperationalState::GenericOperationalState & operationalState) override;

/**
* Fills in the provided MutableCharSpan with the phase at index `index` if there is one,
* Fills in the provided GenericOperationalPhase with the phase at index `index` if there is one,
* or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of phases.
*
* If CHIP_ERROR_NOT_FOUND is returned for index 0, that indicates that the PhaseList attribute is null
* (there are no phases defined at all).
*
* Note: This is used by the SDK to populate the phase list attribute. If the contents of this list changes, the
* device SHALL call the Instance's ReportPhaseListChange method to report that this attribute has changed.
* @param index The index of the phase, with 0 representing the first phase.
* @param operationalPhase The MutableCharSpan is filled.
* @param operationalPhase The GenericOperationalPhase is filled.
*/
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase) override;

Expand All @@ -72,82 +82,37 @@ class GenericOperationalStateDelegateImpl : public Delegate
* Handle Command Callback in application: Pause
* @param[out] get operational error after callback.
*/
void HandlePauseStateCallback(GenericOperationalError & err) override;
void HandlePauseStateCallback(OperationalState::GenericOperationalError & err) override;

/**
* Handle Command Callback in application: Resume
* @param[out] get operational error after callback.
*/
void HandleResumeStateCallback(GenericOperationalError & err) override;
void HandleResumeStateCallback(OperationalState::GenericOperationalError & err) override;

/**
* Handle Command Callback in application: Start
* @param[out] get operational error after callback.
*/
void HandleStartStateCallback(GenericOperationalError & err) override;
void HandleStartStateCallback(OperationalState::GenericOperationalError & err) override;

/**
* Handle Command Callback in application: Stop
* @param[out] get operational error after callback.
*/
void HandleStopStateCallback(GenericOperationalError & err) override;

protected:
Span<const GenericOperationalState> mOperationalStateList;
Span<const CharSpan> mOperationalPhaseList;
};

// This is an application level delegate to handle operational state commands according to the specific business logic.
class OperationalStateDelegate : public GenericOperationalStateDelegateImpl
{
private:
const GenericOperationalState opStateList[4] = {
GenericOperationalState(to_underlying(OperationalStateEnum::kStopped)),
GenericOperationalState(to_underlying(OperationalStateEnum::kRunning)),
GenericOperationalState(to_underlying(OperationalStateEnum::kPaused)),
GenericOperationalState(to_underlying(OperationalStateEnum::kError)),
};
void HandleStopStateCallback(OperationalState::GenericOperationalError & err) override;

public:
OperationalStateDelegate()
{
GenericOperationalStateDelegateImpl::mOperationalStateList = Span<const GenericOperationalState>(opStateList);
}
/**
* Handle the GoHome command.
* @param err
*/
void HandleGoHomeCommandCallback(OperationalState::GenericOperationalError & err) override;
};

void Shutdown();

} // namespace OperationalState

namespace RvcOperationalState {

Instance * GetRvcOperationalStateInstance();

// This is an application level delegate to handle operational state commands according to the specific business logic.
class RvcOperationalStateDelegate : public OperationalState::GenericOperationalStateDelegateImpl
{
private:
const OperationalState::GenericOperationalState rvcOpStateList[7] = {
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kError)),
OperationalState::GenericOperationalState(
to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kSeekingCharger)),
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kCharging)),
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kDocked)),
};

public:
RvcOperationalStateDelegate()
{
GenericOperationalStateDelegateImpl::mOperationalStateList =
Span<const OperationalState::GenericOperationalState>(rvcOpStateList);
}
};

void Shutdown();

} // namespace RvcOperationalState
} // namespace Clusters
} // namespace app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ void GenericOperationalStateDelegateImpl::HandleStopStateCallback(GenericOperati
static OperationalState::Instance * gOperationalStateInstance = nullptr;
static OperationalStateDelegate * gOperationalStateDelegate = nullptr;

OperationalState::Instance * OperationalState::GetOperationalStateInstance()
{
return gOperationalStateInstance;
}

void OperationalState::Shutdown()
{
if (gOperationalStateInstance != nullptr)
Expand Down Expand Up @@ -130,36 +135,3 @@ void emberAfOperationalStateClusterInitCallback(chip::EndpointId endpointId)

gOperationalStateInstance->Init();
}

// Init RVC Operational State cluster

static OperationalState::Instance * gRvcOperationalStateInstance = nullptr;
static RvcOperationalStateDelegate * gRvcOperationalStateDelegate = nullptr;

void RvcOperationalState::Shutdown()
{
if (gRvcOperationalStateInstance != nullptr)
{
delete gRvcOperationalStateInstance;
gRvcOperationalStateInstance = nullptr;
}
if (gRvcOperationalStateDelegate != nullptr)
{
delete gRvcOperationalStateDelegate;
gRvcOperationalStateDelegate = nullptr;
}
}

void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gRvcOperationalStateInstance == nullptr && gRvcOperationalStateDelegate == nullptr);

gRvcOperationalStateDelegate = new RvcOperationalStateDelegate;
EndpointId operationalStateEndpoint = 0x01;
gRvcOperationalStateInstance = new RvcOperationalState::Instance(gRvcOperationalStateDelegate, operationalStateEndpoint);

gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped));

gRvcOperationalStateInstance->Init();
}
Loading

0 comments on commit 4ac4a7f

Please sign in to comment.