xsens_imu
cmt2.h
Go to the documentation of this file.
1 #ifndef XSENS_MONOLITHIC
2 
20 #endif
21 #ifndef CMT2_H
22 #define CMT2_H
23 
24 #ifndef XSENS_MONOLITHIC
25 # include "cmt1.h"
26 # include "cmtmessage.h"
27 # include "xsens_fifoqueue.h"
28 #endif
29 
30 namespace xsens {
31 
35 
37 int32_t findValidMessage(const uint8_t* buffer, const uint16_t bufferLength);
38 
39 
43 
48 class Cmt2s {
49 private:
51  Cmt2s(const Cmt2s& ref);
52 
58  CmtCallbackFunction m_onMessageReceived;
60  int32_t m_onMessageReceivedInstance;
62  void* m_onMessageReceivedParam;
63 
69  CmtCallbackFunction m_onMessageSent;
71  int32_t m_onMessageSentInstance;
73  void* m_onMessageSentParam;
74 
75 protected:
77  uint32_t m_baudrate;
87  uint32_t m_timeout;
89  uint32_t m_toEnd;
90 public:
92  Cmt2s();
93 
95  ~Cmt2s();
96 
98  XsensResultValue close(void);
99 
101  uint32_t getBaudrate(void) { return (m_baudrate = m_cmt1s.getBaudrate()); }
107  Cmt1s* getCmt1s(void) { return &m_cmt1s; }
111  XsensResultValue getPortNr(uint16_t& port) const;
112  XsensResultValue getPortNr(int32_t& port) const;
113  XsensResultValue getPortName(char *portname) const;
115  uint32_t getTimeout(void) const { return m_timeout; }
117  bool isOpen (void) const { return (m_cmt1s.isOpen()); }
119  XsensResultValue open(const char *portName,
120  const uint32_t baudRate = CMT_DEFAULT_BAUD_RATE,
121  uint32_t readBufSize = CMT_DEFAULT_READ_BUFFER_SIZE,
122  uint32_t writeBufSize = CMT_DEFAULT_WRITE_BUFFER_SIZE);
123 #ifdef _WIN32
124  XsensResultValue open(const uint32_t portNumber,
126  const uint32_t baudRate = CMT_DEFAULT_BAUD_RATE,
127  uint32_t readBufSize = CMT_DEFAULT_READ_BUFFER_SIZE,
128  uint32_t writeBufSize = CMT_DEFAULT_WRITE_BUFFER_SIZE);
129 #endif
130 
138 
140  XsensResultValue setCallbackFunction(CmtCallbackType tp, int32_t instance, CmtCallbackFunction func, void* param);
141 
147  XsensResultValue setTimeout(const uint32_t ms = CMT2_DEFAULT_TIMEOUT);
148 
162  XsensResultValue waitForMessage(Message* rcv, const uint8_t msgId, uint32_t timeoutOverride, bool acceptErrorMessage);
169 };
170 
174 
180 class Cmt2f {
181 private:
183  Cmt2f(const Cmt2f& ref);
184 
185 protected:
190 
191  bool m_readOnly;
192 
193 public:
195  Cmt2f();
197  ~Cmt2f();
199  XsensResultValue close(void);
203  XsensResultValue create(const char* filename);
205  XsensResultValue create(const wchar_t* filename);
207  Cmt1f* getCmt1f(void);
208 
210  XsensResultValue getLastResult(void) const;
212  XsensResultValue getName(char* filename) const;
214  XsensResultValue getName(wchar_t* filename) const;
216  bool isOpen(void) const;
218  XsensResultValue open(const char* filename, const bool readOnly = false);
220  XsensResultValue open(const wchar_t* filename, const bool readOnly = false);
222  XsensResultValue readMessage(Message* msg, const uint8_t msgId = 0);
231 };
232 
233 } // end of xsens namespace
234 
235 #endif // CMT2_H
XsensResultValue writeMessage(Message *msg)
Send a message over the COM port.
Definition: cmt2.cpp:536
Cmt1s * getCmt1s(void)
Return a reference to the embedded Cmt1s object.
Definition: cmt2.h:107
XsensResultValue getPortName(char *portname) const
Definition: cmt2.cpp:134
XsensResultValue setReadPosition(XsensFilePos pos)
Set the read position to the given position.
Definition: cmt2.cpp:819
XsensResultValue getName(char *filename) const
Retrieve the filename that was last successfully opened.
Definition: cmt2.cpp:684
Contains the FIFO queue interface and implementation (inline)
XsensResultValue open(const char *filename, const bool readOnly=false)
Open a file and read the header.
Definition: cmt2.cpp:705
Cmt1f m_cmt1f
The Cmt1f object that is used for the low-level operations.
Definition: cmt2.h:187
bool m_readOnly
When set to true, the file is read-only and attempts to write to it will fail.
Definition: cmt2.h:191
XsensResultValue setTimeout(const uint32_t ms=CMT2_DEFAULT_TIMEOUT)
Set the default timeout value to use in blocking operations.
Definition: cmt2.cpp:342
XsensResultValue closeAndDelete(void)
Close the file and delete it.
Definition: cmt2.cpp:612
The low-level serial communication class.
Definition: cmt1.h:67
XsensResultValue getLastResult(void) const
Return the error code of the last operation.
Definition: cmt2.cpp:677
#define CMT_DEFAULT_BAUD_RATE
The default baud rate of the Cmt1s serial communication.
Definition: cmtdef.h:828
CmtCallbackType
Definition: cmtdef.h:1101
Cmt2s()
Default constructor, initialize all members to their default values.
Definition: cmt2.cpp:102
XsensFilePos getFileSize(void)
Get the current file size.
Definition: cmt2.cpp:805
uint32_t m_timeout
Timeout in ms for blocking operations.
Definition: cmt2.h:87
XsensResultValue
Xsens return values.
Definition: xsens_std.h:43
bool isOpen(void) const
Return whether the communication port is open or not.
Definition: cmt2.h:117
#define CMT2_DEFAULT_TIMEOUT
Timeout in ms for level 2.
Definition: cmtdef.h:837
XsensResultValue getLastResult(void) const
Return the error code of the last operation.
Definition: cmt2.h:109
uint16_t m_readBufferCount
The number of valid bytes in the readBuffer.
Definition: cmt2.h:85
uint32_t getBaudrate(void) const
Return the baudrate that is currently being used by the port.
Definition: cmt1.cpp:298
XsensResultValue waitForMessage(Message *rcv, const uint8_t msgId, uint32_t timeoutOverride, bool acceptErrorMessage)
Wait for a message to arrive.
Definition: cmt2.cpp:354
The low-level file communication class.
Definition: cmt1.h:217
void(__cdecl * CmtCallbackFunction)(int32_t instance, int32_t callbackType, void *param, void *userParam)
Function prototype for Cmt callback functions.
Definition: cmtdef.h:1134
XsensResultValue create(const char *filename)
Create a new file with level 2 header.
Definition: cmt2.cpp:625
~Cmt2s()
Destructor, de-initialize, free memory allocated for buffers, etc.
Definition: cmt2.cpp:115
uint32_t getBaudrate(void)
Return the baudrate that is currently being used by the port.
Definition: cmt2.h:101
XsensResultValue setCallbackFunction(CmtCallbackType tp, int32_t instance, CmtCallbackFunction func, void *param)
Set the callback function for when a message has been received or sent.
Definition: cmt2.cpp:320
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...
Definition: cmt2.cpp:727
Class for storing a single message.
Definition: cmtmessage.h:76
XsensFilePos getReadPosition(void)
Get the current read position.
Definition: cmt2.cpp:812
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...
Definition: cmt2.cpp:36
uint8_t m_readBuffer[CMT_DEFAULT_READ_BUFFER_SIZE]
Buffer for reading data until a valid message is read. Should be rarely used.
Definition: cmt2.h:83
#define CMT_DEFAULT_WRITE_BUFFER_SIZE
The default size of the serial write buffer in bytes.
Definition: cmtdef.h:826
XsensResultValue readMessage(Message *rcv)
Read a message from the COM port.
Definition: cmt2.cpp:191
XsensResultValue getPortNr(uint16_t &port) const
Retrieve the port that the object is connected to.
Definition: cmt2.cpp:145
bool isOpen(void) const
Return whether the file is open or not.
Definition: cmt2.cpp:698
XsensResultValue close(void)
Close the file.
Definition: cmt2.cpp:598
Mid-level serial communication class.
Definition: cmt2.h:48
XsensResultValue m_lastResult
The last result of an operation.
Definition: cmt2.h:81
Cmt1f * getCmt1f(void)
Get a reference to the embedded Cmt1f object.
Definition: cmt2.cpp:670
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 communication channel to the given serial port name.
Definition: cmt2.cpp:165
Cmt1s m_cmt1s
The CMT level 1 object that this class operates on.
Definition: cmt2.h:79
uint32_t getTimeout(void) const
Return the current timeout value in ms.
Definition: cmt2.h:115
Contains the CMT Level 1 interface.
Cmt2f()
Default constructor.
Definition: cmt2.cpp:583
#define CMT_DEFAULT_READ_BUFFER_SIZE
The default size of the serial read buffer in bytes.
Definition: cmtdef.h:824
Contains the CMT Message interface.
uint32_t m_baudrate
The baudrate that was last set to be used by the port.
Definition: cmt2.h:77
XsensResultValue close(void)
Close the serial communication port.
Definition: cmt2.cpp:120
bool isOpen(void) const
Return whether the communication port is open or not.
Definition: cmt1.cpp:310
~Cmt2f()
Destructor.
Definition: cmt2.cpp:591
XsensResultValue m_lastResult
The last result of an operation.
Definition: cmt2.h:189
__off64_t XsensFilePos
Definition: xsens_file.h:21
The mid-level file communication class.
Definition: cmt2.h:180
XsensResultValue writeMessage(const Message *msg)
Write a message to the end of the file.
Definition: cmt2.cpp:826
uint32_t m_toEnd
The timestamp at which to end an operation.
Definition: cmt2.h:89