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 ()
bool | isArgOk ()
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)
bool | sendCmd (int cmdId)
bool | sendCmd (int cmdId, bool reqAc, int ackCmdId)
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)
void | sendCmdSciArg (double arg, 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(), 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

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 | ( | 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().

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

Send a command without arguments, without acknowledge

References sendCmdEnd(), and sendCmdStart().

bool CmdMessenger::sendCmd | ( | int | cmdId,
|  | bool | reqAc,
|  | int | 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,
|  | 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::sendCmdSciArg | ( | double | arg,
|  | 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 | ( | 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