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.
#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... | |
Cmt1s * | getCmt1s (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 |
The message received function. More... | |
int32_t | m_onMessageReceivedInstance |
Custom, user supplied parameter for the OnMessageReceived callback function, passed as the first argument. More... | |
void * | m_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... | |
void * | m_onMessageSentParam |
Custom, user supplied parameter for the OnMessageSent callback function, passed as the last argument. More... | |
|
private |
This object cannot be copied, so this function is not implemented.
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.
xsens::Cmt2s::~Cmt2s | ( | ) |
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().
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.
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().
|
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().
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().
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().
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.
|
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().
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().
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().
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, 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, mrpt::system::os::memcpy(), xsens::Cmt1s::readData(), XRV_OK, and XRV_TIMEOUT.
Referenced by xsens::Cmt3::readDataPacket().
XsensResultValue xsens::Cmt2s::setCallbackFunction | ( | CmtCallbackSelector | tp, |
int32_t | instance, | ||
CmtCallbackFunction | func, | ||
void * | param | ||
) |
Set the callback function for when a message has been received or sent.
Definition at line 346 of file cmt2.cpp.
References CMT_CALLBACK_ONMESSAGERECEIVED, CMT_CALLBACK_ONMESSAGESENT, m_lastResult, m_onMessageReceived, m_onMessageReceivedInstance, m_onMessageReceivedParam, m_onMessageSent, m_onMessageSentInstance, m_onMessageSentParam, XRV_INVALIDPARAM, and XRV_OK.
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 370 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().
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.
Definition at line 382 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().
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.
msg | The message to send. |
Definition at line 599 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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
protected |
The number of valid bytes in the readBuffer.
Definition at line 86 of file cmt2.h.
Referenced by Cmt2s(), readMessage(), and waitForMessage().
|
protected |
Timeout in ms for blocking operations.
Definition at line 88 of file cmt2.h.
Referenced by Cmt2s(), getTimeout(), setTimeout(), and waitForMessage().
|
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: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019 |