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

#include <Message.h>

Inheritance diagram for clearpath::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 ()
 
uint32_t getTimestamp ()
 
size_t getTotalLength ()
 
uint16_t getType ()
 
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 ()
 
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)
 

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,
  TIMESTAMP_OFST, FLAGS_OFST = 8, TYPE_OFST, STX_OFST = 11,
  PAYLOAD_OFST
}
 

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 setTimestamp (uint32_t timestamp)
 
void setType (uint16_t type)
 
void setVersion (uint8_t version)
 

Protected Attributes

uint8_t data [MAX_MSG_LENGTH]
 
bool is_sent
 
size_t total_len
 

Static Protected Attributes

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

Friends

class Transport
 

Detailed Description

Definition at line 75 of file Message.h.

Member Enumeration Documentation

◆ dataOffsets

Enumerator
SOH_OFST 
LENGTH_OFST 
LENGTH_COMP_OFST 
VERSION_OFST 
TIMESTAMP_OFST 
FLAGS_OFST 
TYPE_OFST 
STX_OFST 
PAYLOAD_OFST 

Definition at line 88 of file Message.h.

Constructor & Destructor Documentation

◆ Message() [1/4]

clearpath::Message::Message ( )

Definition at line 74 of file Message.cpp.

◆ Message() [2/4]

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

Definition at line 81 of file Message.cpp.

◆ Message() [3/4]

clearpath::Message::Message ( const Message other)

Definition at line 89 of file Message.cpp.

◆ Message() [4/4]

clearpath::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 97 of file Message.cpp.

◆ ~Message()

clearpath::Message::~Message ( )
virtual

Definition at line 127 of file Message.cpp.

Member Function Documentation

◆ crcOffset()

size_t clearpath::Message::crcOffset ( )
inlineprotected

Definition at line 117 of file Message.h.

◆ factory()

Message * clearpath::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 385 of file Message.cpp.

◆ getChecksum()

uint16_t clearpath::Message::getChecksum ( )

Definition at line 216 of file Message.cpp.

◆ getFlags()

uint8_t clearpath::Message::getFlags ( )

Definition at line 206 of file Message.cpp.

◆ getLength()

uint8_t clearpath::Message::getLength ( )

Definition at line 186 of file Message.cpp.

◆ getLengthComp()

uint8_t clearpath::Message::getLengthComp ( )

Definition at line 191 of file Message.cpp.

◆ getPayload()

size_t clearpath::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 167 of file Message.cpp.

◆ getPayloadLength()

size_t clearpath::Message::getPayloadLength ( )
inline

Definition at line 167 of file Message.h.

◆ getPayloadPointer()

uint8_t * clearpath::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 181 of file Message.cpp.

◆ getTimestamp()

uint32_t clearpath::Message::getTimestamp ( )

Definition at line 201 of file Message.cpp.

◆ getTotalLength()

size_t clearpath::Message::getTotalLength ( )
inline

Definition at line 174 of file Message.h.

◆ getType()

uint16_t clearpath::Message::getType ( )

Definition at line 211 of file Message.cpp.

◆ getVersion()

uint8_t clearpath::Message::getVersion ( )

Definition at line 196 of file Message.cpp.

◆ isCommand()

bool clearpath::Message::isCommand ( )
inline

Definition at line 183 of file Message.h.

◆ isData()

bool clearpath::Message::isData ( )
inline

Definition at line 193 of file Message.h.

◆ isRequest()

bool clearpath::Message::isRequest ( )
inline

Definition at line 188 of file Message.h.

◆ isValid()

bool clearpath::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 302 of file Message.cpp.

◆ makeValid()

void clearpath::Message::makeValid ( )
protected

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

Definition at line 340 of file Message.cpp.

◆ popNext()

Message * clearpath::Message::popNext ( )
static

Definition at line 486 of file Message.cpp.

◆ printMessage()

std::ostream & clearpath::Message::printMessage ( std::ostream &  stream = std::cout)
virtual

◆ printRaw()

void clearpath::Message::printRaw ( std::ostream &  stream = std::cout)

Definition at line 367 of file Message.cpp.

◆ send()

void clearpath::Message::send ( )

Definition at line 132 of file Message.cpp.

◆ setFlags()

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

Definition at line 240 of file Message.cpp.

◆ setLength()

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

Definition at line 221 of file Message.cpp.

◆ setPayload()

void clearpath::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 270 of file Message.cpp.

◆ setPayloadLength()

void clearpath::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 256 of file Message.cpp.

◆ setTimestamp()

void clearpath::Message::setTimestamp ( uint32_t  timestamp)
protected

Definition at line 235 of file Message.cpp.

◆ setType()

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

Definition at line 245 of file Message.cpp.

◆ setVersion()

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

Definition at line 230 of file Message.cpp.

◆ toBytes()

size_t clearpath::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 284 of file Message.cpp.

◆ waitNext()

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

Definition at line 491 of file Message.cpp.

Friends And Related Function Documentation

◆ Transport

friend class Transport
friend

Definition at line 109 of file Message.h.

Member Data Documentation

◆ CRC_INIT_VAL

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

Definition at line 83 of file Message.h.

◆ CRC_LENGTH

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

Definition at line 82 of file Message.h.

◆ data

uint8_t clearpath::Message::data[MAX_MSG_LENGTH]
protected

Definition at line 101 of file Message.h.

◆ HEADER_LENGTH

const size_t clearpath::Message::HEADER_LENGTH = 12
staticprotected

Definition at line 85 of file Message.h.

◆ is_sent

bool clearpath::Message::is_sent
protected

Definition at line 107 of file Message.h.

◆ MAX_MSG_LENGTH

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

Definition at line 78 of file Message.h.

◆ MIN_MSG_LENGTH

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

Definition at line 112 of file Message.h.

◆ SOH

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

Definition at line 113 of file Message.h.

◆ STX

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

Definition at line 114 of file Message.h.

◆ total_len

size_t clearpath::Message::total_len
protected

Definition at line 103 of file Message.h.


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


husky_base
Author(s): Mike Purvis , Paul Bovbel
autogenerated on Sat Nov 26 2022 03:56:48