CmdMessenger 4.0.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 ()
bool | isArgOk ()
uint8_t | commandID ()
template<class T >
bool | sendCmd (byte cmdId, T arg, bool reqAc=false, byte ackCmdId=1, unsigned int timeout=5000)
template<class T >
bool | sendBinCmd (byte cmdId, T arg, bool reqAc=false, byte ackCmdId=1, unsigned int timeout=5000)
bool | sendCmd (byte cmdId)
bool | sendCmd (byte cmdId, bool reqAc, byte ackCmdId)
void | sendCmdStart (byte cmdId)
void | sendCmdEscArg (char *arg)
void | sendCmdfArg (char *fmt,...)
bool | sendCmdEnd (bool reqAc=false, byte ackCmdId=1, unsigned int timeout=5000)
template<class T >
void | sendCmdArg (T arg)
template<class T >
void | sendCmdArg (T arg, unsigned int n)
void | sendCmdSciArg (double arg, unsigned int n=6)
template<class T >
void | sendCmdBinArg (T arg)
bool | readBoolArg ()
int16_t | readInt16Arg ()
int32_t | readInt32Arg ()
char | readCharArg ()
float | readFloatArg ()
double | readDoubleArg ()
char * | readStringArg ()
void | copyStringArg (char *string, uint8_t size)
uint8_t | compareStringArg (char *string)
template<class T >
T | readBinArg ()
void | unescape (char *fromChar)
void | printSci (double f, unsigned int digits)

## 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::isArgOk | ( |  | ) |

Returns if the latest argument is well formed.

bool CmdMessenger::next | ( |  | ) |

Gets next argument. Returns true if an argument is available

Referenced by available(), compareStringArg(), copyStringArg(), readBinArg(), readCharArg(), readDoubleArg(), readFloatArg(), readInt16Arg(), readInt32Arg(), and readStringArg().

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

Enables printing newline after a sent command

void CmdMessenger::printSci | ( | double | f,
|  | unsigned int | digits
| ) |  |

Print float and double in scientific format

Referenced by sendCmdSciArg().

template<class T >

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

Read an argument of any type in binary format

References next().

bool CmdMessenger::readBoolArg | ( |  | ) |

Read the next argument as bool

References readInt16Arg().

char CmdMessenger::readCharArg | ( |  | ) |

Read the next argument as char

References next().

double CmdMessenger::readDoubleArg | ( |  | ) |

Read the next argument as double

References next().

float CmdMessenger::readFloatArg | ( |  | ) |

Read the next argument as float

References next().

int16_t CmdMessenger::readInt16Arg | ( |  | ) |

Read the next argument as int

References next().

Referenced by readBoolArg().

int32_t CmdMessenger::readInt32Arg | ( |  | ) |

Read the next argument as int

References next().

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 | ( | byte | cmdId,
|  | T | arg,
|  | bool | reqAc = `false`,
|  | byte | ackCmdId = `1`,
|  | unsigned 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 | ( | byte | cmdId,
|  | T | arg,
|  | bool | reqAc = `false`,
|  | byte | ackCmdId = `1`,
|  | unsigned 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().

bool CmdMessenger::sendCmd | ( | byte | cmdId | ) |

Send a command without arguments, without acknowledge

References sendCmdEnd(), and sendCmdStart().

bool CmdMessenger::sendCmd | ( | byte | cmdId,
|  | bool | reqAc,
|  | byte | ackCmdId
| ) |  |

Send a command without arguments, with acknowledge

References 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,
|  | unsigned 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`,
|  | byte | ackCmdId = `1`,
|  | unsigned 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::sendCmdSciArg | ( | double | arg,
|  | unsigned int | n = `6`
| ) |  |

Send double argument in scientific format. This will overcome the boundary of normal d sending which is limited to abs(f) <= MAXLONG

Send double argument in scientific format. This will overcome the boundary of normal float sending which is limited to abs(f) <= MAXLONG

References printSci().

void CmdMessenger::sendCmdStart | ( | byte | 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/Own Arduino libraries/CmdMessenger/Arduino-CmdMessenger/CmdMessenger.h
- D:/My Documents/Github/Arduino/Own Arduino libraries/CmdMessenger/Arduino-CmdMessenger/CmdMessenger.cpp