diff --git a/src/cli/cli_uart.cpp b/src/cli/cli_uart.cpp index 9dc894b80..9818a9d5d 100644 --- a/src/cli/cli_uart.cpp +++ b/src/cli/cli_uart.cpp @@ -126,24 +126,11 @@ extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength) void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength) { - static const char sCommandPrompt[] = {'>', ' '}; - -#if OPENTHREAD_CONFIG_UART_CLI_RAW - if (aBufLength > 0) - { - memcpy(mRxBuffer + mRxLength, aBuf, aBufLength); - mRxLength += aBufLength; - } - - if (aBuf[aBufLength - 1] == '\r' || aBuf[aBufLength - 1] == '\n') - { - mRxBuffer[mRxLength] = '\0'; - ProcessCommand(); - Output(sCommandPrompt, sizeof(sCommandPrompt)); - } -#else // OPENTHREAD_CONFIG_UART_CLI_RAW +#if !OPENTHREAD_CONFIG_UART_CLI_RAW static const char sEraseString[] = {'\b', ' ', '\b'}; static const char CRNL[] = {'\r', '\n'}; +#endif + static const char sCommandPrompt[] = {'>', ' '}; const uint8_t * end; end = aBuf + aBufLength; @@ -154,8 +141,9 @@ void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength) { case '\r': case '\n': +#if !OPENTHREAD_CONFIG_UART_CLI_RAW Output(CRNL, sizeof(CRNL)); - +#endif if (mRxLength > 0) { mRxBuffer[mRxLength] = '\0'; @@ -166,6 +154,7 @@ void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength) break; +#if !OPENTHREAD_CONFIG_UART_CLI_RAW #if OPENTHREAD_POSIX case 0x04: // ASCII for Ctrl-D @@ -182,30 +171,27 @@ void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength) } break; +#endif // !OPENTHREAD_CONFIG_UART_CLI_RAW default: if (mRxLength < kRxBufferSize - 1) { +#if !OPENTHREAD_CONFIG_UART_CLI_RAW Output(reinterpret_cast(aBuf), 1); +#endif mRxBuffer[mRxLength++] = static_cast(*aBuf); } break; } } -#endif // OPENTHREAD_CONFIG_UART_CLI_RAW } otError Uart::ProcessCommand(void) { otError error = OT_ERROR_NONE; - if (mRxBuffer[mRxLength - 1] == '\n') - { - mRxBuffer[--mRxLength] = '\0'; - } - - if (mRxBuffer[mRxLength - 1] == '\r') + while (mRxBuffer[mRxLength - 1] == '\n' || mRxBuffer[mRxLength - 1] == '\r') { mRxBuffer[--mRxLength] = '\0'; } diff --git a/src/posix/Makefile-posix b/src/posix/Makefile-posix index 72aabc038..b63ca4036 100644 --- a/src/posix/Makefile-posix +++ b/src/posix/Makefile-posix @@ -62,7 +62,6 @@ SNTP_CLIENT ?= 1 UDP_FORWARD ?= 1 COMMONCFLAGS := \ - -DOPENTHREAD_CONFIG_UART_CLI_RAW=1 \ -g \ $(NULL) diff --git a/src/posix/platform/openthread-core-posix-config.h b/src/posix/platform/openthread-core-posix-config.h index 37480e709..d22ca98b0 100644 --- a/src/posix/platform/openthread-core-posix-config.h +++ b/src/posix/platform/openthread-core-posix-config.h @@ -52,4 +52,6 @@ #define OPENTHREAD_CONFIG_ENABLE_SLAAC 1 #endif +#define OPENTHREAD_CONFIG_UART_CLI_RAW 1 + #endif // OPENTHREAD_CORE_POSIX_CONFIG_H_