CmdMessenger 3.0 CmdMessenger is a messaging library for the Arduino Platform. It has uses the serial port as its transport layer

- Main Page
- Classes
- Files

- Class List
- Class Index
- Class Members

Public Member Functions
CmdMessenger Class Reference

List of all members.

## Public Member Functions
| CmdMessenger (Stream &comms, const char fld_separator= ',', const char cmd_separator= ';', const char esc_character= '/')
void | printLfCr (bool addNewLine=true)
void | attach (messengerCallbackFunction newFunction)
void | attach (byte msgId, messengerCallbackFunction newFunction)
void | feedinSerialData ()
bool | next ()
bool | available ()
uint8_t | CommandID ()
template<class T >
bool | sendCmd (int cmdId, T arg, bool reqAc=false, int ackCmdId=1, int timeout=5000)
template<class T >
bool | sendBinCmd (int cmdId, T arg, bool reqAc=false, int ackCmdId=1, int timeout=5000)
void | sendCmdStart (int cmdId)
void | sendCmdEscArg (char *arg)
void | sendCmdfArg (char *fmt,...)
bool | sendCmdEnd (bool reqAc=false, int ackCmdId=1, int timeout=5000)
template<class T >
void | sendCmdArg (T arg)
template<class T >
void | sendCmdArg (T arg, int n)
template<class T >
void | sendCmdBinArg (T arg)
bool | readBoolArg ()
int | readIntArg ()
char | readCharArg ()
float | readFloatArg ()
char * | readStringArg ()
void | copyStringArg (char *string, uint8_t size)
uint8_t | compareStringArg (char *string)
template<class T >
T | readBinArg ()
void | unescape (char *fromChar)

## Constructor & Destructor Documentation

CmdMessenger::CmdMessenger | ( | Stream & | ccomms,
|  | const char | fld_separator = `','`,
|  | const char | cmd_separator = `';'`,
|  | const char | esc_character = `'/'`
| ) |  |

CmdMessenger constructor

## Member Function Documentation

void CmdMessenger::attach | ( | messengerCallbackFunction | newFunction | ) |

Attaches an default function for commands that are not explicitly attached

void CmdMessenger::attach | ( | byte | msgId,
|  | messengerCallbackFunction | newFunction
| ) |  |

Attaches a function to a command ID

bool CmdMessenger::available | ( |  | ) |

Returns if an argument is available. Alias for next()

References next().

uint8_t CmdMessenger::CommandID | ( |  | ) |

Returns the CommandID of the current command

uint8_t CmdMessenger::compareStringArg | ( | char * | string | ) |

Compare the next argument with a string

References next().

void CmdMessenger::copyStringArg | ( | char * | string,
|  | uint8_t | size
| ) |  |

Return next argument as a new string Note that this is useful if the string needs to be persisted

References next().

void CmdMessenger::feedinSerialData | ( |  | ) |

Feeds serial data in CmdMessenger

bool CmdMessenger::next | ( |  | ) |

Gets next argument. Returns true if an argument is available

Referenced by available(), compareStringArg(), copyStringArg(), readCharArg(), readFloatArg(), readIntArg(), and readStringArg().

void CmdMessenger::printLfCr | ( | bool | addNewLine = `true` | ) |

Enables printing newline after a sent command

template<class T >

T CmdMessenger::readBinArg | ( |  | ) | `[inline]`

Read an argument of any type in binary format

bool CmdMessenger::readBoolArg | ( |  | ) |

Read the next argument as bool

References readIntArg().

char CmdMessenger::readCharArg | ( |  | ) |

Read the next argument as char

References next().

float CmdMessenger::readFloatArg | ( |  | ) |

Read the next argument as float

References next().

int CmdMessenger::readIntArg | ( |  | ) |

Read the next argument as int

References next().

Referenced by readBoolArg().

char * CmdMessenger::readStringArg | ( |  | ) |

Read next argument as string. Note that the String is valid until the current command is replaced

References next().

template<class T >

bool CmdMessenger::sendBinCmd | ( | int | cmdId,
|  | T | arg,
|  | bool | reqAc = `false`,
|  | int | ackCmdId = `1`,
|  | int | timeout = `5000`
| ) |  | `[inline]`

Send a command with a single argument of any type Note that the argument is sent in binary format

References sendCmdBinArg(), sendCmdEnd(), and sendCmdStart().

template<class T >

bool CmdMessenger::sendCmd | ( | int | cmdId,
|  | T | arg,
|  | bool | reqAc = `false`,
|  | int | ackCmdId = `1`,
|  | int | timeout = `5000`
| ) |  | `[inline]`

Send a command with a single argument of any type Note that the argument is sent as string

References sendCmdArg(), sendCmdEnd(), and sendCmdStart().

template<class T >

void CmdMessenger::sendCmdArg | ( | T | arg | ) | `[inline]`

Send a single argument as string Note that this will only succeed if a sendCmdStart has been issued first

Referenced by sendCmd().

template<class T >

void CmdMessenger::sendCmdArg | ( | T | arg,
|  | int | n
| ) |  | `[inline]`

Send a single argument as string with custom accuracy Note that this will only succeed if a sendCmdStart has been issued first

template<class T >

void CmdMessenger::sendCmdBinArg | ( | T | arg | ) | `[inline]`

Send a single argument in binary format Note that this will only succeed if a sendCmdStart has been issued first

Referenced by sendBinCmd().

bool CmdMessenger::sendCmdEnd | ( | bool | reqAc = `false`,
|  | int | ackCmdId = `1`,
|  | int | timeout = `5000`
| ) |  |

Send end of command

Referenced by sendBinCmd(), and sendCmd().

void CmdMessenger::sendCmdEscArg | ( | char * | arg | ) |

Send an escaped command argument

void CmdMessenger::sendCmdfArg | ( | char * | fmt,
|  |  | ...
| ) |  |

Send formatted argument. Note that floating points are not supported and resulting string is limited to 128 chars

void CmdMessenger::sendCmdStart | ( | int | cmdId | ) |

Send start of command. This makes it easy to send multiple arguments per command

Referenced by sendBinCmd(), and sendCmd().

void CmdMessenger::unescape | ( | char * | fromChar | ) |

Unescapes a string Note that this is done inline

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

- D:/My Documents/Github/Arduino-Code-and-Libraries/Libraries/CmdMessenger/CmdMessenger.h
- D:/My Documents/Github/Arduino-Code-and-Libraries/Libraries/CmdMessenger/CmdMessenger.cpp