Skip to content

Commit

Permalink
[cli] add docs for detach command
Browse files Browse the repository at this point in the history
  • Loading branch information
abtink committed Jul 19, 2023
1 parent 5340a6e commit 6eba50c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
20 changes: 20 additions & 0 deletions src/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Done
- [csl](#csl)
- [dataset](README_DATASET.md)
- [delaytimermin](#delaytimermin)
- [detach](#detach)
- [deviceprops](#deviceprops)
- [diag](#diag)
- [discover](#discover-channel)
Expand Down Expand Up @@ -1061,6 +1062,25 @@ Set the minimal delay timer (in seconds).
Done
```
### detach
Start the graceful detach process by first notifying other nodes (sending Address Release if acting as a router, or setting Child Timeout value to zero on parent if acting as a child) and then stopping Thread protocol operation.
```bash
> detach
Finished detaching
Done
```
### detach async
Start the graceful detach process similar to `detach` command without blocking and waiting for the callback indicating that detach is finished.
```bash
> detach async
Done
```
### deviceprops
Get the current device properties.
Expand Down
47 changes: 34 additions & 13 deletions src/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2443,25 +2443,57 @@ template <> otError Interpreter::Process<Cmd("delaytimermin")>(Arg aArgs[])
}
#endif

/**
* @cli detach
* @code
* detach
* Finished detaching
* Done
* @endcode
* @par
* Start the graceful detach process by first notifying other nodes (sending Address Release if acting as a router, or
* setting Child Timeout value to zero on parent if acting as a child) and then stopping Thread protocol operation.
* @sa otThreadDetachGracefully
*/
template <> otError Interpreter::Process<Cmd("detach")>(Arg aArgs[])
{
otError error = OT_ERROR_NONE;

/**
* @cli detach async
* @code
* detach async
* Done
* @endcode
* @par
* Start the graceful detach process similar to `detach` command without blocking and waiting for the callback
* indicating that detach is finished.
*/
if (aArgs[0] == "async")
{
SuccessOrExit(error = otThreadDetachGracefully(GetInstancePtr(), nullptr, nullptr));
}
else
{
SuccessOrExit(error =
otThreadDetachGracefully(GetInstancePtr(), &Interpreter::HandleDetachGracefullyResult, this));
SuccessOrExit(error = otThreadDetachGracefully(GetInstancePtr(), HandleDetachGracefullyResult, this));
error = OT_ERROR_PENDING;
}

exit:
return error;
}

void Interpreter::HandleDetachGracefullyResult(void *aContext)
{
static_cast<Interpreter *>(aContext)->HandleDetachGracefullyResult();
}

void Interpreter::HandleDetachGracefullyResult(void)
{
OutputLine("Finished detaching");
OutputResult(OT_ERROR_NONE);
}

/**
* @cli discover
* @code
Expand Down Expand Up @@ -7749,17 +7781,6 @@ void Interpreter::OutputChildTableEntry(uint8_t aIndentSize, const otNetworkDiag
}
#endif // OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE

void Interpreter::HandleDetachGracefullyResult(void *aContext)
{
static_cast<Interpreter *>(aContext)->HandleDetachGracefullyResult();
}

void Interpreter::HandleDetachGracefullyResult(void)
{
OutputLine("Finished detaching");
OutputResult(OT_ERROR_NONE);
}

#if OPENTHREAD_FTD
void Interpreter::HandleDiscoveryRequest(const otThreadDiscoveryRequestInfo *aInfo, void *aContext)
{
Expand Down

0 comments on commit 6eba50c

Please sign in to comment.