/* Was it the end of the line? */ if( c == '\n' || c == '\r' ) { printf("\r\n"); fflush(stdout);
/* See if the command is empty, indicating that the last command is to be executed again. */ if( index == 0 ) { /* Copy the last command back into the input string. */ strcpy( inbuff, lastinbuff ); }
/* 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. */ ret = FreeRTOS_CLIProcessCommand( inbuff, outbuff, configCOMMAND_INT_MAX_OUTPUT_SIZE );
/* Write the generated string to the UART. */ printf("%s",outbuff); fflush(stdout);
} while( ret != pdFALSE );
/* 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( lastinbuff, inbuff ); index = 0; memset( inbuff, 0x00, 64 );
printf("\r\n>"); fflush(stdout);
} else { if( c == '\r' ) { /* Ignore the character. */ } elseif( ( c == '\b' ) || ( c == 0x7f ) )//del { /* Backspace was pressed. Erase the last character in the string - if any. */ if( index > 0 ) { index--; inbuff[ index ] = '\0'; } } 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( ( c >= ' ' ) && ( c <= '~' ) ) { if( index < 64 ) { inbuff[ index ] = c; index++; } } } }