AceRoutine  1.0
A low-memory, fast-switching, cooperative multitasking library using stackless coroutines on Arduino platforms.
Public Member Functions | List of all members
ace_routine::cli::StreamLineReader Class Reference

An AceRoutine coroutine that reads lines (terminated by '\n' or '\r' from the Stream device, and write the InputLine message into the provided Channel. More...

#include <StreamLineReader.h>

Inheritance diagram for ace_routine::cli::StreamLineReader:
Inheritance graph
[legend]
Collaboration diagram for ace_routine::cli::StreamLineReader:
Collaboration graph
[legend]

Public Member Functions

 StreamLineReader (ace_routine::Channel< InputLine > &channel, Stream &stream, char *buffer, int bufferSize)
 Constructor. More...
 
int runCoroutine () override
 The body of the coroutine. 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 coroutineMillis () const
 Returns the current millisecond clock. More...
 
virtual unsigned long coroutineMicros () const
 Returns the current millisecond clock. More...
 
virtual unsigned long coroutineSeconds () const
 Returns the current clock in unit of seconds, truncated to the lower 16-bits. 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...
 
virtual ~Coroutine ()
 Destructor. 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 setEnding ()
 Set the kStatusEnding state. More...
 
void setTerminated ()
 Set status to indicate that the Coroutine has been removed from the Scheduler queue. More...
 
void setDelayMillis (uint16_t delayMillis)
 Configure the delay timer for delayMillis. More...
 
void setDelayMicros (uint16_t delayMicros)
 Configure the delay timer for delayMicros. More...
 
void setDelaySeconds (uint16_t delaySeconds)
 Configure the delay timer for delaySeconds. 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...
 
static const uint8_t kDelayTypeMillis = 0
 Delay using units of millis. More...
 
static const uint8_t kDelayTypeMicros = 1
 Delay using units of micros. More...
 
static const uint8_t kDelayTypeSeconds = 2
 Delay using units of seconds. More...
 

Detailed Description

An AceRoutine coroutine that reads lines (terminated by '\n' or '\r' from the Stream device, and write the InputLine message into the provided Channel.

The Stream will normally be the global Serial object.

Definition at line 40 of file StreamLineReader.h.

Constructor & Destructor Documentation

◆ StreamLineReader()

ace_routine::cli::StreamLineReader::StreamLineReader ( ace_routine::Channel< InputLine > &  channel,
Stream &  stream,
char *  buffer,
int  bufferSize 
)
inline

Constructor.

Parameters
channelThe output Channel used to send an InputLine message back to the receiver.
streamThe input stream, usually the global Serial object.
bufferThe input character buffer.
bufferSizeThe size of the buffer, should be set large enough to hold the longest line without triggering buffer overflow.

Definition at line 52 of file StreamLineReader.h.

Member Function Documentation

◆ runCoroutine()

int ace_routine::cli::StreamLineReader::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 60 of file StreamLineReader.h.


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