Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
sawyer::Message Class Reference

#include <Message.h>

Inheritance diagram for sawyer::Message:
Inheritance graph
[legend]

Public Member Functions

uint16_t getChecksum ()
 
uint8_t getFlags ()
 
uint8_t getLength ()
 
uint8_t getLengthComp ()
 
size_t getPayload (void *buf, size_t max_size)
 
size_t getPayloadLength ()
 
size_t getTotalLength ()
 
uint16_t getType ()
 
size_t getType (void *buf, size_t max_size)
 
size_t getTypeLength ()
 
uint8_t getVersion ()
 
bool isCommand ()
 
bool isData ()
 
bool isRequest ()
 
bool isValid (char *whyNot=NULL, size_t strLen=0)
 
 Message ()
 
 Message (void *input, size_t msg_len)
 
 Message (const Message &other)
 
 Message (uint16_t type, uint8_t *payload, size_t payload_len, uint32_t timestamp=0, uint8_t flags=0, uint8_t version=0)
 
virtual std::ostream & printMessage (std::ostream &stream=std::cout)
 
void printRaw (std::ostream &stream=std::cout)
 
void send ()
 
MessagesendRequest ()
 
size_t toBytes (void *buf, size_t buf_size)
 
virtual ~Message ()
 

Static Public Member Functions

static Messagefactory (void *input, size_t msg_len)
 
static MessagepopNext ()
 
static MessagewaitNext (double timeout=0.0)
 

Public Attributes

uint8_t data [MAX_MSG_LENGTH]
 
size_t total_len
 

Static Public Attributes

static const size_t MAX_MSG_LENGTH = 256
 
static const size_t MIN_MSG_LENGTH = HEADER_LENGTH + CRC_LENGTH
 
static const uint8_t SOH = 0xAA
 
static const uint8_t STX = 0x55
 

Protected Types

enum  dataOffsets {
  SOH_OFST = 0, LENGTH_OFST, LENGTH_COMP_OFST, VERSION_OFST,
  FLAGS_OFST = 4, STX_OFST = 5, TYPE_OFST, PAYLOAD_OFST =8
}
 

Protected Member Functions

size_t crcOffset ()
 
uint8_t * getPayloadPointer (size_t offset=0)
 
void makeValid ()
 
void setFlags (uint8_t flags)
 
void setLength (uint8_t len)
 
void setPayload (void *buf, size_t buf_size)
 
void setPayloadLength (uint8_t len)
 
void setType (uint16_t type)
 
void setVersion (uint8_t version)
 

Protected Attributes

bool is_sent
 

Static Protected Attributes

static const uint16_t CRC_INIT_VAL = 0xFFFF
 
static const size_t CRC_LENGTH = 2
 
static const size_t HEADER_LENGTH = 8
 

Friends

class Transport
 

Detailed Description

Definition at line 67 of file Message.h.

Member Enumeration Documentation

Enumerator
SOH_OFST 
LENGTH_OFST 
LENGTH_COMP_OFST 
VERSION_OFST 
FLAGS_OFST 
STX_OFST 
TYPE_OFST 
PAYLOAD_OFST 

Definition at line 83 of file Message.h.

Constructor & Destructor Documentation

sawyer::Message::Message ( )

Definition at line 77 of file Message.cpp.

sawyer::Message::Message ( void *  input,
size_t  msg_len 
)

Definition at line 84 of file Message.cpp.

sawyer::Message::Message ( const Message other)

Definition at line 93 of file Message.cpp.

sawyer::Message::Message ( uint16_t  type,
uint8_t *  payload,
size_t  payload_len,
uint32_t  timestamp = 0,
uint8_t  flags = 0,
uint8_t  version = 0 
)

Definition at line 101 of file Message.cpp.

sawyer::Message::~Message ( )
virtual

Definition at line 131 of file Message.cpp.

Member Function Documentation

size_t sawyer::Message::crcOffset ( )
inlineprotected

Definition at line 107 of file Message.h.

Message * sawyer::Message::factory ( void *  input,
size_t  msg_len 
)
static

Instantiates the Message subclass corresponding to the type field in raw message data.

Parameters
inputThe raw message data to instantiate from
msg_lenThe length of input.
Returns
An instance of the correct Message subclass

Definition at line 423 of file Message.cpp.

uint16_t sawyer::Message::getChecksum ( )

Definition at line 248 of file Message.cpp.

uint8_t sawyer::Message::getFlags ( )

Definition at line 238 of file Message.cpp.

uint8_t sawyer::Message::getLength ( )

Definition at line 223 of file Message.cpp.

uint8_t sawyer::Message::getLengthComp ( )

Definition at line 228 of file Message.cpp.

size_t sawyer::Message::getPayload ( void *  buf,
size_t  buf_size 
)

Copies message payload into a provided buffer.

Parameters
bufThe buffer to fill
buf_sizeMaximum length of buf
Returns
number of bytes copied.

Definition at line 204 of file Message.cpp.

size_t sawyer::Message::getPayloadLength ( )
inline

Definition at line 161 of file Message.h.

uint8_t * sawyer::Message::getPayloadPointer ( size_t  offset = 0)
protected

Get a pointer to the payload withing this Message's internal storage.

Parameters
offsetThe offset from the beginning of the payload.
Returns
a pointer to this Message's internal storage.

Definition at line 218 of file Message.cpp.

size_t sawyer::Message::getTotalLength ( )
inline

Definition at line 168 of file Message.h.

uint16_t sawyer::Message::getType ( )

Definition at line 243 of file Message.cpp.

size_t sawyer::Message::getType ( void *  buf,
size_t  max_size 
)
size_t sawyer::Message::getTypeLength ( )
inline

Definition at line 156 of file Message.h.

uint8_t sawyer::Message::getVersion ( )

Definition at line 233 of file Message.cpp.

bool sawyer::Message::isCommand ( )
inline

Definition at line 177 of file Message.h.

bool sawyer::Message::isData ( )
inline

Definition at line 187 of file Message.h.

bool sawyer::Message::isRequest ( )
inline

Definition at line 182 of file Message.h.

bool sawyer::Message::isValid ( char *  whyNot = NULL,
size_t  strLen = 0 
)

Checks the consistency of this message.

Parameters
whyNotOptionally, a reason for validation failure will be written here.
strLenLength of the optional whyNot string
Returns
true if the message is valid, false otherwise.

Definition at line 329 of file Message.cpp.

void sawyer::Message::makeValid ( )
protected

Sets SOH, STX, length, and checksum so that this message becomes valid.

Definition at line 372 of file Message.cpp.

Message * sawyer::Message::popNext ( )
static

Definition at line 532 of file Message.cpp.

std::ostream & sawyer::Message::printMessage ( std::ostream &  stream = std::cout)
virtual
void sawyer::Message::printRaw ( std::ostream &  stream = std::cout)

Definition at line 405 of file Message.cpp.

void sawyer::Message::send ( )

Definition at line 136 of file Message.cpp.

Message * sawyer::Message::sendRequest ( )

Definition at line 168 of file Message.cpp.

void sawyer::Message::setFlags ( uint8_t  flags)
protected

Definition at line 267 of file Message.cpp.

void sawyer::Message::setLength ( uint8_t  len)
protected

Definition at line 253 of file Message.cpp.

void sawyer::Message::setPayload ( void *  buf,
size_t  buf_size 
)
protected

Set the payload of this message. Modifies the length of the message as necessary, as per setPayloadLength.

See also
Message::setPayloadLength()
Parameters
bufBuffer containing the new payload.
buf_sizeLength of buf.

Definition at line 296 of file Message.cpp.

void sawyer::Message::setPayloadLength ( uint8_t  len)
protected

Changes the payload length of the packet. Does not update packet len/~len fields or the checksum. Call makeValid() to update these fields.

Parameters
lenThe new payload length

Definition at line 282 of file Message.cpp.

void sawyer::Message::setType ( uint16_t  type)
protected

Definition at line 272 of file Message.cpp.

void sawyer::Message::setVersion ( uint8_t  version)
protected

Definition at line 262 of file Message.cpp.

size_t sawyer::Message::toBytes ( void *  buf,
size_t  buf_size 
)

Copy the complete raw content of this message to a buffer.

Parameters
bufThe buffer to copy to
buf_sizeThe maximum length of buf
Returns
buf on success, NULL on failure

Definition at line 311 of file Message.cpp.

Message * sawyer::Message::waitNext ( double  timeout = 0.0)
static

Definition at line 537 of file Message.cpp.

Friends And Related Function Documentation

friend class Transport
friend

Definition at line 99 of file Message.h.

Member Data Documentation

const uint16_t sawyer::Message::CRC_INIT_VAL = 0xFFFF
staticprotected

Definition at line 78 of file Message.h.

const size_t sawyer::Message::CRC_LENGTH = 2
staticprotected

Definition at line 77 of file Message.h.

uint8_t sawyer::Message::data[MAX_MSG_LENGTH]

Definition at line 72 of file Message.h.

const size_t sawyer::Message::HEADER_LENGTH = 8
staticprotected

Definition at line 80 of file Message.h.

bool sawyer::Message::is_sent
protected

Definition at line 97 of file Message.h.

const size_t sawyer::Message::MAX_MSG_LENGTH = 256
static

Definition at line 70 of file Message.h.

const size_t sawyer::Message::MIN_MSG_LENGTH = HEADER_LENGTH + CRC_LENGTH
static

Definition at line 102 of file Message.h.

const uint8_t sawyer::Message::SOH = 0xAA
static

Definition at line 103 of file Message.h.

const uint8_t sawyer::Message::STX = 0x55
static

Definition at line 104 of file Message.h.

size_t sawyer::Message::total_len

Definition at line 74 of file Message.h.


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


roch_base
Author(s): Mike Purvis , Paul Bovbel , Chen
autogenerated on Mon Jun 10 2019 14:41:14