funbiscuit / embedded-cli Goto Github PK
View Code? Open in Web Editor NEWSingle-header CLI with history and autocompletion for embedded systems (like Arduino or STM32)
License: MIT License
Single-header CLI with history and autocompletion for embedded systems (like Arduino or STM32)
License: MIT License
There appears to be a typo in the released v0.1.3 .h file
See : https://github.com/funbiscuit/embedded-cli/releases/tag/v0.1.3
Line 49,
#elif UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFu
should probably be:
#elif UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF
right ?
Currently on any user input something is called - either registered binding or general onCommand
when given command is not registered. The only exception is if input empty (user pressed "enter" multiple times). In this case nothing is called.
Add extra optional command binding - onEmpty
which will be called when entered command is empty (or contains only whitespace).
Initial request by @Jeff-RavenLabs in #18
Add generation of single-header distribution that will be easier to integrate into projects.
In generated embedded_cli.h
file, #endif //EMBEDDED_CLI_H
should be in the end of the file to prevent redefinitions of implementations in case where header is included multiple times (e.g. via other header files).
In CMakeLists for library single-header build should be optional (since it requires python) and disabled by default.
It should be configurable via BUILD_SINGLE_HEADER option e.g. cmake -DBUILD_SINGLE_HEADER=On
Example:
void onAdc(EmbeddedCli *cli, char *args, void *context) {
// somehow get input
while (embeddedCliBytesAvailable(cli) > 0) {
uint8_t b = embeddedCliReadByte(cli);
}
}
If you input is read from cli, it will not be then processed as command. For example suppose command binding for get-adc
and following input is given:
get-adc
get-adc
get-adc
If in binding get-adc
3 bytes are read, then cli will see following:
get-adc // call binding get-adc
-adc // call unknown command "-adc" ("get" was read by user inside binding)
get-adc // call binding get-adc
Another important thing is that this will work correctly only if raw input is provided to cli only inside ISR. Otherwise new input will not be added while command binding is executing (unless it is added it manually, but that's a bad design)
Initial request by @windsunsjtu in #15
It would be nice if the equals sign, or other operators could be identified as tokens, the problem would be that there might be no space character, 1+2 would be one token compared to 1 + 2, which would be 3 tokens.
If you did this, too, the argument list could not be edited on top of itself during the tokenizing process because the tokens would end up longer than the input string, destroying the input string before tokenizing completes.
Just an idea, I'm going down this path using your code as a starting point.
Please let me know what you think,
I pulled your code into a project I'm writing now and it works great, thanks for providing this, it was exactly what I was looking for.
Compiling the code with a old gcc 5.4.0 cross compiler with the -Wall flag gives one warning:
embedded-cli/lib/src/embedded_cli.c:7:20: warning: unused variable 'impl' [-Wunused-variable]
EmbeddedCliImpl* impl = (EmbeddedCliImpl*)t->_impl;
^
embedded-cli/lib/src/embedded_cli.c:803:5: note: in expansion of macro 'PREPARE_IMPL'
PREPARE_IMPL(cli)
^
It looks like the PREPARE_IMPL macro does not need to be called in the initInternalBindings() routine.
Thanks!
Hi.
Your library is very cool. I'm using it in my hobby project in ESP-IDF. Can you solve somehow the quoted arguments?
mycmd "this is my arg" 123 //--- //command is mycmd, first arg is "this is my arg" and other is 123.
This would be nice.
Since cli depends on malloc, calls to instantiate the cli should first check for malloc fail.
in main.cpp:
EmbeddedCli *cli = embeddedCliNewDefault();
cli->onCommand = ...
Using a CMake project configured for C source code only, CMAKE_CXX_COMPILER_ID
is undefined resulting in
a warning being printed to terminal, "Can't enable extra flags for compiler ".
Compiler used for project is arm-none-eabi-gcc
Assuming embedded-cli
is a git submodule, from root CMakeLists.txt, include add_subdirectory(embedded-cli)
line to build embedded-cli
as a library.
Generate CMake environment. During generation, CMake will print warning "Can't enable extra flags for compiler ".
No warning should be printed, and embedded-cli
flags should be added to GNU compiler.
Embedded-cli is configured as a C project
project(embedded_cli C)
The above does not include CXX
, as such, CMAKE_CXX_COMPILER_ID
will never be populated.
Two methods can be used to resolve bug:
CXX
to project
project(embedded_cli C CXX)
CMAKE_CXX_COMPILER_ID
to CMAKE_C_COMPILER_ID
Option 2 should be preffered as embedded-cli uses C source files and not C++.
Currently only normal distribution (.h+.c files) is tested in CI. Single header build is not tested.
In tests we should test single header version (if it was build) or nomal version (if single header not configured). Single header version will be configurable via BUILD_SINGLE_HEADER in #26
In CI both versions must be tested.
Hi,
could you please make auto completion optional by a flag e.g. in the NewEmbeddedCLI construction and/or an activation/deactivation function?
This would help to be able to use the interface for human operators at the start and switch to e.g. scripted commands from a computer alter.
Cheers
Philipp
When building CMake on Windows, the following is output to console:
Target "embedded_cli_win32" links to:
EmbeddedCLI::SingleHeader
but the target was not found. Possible reasons include:
* There is a typo in the target name.
* A find_package call is missing for an IMPORTED target.
* An ALIAS target is missing.
cd embedded cli
mkdir build
cd build
cmake -G "Ninja" ..
Example programs should not be generated by default, example applications should only generate if user has explicitly asked to generate test application.
Currently it is possible to add bindings at runtime without any issues. It will add more flexibility if there was an option to also remove bindings at runtime.
Default implementations might be unused but still take memory space. Allow to remove them or overwrite implementations.
I used sligthly edited code from example in nrf52840 build. I think I was able to spot potential bug.
Using: BYTES_TO_CLI_UINTS(CLI_BUFFER_SIZE)
for static allocation of cliBuffer, and totalSize
in embeddedCliNew
for memset can cause overwritting config struct with zeros. It doesn't cause problems as long as buffer is allocated in memory after struct.
In case buffer is allocated before struct it can set zeros to entire config struct while calling embeddedCliNew
due to starting address of cliBuffer
being only BYTES_TO_CLI_UINTS(CLI_BUFFER_SIZE)
bytes before config struct.
It happened on nrf52840. I could neither isolate any causing allocation issue compiler flags, nor replicate it in other systems.
Currently library uses old single-header version of catch2. Catch2 v3 is released, we should migrate to it.
Currently invitation char is hardcoded into impl of cli. It would be much better if user could change it via config.
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.