AceRoutine  0.2
A low-memory, fast-switching, cooperative multitasking library using stackless coroutines on Arduino platforms.
Public Member Functions | List of all members
ace_routine::cli::CommandManager< BUF_SIZE, ARGV_SIZE > Class Template Reference

A convenience wrapper around a CommandDispatcher that hides complexity of creating, initializing and injecting the resources needed by the CommandDispatcher. More...

#include <CommandManager.h>

Inheritance diagram for ace_routine::cli::CommandManager< BUF_SIZE, ARGV_SIZE >:
Inheritance graph
[legend]
Collaboration diagram for ace_routine::cli::CommandManager< BUF_SIZE, ARGV_SIZE >:
Collaboration graph
[legend]

Public Member Functions

 CommandManager (const CommandHandler *const *commands, uint8_t numCommands, Stream &serial, const char *prompt=nullptr)
 Constructor. More...
 
virtual int runCoroutine () override
 The body of the coroutine. More...
 
const CommandDispatchergetDispatcher () const
 Return the CommandDispatcher. More...
 
- Public Member Functions inherited from ace_routine::Coroutine
Coroutine ** getNext ()
 Return the next pointer as a pointer to the pointer, similar to getRoot(). More...
 
const FCStringgetName () 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 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...
 
void setupCoroutine (const char *name)
 Initialize the coroutine for the CoroutineScheduler, set it to Yielding state, and add it to the linked list of coroutines. More...
 
void setupCoroutine (const __FlashStringHelper *name)
 Same as setupCoroutine(const char*) except using flash string type. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ace_routine::Coroutine
static Coroutine ** getRoot ()
 Get the pointer to the root pointer. More...
 
- Protected Types inherited from ace_routine::Coroutine
typedef uint8_t Status
 The execution status of the coroutine, corresponding to the COROUTINE_YIELD(), COROUTINE_DELAY(), COROUTINE_AWAIT() and COROUTINE_END() macros. More...
 
- Protected Member Functions inherited from ace_routine::Coroutine
 Coroutine ()
 Constructor. More...
 
Status getStatus () const
 Return the status of the coroutine. More...
 
void statusPrintTo (Print &printer)
 Print the human-readable string of the Status. More...
 
void setJump (void *jumpPoint)
 Pointer to label where execute will start on the next call to runCoroutine().
 
void * getJump () const
 Pointer to label where execute will start on the next call to runCoroutine().
 
void setRunning ()
 Set the kStatusRunning state. More...
 
void setYielding ()
 Set the kStatusDelaying 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...
 
- Static Protected Attributes inherited from ace_routine::Coroutine
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 kStatusDelaying = 2
 Coroutine returned using the COROUTINE_DELAY() statement. More...
 
static const Status kStatusRunning = 3
 Coroutine is currenly running. More...
 
static const Status kStatusEnding = 4
 Coroutine executed the COROUTINE_END() statement. More...
 
static const Status kStatusTerminated = 5
 Coroutine has ended and no longer in the scheduler queue. More...
 

Detailed Description

template<uint8_t BUF_SIZE, uint8_t ARGV_SIZE>
class ace_routine::cli::CommandManager< BUF_SIZE, ARGV_SIZE >

A convenience wrapper around a CommandDispatcher that hides complexity of creating, initializing and injecting the resources needed by the CommandDispatcher.

It is not strictly necessary to use this, but the setup is much easier using this class.

This is a subclass of Coroutine, just like CommandDispatcher. The runCoroutine() method simply delegates to the underlying CommandDispatcher, so this class can be used as a substitute for CommandDispatcher. The setupCoroutine() method should be called to initialize the name of the coroutine and insert it into the CoroutineScheduler.

Example usage:

class CommandA: public CommandHandler {
...
};
class CommandB: public CommandHandler {
...
};
CommandA commandA;
CommandB commandB;
static const CommandHandler* COMMANDS[] = {
};
const uint8_t BUF_SIZE = 64;
const uint8_t ARGV_SIZE = 5;
const char PROMPT[] = "$ ";
CommandManager<BUF_SIZE, ARGV_SIZE> commandManager(
COMMANDS, NUM_COMMANDS, Serial, PROMPT);
void setup() {
...
commandManager.setupCoroutine("commandManager");
}
Parameters
BUF_SIZESize of the input line buffer.
ARGV_SIZESize of the command line argv token list.

Definition at line 82 of file CommandManager.h.

Constructor & Destructor Documentation

◆ CommandManager()

template<uint8_t BUF_SIZE, uint8_t ARGV_SIZE>
ace_routine::cli::CommandManager< BUF_SIZE, ARGV_SIZE >::CommandManager ( const CommandHandler *const *  commands,
uint8_t  numCommands,
Stream &  serial,
const char *  prompt = nullptr 
)
inline

Constructor.

Parameters
commandsArray of (CommandHandler*).
numCommandsNumber of commands in 'commands'.
serialThe serial port used to read commands and send output, will normally be 'Serial', but can be set to something else.
promptIf not null, print a prompt and echo the command entered by the user. If null, don't print the prompt and don't echo the input from the user.

Definition at line 96 of file CommandManager.h.

Member Function Documentation

◆ getDispatcher()

template<uint8_t BUF_SIZE, uint8_t ARGV_SIZE>
const CommandDispatcher* ace_routine::cli::CommandManager< BUF_SIZE, ARGV_SIZE >::getDispatcher ( ) const
inline

Return the CommandDispatcher.

VisibleForTesting.

Definition at line 113 of file CommandManager.h.

◆ runCoroutine()

template<uint8_t BUF_SIZE, uint8_t ARGV_SIZE>
virtual int ace_routine::cli::CommandManager< BUF_SIZE, ARGV_SIZE >::runCoroutine ( )
inlineoverridevirtual

The body of the coroutine.

The COROUTINE macro creates a subclass of this class and puts the body of the coroutine into this method.

Returns
The return value is always ignored. This method is declared to return an int to prevent the user from accidentally returning from this method using an explicit 'return' statement instead of through one of the macros (e.g. COROUTINE_YIELD(), COROUTINE_DELAY(), COROUTINE_AWAIT() or COROUTINE_END()).

Implements ace_routine::Coroutine.

Definition at line 106 of file CommandManager.h.


The documentation for this class was generated from the following file: