39 #define CMT2LOG CMTLOG 58 if (pre >= bufferLength)
return -1;
61 length = bufferLength - pre;
97 if (
res == -1)
return -1;
108 Cmt2s::Cmt2s() : m_onMessageReceived(nullptr), m_onMessageSent(nullptr)
164 CMT2LOG(
"L2: Opening port %s @baud %d\n", portName, baudRate);
179 CMT2LOG(
"L2: Opening port %d @baud %d\n", (
int32_t)portNumber, baudRate);
199 bool extended =
false;
224 CMT2LOG(
"L2: readMessage no preamble found in buffer\n");
230 "L2: readMessage preamble found at position %u\n",
242 CMT2LOG(
"L2: readMessage not enough header data read\n");
253 "L2: readMessage not enough extended header data " 269 "L2: readMessage bytes in buffer=%u, extended=%u, target=%u\n",
277 "L2: readMessage invalid message length %u\n",
294 "L2: readMessage readBufferCount %u < target %u\n",
302 CMT2LOG(
"L2: readMessage OK\n");
311 #ifdef _LOG_CALLBACKS 313 "C2: m_onMessageReceived(%d,(%d,%d),%p)\n",
331 "L2: readMessage invalid checksum %02x %02x %02x %02x %02x\n",
339 CMT2LOG(
"L2: readMessage timed out\n");
372 CMT2LOG(
"L2: Setting timeout to %u ms\n", ms);
384 bool acceptErrorMessage)
396 "L2: waitForMessage x%02x, TO=%u, TOend=%u, TOO=%u\n", (
uint32_t)msgId,
404 if (timeoutOverride != 0)
460 "L2: waitForMessage timeout occurred trying to read header\n");
479 "L2: waitForMessage timeout occurred trying to read " 480 "extended header\n");
512 CMT2LOG(
"L2: waitForMessage timeout occurred\n");
521 "L2: waitForMessage received msg Id x%02x while expecting " 522 "x%02x, msg size=%u\n",
532 #ifdef _LOG_CALLBACKS 534 "C2: m_onMessageReceived(%d,(%d,%d),%p)\n",
563 CMT2LOG(
"L2: waitForMessage load from string failed\n");
575 CMT2LOG(
"L2: waitForMessage found message in message\n");
584 rcv, msgId, 0, acceptErrorMessage);
602 "L2: writeMessage %2x %2x %2x %2x %2x\n",
621 "L2: writeMessage wrote %u of %u bytes, returns %d: %s\n", written,
634 #ifdef _LOG_CALLBACKS 636 "C2: m_onMessageSent(%d,(%d,%d),%p)\n",
645 CMT2LOG(
"L2: writeMessage successful\n");
Operation was performed successfully.
unsigned __int16 uint16_t
XsensResultValue appendData(const uint32_t length, const void *data)
Write data to the end of the file.
void getPortName(char *portname) const
Retrieve the port name that was last successfully opened.
XsensResultValue setReadPos(const CmtFilePos pos)
Set the new absolute read position.
XsensResultValue open(const char *filename, const bool readOnly=false)
Open a file and read the header.
XsensResultValue writeData(const uint32_t length, const uint8_t *data, uint32_t *written)
Write the data to the serial port.
XsensResultValue getName(char *filename) const
Retrieve the filename that was last successfully opened.
#define XSENS_MS_PER_DAY
The number of milliseconds in a normal day.
CmtCallbackFunction m_onMessageReceived
The message received function.
XsensResultValue getPortNr(uint8_t &port) const
Retrieve the port that the object is connected to.
XsensResultValue setCallbackFunction(CmtCallbackSelector tp, int32_t instance, CmtCallbackFunction func, void *param)
Set the callback function for when a message has been received or sent.
bool isOpen(void) const
Return whether the file is open or not.
#define CMT_DEFAULT_BAUD_RATE
The default baud rate of the Cmt1s serial communication.
CmtFilePos getReadPos(void) const
Return the current read position.
XsensResultValue readData(const uint32_t maxLength, void *data, uint32_t *length)
Read data from the file and put it into the data buffer.
XsensResultValue writeData(const uint32_t length, const void *data)
Write data to the file.
XsensResultValue closeAndDelete(void)
Close the file and delete it.
void clear(void)
Clear all data in the message.
Callback function, called when a full message has been received from a port.
XsensResultValue deleteData(const CmtFilePos start, const uint32_t length)
Delete the given data from the file. The function erases the given data from the file at the given wr...
CmtCallbackFunction m_onMessageSent
The message sent function.
XsensResultValue getName(char *filename) const
Retrieve the filename that was last successfully opened.
uint32_t m_toEnd
The timestamp at which to end an operation.
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.
#define CMT2_DEFAULT_TIMEOUT
Timeout in ms for level 2.
Cmt1s m_cmt1s
The CMT level 1 object that this class operates on.
XsensResultValue getPortName(char *portname) const
XsensResultValue open(const char *filename, const bool create, const bool readOnly)
Open a file.
Callback function, called when a full message has been sent by a port.
int32_t m_onMessageReceivedInstance
Custom, user supplied parameter for the OnMessageReceived callback function, passed as the first argu...
XsensResultValue setTimeout(const uint32_t ms=CMT1_DEFAULT_TIMEOUT)
Set the default timeout value to use in blocking operations.
void * m_onMessageSentParam
Custom, user supplied parameter for the OnMessageSent callback function, passed as the last argument...
int32_t m_onMessageSentInstance
Custom, user supplied parameter for the OnMessageSent callback function, passed as the first argument...
XsensResultValue close(void)
Close the file.
XsensResultValue
Xsens return values.
XsensResultValue closeAndDelete(void)
Close the file and delete it.
XsensResultValue(__cdecl * CmtCallbackFunction)(int32_t, CmtCallbackSelector, void *, void *)
CmtFilePos getReadPosition(void)
Get the current read position.
XsensResultValue find(const void *needle, const uint32_t needleLength, CmtFilePos &pos)
Find a string of bytes in the file.
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.
Cmt2s()
Default constructor, initialize all members to their default values.
#define CMT_LEN_MSGEXTHEADERCS
XsensResultValue open(const char *portName, const uint32_t baudRate=CMT_DEFAULT_BAUD_RATE)
Open a communication channel to the given serial port name.
XsensResultValue waitForMessage(Message *rcv, const uint8_t msgId, uint32_t timeoutOverride, bool acceptErrorMessage)
Wait for a message to arrive.
uint16_t m_readBufferCount
The number of valid bytes in the readBuffer.
uint8_t m_readBuffer[CMT_DEFAULT_READ_BUFFER_SIZE]
Buffer for reading data until a valid message is read.
XsensResultValue loadFromString(const uint8_t *source, const uint16_t size)
Read the entire message from the given source string.
XsensResultValue close(void)
Close the file.
void * m_onMessageReceivedParam
Custom, user supplied parameter for the OnMessageReceived callback function, passed as the last argum...
int32_t findValidMessage(const uint8_t *buffer, const uint16_t bufferLength)
Find a valid message in the given buffer.
CmtFilePos getFileSize(void)
Get the current file size.
XsensResultValue setReadPosition(CmtFilePos pos)
Set the read position to the given position.
uint8_t getMessageId(void) const
Return the current value of the m_messageId field.
XsensResultValue close(void)
Close the serial communication port.
Cmt1f * getCmt1f(void)
Get a reference to the embedded Cmt1f object.
const uint8_t * getMessageStart(void) const
Return the start of the message buffer.
XsensResultValue getLastResult(void) const
Return the error code of the last operation.
uint8_t getPortNr(void) const
Retrieve the port number that was last successfully opened.
XsensResultValue setTimeout(const uint32_t ms=CMT2_DEFAULT_TIMEOUT)
Set the default timeout value to use in blocking operations.
~Cmt2s()
Destructor, de-initialize, free memory allocated for buffers, etc.
CmtFilePos getFileSize(void) const
Return the size of the file.
XsensResultValue writeMessage(Message *msg)
Send a message over the COM port.
#define CMT_LEN_MSGHEADERCS
XsensResultValue m_lastResult
The last result of an operation.
XsensResultValue create(const char *filename)
Create a new file with level 2 header.
GLuint GLsizei GLsizei * length
const char * xsensResultText(const XsensResultValue result)
The low-level file communication class.
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...
bool isOpen(void) const
Return whether the file is open or not.
The namespace of all Xsens software since 2006.
Cmt2f()
Default constructor.
XsensResultValue create(const char *filename)
Open an empty file.
XsensResultValue close(void)
Close the serial communication port.
#define CMT_LEN_MSGHEADER
Cmt1f m_cmt1f
The Cmt1f object that is used for the low-level operations.
uint16_t getTotalMessageSize(void) const
Return the length of the message buffer.
XsensResultValue writeMessage(const Message *msg)
Write a message to the end of the file.
unsigned __int32 uint32_t
bool isChecksumOk(void) const
Compute the checksum and compare it with the stored checksum.
uint32_t m_baudrate
The baudrate that was last set to be used by the port.
uint32_t getTimeOfDay(tm *date_, time_t *secs_)
A platform-independent clock.
uint32_t m_timeout
Timeout in ms for blocking operations.
uint8_t m_data[CMT_MAXMSGLEN]
bool m_readOnly
When set to true, the file is read-only and attempts to write to it will fail.
Class for storing a single message.
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
XsensResultValue readMessage(Message *rcv)
Read a message from the COM port.
XsensResultValue m_lastResult
The last result of an operation.