AceRoutine
0.1
A low-memory, fast-switching, cooperative multitasking library using stackless coroutines on Arduino platforms.
|
A CommandDispatcher that takes DispatchRecordC records using C-strings. More...
#include <CommandDispatcher.h>
Public Member Functions | |
CommandDispatcherC (StreamReader &streamReader, Print &printer, const DispatchRecordC *dispatchTable, uint8_t numCommands, const char **argv, uint8_t argvSize) | |
Constructor. More... | |
![]() | |
CommandDispatcher (StreamReader &streamReader, Print &printer, uint8_t numCommands, const char **argv, uint8_t argvSize) | |
Constructor. More... | |
![]() | |
Coroutine ** | getNext () |
Return the next pointer as a pointer to the pointer, similar to getRoot(). More... | |
const FCString & | getName () const |
Human-readable name of the coroutine. More... | |
virtual unsigned long | millis () const |
Returns the current millisecond clock. More... | |
void | suspend () |
Suspend the coroutine at the next scheduler iteration. More... | |
void | resume () |
Add a Suspended coroutine into the head of the scheduler linked list, and change the state to Yielding. More... | |
bool | isDelayExpired () |
Check if delay time is over. More... | |
bool | isSuspended () const |
The coroutine was suspended with a call to suspend(). More... | |
bool | isYielding () const |
The coroutine returned using COROUTINE_YIELD(). More... | |
bool | isAwaiting () const |
The coroutine returned using COROUTINE_AWAIT(). More... | |
bool | isDelaying () const |
The coroutine returned using COROUTINE_DELAY(). More... | |
bool | isRunning () const |
The coroutine is currently running. More... | |
bool | isEnding () const |
The coroutine returned using COROUTINE_END(). More... | |
bool | isTerminated () const |
The coroutine was terminated by the scheduler with a call to setTerminated(). More... | |
bool | isDone () const |
The coroutine is either Ending or Terminated. More... | |
Static Public Member Functions | |
static const DispatchRecordC * | findCommand (const DispatchRecordC *dispatchTable, uint8_t numCommands, const char *cmd) |
Find the CommandHandler of the given command name. More... | |
![]() | |
static uint8_t | tokenize (char *line, const char **argv, uint8_t argvSize) |
Tokenize the line, and fill argv with each token until argvSize is reached. More... | |
![]() | |
static Coroutine ** | getRoot () |
Get the pointer to the root pointer. More... | |
Additional Inherited Members | |
![]() | |
typedef uint8_t | Status |
The execution status of the coroutine, corresponding to the COROUTINE_YIELD(), COROUTINE_DELAY(), COROUTINE_AWAIT() and COROUTINE_END() macros. More... | |
![]() | |
CommandDispatcher (const CommandDispatcher &)=delete | |
CommandDispatcher & | operator= (const CommandDispatcher &)=delete |
void | printLineError (const char *line, uint8_t statusCode) |
Print the error caused by the given line. More... | |
void | helpCommandHandler (Print &printer, int argc, const char **argv) |
Handle the 'help' command. More... | |
void | runCommand (char *line) |
Tokenize the given line and run the command handler. More... | |
virtual int | run () override |
The body of the coroutine. More... | |
![]() | |
Coroutine () | |
Constructor. More... | |
void | init (const char *name) |
Initialize the coroutine, set it to Yielding state, and add it to the linked list of coroutines. More... | |
void | init (const __FlashStringHelper *name) |
Same as init(const char*) except using flash string type. More... | |
Status | getStatus () const |
Return the status of the coroutine. More... | |
void | setJump (void *jumpPoint) |
Pointer to label where execute will start on the next call to run(). More... | |
void * | getJump () const |
Pointer to label where execute will start on the next call to run(). More... | |
void | setRunning () |
Set the kStatusRunning state. More... | |
void | setYielding () |
Set the kStatusDelaying state. More... | |
void | setAwaiting () |
Set the kStatusAwaiting state. More... | |
void | setDelaying () |
Set the kStatusDelaying state. More... | |
void | setDelay (uint16_t delayMillisDuration) |
Configure the delay timer. More... | |
void | setEnding () |
Set the kStatusEnding state. More... | |
void | setTerminated () |
Set status to indicate that the Coroutine has been removed from the Scheduler queue. More... | |
![]() | |
StreamReader & | mStreamReader |
Print & | mPrinter |
const uint8_t | mNumCommands |
const char **const | mArgv |
const uint8_t | mArgvSize |
![]() | |
static const uint8_t | STATUS_SUCCESS = 0 |
static const uint8_t | STATUS_BUFFER_OVERFLOW = 1 |
static const uint8_t | STATUS_FLUSH_TO_EOL = 2 |
static const char | DELIMS [] = " \t\n" |
![]() | |
static const Status | kStatusSuspended = 0 |
Coroutine has been suspended using suspend() and the scheduler should remove it from the queue upon the next iteration. More... | |
static const Status | kStatusYielding = 1 |
Coroutine returned using the COROUTINE_YIELD() statement. More... | |
static const Status | kStatusAwaiting = 2 |
Coroutine returned using the COROUTINE_AWAIT() statement. More... | |
static const Status | kStatusDelaying = 3 |
Coroutine returned using the COROUTINE_DELAY() statement. More... | |
static const Status | kStatusRunning = 4 |
Coroutine is currenly running. More... | |
static const Status | kStatusEnding = 5 |
Coroutine executed the COROUTINE_END() statement. More... | |
static const Status | kStatusTerminated = 6 |
Coroutine has ended and no longer in the scheduler queue. More... | |
A CommandDispatcher that takes DispatchRecordC records using C-strings.
Definition at line 147 of file CommandDispatcher.h.
|
inline |
Constructor.
streamReader | An instance of StreamReader. |
printer | The output object, normally the global Serial object. |
dispatchTable | An array of DispatchRecords. |
numCommands | Number of entries in the dispatchTable. |
argv | Array of (const char*) that will be used to hold the word tokens of a command line string. |
argvSize | The size of the argv array. Tokens which are beyond this limit will be silently dropped. |
Definition at line 161 of file CommandDispatcher.h.
|
static |
Find the CommandHandler of the given command name.
VisibleForTesting.
NOTE: this is currently a linear O(N) scan which is good enough for small number of commands. If we sorted the handlers, we could do a binary search for O(log(N)) and handle larger number of commands.
Definition at line 153 of file CommandDispatcher.cpp.