AceRoutine
1.0
A low-memory, fast-switching, cooperative multitasking library using stackless coroutines on Arduino platforms.
|
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>
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... | |
![]() | |
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 | 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 Coroutine ** | getRoot () |
Get the pointer to the root pointer. More... | |
![]() | |
typedef uint8_t | Status |
The execution status of the coroutine, corresponding to the COROUTINE_YIELD(), COROUTINE_DELAY(), COROUTINE_AWAIT() and COROUTINE_END() macros. More... | |
![]() | |
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 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... | |
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.
|
inline |
Constructor.
channel | The output Channel used to send an InputLine message back to the receiver. |
stream | The input stream, usually the global Serial object. |
buffer | The input character buffer. |
bufferSize | The 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.
|
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.
Implements ace_routine::Coroutine.
Definition at line 60 of file StreamLineReader.h.