Main MRPT website > C++ reference for MRPT 1.5.7
List of all members | Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
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 37 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. 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...
 

Private Member Functions

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

Private Attributes

CmtCallbackFunction m_onMessageReceived
 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
 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 111 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 124 of file cmt2.cpp.

Member Function Documentation

◆ close()

XsensResultValue xsens::Cmt2s::close ( void  )

Close the serial communication port.

Definition at line 129 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().

◆ getBaudrate()

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

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

Definition at line 90 of file cmt2.h.

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

◆ 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 96 of file cmt2.h.

References m_cmt1s.

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

◆ getLastResult()

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

Return the error code of the last operation.

Definition at line 98 of file cmt2.h.

References m_lastResult.

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

◆ getPortName()

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

Definition at line 143 of file cmt2.cpp.

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

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

◆ getPortNr() [1/2]

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

Retrieve the port that the object is connected to.

Definition at line 154 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().

◆ getPortNr() [2/2]

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

Definition at line 164 of file cmt2.cpp.

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

◆ getTimeout()

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

Return the current timeout value in ms.

Definition at line 104 of file cmt2.h.

References m_timeout.

◆ isOpen()

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

◆ 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 174 of file cmt2.cpp.

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

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

◆ 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 187 of file cmt2.cpp.

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

◆ readMessage()

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

◆ 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 349 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().

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

Definition at line 361 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, CmtBinaryData::m_data, xsens::MessageHeader::m_datlen, xsens::MessageHeader::_mdl::m_extended, xsens::MessageHeader::_mdl::_mextd::_mlen::m_high, m_lastResult, xsens::MessageHeader::m_length, xsens::MessageHeader::_mdl::_mextd::m_length, xsens::MessageHeader::_mdl::_mextd::_mlen::m_low, m_onMessageReceived, m_onMessageReceivedInstance, m_onMessageReceivedParam, CmtBinaryData::m_portNr, m_readBuffer, m_readBufferCount, CmtBinaryData::m_size, 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().

◆ 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 541 of file cmt2.cpp.

References CMT2LOG, CMT_CALLBACK_ONMESSAGESENT, CMTLOG, xsens::Message::getMessageStart(), xsens::Cmt1s::getPortNr(), xsens::Message::getTotalMessageSize(), m_cmt1s, CmtBinaryData::m_data, m_lastResult, m_onMessageSent, m_onMessageSentInstance, m_onMessageSentParam, CmtBinaryData::m_portNr, CmtBinaryData::m_size, 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().

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 66 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 68 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 70 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
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 47 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 49 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 51 of file cmt2.h.

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

◆ m_onMessageSent

CmtCallbackFunction xsens::Cmt2s::m_onMessageSent
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 58 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 60 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 62 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 72 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 74 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 76 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 78 of file cmt2.h.

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




Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019