xsens_imu
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
xsens::Message Class Reference

Class for storing a single message. More...

#include <cmtmessage.h>

Public Member Functions

 Message (const uint8_t msgId=0, const uint16_t length=0, const uint16_t maxLength=CMT_MAXMSGLEN)
 Create a Message object with the given data length and message Id. More...
 
 Message (const uint8_t *source, const uint16_t size, const uint16_t maxLength=CMT_MAXMSGLEN)
 Create a message from the given source string. More...
 
 Message (const Message &src)
 
 ~Message ()
 Destructor. More...
 
void clear (void)
 Clear all data in the message. More...
 
uint8_t getBusId (void) const
 Return the current value of the m_busId field. More...
 
uint8_t * getDataBuffer (const uint16_t offset=0)
 Return a pointer to the data buffer. More...
 
const uint8_t * getDataBuffer (const uint16_t offset=0) const
 
uint8_t getDataByte (const uint16_t offset=0) const
 Return the current value of the data as an unsigned byte (8 bits). More...
 
double getDataDouble (const uint16_t offset=0) const
 Return the current value of the data as a double (64 bits). More...
 
float getDataFloat (const uint16_t offset=0) const
 Return the current value of the data as a float (32 bits). More...
 
double getDataF1220 (const uint16_t offset=0) const
 Return the current value of the data as a double, converting it from FP 12.20. More...
 
double getDataFP1632 (const uint16_t offset=0) const
 Return the current value of the data as a double, converting it from FP 16.32. More...
 
double getDataFPValue (const uint64_t outputSettings, const uint16_t offset=0) const
 Return current data value as double, conversion depends on outputSettings. More...
 
void getDataFPValue (double *dest, const uint64_t outputSettings, uint16_t offset, const int16_t numValues) const
 Return current data values as double, conversion depends on outputSetting. More...
 
uint32_t getDataLong (const uint16_t offset=0) const
 Return the current value of the data as an uint32_t (32 bits). More...
 
uint16_t getDataShort (const uint16_t offset=0) const
 Return the current value of the data as an uint16_t (16 bits). More...
 
uint16_t getDataSize (void) const
 Return the length of the data part of the message. More...
 
uint8_t getMessageId (void) const
 Return the current value of the m_messageId field. More...
 
const uint8_t * getMessageStart (void) const
 Return the start of the message buffer. More...
 
uint16_t getTotalMessageSize (void) const
 Return the length of the message buffer. More...
 
bool isChecksumOk (void) const
 Compute the checksum and compare it with the stored checksum. Equal is ok. More...
 
XsensResultValue loadFromString (const uint8_t *source, const uint16_t size)
 Read the entire message from the given source string. More...
 
void recomputeChecksum (void)
 Compute the checksum field and fill it. More...
 
void resizeData (const uint16_t newSize)
 Resize the data area to the given size. More...
 
void setBusId (const uint8_t busId)
 Set the new value of the m_busId field and update the checksum. More...
 
void setDataBuffer (const uint8_t *data, const uint16_t offset=0, const uint16_t count=0)
 Write a string of bytes into the data buffer. More...
 
void setDataByte (const uint8_t data, const uint16_t offset=0)
 Write an unsigned byte (8 bits) into the data buffer. More...
 
void setDataDouble (const double data, const uint16_t offset=0)
 Write a double (64 bits) into the data buffer. More...
 
void setDataFloat (const float data, const uint16_t offset=0)
 Write a float (32 bits) into the data buffer. More...
 
void setDataF1220 (const double data, const uint16_t offset=0)
 Write a double (64 bits) into the data buffer, after converting it to F1220. More...
 
void setDataFP1632 (const double data, const uint16_t offset=0)
 Write a double (64 bits) into the data buffer, after converting it to FP1632. More...
 
void setDataFPValue (const uint64_t outputSettings, const double data, const uint16_t offset=0)
 Write a floating/fixed point value into to the data buffer, conversion depends on outputSettings. More...
 
void setDataFPValue (const uint64_t outputSettings, const double *data, uint16_t offset, const uint16_t numValues)
 Write a floating/fixed point value into to the data buffer, conversion depends on outputSettings. More...
 
void setDataLong (const uint32_t data, const uint16_t offset=0)
 Write an uint32_t (32 bits) into the data buffer. More...
 
void setDataShort (const uint16_t data, const uint16_t offset=0)
 Write an uint16_t (16 bits) into the data buffer. More...
 
void setMessageId (const uint8_t msgId)
 Set the new value of the m_messageId field and update the checksum. More...
 
void operator= (const Message &src)
 Copy message src into this. More...
 
void deleteData (uint16_t size, uint16_t offset=0)
 Remove a number of bytes from the message (this will reduce the message size) More...
 
void insertData (uint16_t size, uint16_t offset=0)
 Insert a number of bytes into the message (this will increase the message size) More...
 

Public Attributes

bool m_autoUpdateChecksum
 

Protected Member Functions

uint8_t calcChecksum (void) const
 Internal checksum computation. More...
 
uint8_t * getDataStart (void) const
 Internal function to get the start of the data buffer. More...
 

Protected Attributes

MessageHeaderm_buffer
 The message header is the data buffer with interpretation. More...
 
uint8_t * m_checksum
 The checksum in the m_data or m_extendedData buffer. More...
 
uint32_t m_maxLength
 The maximum size of the message, including header and footer. More...
 

Detailed Description

Class for storing a single message.

Constructor & Destructor Documentation

◆ Message() [1/3]

xsens::Message::Message ( const uint8_t  msgId = 0,
const uint16_t  length = 0,
const uint16_t  maxLength = CMT_MAXMSGLEN 
)

Create a Message object with the given data length and message Id.

The function allocates enough memory to hold an entire message with the given data length.

Parameters
msgIdThe message Id that will be assigend to the m_messageId field.
lengthThe length of the data in the message. This value is stored in m_createdLength as well as m_length or m_extendedLength.
maxLengthThe maximum data length that can be stored in the structure.

◆ Message() [2/3]

xsens::Message::Message ( const uint8_t *  source,
const uint16_t  size,
const uint16_t  maxLength = CMT_MAXMSGLEN 
)

Create a message from the given source string.

This is done through a simple memory copy. The number of bytes copied is taken from the data in the message (so the message is interpreted first). Note that this does NOT recompute the checksum, nor is it checked.

Parameters
sourceThe source string containing message data
sizeThe size of the source string
maxLengthThe maximum data length that can be stored in the structure.

◆ Message() [3/3]

xsens::Message::Message ( const Message src)

◆ ~Message()

xsens::Message::~Message ( )

Destructor.

Member Function Documentation

◆ calcChecksum()

uint8_t xsens::Message::calcChecksum ( void  ) const
inlineprotected

Internal checksum computation.

◆ clear()

void xsens::Message::clear ( void  )

Clear all data in the message.

◆ deleteData()

void xsens::Message::deleteData ( uint16_t  size,
uint16_t  offset = 0 
)

Remove a number of bytes from the message (this will reduce the message size)

◆ getBusId()

uint8_t xsens::Message::getBusId ( void  ) const
inline

Return the current value of the m_busId field.

◆ getDataBuffer() [1/2]

uint8_t* xsens::Message::getDataBuffer ( const uint16_t  offset = 0)
inline

Return a pointer to the data buffer.

Parameters
offsetAn optional offset in the data buffer from where to start reading.

◆ getDataBuffer() [2/2]

const uint8_t* xsens::Message::getDataBuffer ( const uint16_t  offset = 0) const
inline

◆ getDataByte()

uint8_t xsens::Message::getDataByte ( const uint16_t  offset = 0) const
inline

Return the current value of the data as an unsigned byte (8 bits).

Parameters
offsetAn optional offset in the data buffer from where to start reading.

◆ getDataDouble()

double xsens::Message::getDataDouble ( const uint16_t  offset = 0) const

Return the current value of the data as a double (64 bits).

Parameters
offsetAn optional offset in the data buffer from where to start reading.

◆ getDataF1220()

double xsens::Message::getDataF1220 ( const uint16_t  offset = 0) const

Return the current value of the data as a double, converting it from FP 12.20.

Parameters
offsetAn optional offset in the data buffer from where to start reading.

◆ getDataFloat()

float xsens::Message::getDataFloat ( const uint16_t  offset = 0) const

Return the current value of the data as a float (32 bits).

Parameters
offsetAn optional offset in the data buffer from where to start reading.

◆ getDataFP1632()

double xsens::Message::getDataFP1632 ( const uint16_t  offset = 0) const

Return the current value of the data as a double, converting it from FP 16.32.

Parameters
offsetAn optional offset in the data buffer from where to start reading.

◆ getDataFPValue() [1/2]

double xsens::Message::getDataFPValue ( const uint64_t  outputSettings,
const uint16_t  offset = 0 
) const

Return current data value as double, conversion depends on outputSettings.

Parameters
outputSettingsMT output settings
offsetAn optional offset in the data buffer from where to start reading.

◆ getDataFPValue() [2/2]

void xsens::Message::getDataFPValue ( double *  dest,
const uint64_t  outputSettings,
uint16_t  offset,
const int16_t  numValues 
) const

Return current data values as double, conversion depends on outputSetting.

Parameters
destdestination array
outputSettingsMT output settings
offsetoffset in the data buffer from where to start reading.
numValuesnumber of values to be read

◆ getDataLong()

uint32_t xsens::Message::getDataLong ( const uint16_t  offset = 0) const

Return the current value of the data as an uint32_t (32 bits).

Parameters
offsetAn optional offset in the data buffer from where to start reading.

◆ getDataShort()

uint16_t xsens::Message::getDataShort ( const uint16_t  offset = 0) const

Return the current value of the data as an uint16_t (16 bits).

Parameters
offsetAn optional offset in the data buffer from where to start reading.

◆ getDataSize()

uint16_t xsens::Message::getDataSize ( void  ) const

Return the length of the data part of the message.

◆ getDataStart()

uint8_t * xsens::Message::getDataStart ( void  ) const
protected

Internal function to get the start of the data buffer.

◆ getMessageId()

uint8_t xsens::Message::getMessageId ( void  ) const
inline

Return the current value of the m_messageId field.

◆ getMessageStart()

const uint8_t* xsens::Message::getMessageStart ( void  ) const
inline

Return the start of the message buffer.

The function returns the address of the m_preamble member.

◆ getTotalMessageSize()

uint16_t xsens::Message::getTotalMessageSize ( void  ) const

Return the length of the message buffer.

The function returns the total size of the message, including the checksum. This is in effect the number of bytes that would be transferred if the message were to be sent over a communications channel.

◆ insertData()

void xsens::Message::insertData ( uint16_t  size,
uint16_t  offset = 0 
)

Insert a number of bytes into the message (this will increase the message size)

◆ isChecksumOk()

bool xsens::Message::isChecksumOk ( void  ) const

Compute the checksum and compare it with the stored checksum. Equal is ok.

◆ loadFromString()

XsensResultValue xsens::Message::loadFromString ( const uint8_t *  source,
const uint16_t  size 
)

Read the entire message from the given source string.

This is done through a simple memory copy. The number of bytes copied is m_createdLength.

Parameters
sourceThe source string containing message data
sizeThe size of the source string

◆ operator=()

void xsens::Message::operator= ( const Message src)

Copy message src into this.

◆ recomputeChecksum()

void xsens::Message::recomputeChecksum ( void  )
inline

Compute the checksum field and fill it.

The checksum field should normally be correct at all times, but if you have somehow managed to mess it up, this function can be used to recompute it.

◆ resizeData()

void xsens::Message::resizeData ( const uint16_t  newSize)

Resize the data area to the given size.

◆ setBusId()

void xsens::Message::setBusId ( const uint8_t  busId)

Set the new value of the m_busId field and update the checksum.

◆ setDataBuffer()

void xsens::Message::setDataBuffer ( const uint8_t *  data,
const uint16_t  offset = 0,
const uint16_t  count = 0 
)

Write a string of bytes into the data buffer.

Parameters
dataThe data to write to the buffer.
offsetAn optional offset in the data buffer from where to start writing.
countAn optional number of bytes to write, if set to 0 (not set), as many bytes as will fit into the buffer from the given point will be written.

◆ setDataByte()

void xsens::Message::setDataByte ( const uint8_t  data,
const uint16_t  offset = 0 
)

Write an unsigned byte (8 bits) into the data buffer.

Parameters
dataThe data to write to the buffer.
offsetAn optional offset in the data buffer from where to start writing.

◆ setDataDouble()

void xsens::Message::setDataDouble ( const double  data,
const uint16_t  offset = 0 
)

Write a double (64 bits) into the data buffer.

Parameters
dataThe data to write to the buffer.
offsetAn optional offset in the data buffer from where to start writing.

◆ setDataF1220()

void xsens::Message::setDataF1220 ( const double  data,
const uint16_t  offset = 0 
)

Write a double (64 bits) into the data buffer, after converting it to F1220.

Parameters
dataThe data to write to the buffer.
offsetAn optional offset in the data buffer from where to start writing.

◆ setDataFloat()

void xsens::Message::setDataFloat ( const float  data,
const uint16_t  offset = 0 
)

Write a float (32 bits) into the data buffer.

Parameters
dataThe data to write to the buffer.
offsetAn optional offset in the data buffer from where to start writing.

◆ setDataFP1632()

void xsens::Message::setDataFP1632 ( const double  data,
const uint16_t  offset = 0 
)

Write a double (64 bits) into the data buffer, after converting it to FP1632.

Parameters
dataThe data to write to the buffer.
offsetAn optional offset in the data buffer from where to start writing.

◆ setDataFPValue() [1/2]

void xsens::Message::setDataFPValue ( const uint64_t  outputSettings,
const double  data,
const uint16_t  offset = 0 
)

Write a floating/fixed point value into to the data buffer, conversion depends on outputSettings.

Parameters
outputSettingsMT output settings
dataThe data to write to the buffer.
offsetAn optional offset in the data buffer from where to start writing.

◆ setDataFPValue() [2/2]

void xsens::Message::setDataFPValue ( const uint64_t  outputSettings,
const double *  data,
uint16_t  offset,
const uint16_t  numValues 
)

Write a floating/fixed point value into to the data buffer, conversion depends on outputSettings.

Parameters
outputSettingsMT output settings
dataThe data array to be written to the buffer.
offsetOffset in the data buffer from where to start writing.
numValuesnumber of values to be written

◆ setDataLong()

void xsens::Message::setDataLong ( const uint32_t  data,
const uint16_t  offset = 0 
)

Write an uint32_t (32 bits) into the data buffer.

Parameters
dataThe data to write to the buffer.
offsetAn optional offset in the data buffer from where to start writing.

◆ setDataShort()

void xsens::Message::setDataShort ( const uint16_t  data,
const uint16_t  offset = 0 
)

Write an uint16_t (16 bits) into the data buffer.

Parameters
dataThe data to write to the buffer.
offsetAn optional offset in the data buffer from where to start writing.

◆ setMessageId()

void xsens::Message::setMessageId ( const uint8_t  msgId)

Set the new value of the m_messageId field and update the checksum.

Member Data Documentation

◆ m_autoUpdateChecksum

bool xsens::Message::m_autoUpdateChecksum

◆ m_buffer

MessageHeader* xsens::Message::m_buffer
protected

The message header is the data buffer with interpretation.

◆ m_checksum

uint8_t* xsens::Message::m_checksum
protected

The checksum in the m_data or m_extendedData buffer.

◆ m_maxLength

uint32_t xsens::Message::m_maxLength
protected

The maximum size of the message, including header and footer.


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