Skip to content

Commit

Permalink
[cli] allow executing the factoryreset command when running sync co…
Browse files Browse the repository at this point in the history
…mmands

When running the sync command, such as `diag radio receive 10000`, the cli
doesn't allow running other commands before the sync command returns. Which
causes that the sync command may be blocked for a very long time and users
can't do anything to terminate the sync command. This will also cause the
test script to fail to run the second case after running first case fails.

This commit allows the cli to execute the `factoryreset` command when running
the sync command.
  • Loading branch information
zhanglongxia committed Jan 2, 2025
1 parent 1024a1f commit 78dcaad
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,29 +287,42 @@ template <> otError Interpreter::Process<Cmd("reset")>(Arg aArgs[])

void Interpreter::ProcessLine(char *aBuf)
{
Arg args[kMaxArgs + 1];
otError error = OT_ERROR_NONE;
static const char *const kCmdFactoryReset = "factoryreset";
Arg args[kMaxArgs + 1];
otError error = OT_ERROR_NONE;

OT_ASSERT(aBuf != nullptr);

args[0].Clear();

if (!mInternalDebugCommand)
{
// Ignore the command if another command is pending.
VerifyOrExit(!mCommandIsPending, args[0].Clear());
mCommandIsPending = true;

VerifyOrExit(StringLength(aBuf, kMaxLineLength) <= kMaxLineLength - 1, error = OT_ERROR_PARSE);
if (!mCommandIsPending)
{
mCommandIsPending = true;
VerifyOrExit(StringLength(aBuf, kMaxLineLength) <= kMaxLineLength - 1, error = OT_ERROR_PARSE);
}
else
{
VerifyOrExit(StringLength(aBuf, kMaxLineLength) <= kMaxLineLength - 1, args[0].Clear());
VerifyOrExit(ot::Utils::CmdLineParser::ParseCmd(aBuf, args, kMaxArgs) == OT_ERROR_NONE, args[0].Clear());
VerifyOrExit(((!args[0].IsEmpty()) && (args[0] == kCmdFactoryReset)), args[0].Clear());
}
}

SuccessOrExit(error = ot::Utils::CmdLineParser::ParseCmd(aBuf, args, kMaxArgs));
VerifyOrExit(!args[0].IsEmpty(), mCommandIsPending = false);
if (args[0].IsEmpty())
{
SuccessOrExit(error = ot::Utils::CmdLineParser::ParseCmd(aBuf, args, kMaxArgs));
VerifyOrExit(!args[0].IsEmpty(), mCommandIsPending = false);
}

if (!mInternalDebugCommand)
{
LogInput(args);

#if OPENTHREAD_CONFIG_DIAG_ENABLE
if (otDiagIsEnabled(GetInstancePtr()) && (args[0] != "diag") && (args[0] != "factoryreset"))
if (otDiagIsEnabled(GetInstancePtr()) && (args[0] != "diag") && (args[0] != kCmdFactoryReset))
{
OutputLine("under diagnostics mode, execute 'diag stop' before running any other commands.");
ExitNow(error = OT_ERROR_INVALID_STATE);
Expand Down

0 comments on commit 78dcaad

Please sign in to comment.