MRPT  1.9.9
xsens::Cmt1s Class Reference

Detailed Description

The low-level serial communication class.

Definition at line 57 of file cmt1.h.

#include <xSens_MT3/cmt1.h>

Public Member Functions

 Cmt1s ()
 Default constructor, initializes all members to their default values. More...
 
 ~Cmt1s ()
 Destructor, de-initializes, frees memory allocated for buffers, etc. More...
 
XsensResultValue close (void)
 Close the serial communication port. More...
 
XsensResultValue escape (const CmtControlLine mask, const CmtControlLine state)
 Manipulate the Serial control lines. More...
 
XsensResultValue flushData (void)
 Flush all data to be transmitted / received. More...
 
uint32_t getBaudrate (void) const
 Return the baudrate that is currently being used by the port. More...
 
HANDLE getHandle (void) const
 Return the handle of the port. More...
 
uint8_t getPortNr (void) const
 Retrieve the port number that was last successfully opened. More...
 
void getPortName (char *portname) const
 Retrieve the port name that was last successfully opened. More...
 
XsensResultValue getLastResult (void) const
 Return the error code of the last operation. More...
 
uint32_t getTimeout (void) const
 Return the current timeout value. 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 communcation channel to the given serial port name. More...
 
XsensResultValue open (const uint32_t portNumber, 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 COM port number. More...
 
XsensResultValue readData (const uint32_t maxLength, uint8_t *data, uint32_t *length=nullptr)
 Read data from the serial port and put it into the data buffer. More...
 
XsensResultValue setCallbackFunction (CmtCallbackSelector tp, int32_t instance, CmtCallbackFunction func, void *param)
 Set the callback function for when bytes have been received. More...
 
XsensResultValue setTimeout (const uint32_t ms=CMT1_DEFAULT_TIMEOUT)
 Set the default timeout value to use in blocking operations. More...
 
XsensResultValue waitForData (const uint32_t maxLength, uint8_t *data, uint32_t *length=nullptr)
 Wait for data to arrive or a timeout to occur. More...
 
XsensResultValue writeData (const uint32_t length, const uint8_t *data, uint32_t *written)
 Write the data to the serial port. More...
 

Protected Attributes

uint32_t m_baudrate
 The baudrate that was last set to be used by the port. More...
 
uint32_t m_endTime
 The time at which an operation will end in ms, used by several functions. More...
 
bool m_isOpen
 Indicates if the port is open or not. More...
 
XsensResultValue m_lastResult
 The last result of an operation. More...
 
uint8_t m_port
 The opened COM port nr. More...
 
char m_portname [260]
 
uint32_t m_timeout
 
DCB m_commState
 Stored settings about the serial port. More...
 
HANDLE m_handle
 The serial port handle. More...
 

Private Member Functions

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

Private Attributes

CmtCallbackFunction m_onBytesReceived {nullptr}
 The bytes received function. More...
 
int32_t m_onBytesReceivedInstance
 Custom, user supplied parameter for the OnBytesReceived callback function, passed as the first argument. More...
 
voidm_onBytesReceivedParam
 Custom, user supplied parameter for the OnBytesReceived callback function, passed as the last argument. More...
 

Constructor & Destructor Documentation

◆ Cmt1s() [1/2]

xsens::Cmt1s::Cmt1s ( const Cmt1s ref)
private

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

◆ Cmt1s() [2/2]

xsens::Cmt1s::Cmt1s ( )

Default constructor, initializes all members to their default values.

Definition at line 185 of file cmt1.cpp.

References CMT1_DEFAULT_TIMEOUT, m_baudrate, m_endTime, m_isOpen, m_lastResult, m_port, m_timeout, and XRV_OK.

◆ ~Cmt1s()

xsens::Cmt1s::~Cmt1s ( )

Destructor, de-initializes, frees memory allocated for buffers, etc.

Definition at line 202 of file cmt1.cpp.

References close().

Here is the call graph for this function:

Member Function Documentation

◆ close()

XsensResultValue xsens::Cmt1s::close ( void  )

Close the serial communication port.

Definition at line 205 of file cmt1.cpp.

References mrpt::system::os::fclose(), m_endTime, m_handle, m_isOpen, m_lastResult, XRV_NOPORTOPEN, and XRV_OK.

Referenced by xsens::Cmt2s::close(), and ~Cmt1s().

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

◆ escape()

XsensResultValue xsens::Cmt1s::escape ( const CmtControlLine  mask,
const CmtControlLine  state 
)

Manipulate the Serial control lines.

The function manipulates the serial control lines that are indicated by the mask parameter. Note that only the DTR and RTS lines can be set by win32.

Parameters
maskIndicates which lines are to be manipulated and which should be left alone.
stateContains the new state of the control lines.

Definition at line 245 of file cmt1.cpp.

References CMT_CONTROL_DTR, CMT_CONTROL_RTS, m_handle, m_isOpen, m_lastResult, status, XRV_ERROR, XRV_NOPORTOPEN, and XRV_OK.

◆ flushData()

XsensResultValue xsens::Cmt1s::flushData ( void  )

Flush all data to be transmitted / received.

This function tries to send and receive any remaining data immediately and does not return until the buffers are empty.

Definition at line 308 of file cmt1.cpp.

References m_endTime, m_handle, m_lastResult, and XRV_OK.

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

Here is the caller graph for this function:

◆ getBaudrate()

uint32_t xsens::Cmt1s::getBaudrate ( void  ) const
inline

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

Definition at line 139 of file cmt1.h.

References m_baudrate.

Referenced by xsens::Cmt2s::getBaudrate().

Here is the caller graph for this function:

◆ getHandle()

HANDLE xsens::Cmt1s::getHandle ( void  ) const
inline

Return the handle of the port.

Definition at line 141 of file cmt1.h.

References m_handle.

◆ getLastResult()

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

Return the error code of the last operation.

Definition at line 150 of file cmt1.h.

References m_lastResult.

◆ getPortName()

void xsens::Cmt1s::getPortName ( char *  portname) const
inline

Retrieve the port name that was last successfully opened.

Definition at line 145 of file cmt1.h.

References m_portname, and mrpt::system::os::sprintf().

Referenced by xsens::Cmt2s::getPortName().

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

◆ getPortNr()

uint8_t xsens::Cmt1s::getPortNr ( void  ) const
inline

Retrieve the port number that was last successfully opened.

Definition at line 143 of file cmt1.h.

References m_port.

Referenced by xsens::Cmt2s::close(), xsens::Cmt2s::getPortNr(), xsens::Cmt3::gotoConfig(), xsens::Cmt3::gotoMeasurement(), xsens::Cmt3::initBus(), xsens::Cmt2s::readMessage(), xsens::Cmt2s::waitForMessage(), and xsens::Cmt2s::writeMessage().

Here is the caller graph for this function:

◆ getTimeout()

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

Return the current timeout value.

Definition at line 152 of file cmt1.h.

References m_timeout.

◆ isOpen()

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

Return whether the communication port is open or not.

Definition at line 154 of file cmt1.h.

References m_isOpen.

Referenced by xsens::Cmt2s::isOpen().

Here is the caller graph for this function:

◆ open() [1/2]

XsensResultValue xsens::Cmt1s::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 communcation channel to the given serial port name.

The port is automatically initialized to the given baudrate. If the baudrate is set to 0, the baud rate is automatically detected. If possible.

Definition at line 322 of file cmt1.cpp.

References CMT1LOG, FALSE, m_baudrate, m_commState, m_endTime, m_handle, m_isOpen, m_lastResult, m_port, m_portname, m_timeout, MRPT_UNUSED_PARAM, setTimeout(), mrpt::system::os::sprintf(), XRV_ALREADYOPEN, XRV_ERROR, XRV_INPUTCANNOTBEOPENED, and XRV_OK.

Referenced by xsens::Cmt2s::open(), and open().

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

◆ open() [2/2]

XsensResultValue xsens::Cmt1s::open ( const uint32_t  portNumber,
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 COM port number.

The port is automatically initialized to the given baud rate. If the baudrate is set to 0, the baud rate is automatically detected. If possible.

Definition at line 470 of file cmt1.cpp.

References open(), and mrpt::system::os::sprintf().

Here is the call graph for this function:

◆ readData()

XsensResultValue xsens::Cmt1s::readData ( const uint32_t  maxLength,
uint8_t data,
uint32_t length = nullptr 
)

Read data from the serial port and put it into the data buffer.

This function reads as much data as possible from the com port (non-blocking) and put as much data as will fit into the data buffer. Any excess data is stored in the m_readBuffer member variable. If there was enough data in m_readBuffer to fulfill the request, the data parameter is first filled and the port is polled afterwards.

Parameters
maxLengthThe maximum amount of data read.
dataPointer to a buffer that will store the received data.
lengthThe number of bytes placed into data.

Definition at line 485 of file cmt1.cpp.

References CMT1LOG, CMT_CALLBACK_ONBYTESRECEIVED, CMT_MAX_FILENAME_LENGTH, CMTLOG, mrpt::system::os::fopen(), m_baudrate, CmtBinaryData::m_data, m_handle, m_isOpen, m_lastResult, m_onBytesReceived, m_onBytesReceivedInstance, m_onBytesReceivedParam, m_port, CmtBinaryData::m_portNr, CmtBinaryData::m_size, mrpt::system::os::memcpy(), mrpt::system::os::sprintf(), XRV_ERROR, XRV_NOPORTOPEN, and XRV_OK.

Referenced by xsens::Cmt2s::readMessage(), waitForData(), and xsens::Cmt2s::waitForMessage().

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

◆ setCallbackFunction()

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

Set the callback function for when bytes have been received.

Definition at line 545 of file cmt1.cpp.

References CMT_CALLBACK_ONBYTESRECEIVED, m_lastResult, m_onBytesReceived, m_onBytesReceivedInstance, m_onBytesReceivedParam, XRV_INVALIDPARAM, and XRV_OK.

◆ setTimeout()

XsensResultValue xsens::Cmt1s::setTimeout ( const uint32_t  ms = CMT1_DEFAULT_TIMEOUT)

Set the default timeout value to use in blocking operations.

This function sets the value of m_timeout. There is no infinity value. The value 0 means that all blocking operations now become polling (non-blocking) operations. If the value is set to or from 0, the low-level serial port settings may be changed in addition to the m_timeout value.

Definition at line 561 of file cmt1.cpp.

References CMT1LOG, m_commState, m_handle, m_isOpen, m_lastResult, m_timeout, and XRV_OK.

Referenced by open(), and xsens::Cmt2s::setTimeout().

Here is the caller graph for this function:

◆ waitForData()

XsensResultValue xsens::Cmt1s::waitForData ( const uint32_t  maxLength,
uint8_t data,
uint32_t length = nullptr 
)

Wait for data to arrive or a timeout to occur.

The function waits until maxLength data is available or until a timeout occurs. The function returns success if data is available or XsensResultValue::TIMEOUT if a timeout occurred. A timeout value of 0 indicates that the default timeout stored in the class should be used.

Definition at line 605 of file cmt1.cpp.

References CMT1LOG, xsens::getTimeOfDay(), m_lastResult, m_timeout, readData(), XRV_OK, and XRV_TIMEOUT.

Here is the call graph for this function:

◆ writeData()

XsensResultValue xsens::Cmt1s::writeData ( const uint32_t  length,
const uint8_t data,
uint32_t written 
)

Write the data to the serial port.

The function writes the given data to the connected COM port. The default timeout is respected in this operation.

Definition at line 633 of file cmt1.cpp.

References CMT_MAX_FILENAME_LENGTH, mrpt::system::os::fopen(), m_baudrate, m_handle, m_isOpen, m_lastResult, m_port, mrpt::system::os::sprintf(), XRV_ERROR, XRV_NOPORTOPEN, and XRV_OK.

Referenced by xsens::Cmt2s::writeMessage().

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

Member Data Documentation

◆ m_baudrate

uint32_t xsens::Cmt1s::m_baudrate
protected

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

Definition at line 84 of file cmt1.h.

Referenced by Cmt1s(), getBaudrate(), open(), readData(), and writeData().

◆ m_commState

DCB xsens::Cmt1s::m_commState
protected

Stored settings about the serial port.

Definition at line 102 of file cmt1.h.

Referenced by open(), and setTimeout().

◆ m_endTime

uint32_t xsens::Cmt1s::m_endTime
protected

The time at which an operation will end in ms, used by several functions.

Definition at line 87 of file cmt1.h.

Referenced by close(), Cmt1s(), flushData(), and open().

◆ m_handle

HANDLE xsens::Cmt1s::m_handle
protected

The serial port handle.

Definition at line 104 of file cmt1.h.

Referenced by close(), escape(), flushData(), getHandle(), open(), readData(), setTimeout(), and writeData().

◆ m_isOpen

bool xsens::Cmt1s::m_isOpen
protected

Indicates if the port is open or not.

Definition at line 89 of file cmt1.h.

Referenced by close(), Cmt1s(), escape(), isOpen(), open(), readData(), setTimeout(), and writeData().

◆ m_lastResult

XsensResultValue xsens::Cmt1s::m_lastResult
mutableprotected

The last result of an operation.

Definition at line 91 of file cmt1.h.

Referenced by close(), Cmt1s(), escape(), flushData(), getLastResult(), open(), readData(), setCallbackFunction(), setTimeout(), waitForData(), and writeData().

◆ m_onBytesReceived

CmtCallbackFunction xsens::Cmt1s::m_onBytesReceived {nullptr}
private

The bytes received function.

This function is automatically called every time binary data is read from the connected COM port.

Definition at line 74 of file cmt1.h.

Referenced by readData(), and setCallbackFunction().

◆ m_onBytesReceivedInstance

int32_t xsens::Cmt1s::m_onBytesReceivedInstance
private

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

Definition at line 77 of file cmt1.h.

Referenced by readData(), and setCallbackFunction().

◆ m_onBytesReceivedParam

void* xsens::Cmt1s::m_onBytesReceivedParam
private

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

Definition at line 80 of file cmt1.h.

Referenced by readData(), and setCallbackFunction().

◆ m_port

uint8_t xsens::Cmt1s::m_port
protected

The opened COM port nr.

Definition at line 93 of file cmt1.h.

Referenced by Cmt1s(), getPortNr(), open(), readData(), and writeData().

◆ m_portname

char xsens::Cmt1s::m_portname[260]
protected

Definition at line 94 of file cmt1.h.

Referenced by getPortName(), and open().

◆ m_timeout

uint32_t xsens::Cmt1s::m_timeout
protected

The default timeout value to use during blocking operations. A value of 0 means that all operations become non-blocking.

Definition at line 98 of file cmt1.h.

Referenced by Cmt1s(), getTimeout(), open(), setTimeout(), and waitForData().




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