How to add a command line to your FREERTOS-PLUS-CLI

Source: Internet
Author: User


Following the previous add, here is a command line to add your own. In fact, adding a command-line format is simple, is to follow the data format in the demo to add a struct, and then register in the registration function can be used.


step one: add your own structure

/* The structure that defines command line commands. A Command line command
Should is defined by declaring a const structure of this type. */
typedef struct XCOMMAND_LINE_INPUT
{
const char * const Pccommand; /* The command is causes Pxcommandinterpreter to be executed.              For example ' help '. Must is all lower case. */
const char * const pchelpstring; /* String that describes the command.  Should start with the command itself, and end with "\ r \ n". For example "help:returns a list of all the commands\r\n". */
Const Pdcommand_line_callback Pxcommandinterpreter;/* A Pointer to the callback function, that would return the output generated by the command. */
int8_t cexpectednumberofparameters; /* Commands Expect a fixed number of parameters, which May is zero. */
} cli_command_definition_t;

Refer to the actual format:
/* Structure that defines the ' task-stats ' command line command. This generates
A table that gives information on each task in the system. */
static const cli_command_definition_t Xtaskstats =
{
"Task-stats",/* the command string to type. */
"\r\ntask-stats:\r\n displays a table showing the state of each FreeRTOS task\r\n",
Prvtaskstatscommand,/* The function to run. */
0/* No parameters is expected. */
};
So according to gourd painting scoop himself write a own command "Whatbook" it! As follows:
static const cli_command_definition_t Xwhatbook =
{
"Whatbook",
"\r\nwhatbook:\r\n displays a string" I love zml! " \ r \ n ",
Prvwhatbookcommand,/* The function to run. */
0/* No parameters is expected. */
};


Step two: Implement the above data structure, and then write the callback function in the data structure.
Static basetype_t Prvwhatbookcommand (char *pcwritebuffer, size_t xwritebufferlen, const char *pccommandstring)
{
basetype_t Xreturn;
/* Remove compile time warnings about unused parameters, and check the
Write buffer is not NULL. Note-for simplicity, this example assumes the
Write buffer length is adequate, so does not check for buffer overflows. */
(void) pccommandstring;
(void) Xwritebufferlen;
Configassert (Pcwritebuffer);
/* The first time the function is called after the command have been
Entered just a header string is returned. */
sprintf (Pcwritebuffer, "I love ZML!!! \ r \ n ");
Xreturn = Pdfalse;
return xreturn;
}


Step three: Register the data structure.
Freertos_cliregistercommand (&xwhatbook);


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.



How to add a command line to your FREERTOS-PLUS-CLI


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.