AceUtils
0.3
Useful Arduino utilties which are too small as separate libraries, but complex enough to have external dependencies to other libraries.
|
31 #include "CommandDispatcher.h"
36 const char CommandDispatcher::DELIMS[] =
" \f\r\n\t\v";
40 if (statusCode == STATUS_BUFFER_OVERFLOW) {
41 mPrinter.print(F(
"BufferOverflow: "));
42 mPrinter.println(line);
43 }
else if (statusCode == STATUS_FLUSH_TO_EOL) {
44 mPrinter.print(F(
"FlushToEOL: "));
45 mPrinter.println(line);
47 mPrinter.print(F(
"UnknownError: "));
48 mPrinter.print(statusCode);
49 mPrinter.print(F(
": "));
50 mPrinter.println(line);
55 Print& printer,
int argc,
const char*
const* argv)
const {
57 const char* cmd = argv[1];
60 if (strcmp(cmd,
"help") == 0) {
61 printer.println(F(
"Usage: help [command]"));
67 printer.print(F(
"Unknown command: "));
70 printer.println(F(
"Commands:"));
71 printer.println(F(
" help [command]"));
77 for (uint8_t i = 0; i < mNumCommands; i++) {
86 if (command !=
nullptr) {
87 printer.print(F(
"Usage: "));
96 command->
getName().printTo(printer);
108 int argc =
tokenize(line, mArgv, mArgvSize);
109 if (argc == 0)
return;
110 const char* cmd = mArgv[0];
113 if (strcmp(cmd,
"help") == 0) {
122 const char* cmd,
int argc,
const char*
const* argv)
const {
124 if (command !=
nullptr) {
125 command->
run(mPrinter, argc, argv);
129 mPrinter.print(F(
"Unknown command: "));
130 mPrinter.println(cmd);
static uint8_t tokenize(char *line, const char **argv, uint8_t argvSize)
Tokenize the line, separating tokens delimited by whitespace (space, formfeed, carriage return,...
static void printHelp(Print &printer, const CommandHandler *command)
Print help string for the given command.
void printLineError(const char *line, uint8_t statusCode) const
Print the input line that caused an error along with its status code.
bool helpSpecific(Print &printer, const char *cmd) const
Print helpString of specific cmd.
void runCommand(char *line) const
Tokenize the given line and run the command handler.
Signature for a command handler.
ace_common::FCString getHelpString() const
Return the help string of the command.
virtual void run(Print &printer, int argc, const char *const *argv) const =0
Run the command.
void findAndRunCommand(const char *cmd, int argc, const char *const *argv) const
Find and run the given command.
void helpAll(Print &printer) const
Print help on all commands.
const CommandHandler * findCommand(const char *cmd) const
Find the CommandHandler of the given command name.
void helpCommandHandler(Print &printer, int argc, const char *const *argv) const
Handle the 'help' command.
ace_common::FCString getName() const
Return the name of the command.