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

Mid-level serial communication class. More...

#include <cmt2.h>

Public Member Functions

 Cmt2s ()
 Default constructor, initialize all members to their default values. More...
 
 ~Cmt2s ()
 Destructor, de-initialize, free memory allocated for buffers, etc. More...
 
XsensResultValue close (void)
 Close the serial communication port. More...
 
uint32_t getBaudrate (void)
 Return the baudrate that is currently being used by the port. More...
 
Cmt1sgetCmt1s (void)
 Return a reference to the embedded Cmt1s object. More...
 
XsensResultValue getLastResult (void) const
 Return the error code of the last operation. More...
 
XsensResultValue getPortNr (uint16_t &port) const
 Retrieve the port that the object is connected to. More...
 
XsensResultValue getPortNr (int32_t &port) const
 
XsensResultValue getPortName (char *portname) const
 
uint32_t getTimeout (void) const
 Return the current timeout value in ms. More...
 
bool isOpen (void) const
 Return whether the communication port is open or not. More...
 
XsensResultValue open (const char *portName, const uint32_t baudRate=CMT_DEFAULT_BAUD_RATE, uint32_t readBufSize=CMT_DEFAULT_READ_BUFFER_SIZE, uint32_t writeBufSize=CMT_DEFAULT_WRITE_BUFFER_SIZE)
 Open a communication channel to the given serial port name. More...
 
XsensResultValue readMessage (Message *rcv)
 Read a message from the COM port. More...
 
XsensResultValue setCallbackFunction (CmtCallbackType tp, int32_t instance, CmtCallbackFunction func, void *param)
 Set the callback function for when a message has been received or sent. More...
 
XsensResultValue setTimeout (const uint32_t ms=CMT2_DEFAULT_TIMEOUT)
 Set the default timeout value to use in blocking operations. More...
 
XsensResultValue waitForMessage (Message *rcv, const uint8_t msgId, uint32_t timeoutOverride, bool acceptErrorMessage)
 Wait for a message to arrive. More...
 
XsensResultValue writeMessage (Message *msg)
 Send a message over the COM port. More...
 

Protected Attributes

uint32_t m_baudrate
 The baudrate that was last set to be used by the port. More...
 
Cmt1s m_cmt1s
 The CMT level 1 object that this class operates on. More...
 
XsensResultValue m_lastResult
 The last result of an operation. More...
 
uint8_t m_readBuffer [CMT_DEFAULT_READ_BUFFER_SIZE]
 Buffer for reading data until a valid message is read. Should be rarely used. More...
 
uint16_t m_readBufferCount
 The number of valid bytes in the readBuffer. More...
 
uint32_t m_timeout
 Timeout in ms for blocking operations. More...
 
uint32_t m_toEnd
 The timestamp at which to end an operation. More...
 

Detailed Description

Mid-level serial communication class.

The class uses CMT level 1, but does not inherit from it. If software needs to access the level 1 component, it needs to be done through the getCmt1s() function.

Constructor & Destructor Documentation

◆ Cmt2s()

xsens::Cmt2s::Cmt2s ( )

Default constructor, initialize all members to their default values.

◆ ~Cmt2s()

xsens::Cmt2s::~Cmt2s ( )

Destructor, de-initialize, free memory allocated for buffers, etc.

Member Function Documentation

◆ close()

XsensResultValue xsens::Cmt2s::close ( void  )

Close the serial communication port.

◆ getBaudrate()

uint32_t xsens::Cmt2s::getBaudrate ( void  )
inline

Return the baudrate that is currently being used by the port.

◆ getCmt1s()

Cmt1s* xsens::Cmt2s::getCmt1s ( void  )
inline

Return a reference to the embedded Cmt1s object.

Any manipulation of the object should be done through Cmt2s. Cmt2s integrity is not guaranteed if the Cmt1s object is manipulated directly.

◆ getLastResult()

XsensResultValue xsens::Cmt2s::getLastResult ( void  ) const
inline

Return the error code of the last operation.

◆ getPortName()

XsensResultValue xsens::Cmt2s::getPortName ( char *  portname) const

◆ getPortNr() [1/2]

XsensResultValue xsens::Cmt2s::getPortNr ( uint16_t &  port) const

Retrieve the port that the object is connected to.

◆ getPortNr() [2/2]

XsensResultValue xsens::Cmt2s::getPortNr ( int32_t &  port) const

◆ getTimeout()

uint32_t xsens::Cmt2s::getTimeout ( void  ) const
inline

Return the current timeout value in ms.

◆ isOpen()

bool xsens::Cmt2s::isOpen ( void  ) const
inline

Return whether the communication port is open or not.

◆ open()

XsensResultValue xsens::Cmt2s::open ( const char *  portName,
const uint32_t  baudRate = CMT_DEFAULT_BAUD_RATE,
uint32_t  readBufSize = CMT_DEFAULT_READ_BUFFER_SIZE,
uint32_t  writeBufSize = CMT_DEFAULT_WRITE_BUFFER_SIZE 
)

Open a communication channel to the given serial port name.

◆ readMessage()

XsensResultValue xsens::Cmt2s::readMessage ( Message rcv)

Read a message from the COM port.

The function reads data from the embedded Cmt1s object. The data is then converted into a Message object. If an error occurred, a NULL pointer is returned and the error code can be retrieved with getLastError().

◆ setCallbackFunction()

XsensResultValue xsens::Cmt2s::setCallbackFunction ( CmtCallbackType  tp,
int32_t  instance,
CmtCallbackFunction  func,
void *  param 
)

Set the callback function for when a message has been received or sent.

◆ setTimeout()

XsensResultValue xsens::Cmt2s::setTimeout ( const uint32_t  ms = CMT2_DEFAULT_TIMEOUT)

Set the default timeout value to use in blocking operations.

This function sets the level 2 timeout value. The L1 value is set to half the given timeout value.

◆ waitForMessage()

XsensResultValue xsens::Cmt2s::waitForMessage ( Message rcv,
const uint8_t  msgId,
uint32_t  timeoutOverride,
bool  acceptErrorMessage 
)

Wait for a message to arrive.

The function waits for a message to arrive or until a timeout occurs. If the msgId parameter is set to a value other than 0, the function will wait until a message has arrived with that particular msgId.

Note
msgId 0 is the ReqDeviceID MID, but that is an outgoing only message. It is illogical to wait for a message that will never be sent to the host. So 0 is a safe value for the 'all' messages option.
If an error message is received, the contents are stored in the m_lastResult field and a NULL value is returned immediately.

◆ writeMessage()

XsensResultValue xsens::Cmt2s::writeMessage ( Message msg)

Send a message over the COM port.

The function attempts to write the message over the connected COM port.

Parameters
msgThe message to send.

Member Data Documentation

◆ m_baudrate

uint32_t xsens::Cmt2s::m_baudrate
protected

The baudrate that was last set to be used by the port.

◆ m_cmt1s

Cmt1s xsens::Cmt2s::m_cmt1s
protected

The CMT level 1 object that this class operates on.

◆ m_lastResult

XsensResultValue xsens::Cmt2s::m_lastResult
mutableprotected

The last result of an operation.

◆ m_readBuffer

uint8_t xsens::Cmt2s::m_readBuffer[CMT_DEFAULT_READ_BUFFER_SIZE]
protected

Buffer for reading data until a valid message is read. Should be rarely used.

◆ m_readBufferCount

uint16_t xsens::Cmt2s::m_readBufferCount
protected

The number of valid bytes in the readBuffer.

◆ m_timeout

uint32_t xsens::Cmt2s::m_timeout
protected

Timeout in ms for blocking operations.

◆ m_toEnd

uint32_t xsens::Cmt2s::m_toEnd
protected

The timestamp at which to end an operation.


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