Skip to content

Commit

Permalink
[cli] add targetpower command support (openthread#11321)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglongxia authored Mar 5, 2025
1 parent b1ca77a commit a470e8b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Done
- [sntp](#sntp-query-sntp-server-ip-sntp-server-port)
- [state](#state)
- [srp](README_SRP.md)
- [targetpower](#targetpower-channel-targetpower)
- [tcat](README_TCAT.md)
- [tcp](README_TCP.md)
- [test](#test-tmforiginfilter-enabledisable)
Expand Down Expand Up @@ -3809,6 +3810,18 @@ Try to switch to state `detached`, `child`, `router`.
Done
```
### targetpower \<channel\> \<targetpower\>
Set the target power.
- `channel` : Thread channel.
- `targetpower` : The target power in the unit of 0.01dBm.
```bash
> targetpower 12 1000
Done
```
### test tmforiginfilter \[enable|disable\]
Enable/disable filter that drops UDP messages sent to the TMF port from untrusted origin. Also get the current state of the filter if no argument is specified.
Expand Down
30 changes: 30 additions & 0 deletions src/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6698,6 +6698,35 @@ template <> otError Interpreter::Process<Cmd("txpower")>(Arg aArgs[])
return error;
}

/**
* @cli targetpower (set)
* @code
* targetpower 12 2000
* Done
* @endcode
* @cparam targetpower @ca{channel} @ca{targetpower}
* @par
* Sets the target power in the unit of 0.01 dBm.
* @sa otPlatRadioSetChannelTargetPower
*/
template <> otError Interpreter::Process<Cmd("targetpower")>(Arg aArgs[])
{
otError error = OT_ERROR_NONE;
uint8_t channel;
int16_t targetPower;
uint32_t channelMask;

SuccessOrExit(error = aArgs[0].ParseAsUint8(channel));
channelMask = otLinkGetSupportedChannelMask(GetInstancePtr());
VerifyOrExit((1 << channel) & channelMask, error = OT_ERROR_INVALID_ARGS);
SuccessOrExit(error = aArgs[1].ParseAsInt16(targetPower));

error = otPlatRadioSetChannelTargetPower(GetInstancePtr(), channel, targetPower);

exit:
return error;
}

/**
* @cli debug
* @par
Expand Down Expand Up @@ -8338,6 +8367,7 @@ otError Interpreter::ProcessCommand(Arg aArgs[])
CmdEntry("srp"),
#endif
CmdEntry("state"),
CmdEntry("targetpower"),
#if OPENTHREAD_CONFIG_BLE_TCAT_ENABLE && OPENTHREAD_CONFIG_CLI_BLE_SECURE_ENABLE
CmdEntry("tcat"),
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/core/radio/radio_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,5 @@ extern "C" OT_TOOL_WEAK void otPlatRadioSetRxOnWhenIdle(otInstance *aInstance, b
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aEnable);
}

OT_TOOL_WEAK otError otPlatRadioSetChannelTargetPower(otInstance *, uint8_t, int16_t) { return kErrorNotImplemented; }
9 changes: 9 additions & 0 deletions tests/scripts/expect/cli-misc.exp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ send "txpower\n"
expect -- "-10 dBm"
expect_line "Done"

send "targetpower 12 1000\n"
expect_line "Done"

send "targetpower 12 -1000\n"
expect_line "Done"

send "targetpower 10 1000\n"
expect_line "Error 7: InvalidArgs"

send "thread version\n"
expect_line "Done"

Expand Down

0 comments on commit a470e8b

Please sign in to comment.