[Country EMBED strategy] [057] [Serial console Setup]

Source: Internet
Author: User

Console classification

1. Menu-based console, select menu to execute command

2. Analytic console to execute commands by entering commands

printf (), scanf () function porting

1. function with variable parameter

2. Printing information to the serial port

3. The key is to convert the argument to a string, and the correlation function needs to be ported from the Linux kernel or the standard C library

Va_list args;

Va_start (args, FMT);

vsprintf (buf, FMT, args);

Va_end (args);

/********************************************************************* Name: puts* parameter: str output String * Return: I output character number * Function: output String * *   /int puts (const char *str) {int i; The output character count for (i = 0; Str[i]! = ' \ "; i++) {//If the output character is a terminator, end the output string PUTC (Str[i]);} return i;} /********************************************************************* Name: gets* parameter: str input string * Return: I input character number * Function: input String * * /int gets (char *str) {//standard C returned as char *   The input string pointer of type char ch;     input character int i; Enter the number of characters ch = getc_echo (); for (i = 0; ch! = ' \ r '; i++) {///if the input character is carriage return, end the input string str[i] = Ch;ch = Getc_echo ();}   str[i++] = ' \ r ';   Add carriage return str[i++] = ' \ n ';     Add newline str[i] = ' + '; Add terminator return i;} /********************************************************************* Name: printf* parameter: Format formatted string * Return: num OUTPUT characters * function : Formatted output string *********************************************************************/int printf (const char *format, ...) {ChaR Buffer[bufsize];           string caching va_list args;                parameter list int num;           The number of output characters//conversion parameters are string Va_start (args, format);   Read parameter vsprintf (buffer, format, args);                     The conversion parameter is String va_end (args); End conversion//output string to Serial num = puts (buffer); return num;} /********************************************************************* Name: scanf* parameter: Format formatted input string * return: num input character number * Function: Format input string *********************************************************************/int scanf (const char *format, ...                } {//Standard C Returns whether the success flag of type int is the int num;   Enter the number of characters Char buffer[bufsize];           string caching va_list args;          parameter list//input string to serial num = gets (buffer);//convert string to parameter Va_start (args, format);   Read parameter vsscanf (buffer, format, args);                    The conversion string is the parameter va_end (args); End convert return num;}

[Country EMBED strategy] [057] [Serial console Setup]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.