25 #ifndef ACE_ROUTINE_COMMAND_DISPATCHER_H 26 #define ACE_ROUTINE_COMMAND_DISPATCHER_H 29 #include <AceRoutine.h> 30 #include "CommandHandler.h" 31 #include "InputLine.h" 33 class __FlashStringHelper;
79 mNumCommands(numCommands),
95 static uint8_t
tokenize(
char* line,
const char** argv, uint8_t argvSize) {
96 char* token = strtok(line, DELIMS);
98 while (token !=
nullptr && argc < argvSize) {
101 token = strtok(
nullptr, DELIMS);
109 if (mPrompt !=
nullptr) {
110 mPrinter.print(mPrompt);
112 COROUTINE_CHANNEL_READ(mChannel, input);
114 if (input.status == InputLine::kStatusOverflow) {
119 if (mPrompt !=
nullptr) {
120 mPrinter.print(input.line);
136 for (uint8_t i = 0; i < mNumCommands; i++) {
157 void helpAll(Print& printer)
const;
160 bool helpSpecific(Print& printer,
const char* cmd)
const;
171 static const uint8_t STATUS_SUCCESS = 0;
172 static const uint8_t STATUS_BUFFER_OVERFLOW = 1;
173 static const uint8_t STATUS_FLUSH_TO_EOL = 2;
174 static const char DELIMS[];
179 uint8_t
const mNumCommands;
180 const char**
const mArgv;
181 uint8_t
const mArgvSize;
182 const char*
const mPrompt;
Signature for a command handler.
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.
virtual int runCoroutine() override
The body of the coroutine.
const CommandHandler * findCommand(const char *cmd) const
Find the CommandHandler of the given command name.
void findAndRunCommand(const char *cmd, int argc, const char **argv) const
Find and run the given command.
#define COROUTINE_LOOP()
Mark the beginning of a coroutine loop.
A union of (const char*) and (const __FlashStringHelper*) with a discriminator.
An unbuffered synchronized channel.
void helpAll(Print &printer) const
Print help on all commands.
A coroutine that reads lines from the Serial port, tokenizes the line on whitespace boundaries...
int compareTo(const FCString &that) const
Compare to another FCString.
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.
virtual ~CommandDispatcher()
Destructor.
Base class of all coroutines.
void helpCommandHandler(Print &printer, int argc, const char **argv) const
Handle the 'help' command.
CommandDispatcher(Channel< InputLine > &channel, Print &printer, const CommandHandler *const *commands, uint8_t numCommands, const char **argv, uint8_t argvSize, const char *prompt)
Constructor.
FCString getName() const
Return the name of the command.