Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the RvcOperationalState GoHome command #31289

Merged
merged 30 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0976e3b
Added the RvcOpearationalState specific command GoHome to the XML.
hicklin Jan 4, 2024
8cff269
Regenerated files from XMLs.
hicklin Jan 4, 2024
973c150
Added a virtual method to the base operational state class that allow…
hicklin Jan 4, 2024
cfcf293
Added a mechanism by which the OperationalState cluster can call deri…
hicklin Jan 5, 2024
3caa3a4
Implemented a default implementation of the RvcOperationalState::Dele…
hicklin Jan 5, 2024
9a4a9ed
Restyled by clang-format
restyled-commits Jan 8, 2024
9e49ea3
Merge branch 'master' into RvcOpState_add_GoHome_command
hicklin Jan 8, 2024
a9bc90d
Regenerated files from XMLs after merging changes in master.
hicklin Jan 8, 2024
255c976
Merge branch 'RvcOpState_add_GoHome_command' into Handle_RvcOpState_G…
hicklin Jan 8, 2024
feed0db
Separated the RVC OpState delegate implementation in the all-clusters…
hicklin Jan 8, 2024
472aff7
Enabled the GoHome command in the all-clusters-app zap file.
hicklin Jan 8, 2024
c524379
Enabled the GoHome command in the rvc-pp zap file.
hicklin Jan 8, 2024
f4e2f2d
Restyled by clang-format
restyled-commits Jan 8, 2024
db51705
Restyled by gn
restyled-commits Jan 8, 2024
9faf98c
Merge remote-tracking branch 'origin' into RvcOpState_add_GoHome_command
mhazley Jan 9, 2024
9e95efb
Java file regen
mhazley Jan 9, 2024
35ae888
Merge branch 'RvcOpState_add_GoHome_command' into Handle_RvcOpState_G…
hicklin Jan 12, 2024
8b29518
Removed definition of the RvcOperationalState class as it was mistake…
hicklin Jan 12, 2024
e4749da
Fixed the RvcOpState delegate in the all-clusters-app since the Gener…
hicklin Jan 12, 2024
7e4048d
Added functions to get the OpratioalState and RvcOperationalState ins…
hicklin Jan 12, 2024
657348f
Merge branch 'master' into Handle_RvcOpState_GoHome_command
hicklin Jan 12, 2024
cfde2d5
Restyled by clang-format
restyled-commits Jan 12, 2024
2029c1a
Merge branch 'Handle_RvcOpState_GoHome_command' of github.com:dysonlt…
hicklin Jan 12, 2024
4e62a80
Merge branch 'master' into RvcOpState_add_GoHome_command accepting th…
hicklin Jan 17, 2024
c362f4d
Regenerated zap files.
hicklin Jan 17, 2024
08561d0
Added missing license to an all-clusters-app src file.
hicklin Jan 17, 2024
c3b929a
Restyled by clang-format
restyled-commits Jan 17, 2024
1fb5f9a
Merge branch 'RvcOpState_add_GoHome_command' into Handle_RvcOpState_G…
hicklin Jan 17, 2024
cbce399
Removed question comment.
hicklin Jan 18, 2024
e6d687d
Merge branch 'master' into Handle_RvcOpState_GoHome_command
hicklin Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3556,6 +3556,8 @@ cluster RvcOperationalState = 97 {
command Start(): OperationalCommandResponse = 2;
/** Upon receipt, the device SHALL resume its operation from the point it was at when it received the Pause command, or from the point when it was paused by means outside of this cluster (for example by manual button press). */
command Resume(): OperationalCommandResponse = 3;
/** On receipt of this command, the device SHALL start seeking the charging dock, if possible in the current state of the device. */
command GoHome(): OperationalCommandResponse = 128;
}

/** Attributes and commands for monitoring HEPA filters in a device */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,8 @@ cluster RvcOperationalState = 97 {
command Start(): OperationalCommandResponse = 2;
/** Upon receipt, the device SHALL resume its operation from the point it was at when it received the Pause command, or from the point when it was paused by means outside of this cluster (for example by manual button press). */
command Resume(): OperationalCommandResponse = 3;
/** On receipt of this command, the device SHALL start seeking the charging dock, if possible in the current state of the device. */
command GoHome(): OperationalCommandResponse = 128;
}

endpoint 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef void (RvcDevice::*HandleOpStateCommand)(Clusters::OperationalState::Gene
namespace RvcOperationalState {

// This is an application level delegate to handle operational state commands according to the specific business logic.
class RvcOperationalStateDelegate : public OperationalState::Delegate
class RvcOperationalStateDelegate : public RvcOperationalState::Delegate
{
private:
const Clusters::OperationalState::GenericOperationalState mOperationalStateList[7] = {
Expand Down
2 changes: 2 additions & 0 deletions examples/rvc-app/rvc-common/rvc-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,8 @@ cluster RvcOperationalState = 97 {
command Start(): OperationalCommandResponse = 2;
/** Upon receipt, the device SHALL resume its operation from the point it was at when it received the Pause command, or from the point when it was paused by means outside of this cluster (for example by manual button press). */
command Resume(): OperationalCommandResponse = 3;
/** On receipt of this command, the device SHALL start seeking the charging dock, if possible in the current state of the device. */
command GoHome(): OperationalCommandResponse = 128;
}

endpoint 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ void Instance::InvokeCommand(HandlerContext & handlerContext)
HandleCommand<Commands::Stop::DecodableType>(handlerContext,
[this](HandlerContext & ctx, const auto & req) { HandleStopState(ctx, req); });
break;
default:
// Should we check if the command is in the base cluster's number-space and if so respond with an error?
// Is this not possible due to the data model knowing what commands are available
hicklin marked this conversation as resolved.
Show resolved Hide resolved

ChipLogDetail(Zcl, "OperationalState: Entering handling derived cluster commands");

InvokeDerivedClusterCommand(handlerContext);
}
}

Expand Down Expand Up @@ -450,3 +457,42 @@ bool RvcOperationalState::Instance::IsDerivedClusterStateResumeCompatible(uint8_
return (aState == to_underlying(RvcOperationalState::OperationalStateEnum::kCharging) ||
aState == to_underlying(RvcOperationalState::OperationalStateEnum::kDocked));
}

// This function is called by the base operational state cluster when a command in the derived cluster number-space is received.
void RvcOperationalState::Instance::InvokeDerivedClusterCommand(chip::app::CommandHandlerInterface::HandlerContext & handlerContext)
{
ChipLogDetail(Zcl, "RvcOperationalState: InvokeDerivedClusterCommand");
switch (handlerContext.mRequestPath.mCommandId)
{
case RvcOperationalState::Commands::GoHome::Id:
ChipLogDetail(Zcl, "RvcOperationalState: Entering handling GoHome command");

CommandHandlerInterface::HandleCommand<Commands::GoHome::DecodableType>(
handlerContext, [this](HandlerContext & ctx, const auto & req) { HandleGoHomeCommand(ctx, req); });
break;
}
}

void RvcOperationalState::Instance::HandleGoHomeCommand(HandlerContext & ctx, const Commands::GoHome::DecodableType & req)
{
ChipLogDetail(Zcl, "RvcOperationalState: HandleGoHomeCommand");

GenericOperationalError err(to_underlying(OperationalState::ErrorStateEnum::kNoError));
uint8_t opState = GetCurrentOperationalState();

// Handle the case of the device being in an invalid state
if (opState == to_underlying(OperationalStateEnum::kCharging) || opState == to_underlying(OperationalStateEnum::kDocked))
{
err.Set(to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState));
}

if (err.errorStateID == 0 && opState != to_underlying(OperationalStateEnum::kSeekingCharger))
{
mDelegate->HandleGoHomeCommandCallback(err);
}

Commands::OperationalCommandResponse::Type response;
response.commandResponseState = err;

ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface
*/
virtual bool IsDerivedClusterStateResumeCompatible(uint8_t aState) { return false; };

/**
* Handles the invocation of derived cluster commands.
* If a derived cluster defines its own commands, this method SHALL be implemented by the derived cluster's class
* to handle the derived cluster's specific commands.
* @param handlerContext The command handler context containing information about the received command.
*/
virtual void InvokeDerivedClusterCommand(HandlerContext & handlerContext) { return; };

private:
Delegate * mDelegate;

Expand All @@ -191,7 +199,13 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface
uint8_t mOperationalState = 0; // assume 0 for now.
GenericOperationalError mOperationalError = to_underlying(ErrorStateEnum::kNoError);

// Inherited from CommandHandlerInterface
/**
* This method is inherited from CommandHandlerInterface.
* This reimplementation does not check that the cluster ID in the HandlerContext (the cluster the command relates to)
* matches the cluster ID of the RequestT type.
* These cluster IDs may be different in the case where a command defined in the base cluster is intended for a
* derived cluster.
*/
template <typename RequestT, typename FuncT>
void HandleCommand(HandlerContext & handlerContext, FuncT func);

Expand Down Expand Up @@ -315,6 +329,15 @@ class Delegate

namespace RvcOperationalState {

class Delegate : public OperationalState::Delegate
{
public:
virtual void HandleGoHomeCommandCallback(OperationalState::GenericOperationalError & err)
{
err.Set(to_underlying(OperationalState::ErrorStateEnum::kUnknownEnumValue));
};
};

class Instance : public OperationalState::Instance
{
public:
Expand All @@ -327,8 +350,8 @@ class Instance : public OperationalState::Instance
* Note: the caller must ensure that the delegate lives throughout the instance's lifetime.
* @param aEndpointId The endpoint on which this cluster exists. This must match the zap configuration.
*/
Instance(OperationalState::Delegate * aDelegate, EndpointId aEndpointId) :
OperationalState::Instance(aDelegate, aEndpointId, Id)
Instance(Delegate * aDelegate, EndpointId aEndpointId) :
OperationalState::Instance(aDelegate, aEndpointId, Id), mDelegate(aDelegate)
{}

protected:
Expand All @@ -347,6 +370,20 @@ class Instance : public OperationalState::Instance
* @return true if aState is pause-compatible, false otherwise.
*/
bool IsDerivedClusterStateResumeCompatible(uint8_t aState) override;

/**
* Handles the invocation of RvcOperationalState specific commands
* @param handlerContext The command handler context containing information about the received command.
*/
void InvokeDerivedClusterCommand(HandlerContext & handlerContext) override;

private:
Delegate * mDelegate;

/**
* Handle Command: GoHome
*/
void HandleGoHomeCommand(HandlerContext & ctx, const Commands::GoHome::DecodableType & req);
};

} // namespace RvcOperationalState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ both values from this cluster and from the base cluster.
<arg name="CommandResponseState" type="ErrorStateStruct"/>
</command>

<command source="client" code="0x80" name="GoHome" response="OperationalCommandResponse" optional="true">
<description>On receipt of this command, the device SHALL start seeking the charging dock, if possible in the current state of the device.</description>
</command>

<event side="server" code="0x00" priority="critical" name="OperationalError" optional="false">
<description>OperationalError</description>
<field id="0" name="ErrorState" type="ErrorStateStruct" />
Expand Down
2 changes: 2 additions & 0 deletions src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -3892,6 +3892,8 @@ cluster RvcOperationalState = 97 {
command Start(): OperationalCommandResponse = 2;
/** Upon receipt, the device SHALL resume its operation from the point it was at when it received the Pause command, or from the point when it was paused by means outside of this cluster (for example by manual button press). */
command Resume(): OperationalCommandResponse = 3;
/** On receipt of this command, the device SHALL start seeking the charging dock, if possible in the current state of the device. */
command GoHome(): OperationalCommandResponse = 128;
}

/** Attributes and commands for monitoring HEPA filters in a device */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26323,6 +26323,32 @@ public void onResponse(StructType invokeStructValue) {
}}, commandId, value, timedInvokeTimeoutMs);
}

public void goHome(OperationalCommandResponseCallback callback) {
goHome(callback, 0);
}

public void goHome(OperationalCommandResponseCallback callback, int timedInvokeTimeoutMs) {
final long commandId = 128L;

ArrayList<StructElement> elements = new ArrayList<>();
StructType value = new StructType(elements);
invoke(new InvokeCallbackImpl(callback) {
@Override
public void onResponse(StructType invokeStructValue) {
final long commandResponseStateFieldID = 0L;
ChipStructs.RvcOperationalStateClusterErrorStateStruct commandResponseState = null;
for (StructElement element: invokeStructValue.value()) {
if (element.contextTagNum() == commandResponseStateFieldID) {
if (element.value(BaseTLVType.class).type() == TLVType.Struct) {
StructType castingValue = element.value(StructType.class);
commandResponseState = ChipStructs.RvcOperationalStateClusterErrorStateStruct.decodeTlv(castingValue);
}
}
}
callback.onSuccess(commandResponseState);
}}, commandId, value, timedInvokeTimeoutMs);
}

public interface OperationalCommandResponseCallback extends BaseClusterCallback {
void onSuccess(ChipStructs.RvcOperationalStateClusterErrorStateStruct commandResponseState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8509,7 +8509,8 @@ public enum Command {
Pause(0L),
Stop(1L),
Start(2L),
Resume(3L),;
Resume(3L),
GoHome(128L),;
private final long id;
Command(long id) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22781,6 +22781,18 @@ public Map<String, Map<String, InteractionInfo>> getCommandMap() {
);
rvcOperationalStateClusterInteractionInfoMap.put("resume", rvcOperationalStateresumeInteractionInfo);

Map<String, CommandParameterInfo> rvcOperationalStategoHomeCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
InteractionInfo rvcOperationalStategoHomeInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.RvcOperationalStateCluster) cluster)
.goHome((ChipClusters.RvcOperationalStateCluster.OperationalCommandResponseCallback) callback
);
},
() -> new DelegatedRvcOperationalStateClusterOperationalCommandResponseCallback(),
rvcOperationalStategoHomeCommandParams
);
rvcOperationalStateClusterInteractionInfoMap.put("goHome", rvcOperationalStategoHomeInteractionInfo);

commandMap.put("rvcOperationalState", rvcOperationalStateClusterInteractionInfoMap);

Map<String, InteractionInfo> hepaFilterMonitoringClusterInteractionInfoMap = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,48 @@ class RvcOperationalStateCluster(
return OperationalCommandResponse(commandResponseState_decoded)
}

suspend fun goHome(timedInvokeTimeout: Duration? = null): OperationalCommandResponse {
val commandId: UInt = 128u

val tlvWriter = TlvWriter()
tlvWriter.startStructure(AnonymousTag)
tlvWriter.endStructure()

val request: InvokeRequest =
InvokeRequest(
CommandPath(endpointId, clusterId = CLUSTER_ID, commandId),
tlvPayload = tlvWriter.getEncoded(),
timedRequest = timedInvokeTimeout
)

val response: InvokeResponse = controller.invoke(request)
logger.log(Level.FINE, "Invoke command succeeded: ${response}")

val tlvReader = TlvReader(response.payload)
tlvReader.enterStructure(AnonymousTag)
val TAG_COMMAND_RESPONSE_STATE: Int = 0
var commandResponseState_decoded: RvcOperationalStateClusterErrorStateStruct? = null

while (!tlvReader.isEndOfContainer()) {
val tag = tlvReader.peekElement().tag

if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {
commandResponseState_decoded =
RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)
} else {
tlvReader.skipElement()
}
}

if (commandResponseState_decoded == null) {
throw IllegalStateException("commandResponseState not found in TLV")
}

tlvReader.exitContainer()

return OperationalCommandResponse(commandResponseState_decoded)
}

suspend fun readPhaseListAttribute(): PhaseListAttribute {
val ATTRIBUTE_ID: UInt = 0u

Expand Down
6 changes: 6 additions & 0 deletions src/controller/python/chip/clusters/CHIPClusters.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/controller/python/chip/clusters/Objects.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading