MRPT  1.9.9
xsens::Cmt2s Class Reference

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.

Definition at line 41 of file cmt2.h.

#include <xSens_MT3/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 (uint8_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)
 Open a communication channel to the given serial port name. More...
 
XsensResultValue open (const uint32_t portNumber, const uint32_t baudRate=CMT_DEFAULT_BAUD_RATE)
 Open a communication channel to the given COM port number. More...
 
XsensResultValue readMessage (Message *rcv)
 Read a message from the COM port. More...
 
XsensResultValue setCallbackFunction (CmtCallbackSelector 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. 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...
 

Private Member Functions

 Cmt2s (const Cmt2s &ref)
 This object cannot be copied, so this function is not implemented. More...
 

Private Attributes

CmtCallbackFunction m_onMessageReceived {nullptr}
 The message received function. More...
 
int32_t m_onMessageReceivedInstance
 Custom, user supplied parameter for the OnMessageReceived callback function, passed as the first argument. More...
 
voidm_onMessageReceivedParam
 Custom, user supplied parameter for the OnMessageReceived callback function, passed as the last argument. More...
 
CmtCallbackFunction m_onMessageSent {nullptr}
 The message sent function. More...
 
int32_t m_onMessageSentInstance
 Custom, user supplied parameter for the OnMessageSent callback function, passed as the first argument. More...
 
voidm_onMessageSentParam
 Custom, user supplied parameter for the OnMessageSent callback function, passed as the last argument. More...
 

Constructor & Destructor Documentation

◆ Cmt2s() [1/2]

xsens::Cmt2s::Cmt2s ( const Cmt2s ref)
private

This object cannot be copied, so this function is not implemented.

◆ Cmt2s() [2/2]

xsens::Cmt2s::Cmt2s ( )

Default constructor, initialize all members to their default values.

Definition at line 108 of file cmt2.cpp.

References CMT2_DEFAULT_TIMEOUT, CMT_DEFAULT_BAUD_RATE, m_baudrate, m_lastResult, m_readBufferCount, m_timeout, m_toEnd, and XRV_OK.

◆ ~Cmt2s()

xsens::Cmt2s::~Cmt2s ( )

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

Definition at line 119 of file cmt2.cpp.

Member Function Documentation

◆ close()

XsensResultValue xsens::Cmt2s::close ( void  )

Close the serial communication port.

Definition at line 120 of file cmt2.cpp.

References xsens::Cmt1s::close(), CMT2LOG, xsens::Cmt1s::getPortNr(), m_cmt1s, m_lastResult, m_toEnd, and XRV_NOPORTOPEN.

Referenced by xsens::Cmt3::closePort(), xsens::Cmt3::openPort(), and xsens::Cmt3::~Cmt3().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBaudrate()

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

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

Definition at line 103 of file cmt2.h.

References xsens::Cmt1s::getBaudrate(), m_baudrate, and m_cmt1s.

Here is the call graph for this function:

◆ 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.

Definition at line 110 of file cmt2.h.

References m_cmt1s.

Referenced by xsens::Cmt3::gotoConfig(), xsens::Cmt3::gotoMeasurement(), and xsens::Cmt3::initBus().

Here is the caller graph for this function:

◆ getLastResult()

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

Return the error code of the last operation.

Definition at line 112 of file cmt2.h.

References m_lastResult.

Referenced by xsens::Cmt3::gotoConfig().

Here is the caller graph for this function:

◆ getPortName()

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

Definition at line 134 of file cmt2.cpp.

References xsens::Cmt1s::getPortName(), m_cmt1s, m_lastResult, XRV_ERROR, and XRV_OK.

Referenced by xsens::Cmt3::setBaudrate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPortNr() [1/2]

XsensResultValue xsens::Cmt2s::getPortNr ( uint8_t port) const

Retrieve the port that the object is connected to.

Definition at line 144 of file cmt2.cpp.

References xsens::Cmt1s::getPortNr(), m_cmt1s, m_lastResult, XRV_ERROR, and XRV_OK.

Referenced by xsens::Cmt3::getPortNr(), and xsens::Cmt3::setBaudrate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPortNr() [2/2]

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

Definition at line 153 of file cmt2.cpp.

References xsens::Cmt1s::getPortNr(), m_cmt1s, m_lastResult, XRV_ERROR, and XRV_OK.

Here is the call graph for this function:

◆ getTimeout()

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

Return the current timeout value in ms.

Definition at line 118 of file cmt2.h.

References m_timeout.

◆ isOpen()

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

Return whether the communication port is open or not.

Definition at line 120 of file cmt2.h.

References xsens::Cmt1s::isOpen(), and m_cmt1s.

Referenced by xsens::Cmt3::createLogFile(), xsens::Cmt3::getBaudrate(), xsens::Cmt3::getConfiguration(), xsens::Cmt3::getDeviceCount(), xsens::Cmt3::getEMtsData(), xsens::Cmt3::getMasterId(), xsens::Cmt3::getMtCount(), xsens::Cmt3::isPortOpen(), xsens::Cmt3::openLogFile(), xsens::Cmt3::refreshCache(), and xsens::Cmt3::setDataSource().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ open() [1/2]

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

Open a communication channel to the given serial port name.

Definition at line 162 of file cmt2.cpp.

References CMT2LOG, m_baudrate, m_cmt1s, m_lastResult, m_toEnd, xsens::Cmt1s::open(), and xsensResultText().

Referenced by xsens::Cmt3::openPort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ open() [2/2]

XsensResultValue xsens::Cmt2s::open ( const uint32_t  portNumber,
const uint32_t  baudRate = CMT_DEFAULT_BAUD_RATE 
)

Open a communication channel to the given COM port number.

Definition at line 177 of file cmt2.cpp.

References CMT2LOG, m_baudrate, m_cmt1s, m_lastResult, m_toEnd, xsens::Cmt1s::open(), and xsensResultText().

Here is the call graph for this function:

◆ 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 nullptr pointer is returned and the error code can be retrieved with getLastError().

Definition at line 192 of file cmt2.cpp.

References CMT2LOG, CMT_CALLBACK_ONMESSAGERECEIVED, CMT_EXTLENCODE, CMT_LEN_MSGEXTHEADERCS, CMT_LEN_MSGHEADERCS, CMT_MAXDATALEN, CMT_MAXMSGLEN, CMT_PREAMBLE, CMTLOG, xsens::Message::getMessageStart(), xsens::Cmt1s::getPortNr(), xsens::Message::loadFromString(), m_cmt1s, m_lastResult, m_onMessageReceived, m_onMessageReceivedInstance, m_onMessageReceivedParam, m_readBuffer, m_readBufferCount, mrpt::system::os::memcpy(), xsens::Cmt1s::readData(), XRV_OK, and XRV_TIMEOUT.

Referenced by xsens::Cmt3::readDataPacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCallbackFunction()

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

◆ 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.

Definition at line 369 of file cmt2.cpp.

References CMT2LOG, m_cmt1s, m_lastResult, m_timeout, m_toEnd, xsens::Cmt1s::setTimeout(), and XRV_OK.

Referenced by xsens::Cmt3::gotoConfig(), xsens::Cmt3::gotoMeasurement(), xsens::Cmt3::openPort(), xsens::Cmt3::setTimeout(), xsens::Cmt3::setTimeoutConfig(), and xsens::Cmt3::setTimeoutMeasurement().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 nullptr value is returned immediately.

Definition at line 381 of file cmt2.cpp.

References xsens::Message::clear(), CMT2LOG, CMT_CALLBACK_ONMESSAGERECEIVED, CMT_EXTLENCODE, CMT_LEN_MSGEXTHEADERCS, CMT_LEN_MSGHEADER, CMT_LEN_MSGHEADERCS, CMT_MAXDATALEN, CMT_MID_ERROR, CMT_PREAMBLE, CMTLOG, xsens::findValidMessage(), xsens::Message::getMessageId(), xsens::Cmt1s::getPortNr(), xsens::getTimeOfDay(), xsens::Message::loadFromString(), m_cmt1s, m_lastResult, m_onMessageReceived, m_onMessageReceivedInstance, m_onMessageReceivedParam, m_readBuffer, m_readBufferCount, m_timeout, m_toEnd, mrpt::system::os::memcpy(), xsens::Cmt1s::readData(), XRV_OK, XRV_TIMEOUT, XRV_TIMEOUTNODATA, and XSENS_MS_PER_DAY.

Referenced by xsens::Cmt3::getEMtsData(), xsens::Cmt3::getSyncInMode(), xsens::Cmt3::getSyncInOffset(), xsens::Cmt3::getSyncInSettings(), xsens::Cmt3::getSyncInSkipFactor(), xsens::Cmt3::getSyncOutMode(), xsens::Cmt3::getSyncOutOffset(), xsens::Cmt3::getSyncOutPulseWidth(), xsens::Cmt3::getSyncOutSettings(), xsens::Cmt3::getSyncOutSkipFactor(), xsens::Cmt3::gotoConfig(), xsens::Cmt3::gotoMeasurement(), xsens::Cmt3::refreshCache(), xsens::Cmt3::reset(), xsens::Cmt3::setBaudrate(), xsens::Cmt3::setDeviceMode2(), xsens::Cmt3::setGpsLeverArm(), xsens::Cmt3::setSyncInMode(), xsens::Cmt3::setSyncInOffset(), xsens::Cmt3::setSyncInSettings(), xsens::Cmt3::setSyncInSkipFactor(), xsens::Cmt3::setSyncOutMode(), xsens::Cmt3::setSyncOutOffset(), xsens::Cmt3::setSyncOutPulseWidth(), xsens::Cmt3::setSyncOutSettings(), xsens::Cmt3::setSyncOutSkipFactor(), xsens::Cmt3::storeXkfState(), and xsens::Cmt3::waitForDataMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Definition at line 597 of file cmt2.cpp.

References CMT2LOG, CMT_CALLBACK_ONMESSAGESENT, CMTLOG, xsens::Message::getMessageStart(), xsens::Cmt1s::getPortNr(), xsens::Message::getTotalMessageSize(), m_cmt1s, m_lastResult, m_onMessageSent, m_onMessageSentInstance, m_onMessageSentParam, mrpt::system::os::memcpy(), xsens::Cmt1s::writeData(), XRV_ERROR, XRV_OK, and xsensResultText().

Referenced by xsens::Cmt3::getEMtsData(), xsens::Cmt3::getSyncInMode(), xsens::Cmt3::getSyncInOffset(), xsens::Cmt3::getSyncInSettings(), xsens::Cmt3::getSyncInSkipFactor(), xsens::Cmt3::getSyncOutMode(), xsens::Cmt3::getSyncOutOffset(), xsens::Cmt3::getSyncOutPulseWidth(), xsens::Cmt3::getSyncOutSettings(), xsens::Cmt3::getSyncOutSkipFactor(), xsens::Cmt3::gotoConfig(), xsens::Cmt3::gotoMeasurement(), xsens::Cmt3::refreshCache(), xsens::Cmt3::requestData(), xsens::Cmt3::reset(), xsens::Cmt3::setBaudrate(), xsens::Cmt3::setDeviceMode2(), xsens::Cmt3::setGpsLeverArm(), xsens::Cmt3::setSyncInMode(), xsens::Cmt3::setSyncInOffset(), xsens::Cmt3::setSyncInSettings(), xsens::Cmt3::setSyncInSkipFactor(), xsens::Cmt3::setSyncOutMode(), xsens::Cmt3::setSyncOutOffset(), xsens::Cmt3::setSyncOutPulseWidth(), xsens::Cmt3::setSyncOutSettings(), xsens::Cmt3::setSyncOutSkipFactor(), xsens::Cmt3::setXmPowerOff(), and xsens::Cmt3::storeXkfState().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_baudrate

uint32_t xsens::Cmt2s::m_baudrate
protected

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

Definition at line 77 of file cmt2.h.

Referenced by Cmt2s(), getBaudrate(), and open().

◆ m_cmt1s

Cmt1s xsens::Cmt2s::m_cmt1s
protected

The CMT level 1 object that this class operates on.

Definition at line 79 of file cmt2.h.

Referenced by close(), getBaudrate(), getCmt1s(), getPortName(), getPortNr(), isOpen(), open(), readMessage(), setTimeout(), waitForMessage(), and writeMessage().

◆ m_lastResult

XsensResultValue xsens::Cmt2s::m_lastResult
mutableprotected

The last result of an operation.

Definition at line 81 of file cmt2.h.

Referenced by close(), Cmt2s(), getLastResult(), getPortName(), getPortNr(), open(), readMessage(), setCallbackFunction(), setTimeout(), waitForMessage(), and writeMessage().

◆ m_onMessageReceived

CmtCallbackFunction xsens::Cmt2s::m_onMessageReceived {nullptr}
private

The message received function.

This function is automatically called every time a complete message was read from the connected COM port.

Definition at line 53 of file cmt2.h.

Referenced by readMessage(), setCallbackFunction(), and waitForMessage().

◆ m_onMessageReceivedInstance

int32_t xsens::Cmt2s::m_onMessageReceivedInstance
private

Custom, user supplied parameter for the OnMessageReceived callback function, passed as the first argument.

Definition at line 56 of file cmt2.h.

Referenced by readMessage(), setCallbackFunction(), and waitForMessage().

◆ m_onMessageReceivedParam

void* xsens::Cmt2s::m_onMessageReceivedParam
private

Custom, user supplied parameter for the OnMessageReceived callback function, passed as the last argument.

Definition at line 59 of file cmt2.h.

Referenced by readMessage(), setCallbackFunction(), and waitForMessage().

◆ m_onMessageSent

CmtCallbackFunction xsens::Cmt2s::m_onMessageSent {nullptr}
private

The message sent function.

This function is automatically called every time a complete message was sent to the connected COM port.

Definition at line 67 of file cmt2.h.

Referenced by setCallbackFunction(), and writeMessage().

◆ m_onMessageSentInstance

int32_t xsens::Cmt2s::m_onMessageSentInstance
private

Custom, user supplied parameter for the OnMessageSent callback function, passed as the first argument.

Definition at line 70 of file cmt2.h.

Referenced by setCallbackFunction(), and writeMessage().

◆ m_onMessageSentParam

void* xsens::Cmt2s::m_onMessageSentParam
private

Custom, user supplied parameter for the OnMessageSent callback function, passed as the last argument.

Definition at line 73 of file cmt2.h.

Referenced by setCallbackFunction(), and writeMessage().

◆ 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.

Definition at line 84 of file cmt2.h.

Referenced by readMessage(), and waitForMessage().

◆ m_readBufferCount

uint16_t xsens::Cmt2s::m_readBufferCount
protected

The number of valid bytes in the readBuffer.

Definition at line 86 of file cmt2.h.

Referenced by Cmt2s(), readMessage(), and waitForMessage().

◆ m_timeout

uint32_t xsens::Cmt2s::m_timeout
protected

Timeout in ms for blocking operations.

Definition at line 88 of file cmt2.h.

Referenced by Cmt2s(), getTimeout(), setTimeout(), and waitForMessage().

◆ m_toEnd

uint32_t xsens::Cmt2s::m_toEnd
protected

The timestamp at which to end an operation.

Definition at line 90 of file cmt2.h.

Referenced by close(), Cmt2s(), open(), setTimeout(), and waitForMessage().




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019