A very simple template of a super loop which is used to process events in an embedded system.
farly7 / embedded-cli Goto Github PK
View Code? Open in Web Editor NEWA simple command-line interface for use in embedded systems.
License: MIT License
A simple command-line interface for use in embedded systems.
License: MIT License
let CMD_TERMINATOR can be define externally instead of modify directly cli_defs.h
and add a newline to clear warning:
deps\embedded-cli\cli.h(91): warning: #1-D: last line of file ends without a newline
In the example code, the command table needs to be divided by the command size
cli.cmd_cnt = sizeof(cmd_tbl)/sizeof(cmd_t);
The documentation says to call the cli_put() function "within the devices interrupt handler", and "periodically call the cli_process() function", presumably from outside that interrupt handler. That being the case, shouldn't all variables written by cli_put() be marked as volatile?
From example:
.cmd_cnt = sizeof(cmds)
But this gives the size of entire cmds structure, not the number of commands. I guess it should be something like
.cmd_cnt = sizeof(cmds) / sizeof(cmd_t)
Hello,
I am using your library with a NUCLEO-G071RB dev kit and when I use a backspace, the cli buffer is not properly decremented.
For example :
echo on ->backspace -> n will not yield "echo on" but "echo on\127n"
If I add 0x7F (delete ascii char) to the switch case in cli_put(), it works properly.
cli_status_t cli_put(cli_t *cli, char c)
{
switch(c) {
case CMD_TERMINATOR:
if(!cmd_pending) {
*buf_ptr = '\0'; /* Terminate the msg and reset the msg ptr. */
strcpy(cmd_buf, buf); /* Copy string to command buffer for processing. */
cmd_pending = 1;
buf_ptr = buf; /* Reset buf_ptr to beginning. */
}
break;
case '\b':
case 0x7F: // <- If I add this, backspace works properly
/* Backspace. Delete character. */
if(buf_ptr > buf)
buf_ptr--;
break;
default:
/* Normal character received, add to buffer. */
if((buf_ptr - buf) < MAX_BUF_SIZE)
*buf_ptr++ = c;
else
return CLI_E_BUF_FULL;
break;
}
return CLI_OK;
}
I am not sure in which case the delete ascii would be treated differently, so I leave it up to you to add this fix or not.
If cli_process()
is called periodically and it is called while the command is not complete, the message CMD: Command not recognised
appears.
Is not more convenient to modify cli_put
so that it calls cli_process()
when CMD_TERMINATOR
is received?
case '\r':
*buf_ptr = '\0'; /* Terminate the msg and reset the msg ptr. */
strcpy(cmd_buf, buf); /* Copy string to command buffer for processing. */
buf_ptr = buf; /* Reset buf_ptr to beginning. */
cli_print(cli, cli_prompt); /* Print the CLI prompt to the user. */
cli_process(cli);
break;
In the same manner, in the case statement it would be more convenient to use CMD_TERMINATOR
instead of '\r'
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.