|
|
|
@ -83,7 +83,7 @@ static void prvUARTCommandConsoleTask( void *pvParameters );
|
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/* Const messages output by the command console. */
|
|
|
|
|
static const uint8_t * const pcWelcomeMessage = ( uint8_t * ) "FreeRTOS command server.\r\nType Help to view a list of registered commands.\r\n\r\n>";
|
|
|
|
|
static const uint8_t * const pcWelcomeMessage = ( uint8_t * ) "\r\n\r\nFreeRTOS command server.\r\nType Help to view a list of registered commands.\r\n\r\n>";
|
|
|
|
|
static const uint8_t * const pcEndOfOutputMessage = ( uint8_t * ) "\r\n[Press ENTER to execute the previous command again]\r\n>";
|
|
|
|
|
static const uint8_t * const pcNewLine = ( uint8_t * ) "\r\n";
|
|
|
|
|
|
|
|
|
@ -115,9 +115,6 @@ mss_uart_instance_t * const pxUART = &g_mss_uart0;
|
|
|
|
|
interface will be used at any one time. */
|
|
|
|
|
pcOutputString = FreeRTOS_CLIGetOutputBuffer();
|
|
|
|
|
|
|
|
|
|
/* Initialise the UART. */
|
|
|
|
|
MSS_UART_init( pxUART, MSS_UART_115200_BAUD, MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT );
|
|
|
|
|
|
|
|
|
|
/* Send the welcome message. */
|
|
|
|
|
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcWelcomeMessage );
|
|
|
|
|
|
|
|
|
@ -127,77 +124,78 @@ mss_uart_instance_t * const pxUART = &g_mss_uart0;
|
|
|
|
|
cRxedChar = 0;
|
|
|
|
|
|
|
|
|
|
/* Only interested in reading one character at a time. */
|
|
|
|
|
MSS_UART_get_rx( pxUART, &cRxedChar, sizeof( cRxedChar ) );
|
|
|
|
|
|
|
|
|
|
/* Echo the character back. */
|
|
|
|
|
MSS_UART_polled_tx( pxUART, &cRxedChar, sizeof( cRxedChar ) );
|
|
|
|
|
|
|
|
|
|
/* Was it the end of the line? */
|
|
|
|
|
if( cRxedChar == '\n' || cRxedChar == '\r' )
|
|
|
|
|
if( MSS_UART_get_rx( pxUART, ( uint8_t * ) &cRxedChar, sizeof( cRxedChar ) ) > 0 )
|
|
|
|
|
{
|
|
|
|
|
/* Just to space the output from the input. */
|
|
|
|
|
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcNewLine );
|
|
|
|
|
/* Echo the character back. */
|
|
|
|
|
MSS_UART_polled_tx( pxUART, ( uint8_t * ) &cRxedChar, sizeof( cRxedChar ) );
|
|
|
|
|
|
|
|
|
|
/* See if the command is empty, indicating that the last command is
|
|
|
|
|
to be executed again. */
|
|
|
|
|
if( cInputIndex == 0 )
|
|
|
|
|
/* Was it the end of the line? */
|
|
|
|
|
if( cRxedChar == '\n' || cRxedChar == '\r' )
|
|
|
|
|
{
|
|
|
|
|
/* Copy the last command back into the input string. */
|
|
|
|
|
strcpy( ( char * ) cInputString, ( char * ) cLastInputString );
|
|
|
|
|
}
|
|
|
|
|
/* Just to space the output from the input. */
|
|
|
|
|
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcNewLine );
|
|
|
|
|
|
|
|
|
|
/* Pass the received command to the command interpreter. The
|
|
|
|
|
command interpreter is called repeatedly until it returns pdFALSE
|
|
|
|
|
(indicating there is no more output) as it might generate more than
|
|
|
|
|
one string. */
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
/* Get the next output string from the command interpreter. */
|
|
|
|
|
xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );
|
|
|
|
|
/* See if the command is empty, indicating that the last command is
|
|
|
|
|
to be executed again. */
|
|
|
|
|
if( cInputIndex == 0 )
|
|
|
|
|
{
|
|
|
|
|
/* Copy the last command back into the input string. */
|
|
|
|
|
strcpy( ( char * ) cInputString, ( char * ) cLastInputString );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Write the generated string to the UART. */
|
|
|
|
|
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcOutputString );
|
|
|
|
|
vTaskDelay( 1 );
|
|
|
|
|
/* Pass the received command to the command interpreter. The
|
|
|
|
|
command interpreter is called repeatedly until it returns pdFALSE
|
|
|
|
|
(indicating there is no more output) as it might generate more than
|
|
|
|
|
one string. */
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
/* Get the next output string from the command interpreter. */
|
|
|
|
|
xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );
|
|
|
|
|
|
|
|
|
|
} while( xReturned != pdFALSE );
|
|
|
|
|
/* Write the generated string to the UART. */
|
|
|
|
|
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcOutputString );
|
|
|
|
|
vTaskDelay( 1 );
|
|
|
|
|
|
|
|
|
|
/* All the strings generated by the input command have been sent.
|
|
|
|
|
Clear the input string ready to receive the next command. Remember
|
|
|
|
|
the command that was just processed first in case it is to be
|
|
|
|
|
processed again. */
|
|
|
|
|
strcpy( ( char * ) cLastInputString, ( char * ) cInputString );
|
|
|
|
|
cInputIndex = 0;
|
|
|
|
|
memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
|
|
|
|
|
} while( xReturned != pdFALSE );
|
|
|
|
|
|
|
|
|
|
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcEndOfOutputMessage );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if( cRxedChar == '\r' )
|
|
|
|
|
{
|
|
|
|
|
/* Ignore the character. */
|
|
|
|
|
/* All the strings generated by the input command have been sent.
|
|
|
|
|
Clear the input string ready to receive the next command. Remember
|
|
|
|
|
the command that was just processed first in case it is to be
|
|
|
|
|
processed again. */
|
|
|
|
|
strcpy( ( char * ) cLastInputString, ( char * ) cInputString );
|
|
|
|
|
cInputIndex = 0;
|
|
|
|
|
memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
|
|
|
|
|
|
|
|
|
|
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcEndOfOutputMessage );
|
|
|
|
|
}
|
|
|
|
|
else if( cRxedChar == '\b' )
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Backspace was pressed. Erase the last character in the
|
|
|
|
|
string - if any. */
|
|
|
|
|
if( cInputIndex > 0 )
|
|
|
|
|
if( cRxedChar == '\r' )
|
|
|
|
|
{
|
|
|
|
|
cInputIndex--;
|
|
|
|
|
cInputString[ cInputIndex ] = '\0';
|
|
|
|
|
/* Ignore the character. */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* A character was entered. Add it to the string
|
|
|
|
|
entered so far. When a \n is entered the complete
|
|
|
|
|
string will be passed to the command interpreter. */
|
|
|
|
|
if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
|
|
|
|
|
else if( cRxedChar == '\b' )
|
|
|
|
|
{
|
|
|
|
|
/* Backspace was pressed. Erase the last character in the
|
|
|
|
|
string - if any. */
|
|
|
|
|
if( cInputIndex > 0 )
|
|
|
|
|
{
|
|
|
|
|
cInputIndex--;
|
|
|
|
|
cInputString[ cInputIndex ] = '\0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if( cInputIndex < cmdMAX_INPUT_SIZE )
|
|
|
|
|
/* A character was entered. Add it to the string
|
|
|
|
|
entered so far. When a \n is entered the complete
|
|
|
|
|
string will be passed to the command interpreter. */
|
|
|
|
|
if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
|
|
|
|
|
{
|
|
|
|
|
cInputString[ cInputIndex ] = cRxedChar;
|
|
|
|
|
cInputIndex++;
|
|
|
|
|
if( cInputIndex < cmdMAX_INPUT_SIZE )
|
|
|
|
|
{
|
|
|
|
|
cInputString[ cInputIndex ] = cRxedChar;
|
|
|
|
|
cInputIndex++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|