39 # define CMT2LOG CMTLOG
59 if (pre >= bufferLength)
102 return res + pre + 1;
112 m_onMessageReceived(NULL),
113 m_onMessageSent(NULL)
147 if (strlen(portname) < 6)
176 CMT2LOG(
"L2: Opening port %s @baud %d\n", portName, baudRate);
189 CMT2LOG(
"L2: Opening port %d @baud %d\n",(
int32_t)portNumber,baudRate);
228 CMT2LOG(
"L2: readMessage no preamble found in buffer\n");
233 CMT2LOG(
"L2: readMessage preamble found at position %u\n",(
uint32_t) pre);
244 CMT2LOG(
"L2: readMessage not enough header data read\n");
254 CMT2LOG(
"L2: readMessage not enough extended header data read\n");
268 CMT2LOG(
"L2: readMessage invalid message length %u\n",(
uint32_t) target);
290 CMT2LOG(
"L2: readMessage OK\n");
298 #ifdef _LOG_CALLBACKS
320 CMT2LOG(
"L2: readMessage timed out\n");
351 CMT2LOG(
"L2: Setting timeout to %u ms\n",ms);
378 if (timeoutOverride != 0)
427 CMT2LOG(
"L2: waitForMessage timeout occurred trying to read header\n");
441 CMT2LOG(
"L2: waitForMessage timeout occurred trying to read extended header\n");
466 CMT2LOG(
"L2: waitForMessage timeout occurred\n");
482 #ifdef _LOG_CALLBACKS
506 CMT2LOG(
"L2: waitForMessage load from string failed\n");
518 CMT2LOG(
"L2: waitForMessage found message in message\n");
570 #ifdef _LOG_CALLBACKS
576 CMT2LOG(
"L2: writeMessage successful\n");
The low-level file communication class.
XsensResultValue setReadPos(const CmtFilePos pos)
Set the new absolute read position.
XsensResultValue deleteData(const CmtFilePos start, const uint32_t length)
Delete the given data from the file.
CmtFilePos getFileSize(void) const
Return the size of the file.
XsensResultValue appendData(const uint32_t length, const void *data)
Write data to the end of the file.
XsensResultValue closeAndDelete(void)
Close the file and delete it.
XsensResultValue close(void)
Close the file.
XsensResultValue writeData(const uint32_t length, const void *data)
Write data to the file.
CmtFilePos getReadPos(void) const
Return the current read position.
XsensResultValue getName(char *filename) const
Retrieve the filename that was last successfully opened.
XsensResultValue open(const char *filename, const bool create, const bool readOnly)
Open a file.
XsensResultValue find(const void *needle, const uint32_t needleLength, CmtFilePos &pos)
Find a string of bytes in the file.
XsensResultValue readData(const uint32_t maxLength, void *data, uint32_t *length)
Read data from the file and put it into the data buffer.
bool isOpen(void) const
Return whether the file is open or not.
XsensResultValue create(const char *filename)
Open an empty file.
XsensResultValue readData(const uint32_t maxLength, uint8_t *data, uint32_t *length=NULL)
Read data from the serial port and put it into the data buffer.
XsensResultValue close(void)
Close the serial communication port.
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.
XsensResultValue writeData(const uint32_t length, const uint8_t *data, uint32_t *written)
Write the data to the serial port.
void getPortName(char *portname) const
Retrieve the port name that was last successfully opened.
uint8_t getPortNr(void) const
Retrieve the port number that was last successfully opened.
XsensResultValue setTimeout(const uint32_t ms=CMT1_DEFAULT_TIMEOUT)
Set the default timeout value to use in blocking operations.
bool m_readOnly
When set to true, the file is read-only and attempts to write to it will fail.
XsensResultValue writeMessage(const Message *msg)
Write a message to the end of the file.
XsensResultValue readMessage(Message *msg, const uint8_t msgId=0)
Read the next message from the file, when msgId is non-zero, the first matching message will be retur...
CmtFilePos getFileSize(void)
Get the current file size.
CmtFilePos getReadPosition(void)
Get the current read position.
XsensResultValue m_lastResult
The last result of an operation.
XsensResultValue close(void)
Close the file.
Cmt1f * getCmt1f(void)
Get a reference to the embedded Cmt1f object.
XsensResultValue closeAndDelete(void)
Close the file and delete it.
XsensResultValue create(const char *filename)
Create a new file with level 2 header.
Cmt1f m_cmt1f
The Cmt1f object that is used for the low-level operations.
XsensResultValue setReadPosition(CmtFilePos pos)
Set the read position to the given position.
XsensResultValue getName(char *filename) const
Retrieve the filename that was last successfully opened.
Cmt2f()
Default constructor.
XsensResultValue getLastResult(void) const
Return the error code of the last operation.
bool isOpen(void) const
Return whether the file is open or not.
XsensResultValue open(const char *filename, const bool readOnly=false)
Open a file and read the header.
XsensResultValue writeMessage(Message *msg)
Send a message over the COM port.
XsensResultValue setCallbackFunction(CmtCallbackSelector tp, int32_t instance, CmtCallbackFunction func, void *param)
Set the callback function for when a message has been received or sent.
Cmt2s()
Default constructor, initialize all members to their default values.
~Cmt2s()
Destructor, de-initialize, free memory allocated for buffers, etc.
uint32_t m_baudrate
The baudrate that was last set to be used by the port.
uint32_t m_timeout
Timeout in ms for blocking operations.
CmtCallbackFunction m_onMessageReceived
The message received function.
void * m_onMessageReceivedParam
Custom, user supplied parameter for the OnMessageReceived callback function, passed as the last argum...
int32_t m_onMessageReceivedInstance
Custom, user supplied parameter for the OnMessageReceived callback function, passed as the first argu...
uint32_t m_toEnd
The timestamp at which to end an operation.
XsensResultValue close(void)
Close the serial communication port.
XsensResultValue setTimeout(const uint32_t ms=CMT2_DEFAULT_TIMEOUT)
Set the default timeout value to use in blocking operations.
Cmt1s m_cmt1s
The CMT level 1 object that this class operates on.
XsensResultValue getPortNr(uint8_t &port) const
Retrieve the port that the object is connected to.
XsensResultValue readMessage(Message *rcv)
Read a message from the COM port.
CmtCallbackFunction m_onMessageSent
The message sent function.
XsensResultValue m_lastResult
The last result of an operation.
int32_t m_onMessageSentInstance
Custom, user supplied parameter for the OnMessageSent callback function, passed as the first argument...
void * m_onMessageSentParam
Custom, user supplied parameter for the OnMessageSent callback function, passed as the last argument.
XsensResultValue open(const char *portName, const uint32_t baudRate=CMT_DEFAULT_BAUD_RATE)
Open a communication channel to the given serial port name.
uint8_t m_readBuffer[CMT_DEFAULT_READ_BUFFER_SIZE]
Buffer for reading data until a valid message is read. Should be rarely used.
XsensResultValue waitForMessage(Message *rcv, const uint8_t msgId, uint32_t timeoutOverride, bool acceptErrorMessage)
Wait for a message to arrive.
XsensResultValue getPortName(char *portname) const
uint16_t m_readBufferCount
The number of valid bytes in the readBuffer.
Class for storing a single message.
uint16_t getTotalMessageSize(void) const
Return the length of the message buffer.
uint8_t getMessageId(void) const
Return the current value of the m_messageId field.
bool isChecksumOk(void) const
Compute the checksum and compare it with the stored checksum. Equal is ok.
void clear(void)
Clear all data in the message.
const uint8_t * getMessageStart(void) const
Return the start of the message buffer.
XsensResultValue loadFromString(const uint8_t *source, const uint16_t size)
Read the entire message from the given source string.
#define CMT_LEN_MSGHEADERCS
XsensResultValue(__cdecl * CmtCallbackFunction)(int32_t, CmtCallbackSelector, void *, void *)
#define CMT_DEFAULT_BAUD_RATE
The default baud rate of the Cmt1s serial communication.
#define CMT2_DEFAULT_TIMEOUT
Timeout in ms for level 2.
@ CMT_CALLBACK_ONMESSAGESENT
Callback function, called when a full message has been sent by a port.
@ CMT_CALLBACK_ONMESSAGERECEIVED
Callback function, called when a full message has been received from a port.
#define CMT_LEN_MSGEXTHEADERCS
#define CMT_LEN_MSGHEADER
GLuint GLsizei GLsizei * length
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
An OS and compiler independent version of "memcpy".
The namespace of all Xsens software since 2006.
uint32_t getTimeOfDay(tm *date_, time_t *secs_)
A platform-independent clock.
int32_t findValidMessage(const uint8_t *buffer, const uint16_t bufferLength)
Find a valid message in the given buffer. If nothing is found, the function returns -1....
unsigned __int16 uint16_t
unsigned __int32 uint32_t
uint8_t m_data[CMT_MAXMSGLEN]
const char * xsensResultText(const XsensResultValue result)
XsensResultValue
Xsens return values.
@ XRV_ALREADYOPEN
An I/O device is already opened with this object.
@ XRV_NOPORTOPEN
No serial port opened for reading/writing.
@ XRV_NOFILEOPEN
No file opened for reading/writing.
@ XRV_ERROR
A generic error occurred.
@ XRV_TIMEOUT
A timeout occurred.
@ XRV_OK
Operation was performed successfully.
@ XRV_INVALIDPARAM
An invalid parameter is supplied.
@ XRV_READONLY
Tried to change a read-only value.
@ XRV_TIMEOUTNODATA
Operation aborted because of no data read.
#define XSENS_MS_PER_DAY
The number of milliseconds in a normal day.