spacehuhntech / simplecli Goto Github PK
View Code? Open in Web Editor NEWCommand Line Interface Library for Arduino
License: MIT License
Command Line Interface Library for Arduino
License: MIT License
I'm trying to use SimpleCLI in PlatformIO.
As per instruction, I downloaded the SimpleCLI source files and put it under a "SimpleCLI" in the "libs" folder. I then inserted the library by inserting #include <SimpleCLI.h>
at the top of main.cpp
.
The library files compiled sucessfully, but there are linking "undefined reference" errors. I might miss some build configurations under platformio.ini
. I've tried using the option lib_ldf_mode = chain+
and lib_ldf_mode = deep+
, but the linker still fails.
Any idea?
I am programming a Portenta H7 Lite on platformio where I have to include <Arduino.h> in main.
I get the following compilation error even with a blank script, as long as I include <SimpleCLI.h>.
=============================================
cmd_reset': ns_cmdline.c:(.text.cmd_reset+0x0): multiple definition of
cmd_reset'Apparently that there is a name clash of a function name "cmd_reset" with something in the Arduino core?
I then manually searched for all instances of the symbol "cmd_reset" in the SimpleCLI library and changed them to "cmd_reset_4_cli" and it complies successfully. Currently the program uploaded to the board is functioning (almost) flawlessly. Extremely well thought-out library.
I tried modifying the src to add flashstringhelper for the command function name, compiles fine but it does not work. Do you have plans to add progmem for command name in the future? this might help for many commands ram usage.
Is there already something like a subcommand function?
The idea is to have a command "spi read" and "spi write" to have different obligatory parameters.
currently commands with a space are ignored
Hi.
I have been using SimpleCLI and developing code from your examples. I decided to change from the default number of arguments.
SimpleCLI cli(10);
This fails on an Arduino UNO with the message:
Compilation error: macro "cli" passed 1 arguments, but takes just 0
This is because the Arduino UNO system defines a macro "cli".
The code works on and Arduino DUE.
It is possible to do
#undef cli
I think it is better to change the name of the declared object from "cli" to something else in the examples.
Thank you for your work
John Fletcher
I use platformIO to develop arduino-STM32 and use pio's serial monitor.
I cannot guarantee that every command is entered correctly, so I need to use the backspace key, but simpleCLI does not seem to add this function.
I think we can handle special key characters in SimpleCLI::parse func. ???
Thanks..
I tried to edit a small case, but did not solve the problem of the arrow keys.
void loop()
{
// put your main code here, to run repeatedly:
static String input;
// Check if user typed something into the serial monitor
if (Serial.available())
{
// Read out string from the serial monitor
const int c = Serial.read();
// Echo the user input
Serial.write((char)c);
// displayable characters
if (c >= 0x20 && c <= 0x7e)
{
input.concat((char)c);
}
// Backspace or Delect (characters)key receive..
else if (c == 0x08 || c == 0x7f)
{
if (input.length())
input.remove(input.length() - 1);
}
else if (c == '\n')
{
// Parse the user input into the CLI
cli.parse(input);
input = "";
}
}
}
It would be nice to be able to issue a command but execute a command after it, such as
mycommand | wait
It would execute mycommand, then execute wait.
This would be helpful if you need to view the output of the command in the terminal, but have it blocking so you can take time to read it instead of having to scroll back up. It's virtually limitless idea-wise.
I am currently try to use your lib on one of my projects.
First of all:
I am using it on a ti cc3200 (toniebox) with energia (arduino fork).
But it doesn't seem to be able to read my input. (I am sending it as string over the parse interface).
Definition
cmdI2C = cli.addCmd("i2c");
cmdI2C.setDescription("Access I2C");
cmdI2C.addFlagArg("r/ead");
cmdI2C.addFlagArg("w/rite");
cmdI2C.addArg("a/ddress");
cmdI2C.addArg("r/egister");
cmdI2C.addArg("v/alue", "");
cmdI2C.addArg("l/ength", "");
cmdI2C.addArg("o/utput", "b");
cmdHelp = cli.addCmd("h/elp");
cmdHelp.setDescription("Get help!");
Input
i2c read -address 0x10 -register 0b10000000
Output
ERROR: Unknown argument at command 'i2c' at 'read'
Did you mean "i2c [-r/ead] [-w/rite] -a/ddress <value> -r/egister <value> [-v/alue <value>] [-l/ength <value>] [-o/utput <b>]
Access I2C"?
Full code:
https://github.com/toniebox-reverse-engineering/hackiebox_cfw/blob/develop/BoxCLI.cpp
Hi.
I recently used your library and thanks for sharing.
Unfortunately all text variable like below consume a lot of RAM.
cmdPing.setDescription(" Responds with a ping n-times");
I'm using UNO and quickly got run out of RAM.
One variant i found it working is to store all strings in FLASH:
const static char StrInFlash[] PROGMEM = " Responds with a ping n-times";
cmdPing.setDescription(StrInFlash);
if you have just some text to print over Serial you may use directives Serial.print(F("some text"));
Here is error callback function modified to use less RAM
void errorCallback(cmd_error* e) {
CommandError cmdError(e); // Create wrapper object
Serial.print(F("ERROR: "));
Serial.println(cmdError.toString());
if (cmdError.hasCommand()) {
Serial.print(F("Did you mean \""));
Serial.print(cmdError.getCommand().toString());
Serial.println(F("\"?"));
}
};
I hope someone will found it useful too
Hi spacehuhn,
Thanks a lot for sharing this nice cli function lib. I use the SimpleCLI on an Arduino Mega2560 and my implementation works very well.
But what i recognize is, that after 300-500 hundred parsed command lines (slightly depending on which command i send), the Arduino get stuck and is not reacting any more. After a reset, it works fine again, until the same number of commands are parsed again. When i do a direct call to the callback functions as a workaround without using the .parse() function, everything works stable for hours.
So my guess is, that there might be a memory overflow issue within your parser function.
Could you please check?
Thanks a lot and best regards,
Andi
I'm having an odd issue where a negative floating point argument is having the negative sign replaced with an S.
ie -10.0034 actually appears in the argument as S10.0034
This has the unfortunate side effect of any negative numbers turning to 0 when converting the string to a floating point.
Any suggestions?
Hi,
I'm trying to implement a set command that can have multiple arguments. Like,
set -auto <on/off>
set -interval
set -devicename
set -trigger -lowtemp 20 -hightemp 40 -speed 33
Is this possible with SimpleCLI? And how?
I suppose this is were addBoundlessCommand is for since I can't get it to work with addArgument and addPositionalArgument.
Kind regards,
Jacco
Very nice library!
My question is, can the controller do other things, while it processes the text as it is arriving?
I have implemented your wonderful library in my model rocket flight computer and it saved me so much time Thank you!
I have noticed an issue when I send a command in this format:
SET SERVO_1_OFFSET -11
The command is SET and it expects two arguments a setting and a value (in this case SERVO_1_OFFSET and -11)
Everything works just fine when the value is a positive number. However I also need to pass negative values and in that case the library trows a Unknown argument error
Am I doing something wrong or is there a workaround.
Thank you.
This is a very nice project, thanks for sharing it.
While browsing through the examples, I was wondering whether you would be interested in generating a CLI automatically by compile time introspection of function signatures. We use a similar approach here to generate a light weight RPC interface.
Just let me know if you are interested.
Suggestion to correct the misspelling of the method setCaseSensetive
to setCaseSensitive
Since correcting this misspelling will break compatibility with code using the original spelling, maybe create an addition method setCaseSensitive
that simply calls the original method (or vice versa)
Hi, compiling under GCC for ESP32 (idf version 4.4) produces a warning:
../components/cli/SimpleCLI/src/c/cmd.c: In function 'cmd_parse':
../components/cli/SimpleCLI/src/c/cmd.c:258:20: warning: this statement may fall through [-Wimplicit-fallthrough=]
if (prefix != '-') {
^
../components/cli/SimpleCLI/src/c/cmd.c:264:13: note: here
case ARG_DEFAULT:
The problem is here:
switch (a->mode) {
// Anonym, Template Arg -> value = value
case ARG_POS:
if (prefix != '-') {
arg_set_value(a, w->str, w->len);
break;
}
// Default Arg -> value in next word
case ARG_DEFAULT:
Since case ARG_POS
doesn't break
by default. Should there be a break
in line 262 in SimpleCLI/src/c/cmd.c
?
Hi,
I'm trying to implement a command that requires one anonym parameter ( a file name )
and one maybe later two optional parameters.
// =========== Add write command ========== //
Command* writeCard = new Command("write", [](Cmd* cmd) {
String fileName = cmd->getValue(0);
bool resume = cmd->isSet("r");
long volume = cmd->getValue("v").toInt();
ESP_LOGI(TAG, "Prepare card for file \"%s\"%s", fileName.c_str(),
(resume.equalsIgnoreCase("resume"))?" with resume":"");
});
writeCard->addArg(new AnonymReqArg());
writeCard->addArg(new EmptyArg("r"));
writeCard->addArg(new OptArg("write v", "15"));
pCli->addCmd(writeCard);
But no matter what I enter at the command line I could not get the r set a a volume different than 15.
write file -v 20
write file -r -v 20
Could you help we, to read the arguments?
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.