mirror of
https://github.com/espressif/openthread.git
synced 2026-08-17 07:59:51 +00:00
[cli] disallow concurrent commands (#6695)
This commit disallows concurrent commands. With this commit, the CLI only execute a new command after it complete the previous command. CLI can also prompt properly after the command execution is done. Other fixes and enhancements: - Fixes premature command prompt - Add ping async command for ping in async mode: output Done immediately but print ping responses later on. - Fixes networkdiagnostic get outputs multiple Done by always waiting for 5 seconds.
This commit is contained in:
@@ -134,9 +134,9 @@ static otError ProcessCommand(void);
|
||||
|
||||
static void ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength)
|
||||
{
|
||||
static const char sEraseString[] = {'\b', ' ', '\b'};
|
||||
static const char CRNL[] = {'\r', '\n'};
|
||||
static const char sCommandPrompt[] = {'>', ' '};
|
||||
static const char sEraseString[] = {'\b', ' ', '\b'};
|
||||
static const char CRNL[] = {'\r', '\n'};
|
||||
static uint8_t sLastChar = '\0';
|
||||
const uint8_t * end;
|
||||
|
||||
end = aBuf + aBufLength;
|
||||
@@ -145,17 +145,18 @@ static void ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength)
|
||||
{
|
||||
switch (*aBuf)
|
||||
{
|
||||
case '\r':
|
||||
case '\n':
|
||||
Output(CRNL, sizeof(CRNL));
|
||||
if (sRxLength > 0)
|
||||
if (sLastChar == '\r')
|
||||
{
|
||||
sRxBuffer[sRxLength] = '\0';
|
||||
IgnoreError(ProcessCommand());
|
||||
break;
|
||||
}
|
||||
|
||||
Output(sCommandPrompt, sizeof(sCommandPrompt));
|
||||
OT_FALL_THROUGH;
|
||||
|
||||
case '\r':
|
||||
Output(CRNL, sizeof(CRNL));
|
||||
sRxBuffer[sRxLength] = '\0';
|
||||
IgnoreError(ProcessCommand());
|
||||
break;
|
||||
|
||||
#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||
@@ -187,6 +188,8 @@ static void ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength)
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
sLastChar = *aBuf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,16 +197,12 @@ static otError ProcessCommand(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
while (sRxBuffer[sRxLength - 1] == '\n' || sRxBuffer[sRxLength - 1] == '\r')
|
||||
while (sRxLength > 0 && (sRxBuffer[sRxLength - 1] == '\n' || sRxBuffer[sRxLength - 1] == '\r'))
|
||||
{
|
||||
sRxBuffer[--sRxLength] = '\0';
|
||||
}
|
||||
|
||||
if (sRxLength > 0)
|
||||
{
|
||||
otCliInputLine(sRxBuffer);
|
||||
}
|
||||
|
||||
otCliInputLine(sRxBuffer);
|
||||
sRxLength = 0;
|
||||
|
||||
return error;
|
||||
|
||||
Reference in New Issue
Block a user