DvG_StreamCommand
|
Class to manage listening to a stream, such as Serial or Wire, for incoming ASCII commands (or ASCII data packets in general) and act upon them. More...
#include <DvG_StreamCommand.h>
Public Member Functions | |
DvG_StreamCommand (Stream &stream, char *buffer, uint16_t max_len) | |
Construct a new DvG_StreamCommand object. More... | |
bool | available () |
Poll the stream for incoming characters and append them one-by-one to the command buffer buffer . This method should be called repeatedly. More... | |
char * | getCommand () |
Return the reference to the command buffer only when a complete command has been received. Otherwise, an empty C-string is returned. More... | |
Class to manage listening to a stream, such as Serial or Wire, for incoming ASCII commands (or ASCII data packets in general) and act upon them.
We speak of a completely received 'command' once a linefeed ('\n', ASCII 10) character is received, or else when the number of incoming characters has exceeded the command buffer size. Carriage return ('\r', ASCII 13) characters are ignored from the stream.
The command buffer is supplied by the user and must be a fixed-size character array (C-string, i.e. '\0' terminated) to store incoming characters into. This keeps the memory usage low and unfragmented, instead of relying on memory hungry C++ strings.
DvG_StreamCommand::DvG_StreamCommand | ( | Stream & | stream, |
char * | buffer, | ||
uint16_t | max_len | ||
) |
Construct a new DvG_StreamCommand object.
stream | Reference to a stream to listen to, e.g. Serial, Wire, etc. |
buffer | Reference to the command buffer: A fixed-size character array which will be managed by this class to hold a single incoming command. The buffer should be one character larger than the longest incoming command to allow for the C-string termination character '\0' to become appended. |
max_len | Array size of buffer including '\0'. Do not exceed the maximum size of 2^^16 = 65536 characters. |
bool DvG_StreamCommand::available | ( | ) |
Poll the stream for incoming characters and append them one-by-one to the command buffer buffer
. This method should be called repeatedly.
char * DvG_StreamCommand::getCommand | ( | ) |
Return the reference to the command buffer only when a complete command has been received. Otherwise, an empty C-string is returned.