Public Member Functions | Private Member Functions | Private Attributes
CmdMessenger Class Reference

#include <CmdMessenger.h>

List of all members.

Public Member Functions

void attach (messengerCallbackFunction newFunction)
void attach (byte msgId, messengerCallbackFunction newFunction)
bool available ()
 CmdMessenger (Stream &comms, const char fld_separator= ',', const char cmd_separator= ';', const char esc_character= '/')
uint8_t CommandID ()
uint8_t compareStringArg (char *string)
void copyStringArg (char *string, uint8_t size)
void feedinSerialData ()
bool isArgOk ()
bool next ()
void printLfCr (bool addNewLine=true)
void printSci (double f, unsigned int digits)
template<class T >
readBinArg ()
bool readBoolArg ()
char readCharArg ()
double readDoubleArg ()
float readFloatArg ()
int16_t readInt16Arg ()
int32_t readInt32Arg ()
char * readStringArg ()
template<class T >
bool sendBinCmd (int cmdId, T arg, bool reqAc=false, int ackCmdId=1, int timeout=DEFAULT_TIMEOUT)
template<class T >
bool sendCmd (int cmdId, T arg, bool reqAc=false, int ackCmdId=1, int timeout=DEFAULT_TIMEOUT)
bool sendCmd (int cmdId)
bool sendCmd (int cmdId, bool reqAc, int ackCmdId)
template<class T >
void sendCmdArg (T arg)
template<class T >
void sendCmdArg (T arg, int n)
template<class T >
void sendCmdBinArg (T arg)
bool sendCmdEnd (bool reqAc=false, int ackCmdId=1, int timeout=DEFAULT_TIMEOUT)
void sendCmdEscArg (char *arg)
void sendCmdfArg (char *fmt,...)
void sendCmdSciArg (double arg, int n=6)
void sendCmdStart (int cmdId)
void unescape (char *fromChar)

Private Member Functions

bool blockedTillReply (unsigned long timeout=DEFAULT_TIMEOUT, int ackCmdId=1) __attribute__((always_inline))
bool CheckForAck (int AckCommand) __attribute__((always_inline))
template<class T >
empty ()
int findNext (char *str, char delim)
void handleMessage () __attribute__((always_inline))
void init (Stream &comms, const char fld_separator, const char cmd_separator, const char esc_character)
bool isEscaped (char *currChar, const char escapeChar, char *lastChar)
void printEsc (char *str)
void printEsc (char str)
uint8_t processLine (char serialChar) __attribute__((always_inline))
template<class T >
readBin (char *str)
void reset ()
char * split_r (char *str, const char delim, char **nextp)
template<class T >
void writeBin (const T &value)

Private Attributes

char ArglastChar
bool ArgOk
uint8_t bufferIndex
uint8_t bufferLastIndex
uint8_t bufferLength
messengerCallbackFunction callbackList [MAXCALLBACKS]
char CmdlastChar
char command_separator
char commandBuffer [MESSENGERBUFFERSIZE]
Stream * comms
char * current
messengerCallbackFunction default_callback
bool dumped
char escape_character
char field_separator
char * last
uint8_t lastCommandId
uint8_t messageState
bool pauseProcessing
char prevChar
bool print_newlines
bool startCommand
char streamBuffer [MAXSTREAMBUFFERSIZE]

Detailed Description

Definition at line 59 of file CmdMessenger.h.


Constructor & Destructor Documentation

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

CmdMessenger constructor

Definition at line 58 of file CmdMessenger.cpp.


Member Function Documentation

Attaches an default function for commands that are not explicitly attached

Definition at line 107 of file CmdMessenger.cpp.

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

Attaches a function to a command ID

Definition at line 115 of file CmdMessenger.cpp.

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

Definition at line 250 of file CmdMessenger.cpp.

bool CmdMessenger::blockedTillReply ( unsigned long  timeout = DEFAULT_TIMEOUT,
int  ackCmdId = 1 
) [inline, private]

Waits for reply from sender or timeout before continuing

Definition at line 190 of file CmdMessenger.cpp.

bool CmdMessenger::CheckForAck ( int  AckCommand) [inline, private]

Loops as long data is available to determine if acknowledge has come in

Definition at line 205 of file CmdMessenger.cpp.

Returns the CommandID of the current command

Definition at line 266 of file CmdMessenger.cpp.

uint8_t CmdMessenger::compareStringArg ( char *  string)

Compare the next argument with a string

Definition at line 511 of file CmdMessenger.cpp.

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

Definition at line 496 of file CmdMessenger.cpp.

template<class T >
T CmdMessenger::empty ( ) [inline, private]

Definition at line 142 of file CmdMessenger.h.

Feeds serial data in CmdMessenger

Definition at line 126 of file CmdMessenger.cpp.

int CmdMessenger::findNext ( char *  str,
char  delim 
) [private]

Find next argument in command

Definition at line 376 of file CmdMessenger.cpp.

void CmdMessenger::handleMessage ( ) [inline, private]

Dispatches attached callbacks based on command

Definition at line 177 of file CmdMessenger.cpp.

void CmdMessenger::init ( Stream &  ccomms,
const char  fld_separator,
const char  cmd_separator,
const char  esc_character 
) [private]

Enables printing newline after a sent command

Definition at line 66 of file CmdMessenger.cpp.

Returns if the latest argument is well formed.

Definition at line 258 of file CmdMessenger.cpp.

bool CmdMessenger::isEscaped ( char *  currChar,
const char  escapeChar,
char *  lastChar 
) [private]

Indicates if the current character is escaped

Definition at line 584 of file CmdMessenger.cpp.

Gets next argument. Returns true if an argument is available

Definition at line 226 of file CmdMessenger.cpp.

void CmdMessenger::printEsc ( char *  str) [private]

Escape and print a string

Definition at line 600 of file CmdMessenger.cpp.

void CmdMessenger::printEsc ( char  str) [private]

Escape and print a character

Definition at line 610 of file CmdMessenger.cpp.

void CmdMessenger::printLfCr ( bool  addNewLine = true)

Enables printing newline after a sent command

Definition at line 99 of file CmdMessenger.cpp.

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

Print float and double in scientific format

Definition at line 621 of file CmdMessenger.cpp.

uint8_t CmdMessenger::processLine ( char  serialChar) [inline, private]

Processes bytes and determines message state

Definition at line 153 of file CmdMessenger.cpp.

template<class T >
T CmdMessenger::readBin ( char *  str) [inline, private]

Read a variable of any type in binary format

Definition at line 128 of file CmdMessenger.h.

template<class T >
T CmdMessenger::readBinArg ( ) [inline]

Read an argument of any type in binary format

Definition at line 284 of file CmdMessenger.h.

Read the next argument as bool

Definition at line 429 of file CmdMessenger.cpp.

Read the next argument as char

Definition at line 437 of file CmdMessenger.cpp.

Read the next argument as double

Definition at line 466 of file CmdMessenger.cpp.

Read the next argument as float

Definition at line 451 of file CmdMessenger.cpp.

Read the next argument as int

Definition at line 401 of file CmdMessenger.cpp.

Read the next argument as int

Definition at line 415 of file CmdMessenger.cpp.

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

Definition at line 481 of file CmdMessenger.cpp.

void CmdMessenger::reset ( ) [private]

Resets the command buffer and message state

Definition at line 88 of file CmdMessenger.cpp.

template<class T >
bool CmdMessenger::sendBinCmd ( int  cmdId,
arg,
bool  reqAc = false,
int  ackCmdId = 1,
int  timeout = DEFAULT_TIMEOUT 
) [inline]

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

Definition at line 207 of file CmdMessenger.h.

template<class T >
bool CmdMessenger::sendCmd ( int  cmdId,
arg,
bool  reqAc = false,
int  ackCmdId = 1,
int  timeout = DEFAULT_TIMEOUT 
) [inline]

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

Definition at line 191 of file CmdMessenger.h.

bool CmdMessenger::sendCmd ( int  cmdId)

Send a command without arguments, without acknowledge

Definition at line 362 of file CmdMessenger.cpp.

bool CmdMessenger::sendCmd ( int  cmdId,
bool  reqAc,
int  ackCmdId 
)

Send a command without arguments, with acknowledge

Definition at line 350 of file CmdMessenger.cpp.

template<class T >
void CmdMessenger::sendCmdArg ( arg) [inline]

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

Definition at line 231 of file CmdMessenger.h.

template<class T >
void CmdMessenger::sendCmdArg ( 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

Definition at line 243 of file CmdMessenger.h.

template<class T >
void CmdMessenger::sendCmdBinArg ( arg) [inline]

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

Definition at line 262 of file CmdMessenger.h.

bool CmdMessenger::sendCmdEnd ( bool  reqAc = false,
int  ackCmdId = 1,
int  timeout = DEFAULT_TIMEOUT 
)

Send end of command

Definition at line 331 of file CmdMessenger.cpp.

void CmdMessenger::sendCmdEscArg ( char *  arg)

Send an escaped command argument

Definition at line 288 of file CmdMessenger.cpp.

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

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

Definition at line 300 of file CmdMessenger.cpp.

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

Definition at line 319 of file CmdMessenger.cpp.

void CmdMessenger::sendCmdStart ( int  cmdId)

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

Definition at line 276 of file CmdMessenger.cpp.

char * CmdMessenger::split_r ( char *  str,
const char  delim,
char **  nextp 
) [private]

Split string in different tokens, based on delimiter Note that this is basically strtok_r, but with support for an escape character

Definition at line 552 of file CmdMessenger.cpp.

void CmdMessenger::unescape ( char *  fromChar)

Unescapes a string Note that this is done inline

Definition at line 532 of file CmdMessenger.cpp.

template<class T >
void CmdMessenger::writeBin ( const T &  value) [inline, private]

Print variable of type T binary in binary format

Definition at line 110 of file CmdMessenger.h.


Member Data Documentation

char CmdMessenger::ArglastChar [private]

Definition at line 70 of file CmdMessenger.h.

bool CmdMessenger::ArgOk [private]

Definition at line 78 of file CmdMessenger.h.

uint8_t CmdMessenger::bufferIndex [private]

Definition at line 67 of file CmdMessenger.h.

uint8_t CmdMessenger::bufferLastIndex [private]

Definition at line 69 of file CmdMessenger.h.

uint8_t CmdMessenger::bufferLength [private]

Definition at line 68 of file CmdMessenger.h.

Definition at line 89 of file CmdMessenger.h.

char CmdMessenger::CmdlastChar [private]

Definition at line 71 of file CmdMessenger.h.

Definition at line 84 of file CmdMessenger.h.

Definition at line 74 of file CmdMessenger.h.

Stream* CmdMessenger::comms [private]

Definition at line 82 of file CmdMessenger.h.

char* CmdMessenger::current [private]

Definition at line 79 of file CmdMessenger.h.

Definition at line 88 of file CmdMessenger.h.

bool CmdMessenger::dumped [private]

Definition at line 77 of file CmdMessenger.h.

Definition at line 86 of file CmdMessenger.h.

Definition at line 85 of file CmdMessenger.h.

char* CmdMessenger::last [private]

Definition at line 80 of file CmdMessenger.h.

uint8_t CmdMessenger::lastCommandId [private]

Definition at line 66 of file CmdMessenger.h.

uint8_t CmdMessenger::messageState [private]

Definition at line 76 of file CmdMessenger.h.

Definition at line 72 of file CmdMessenger.h.

char CmdMessenger::prevChar [private]

Definition at line 81 of file CmdMessenger.h.

Definition at line 73 of file CmdMessenger.h.

Definition at line 65 of file CmdMessenger.h.

Definition at line 75 of file CmdMessenger.h.


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


ric_mc
Author(s): RoboTiCan
autogenerated on Fri May 20 2016 03:48:57