XsensMTiModule.cpp
Go to the documentation of this file.
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2006 Radu Bogdan Rusu (rusu@cs.tum.edu)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  */
20 /*
21  Desc: Driver for XSens MTx/MTi IMU. CMTComm class borrowed from XSens under GPL.
22  Author: Radu Bogdan Rusu
23  Date: 1 Aug 2006
24  */
25 // MTComm.cpp: implementation of the CMTComm class.
26 //
27 // Version 1.2.0
28 // Public release
29 //
30 // v1.2.0
31 // 27-02-2006 - Renamed Xbus class to Motion Tracker C++ Communication class, short MTComm
32 // - Defines XBRV_* accordingly renamed to MTRV_*
33 // - Fixed device length not correct for bid 0 when using Xbus Master and setDeviceMode function
34 //
35 // v1.1.7
36 // 15-02-2006 - Added fixed point signed 12.20 dataformat support
37 // Added selective calibrated data output per sensor type support
38 // Added outputmode temperature support
39 // Fixed warning C4244: '=' : conversion from '' to '', possible loss of data
40 // v1.1.6
41 // 25-01-2006 - Added escape function for CLRDTR, CLRRTS, SETDTR, SETRTS, SETXOFF, SETXON, SETBREAK, CLRBREAK
42 //
43 // v1.1.5
44 // 14-11-2005 - Made swapEndian a static member function, Job Mulder
45 //
46 // v1.1.4
47 // 08-11-2005 - Changed practically all uses of m_timeOut into uses of the new m_clkEnd
48 // - Changed COM timeout in win32 to return immediately if data is available,
49 // but wait 1ms otherwise
50 //
51 // v1.1.3
52 // 18-10-2005 - Added MID_REQPRODUCTCODE, MID_REQ/SETTRANSMITDELAY
53 // - Added MTRV_TIMEOUTNODATA indicating timeout occurred due to no data read
54 //
55 // v1.1.2
56 // 16-09-2005 - Added eMTS version 0.1->1.0 changes (EMTS_FACTORYMODE)
57 // - Added factory output mode defines
58 //
59 // v1.1.1
60 // 01-09-2005 - Added defines for Extended output mode
61 // - Added reqSetting (byte array in + out & no param variant)
62 //
63 // v1.1
64 // 08-08-2005 - Added file read and write support
65 // - Added functions for data retrieval (getValue etc)
66 // for easy data retrieval of acc, gyr, mag etc
67 // - ReadMessageRaw:
68 // - added a temporary buffer for unprocessed bytes
69 // - check for invalid length messages
70 // - Changed BID_MT into 1 and added BID_MASTER (=0xFF)
71 // - Changed various ....SerialPort functions to .....Port
72 // - Changed mtSendMessage functions to mtWriteMessage
73 // - Added numerous defines
74 // - Deleted obsolete functions
75 // - Changed function getLastErrorCode into getLastDeviceError
76 // - Changed OpenPort function for compatiblity with Bluetooth ports
77 // - Added workaround for lockup of USB driver (close function)
78 // - Added workaround for clock() problem with read function of USB driver
79 //
80 // v1.0.2
81 // 29-06-2005 - Inserted initSerialPort with devicename input
82 // - Changed return value defines names from X_ to MTRV_
83 // - Removed unneeded includes for linux
84 //
85 // v1.0.1
86 // 22-06-2005 - Fixed ReqSetting functions (byte array & param variant)
87 // mtSendRawString had wrong length input
88 //
89 // v1.0.0
90 // 20-06-2005 - Initial release
91 //
92 // ----------------------------------------------------------------------------
93 // This file is an Xsens Code Examples.
94 //
95 // Copyright (C) Xsens Technologies B.V., 2005.
96 //
97 // This source code is intended only as a example of the implementation
98 // of the Xsens MT Communication protocol.
99 // It was written for cross platform capabilities.
100 //
101 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
102 // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
103 // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
104 // PARTICULAR PURPOSE.
105 //////////////////////////////////////////////////////////////////////
106 #include "XsensMTiModule.h"
107 
108 #ifdef _IMU_USE_XSENS_DEVICE_
109 
110 #ifdef _DEBUG
111 #undef THIS_FILE
112 static char THIS_FILE[] = __FILE__;
113 #define new DEBUG_NEW
114 #endif
115 
116 #ifndef CRTSCTS
117 #ifdef IHFLOW
118 #ifdef OHFLOW
119 #define CRTSCTS ((IHFLOW) | (OHFLOW))
120 #endif
121 #endif
122 #endif
123 
124 namespace IMU::Xsens
125 {
126  //////////////////////////////////////////////////////////////////////
127  // Construction/Destruction
128  //////////////////////////////////////////////////////////////////////
129  //
131  {
132  m_handle = -1;
133  m_portOpen = false;
134  m_fileOpen = false;
135  m_deviceError = 0; // No error
136  m_retVal = MTRV_OK;
138  m_nTempBufferLen = 0;
139  m_clkEnd = 0;
140 
141  for (int i = 0 ; i < MAXDEVICES + 1 ; i++)
142  {
145  m_storedDataLength[i] = 0;
146  }
147  }
148 
150  {
151  close();
152  }
153 
154  ////////////////////////////////////////////////////////////////////
155  // clockms
156  //
157  // Calculates the processor time used by the calling process.
158  // For linux use gettimeofday instead of clock() function
159  // When using read from FTDI serial port in a loop the
160  // clock() function very often keeps returning 0.
161  //
162  // Output
163  // returns processor time in milliseconds
164  //
166  {
167  clock_t clk;
168 #ifdef WIN32
169  clk = clock(); // Get current processor time
170 #if (CLOCKS_PER_SEC != 1000)
171  clk /= (CLOCKS_PER_SEC / 1000);
172  // clk = (clk * 1000) / CLOCKS_PER_SEC;
173 #endif
174 #else
175  struct timeval tv;
176  struct timezone tz;
177  gettimeofday(&tv, &tz);
178  clk = tv.tv_sec * 1000 + (tv.tv_usec / 1000);
179 #endif
180  return clk;
181  }
182 
183  ////////////////////////////////////////////////////////////////////
184  // openPort (serial port number as input parameter)
185  //
186  // Opens a 'live' connection to a MT or XM
187  //
188  // Input
189  // portNumber : number of serial port to open (1-99)
190  // baudrate : baudrate value (One of the PBR_* defines), default = PBR_115K2
191  // inqueueSize : size of input queue, default = 4096
192  // outqueueSize: size of output queue, default = 1024
193  //
194  // Output
195  // returns MTRV_OK if serial port is successfully opened, else MTRV_INPUTCANNOTBEOPENED
196  //
197  short CXsensMTiModule::openPort(const int portNumber, const unsigned long baudrate, const unsigned long /*inqueueSize*/, const unsigned long /*outqueueSize*/)
198  {
199  m_clkEnd = 0;
200 
201  if (m_fileOpen || m_portOpen)
202  {
204  }
205 
206 #ifdef WIN32
207  char pchFileName[10];
208 
209  sprintf(pchFileName, "\\\\.\\COM%d", portNumber); // Create file name
210 
211  m_handle = CreateFile(pchFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
212 
213  if (m_handle == INVALID_HANDLE_VALUE)
214  {
216  }
217 
218  // Once here, port is open
219  m_portOpen = true;
220 
221  //Get the current state & then change it
222  DCB dcb;
223 
224  GetCommState(m_handle, &dcb);// Get current state
225 
226  dcb.BaudRate = baudrate;// Setup the baud rate
227  dcb.Parity = NOPARITY;// Setup the Parity
228  dcb.ByteSize = 8;// Setup the data bits
229  dcb.StopBits = TWOSTOPBITS;// Setup the stop bits
230  dcb.fDsrSensitivity = FALSE;// Setup the flow control
231  dcb.fOutxCtsFlow = FALSE;// NoFlowControl:
232  dcb.fOutxDsrFlow = FALSE;
233  dcb.fOutX = FALSE;
234  dcb.fInX = FALSE;
235 
236  if (!SetCommState(m_handle, (LPDCB)&dcb))
237  {
238  // Set new state
239  // Bluetooth ports cannot always be opened with 2 stopbits
240  // Now try to open port with 1 stopbit.
241  dcb.StopBits = ONESTOPBIT;
242 
243  if (!SetCommState(m_handle, (LPDCB)&dcb))
244  {
245  CloseHandle(m_handle);
246  m_handle = INVALID_HANDLE_VALUE;
247  m_portOpen = false;
249  }
250  }
251 
252  // Set COM timeouts
253  COMMTIMEOUTS CommTimeouts;
254 
255  GetCommTimeouts(m_handle, &CommTimeouts); // Fill CommTimeouts structure
256 
257  // immediate return if data is available, wait 1ms otherwise
258  CommTimeouts.ReadTotalTimeoutConstant = 1;
259  CommTimeouts.ReadIntervalTimeout = MAXDWORD;
260  CommTimeouts.ReadTotalTimeoutMultiplier = MAXDWORD;
261 
262  // immediate return whether data is available or not
263  // CommTimeouts.ReadTotalTimeoutConstant = 0;
264  // CommTimeouts.ReadIntervalTimeout = MAXDWORD;
265  // CommTimeouts.ReadTotalTimeoutMultiplier = 0;
266 
267  SetCommTimeouts(m_handle, &CommTimeouts);// Set CommTimeouts structure
268 
269  // Other initialization functions
270  EscapeCommFunction(m_handle, SETRTS);// Enable RTS (for Xbus Master use)
271  SetupComm(m_handle, inqueueSize, outqueueSize); // Set queue size
272 
273  // Remove any 'old' data in buffer
274  PurgeComm(m_handle, PURGE_TXCLEAR | PURGE_RXCLEAR);
275 
276  return (m_retVal = MTRV_OK);
277 #else
278  char chPort[32];
279  struct termios options;
280 
281  /* Open port */
282  sprintf(chPort, "/dev/ttyS%d", (portNumber - 1));
283  m_handle = open(chPort, O_RDWR | O_NOCTTY);
284 
285  // O_RDWR: Read+Write
286  // O_NOCTTY: Raw input, no "controlling terminal"
287  // O_NDELAY: Don't care about DCD signal
288 
289  if (m_handle < 0)
290  {
291  // Port not open
293  }
294 
295  // Once here, port is open
296  m_portOpen = true;
297 
298  /* Start configuring of port for non-canonical transfer mode */
299  // Get current options for the port
300  tcgetattr(m_handle, &options);
301 
302  // Set baudrate.
303  cfsetispeed(&options, baudrate);
304  cfsetospeed(&options, baudrate);
305 
306  // Enable the receiver and set local mode
307  options.c_cflag |= (CLOCAL | CREAD);
308  // Set character size to data bits and set no parity Mask the characte size bits
309  options.c_cflag &= ~(CSIZE | PARENB);
310  options.c_cflag |= CS8; // Select 8 data bits
311  options.c_cflag |= CSTOPB; // send 2 stop bits
312  // Disable hardware flow control
313  options.c_cflag &= ~CRTSCTS;
314  options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
315  // Disable software flow control
316  options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
317  // Set Raw output
318  options.c_oflag &= ~OPOST;
319  // Timeout 0.005 sec for first byte, read minimum of 0 bytes
320  options.c_cc[VMIN] = 0;
321  options.c_cc[VTIME] = 5;
322 
323  // Set the new options for the port
324  tcsetattr(m_handle, TCSANOW, &options);
325 
326  tcflush(m_handle, TCIOFLUSH);
327 
328  return (m_retVal = MTRV_OK);
329 #endif
330  }
331 
332  ////////////////////////////////////////////////////////////////////
333  // openPort (string as input parameter)
334  //
335  // Opens a 'live' connection to a MT or XM
336  //
337  // Input
338  // portName : device name of serial port ("/dev/ttyUSB0" or "\\\\.\\COM1")
339  // baudrate : baudrate value (One of the PBR_* defines), default = PBR_115K2
340  // inqueueSize : size of input queue, default = 4096
341  // outqueueSize: size of output queue, default = 1024
342  //
343  // Output
344  // returns MTRV_OK if serial port is successfully opened, else MTRV_INPUTCANNOTBEOPENED
345  //
346  short CXsensMTiModule::openPort(const char* portName, const unsigned long baudrate, const unsigned long /*inqueueSize*/, const unsigned long /*outqueueSize*/)
347  {
348  m_clkEnd = 0;
349 
350  if (m_fileOpen || m_portOpen)
351  {
353  }
354 
355 #ifdef WIN32
356  m_handle = CreateFile(portName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
357 
358  if (m_handle == INVALID_HANDLE_VALUE)
359  {
361  }
362 
363  // Once here, port is open
364  m_portOpen = true;
365 
366  //Get the current state & then change it
367  DCB dcb;
368 
369  GetCommState(m_handle, &dcb);// Get current state
370 
371  dcb.BaudRate = baudrate;// Setup the baud rate
372  dcb.Parity = NOPARITY;// Setup the Parity
373  dcb.ByteSize = 8;// Setup the data bits
374  dcb.StopBits = TWOSTOPBITS;// Setup the stop bits
375  dcb.fDsrSensitivity = FALSE;// Setup the flow control
376  dcb.fOutxCtsFlow = FALSE;// NoFlowControl:
377  dcb.fOutxDsrFlow = FALSE;
378  dcb.fOutX = FALSE;
379  dcb.fInX = FALSE;
380 
381  if (!SetCommState(m_handle, (LPDCB)&dcb))
382  {
383  // Set new state
384  // Bluetooth ports cannot always be opened with 2 stopbits
385  // Now try to open port with 1 stopbit.
386  dcb.StopBits = ONESTOPBIT;
387 
388  if (!SetCommState(m_handle, (LPDCB)&dcb))
389  {
390  CloseHandle(m_handle);
391  m_handle = INVALID_HANDLE_VALUE;
392  m_portOpen = false;
394  }
395  }
396 
397  // Set COM timeouts
398  COMMTIMEOUTS CommTimeouts;
399 
400  GetCommTimeouts(m_handle, &CommTimeouts); // Fill CommTimeouts structure
401 
402  // immediate return if data is available, wait 1ms otherwise
403  CommTimeouts.ReadTotalTimeoutConstant = 1;
404  CommTimeouts.ReadIntervalTimeout = MAXDWORD;
405  CommTimeouts.ReadTotalTimeoutMultiplier = MAXDWORD;
406 
407  // immediate return whether data is available or not
408  // CommTimeouts.ReadTotalTimeoutConstant = 0;
409  // CommTimeouts.ReadIntervalTimeout = MAXDWORD;
410  // CommTimeouts.ReadTotalTimeoutMultiplier = 0;
411  SetCommTimeouts(m_handle, &CommTimeouts);// Set CommTimeouts structure
412 
413  // Other initialization functions
414  EscapeCommFunction(m_handle, SETRTS);// Enable RTS (for Xbus Master use)
415  SetupComm(m_handle, inqueueSize, outqueueSize); // Set queue size
416 
417  // Remove any 'old' data in buffer
418  PurgeComm(m_handle, PURGE_TXCLEAR | PURGE_RXCLEAR);
419 
420  return (m_retVal = MTRV_OK);
421 #else
422  struct termios options;
423 
424  /* Open port */
425 
426  m_handle = open(portName, O_RDWR | O_NOCTTY);
427 
428  // O_RDWR: Read+Write
429  // O_NOCTTY: Raw input, no "controlling terminal"
430  // O_NDELAY: Don't care about DCD signal
431 
432  if (m_handle < 0)
433  {
434  // Port not open
436  }
437 
438  // Once here, port is open
439  m_portOpen = true;
440 
441  /* Start configuring of port for non-canonical transfer mode */
442  // Get current options for the port
443  tcgetattr(m_handle, &options);
444 
445  // Set baudrate.
446  cfsetispeed(&options, baudrate);
447  cfsetospeed(&options, baudrate);
448 
449  // Enable the receiver and set local mode
450  options.c_cflag |= (CLOCAL | CREAD);
451  // Set character size to data bits and set no parity Mask the characte size bits
452  options.c_cflag &= ~(CSIZE | PARENB);
453  options.c_cflag |= CS8; // Select 8 data bits
454  options.c_cflag |= CSTOPB; // send 2 stop bits
455  // Disable hardware flow control
456  options.c_cflag &= ~CRTSCTS;
457  options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
458  // Disable software flow control
459  options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
460  // Set Raw output
461  options.c_oflag &= ~OPOST;
462  // Timeout 0.005 sec for first byte, read minimum of 0 bytes
463  options.c_cc[VMIN] = 0;
464  options.c_cc[VTIME] = 5;
465 
466  // Set the new options for the port
467  tcsetattr(m_handle, TCSANOW, &options);
468 
469  tcflush(m_handle, TCIOFLUSH);
470 
471  return (m_retVal = MTRV_OK);
472 #endif
473  }
474 
475  ////////////////////////////////////////////////////////////////////
476  // openFile
477  //
478  // Open file for reading and writing
479  // Filepos is at start of file
480  //
481  // Input
482  // fileName : file name including path
483  // createAlways: empties the log file, if existing
484  //
485  // Output
486  // returns MTRV_OK if the file is opened
487  // returns MTRV_INPUTCANNOTBEOPENED if the file can not be opened
488  // returns MTRV_ANINPUTALREADYOPEN if a serial port / file is already opened
489  //
490  short CXsensMTiModule::openFile(const char* fileName, bool createAlways)
491  {
492  m_clkEnd = 0;
493 
494  if (m_portOpen || m_portOpen)
495  {
497  }
498 
499 #ifdef WIN32
500  DWORD disposition = OPEN_ALWAYS;
501 
502  if (createAlways == true)
503  {
504  disposition = CREATE_ALWAYS;
505  }
506 
507  m_handle = CreateFile(fileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, disposition, 0, NULL);
508 
509  if (m_handle == INVALID_HANDLE_VALUE)
510  {
512  }
513 
514 #else
515  int openMode = O_RDWR | O_CREAT;
516 
517  if (createAlways == true)
518  {
519  openMode |= O_TRUNC;
520  }
521 
522  m_handle = open(fileName, openMode, S_IRWXU);
523 
524  if (m_handle < 0)
525  {
527  }
528 
529 #endif
530  m_timeOut = 0; // No timeout when using file input
531  m_fileOpen = true;
532  return (m_retVal = MTRV_OK);
533 
534  }
535 
536  ////////////////////////////////////////////////////////////////////
537  // isPortOpen
538  //
539  // Return if serial port is open or not
540  //
542  {
543  return m_portOpen;
544  }
545 
546  ////////////////////////////////////////////////////////////////////
547  // isFileOpen
548  //
549  // Return if serial port is open or not
550  //
552  {
553  return m_fileOpen;
554  }
555 
556  ////////////////////////////////////////////////////////////////////
557  // readData
558  //
559  // Reads bytes from serial port or file
560  //
561  // Input
562  // msgBuffer : pointer to buffer in which next string will be stored
563  // nBytesToRead : number of buffer bytes to read from serial port
564  // retval : return value, either MTRV_OK, MTRV_ENDOFFILE or MTRV_NOINPUTINITIALIZED
565  //
566  // Output
567  // number of bytes actually read
568  int CXsensMTiModule::readData(unsigned char* msgBuffer, const int nBytesToRead)
569  {
570  //if(!m_fileOpen && !m_portOpen)
571  if (!(m_portOpen || m_fileOpen))
572  {
574  return 0;
575  }
576 
577 #ifdef WIN32
578  DWORD nBytesRead;
579  BOOL retval = ReadFile(m_handle, msgBuffer, nBytesToRead, &nBytesRead, NULL);
580 
581  if (retval && nBytesRead == 0 && m_fileOpen)
582  {
584  }
585  else
586  {
587  m_retVal = MTRV_OK;
588  }
589 
590  return nBytesRead;
591 #else
592  const int nBytesRead = read(m_handle, msgBuffer, nBytesToRead);
593 
594  m_retVal = MTRV_OK;
595 
596  if (nBytesRead)
597  {
598  return nBytesRead;
599  }
600  else if (m_fileOpen)
601  {
603  }
604 
605  return nBytesRead;
606  /*
607  if (nBytesRead == 0 && m_fileOpen)
608  {
609  nBytesRead = 0;
610  m_retVal = MTRV_ENDOFFILE;
611  }
612  else
613  m_retVal = MTRV_OK;
614  return nBytesRead;*/
615 
616  // In Linux it is sometimes better to read per byte instead of a block of bytes at once
617  // Use this block if experiencing problems with the above code
618  /*
619  int j = 0; // Index in buffer for read data
620  int k = 0; // Timeout factor
621  int nRead = 0; // Bytes read from port, return by read function
622 
623  do {
624  nRead = read(m_handle, &msgBuffer[j], 1);
625  if (nRead == 1) { // Byte read
626  k = 0;
627  j++;
628  }
629  else {
630  k++;
631  }
632 
633  if (k == 3) { // Timeout, too long no data read from port
634  return nRead;
635  }
636  }
637  while (j < nBytesToRead);
638 
639  return j;
640  */
641 #endif
642  }
643 
644  ////////////////////////////////////////////////////////////////////
645  // writeData
646  //
647  // Writes bytes to serial port (to do: file)
648  //
649  // Input
650  // msgBuffer : a pointer to a char buffer containing
651  // the characters to be written to serial port
652  // nBytesToWrite : number of buffer bytes to write to serial port
653  //
654  // Output
655  // number of bytes actually written
656  //
657  // The MTComm return value is != MTRV_OK if serial port is closed
658  int CXsensMTiModule::writeData(const unsigned char* msgBuffer, const int nBytesToWrite)
659  {
660  if (!m_fileOpen && !m_portOpen)
661  {
663  return 0;
664  }
665 
666  m_retVal = MTRV_OK;
667 #ifdef WIN32
668  DWORD nBytesWritten;
669  WriteFile(m_handle, msgBuffer, nBytesToWrite, &nBytesWritten, NULL);
670  return nBytesWritten;
671 #else
672  return write(m_handle, msgBuffer, nBytesToWrite);
673 #endif
674  }
675 
676  ////////////////////////////////////////////////////////////////////
677  // flush
678  //
679  // Remove any 'old' data in COM port buffer and flushes internal
680  // temporary buffer
681  //
683  {
684  if (m_portOpen)
685  {
686 #ifdef WIN32
687  // Remove any 'old' data in buffer
688  PurgeComm(m_handle, PURGE_TXCLEAR | PURGE_RXCLEAR);
689 #else
690  tcflush(m_handle, TCIOFLUSH);
691 #endif
692  }
693 
694  m_nTempBufferLen = 0;
695  m_retVal = MTRV_OK;
696  }
697 
698  ////////////////////////////////////////////////////////////////////
699  // escape
700  //
701  // Directs a COM port to perform an extended function
702  //
703  // Input
704  // function : Windows define. Can be one of following:
705  // CLRDTR, CLRRTS, SETDTR, SETRTS, SETXOFF, SETXON, SETBREAK, CLRBREAK
706  void CXsensMTiModule::escape(unsigned long /*function*/)
707  {
708 #ifdef WIN32
709  EscapeCommFunction(m_handle, function);
710 #else
711 #endif
712  }
713 
714  ////////////////////////////////////////////////////////////////////
715  // setPortQueueSize
716  //
717  // Set input and output buffer size of serial port
718  //
719  void CXsensMTiModule::setPortQueueSize(const unsigned long /*inqueueSize = 4096 */, const unsigned long /*outqueueSize = 1024 */)
720  {
721  if (m_portOpen)
722  {
723 #ifdef WIN32
724  SetupComm(m_handle, inqueueSize, outqueueSize); // Set queue size
725 #else
726  // Not yet implemented
727 #endif
728  }
729 
730  m_retVal = MTRV_OK;
731  }
732 
733  ////////////////////////////////////////////////////////////////////
734  // setFilePos
735  //
736  // Sets the current position of the file pointer for file input
737  //
738  // Input
739  // relPos : 32-bit value specifying the relative move in bytes
740  // origin is specified in moveMethod
741  // moveMethod : FILEPOS_BEGIN, FILEPOS_CURRENT or FILEPOS_END
742  // Output
743  //
744  // returns MTRV_OK if file pointer is successfully set
745  //
746  short CXsensMTiModule::setFilePos(long relPos, unsigned long moveMethod)
747  {
748 #ifdef WIN32
749 
750  if (m_fileOpen)
751  {
752  if (SetFilePointer(m_handle, relPos, NULL, moveMethod) != INVALID_SET_FILE_POINTER)
753  {
754  return (m_retVal = MTRV_OK);
755  }
756  }
757 
758 #else
759 
760  if (m_fileOpen)
761  {
762  if (lseek(m_handle, relPos, moveMethod) != -1)
763  {
764  return (m_retVal = MTRV_OK);
765  }
766  }
767 
768 #endif
769  return (m_retVal = MTRV_NOTSUCCESSFUL);
770  }
771 
772  ////////////////////////////////////////////////////////////////////
773  // getFileSize
774  //
775  // Retrieves the file size of the opened file
776  //
777  // Input
778  // Output
779  // fileSize : Number of bytes of the current file
780  //
781  // returns MTRV_OK if successful
782  //
783  short CXsensMTiModule::getFileSize(unsigned long& fileSize)
784  {
785 #ifdef WIN32
786 
787  if (m_fileOpen)
788  {
789  if ((fileSize = GetFileSize(m_handle, NULL)) != INVALID_FILE_SIZE)
790  {
791  return (m_retVal = MTRV_OK);
792  }
793  }
794 
795 #else
796 
797  if (m_fileOpen)
798  {
799  struct stat buf;
800 
801  if (fstat(m_handle, &buf) == 0)
802  {
803  fileSize = buf.st_size;
804  return (m_retVal = MTRV_OK);
805  }
806  }
807 
808 #endif
809  return (m_retVal = MTRV_NOTSUCCESSFUL);
810  }
811 
812  ////////////////////////////////////////////////////////////////////
813  // close
814  //
815  // Closes handle of file or serial port
816  //
818  {
819  if (m_portOpen || m_fileOpen)
820  {
821 #ifdef WIN32
822 
823  if (m_portOpen)
824  {
825  // Because of USB-serial driver bug
826  flush();
827  }
828 
829  CloseHandle(m_handle);
830 #else
831  ::close(m_handle);
832 #endif
833  }
834 
835  m_fileOpen = m_portOpen = false;
836  m_timeOut = TO_DEFAULT; // Restore timeout value (file input)
837  m_clkEnd = 0;
838  m_nTempBufferLen = 0;
839  m_deviceError = 0; // No error
840 
841  for (int i = 0 ; i < MAXDEVICES + 1 ; i++)
842  {
845  m_storedDataLength[i] = 0;
846  }
847 
848  return (m_retVal = MTRV_OK);
849  }
850 
851  ////////////////////////////////////////////////////////////////////
852  // readMessage
853  //
854  // Reads the next message from serial port buffer or file.
855  // To be read within current time out period
856  //
857  // Input
858  // Output
859  // mid : MessageID of message received
860  // data : array pointer to data bytes (no header)
861  // dataLen : number of data bytes read
862  // bid : BID or address of message read (optional)
863  //
864  // returns MTRV_OK if a message has been read else <>MTRV_OK
865  //
866  // Remarks
867  // allocate enough memory for message buffer
868  // use setTimeOut for different timeout value
869  short CXsensMTiModule::readMessage(unsigned char& mid, unsigned char data[], short& dataLen, unsigned char* bid)
870  {
871  unsigned char buffer[MAXMSGLEN ];
872  short msgLen;
873 
874  if (!(m_fileOpen || m_portOpen))
875  {
877  }
878 
879  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
880  {
881  // Message read
882  mid = buffer[IND_MID];
883 
884  if (bid != nullptr)
885  {
886  *bid = buffer[IND_BID];
887  }
888 
889  if (buffer[IND_LEN] != EXTLENCODE)
890  {
891  dataLen = buffer[IND_LEN];
892  memcpy(data, &buffer[IND_DATA0], dataLen);
893  }
894  else
895  {
896  dataLen = buffer[IND_LENEXTH] * 256 + buffer[IND_LENEXTL];
897  memcpy(data, &buffer[IND_DATAEXT0], dataLen);
898  }
899  }
900 
901  return m_retVal;
902  }
903 
904  ////////////////////////////////////////////////////////////////////
905  // readDataMessage
906  //
907  // Read a MTData or XMData message from serial port (using TimeOut val)
908  //
909  // Input
910  // data : pointer to buffer in which the DATA field of MTData/XMData is stored
911  // dataLen : number of bytes in buffer (= number bytes in DATA field)
912  // Output
913  // returns MTRV_OK if MTData / XMData message has been read else <>MTRV_OK
914  //
915  // Remarks
916  // allocate enough memory for data buffer
917  // use setTimeOut for different timeout value
918  short CXsensMTiModule::readDataMessage(unsigned char data[], short& dataLen)
919  {
920  if (!(m_portOpen || m_fileOpen))
921  {
923  }
924 
925  unsigned char buffer[MAXMSGLEN ];
926  short buflen;
927 
928  if (readMessageRaw(buffer, &buflen) == MTRV_OK)
929  {
930  if (buffer[IND_MID] == MID_MTDATA)
931  {
932  // MID_XMDATA is same
933  if (buffer[IND_LEN] != EXTLENCODE)
934  {
935  dataLen = buffer[IND_LEN];
936  memcpy(data, &buffer[IND_DATA0], dataLen);
937  }
938  else
939  {
940  dataLen = buffer[IND_LENEXTH] * 256 + buffer[IND_LENEXTL];
941  memcpy(data, &buffer[IND_DATAEXT0], dataLen);
942  }
943 
944  return (m_retVal = MTRV_OK);
945  }
946  else if (buffer[IND_MID] == MID_ERROR)
947  {
948  m_deviceError = buffer[IND_DATA0];
949  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
950  }
951  }
952 
953  return m_retVal;
954  }
955 
956  ////////////////////////////////////////////////////////////////////
957  // readMessageRaw
958  //
959  // Read a message from serial port for a certain period
960  //
961  // Input
962  // msgBuffer : pointer to buffer in which next msg will be stored
963  // msgBufferLength: integer to number of bytes written in buffer (header + data + chksum)
964  // Output
965  // returns MTRV_OK if a message has been read else <>MTRV_OK
966  //
967  // Remarks
968  // allocate enough memory for message buffer
969  // use setTimeOut for different timeout value
970  short CXsensMTiModule::readMessageRaw(unsigned char* msgBuffer, short* msgBufferLength)
971  {
972  int state = 0;
973  int nBytesToRead = 1;
974  int nBytesRead = 0;
975  int nOffset = 0;
976  int nMsgDataLen = 0;
977  int nMsgLen;
978  unsigned char chCheckSum;
979  bool Synced = false;
980 
981  if (!(m_portOpen || m_fileOpen))
982  {
984  }
985 
986  // Copy previous read bytes if available
987  if (m_nTempBufferLen > 0)
988  {
989  memcpy(msgBuffer, m_tempBuffer, m_nTempBufferLen);
990  nBytesRead = m_nTempBufferLen;
991  m_nTempBufferLen = 0;
992  }
993 
994  clock_t clkStart = clockms(); // Get current processor time
995  clock_t clkEnd = m_clkEnd; // check if the end timer is already set
996 
997  if (clkEnd == 0)
998  {
999  clkEnd = clkStart + m_timeOut;
1000  }
1001 
1002  while (true)
1003  {
1004  do
1005  {
1006  // First check if we already have some bytes read
1007  if (nBytesRead > 0 && nBytesToRead > 0)
1008  {
1009  if (nBytesToRead > nBytesRead)
1010  {
1011  nOffset += nBytesRead;
1012  nBytesToRead -= nBytesRead;
1013  nBytesRead = 0;
1014  }
1015  else
1016  {
1017  nOffset += nBytesToRead;
1018  nBytesRead -= nBytesToRead;
1019  nBytesToRead = 0;
1020  }
1021  }
1022 
1023  // Check if serial port buffer must be read
1024  if (nBytesToRead > 0)
1025  {
1026  nBytesRead = readData(msgBuffer + nOffset, nBytesToRead);
1027 
1028  if (m_retVal == MTRV_ENDOFFILE)
1029  {
1030  return (m_retVal = MTRV_ENDOFFILE);
1031  }
1032 
1033  nOffset += nBytesRead;
1034  nBytesToRead -= nBytesRead;
1035  nBytesRead = 0;
1036  }
1037 
1038  if (!nBytesToRead)
1039  {
1040  switch (state)
1041  {
1042  case 0: // Check preamble
1043  if (msgBuffer[IND_PREAMBLE] == PREAMBLE)
1044  {
1045  state++;
1046  nBytesToRead = 3;
1047  }
1048  else
1049  {
1050  nOffset = 0;
1051  nBytesToRead = 1;
1052  }
1053 
1054  break;
1055 
1056  case 1: // Check ADDR, MID, LEN
1057  if (msgBuffer[IND_LEN] != 0xFF)
1058  {
1059  state = 3;
1060  nBytesToRead = (nMsgDataLen = msgBuffer[IND_LEN]) + 1; // Read LEN + 1 (chksum)
1061  }
1062  else
1063  {
1064  state = 2;
1065  nBytesToRead = 2; // Read extended length
1066  }
1067 
1068  break;
1069 
1070  case 2:
1071  state = 3;
1072  nBytesToRead = (nMsgDataLen = msgBuffer[IND_LENEXTH] * 256 + msgBuffer[IND_LENEXTL]) + 1; // Read LENEXT + CS
1073 
1074  if (nMsgDataLen > MAXMSGLEN - LEN_MSGEXTHEADERCS)
1075  {
1076  // Not synced - check for preamble in the bytes read
1077  for (int i = 1 ; i < LEN_MSGEXTHEADER ; i++)
1078  if (msgBuffer[i] == PREAMBLE)
1079  {
1080  // Found a maybe preamble - 'fill buffer'
1081  nBytesRead = LEN_MSGEXTHEADER - i;
1082  memmove(msgBuffer, msgBuffer + i, nBytesRead);
1083  break;
1084  }
1085 
1086  Synced = false;
1087  nOffset = 0;
1088  state = 0;
1089  nBytesToRead = 1; // Start looking for preamble
1090  }
1091 
1092  break;
1093 
1094  case 3: // Check msg
1095  chCheckSum = 0;
1096  nMsgLen = nMsgDataLen + 5 + (msgBuffer[IND_LEN] == 0xFF ? 2 : 0);
1097 
1098  for (int i = 1 ; i < nMsgLen ; i++)
1099  {
1100  chCheckSum += msgBuffer[i];
1101  }
1102 
1103  if (chCheckSum == 0)
1104  {
1105  // Checksum ok?
1106  if (nBytesRead > 0)
1107  {
1108  // Store bytes if read too much
1109  memcpy(m_tempBuffer, msgBuffer + nMsgLen, nBytesRead);
1110  m_nTempBufferLen = nBytesRead;
1111  }
1112 
1113  *msgBufferLength = nMsgLen;
1114  Synced = true;
1115  return (m_retVal = MTRV_OK);
1116  }
1117  else
1118  {
1119  if (!Synced)
1120  for (int i = 1 ; i < nMsgLen ; i++) // Not synced - maybe recheck for preamble in this incorrect message
1121  if (msgBuffer[i] == PREAMBLE)
1122  {
1123  // Found a maybe preamble - 'fill buffer'
1124  nBytesRead = nMsgLen - i;
1125  memmove(msgBuffer, msgBuffer + i, nBytesRead);
1126  break;
1127  }
1128 
1129  Synced = false;
1130  nOffset = 0;
1131  state = 0;
1132  nBytesToRead = 1; // Start looking for preamble
1133  }
1134 
1135  break;
1136  }
1137  }
1138  }
1139  while ((clkEnd >= clockms()) || m_timeOut == 0 || nBytesRead != 0);
1140 
1141  // Check if pending message has a valid message
1142  if (state > 0)
1143  {
1144  int i;
1145 
1146  // Search for preamble
1147  for (i = 1; i < nOffset ; i++)
1148  if (msgBuffer[i] == PREAMBLE)
1149  {
1150  // Found a maybe preamble - 'fill buffer'
1151  nBytesRead = nOffset - i - 1; // no preamble
1152  memmove(msgBuffer + 1, msgBuffer + i + 1, nBytesRead);
1153  break;
1154  }
1155 
1156  if (i < nOffset)
1157  {
1158  // Found preamble in message - recheck
1159  nOffset = 1;
1160  state = 1;
1161  nBytesToRead = 3; // Start looking for preamble
1162  continue;
1163  }
1164  }
1165 
1166  break;
1167  }
1168 
1169  return (m_retVal = MTRV_TIMEOUT);
1170  }
1171 
1172  ////////////////////////////////////////////////////////////////////
1173  // writeMessage (optional: integer value)
1174  //
1175  // Sends a message and in case of an serial port interface it checks
1176  // if the return message (ack, error or timeout). See return value
1177  // In case an file is opened the functions returns directly after
1178  // 'sending' the message
1179  //
1180  // Use this function for GotoConfig, Reset, ResetOrientation etc
1181  //
1182  // Input
1183  // mid : MessageID of message to send
1184  // dataValue : A integer value that will be included into the data message field
1185  // can be a 1,2 or 4 bytes values
1186  // dataValueLen : Size of dataValue in bytes
1187  // bid : BID or address to use in message to send (default = 0xFF)
1188  //
1189  // Return value
1190  // = MTRV_OK if an Ack message received / or data successfully written to file
1191  // = MTRV_RECVERRORMSG if an error message received
1192  // = MTRV_TIMEOUT if timeout occurred
1193  // = MTRV_NOINPUTINITIALIZED
1194  //
1195  short CXsensMTiModule::writeMessage(const unsigned char mid, const unsigned long dataValue, const unsigned char dataValueLen, const unsigned char bid)
1196  {
1197  unsigned char buffer[MAXMSGLEN ];
1198  short msgLen;
1199 
1200  if (!(m_fileOpen || m_portOpen))
1201  {
1202  return (m_retVal = MTRV_NOINPUTINITIALIZED);
1203  }
1204 
1205  buffer[IND_PREAMBLE] = PREAMBLE;
1206  buffer[IND_BID] = bid;
1207  buffer[IND_MID] = mid;
1208  buffer[IND_LEN] = dataValueLen;
1209 
1210  if (dataValueLen)
1211  {
1212  swapEndian((const unsigned char*) &dataValue, &buffer[IND_DATA0], dataValueLen);
1213  }
1214 
1215  calcChecksum(buffer, LEN_MSGHEADER + dataValueLen);
1216 
1217  // Send message
1218  writeData(buffer, LEN_MSGHEADERCS + dataValueLen);
1219 
1220  // Return if file opened
1221  if (m_fileOpen)
1222  {
1223  return (m_retVal = MTRV_OK);
1224  }
1225 
1226  // Keep reading until an Ack or Error message is received (or timeout)
1227  clock_t clkStart, clkOld;
1228  bool msgRead = false;
1229 
1230  clkStart = clockms(); // Get current processor time
1231  clkOld = m_clkEnd;
1232 
1233  if (clkOld == 0)
1234  {
1235  m_clkEnd = m_timeOut + clkStart;
1236  }
1237 
1238  while (m_clkEnd >= clockms() || (m_timeOut == 0))
1239  {
1240  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
1241  {
1242  // Message received
1243  msgRead = true;
1244 
1245  if (buffer[IND_MID] == (mid + 1))
1246  {
1247  m_clkEnd = clkOld;
1248  return (m_retVal = MTRV_OK); // Acknowledge received
1249  }
1250  else if (buffer[IND_MID] == MID_ERROR)
1251  {
1252  m_deviceError = buffer[IND_DATA0];
1253  m_clkEnd = clkOld;
1254  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
1255  }
1256  }
1257  }
1258 
1259  m_clkEnd = clkOld;
1260 
1261  if (msgRead)
1262  {
1263  return (m_retVal = MTRV_TIMEOUT);
1264  }
1265  else
1266  {
1267  return (m_retVal = MTRV_TIMEOUTNODATA);
1268  }
1269  }
1270 
1271  ////////////////////////////////////////////////////////////////////
1272  // writeMessage (data array)
1273  //
1274  // Sends a message and in case of an serial port interface it checks
1275  // if the return message (ack, error or timeout). See return value
1276  // In case an file is opened the functions returns directly after
1277  // 'sending' the message
1278  //
1279  // Input
1280  // mid : MessageID of message to send
1281  // data : array pointer to data bytes
1282  // dataLen : number of bytes to include in message
1283  // bid : BID or address to use in message to send (default = 0xFF)
1284  //
1285  // Output
1286  // = MTRV_OK if an Ack message received
1287  // = MTRV_RECVERRORMSG if an error message received
1288  // = MTRV_TIMEOUT if timeout occurred
1289  // = MTRV_NOINPUTINITIALIZED
1290  //
1291  short CXsensMTiModule::writeMessage(const unsigned char mid, const unsigned char data[], const unsigned short& dataLen, const unsigned char bid)
1292  {
1293  unsigned char buffer[MAXMSGLEN ];
1294  short msgLen;
1295  short headerLength;
1296 
1297  if (!(m_fileOpen || m_portOpen))
1298  {
1299  return (m_retVal = MTRV_NOINPUTINITIALIZED);
1300  }
1301 
1302  // Build message to send
1303  buffer[IND_PREAMBLE] = PREAMBLE;
1304  buffer[IND_BID] = bid;
1305  buffer[IND_MID] = mid;
1306 
1307  if (dataLen < EXTLENCODE)
1308  {
1309  buffer[IND_LEN] = (unsigned char) dataLen;
1310  headerLength = LEN_MSGHEADER;
1311  }
1312  else
1313  {
1314  buffer[IND_LEN] = EXTLENCODE;
1315  buffer[IND_LENEXTH] = (unsigned char)(dataLen >> 8);
1316  buffer[IND_LENEXTL] = (unsigned char)(dataLen & 0x00FF);
1317  headerLength = LEN_MSGEXTHEADER;
1318  }
1319 
1320  memcpy(&buffer[headerLength], data, dataLen);
1321  calcChecksum(buffer, headerLength + dataLen);
1322 
1323  // Send message
1324  writeData(buffer, headerLength + dataLen + LEN_CHECKSUM);
1325 
1326  // Return if file opened
1327  if (m_fileOpen)
1328  {
1329  return (m_retVal = MTRV_OK);
1330  }
1331 
1332  // Keep reading until an Ack or Error message is received (or timeout)
1333  bool msgRead = false;
1334  clock_t clkStart, clkOld;
1335 
1336  clkStart = clockms(); // Get current processor time
1337  clkOld = m_clkEnd;
1338 
1339  if (clkOld == 0)
1340  {
1341  m_clkEnd = m_timeOut + clkStart;
1342  }
1343 
1344  while (m_clkEnd >= clockms() || (m_timeOut == 0))
1345  {
1346  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
1347  {
1348  // Message received
1349  msgRead = true;
1350 
1351  if (buffer[IND_MID] == (mid + 1))
1352  {
1353  m_clkEnd = clkOld;
1354  return (m_retVal = MTRV_OK); // Acknowledge received
1355  }
1356  else if (buffer[IND_MID] == MID_ERROR)
1357  {
1358  m_deviceError = buffer[IND_DATA0];
1359  m_clkEnd = clkOld;
1360  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
1361  }
1362  }
1363  }
1364 
1365  m_clkEnd = clkOld;
1366 
1367  if (msgRead)
1368  {
1369  return (m_retVal = MTRV_TIMEOUT);
1370  }
1371  else
1372  {
1373  return (m_retVal = MTRV_TIMEOUTNODATA);
1374  }
1375  }
1376 
1377  ////////////////////////////////////////////////////////////////////
1378  // waitForMessage
1379  //
1380  // Read messages from serial port or file using the current timeout period
1381  // until the received message is equal to a specific message identifier
1382  // By default the timeout period by file input is set to infinity (= until
1383  // end of file is reached)
1384  //
1385  // Input/Output
1386  // mid : message identifier of message that should be returned
1387  // data : pointer to buffer in which the data of the requested msg will be stored
1388  // dataLen : integer to number of data bytes
1389  // bid : optional, pointer which holds the bid of the returned message
1390  // Output
1391  // returns MTRV_OK if the message has been read else != MTRV_OK
1392  //
1393  // Remarks
1394  // allocate enough memory for data message buffer
1395  // use setTimeOut for different timeout value
1396  short CXsensMTiModule::waitForMessage(const unsigned char mid, unsigned char data[], short* dataLen, unsigned char* bid)
1397  {
1398  unsigned char buffer[MAXMSGLEN ];
1399  short buflen;
1400 
1401  clock_t clkStart, clkOld;
1402 
1403  if (!(m_fileOpen || m_portOpen))
1404  {
1405  return (m_retVal = MTRV_NOINPUTINITIALIZED);
1406  }
1407 
1408  clkStart = clockms(); // Get current processor time
1409  clkOld = m_clkEnd;
1410 
1411  if (clkOld == 0)
1412  {
1413  m_clkEnd = m_timeOut + clkStart;
1414  }
1415 
1416  while (m_clkEnd >= clockms() || (m_timeOut == 0))
1417  {
1418  if (readMessageRaw(buffer, &buflen) == MTRV_OK)
1419  {
1420  if (buffer[IND_MID] == mid)
1421  {
1422  if (bid != nullptr)
1423  {
1424  *bid = buffer[IND_BID];
1425  }
1426 
1427  if (data != nullptr && dataLen != nullptr)
1428  {
1429  if (buffer[IND_LEN] != EXTLENCODE)
1430  {
1431  *dataLen = buffer[IND_LEN];
1432  memcpy(data, &buffer[IND_DATA0], *dataLen);
1433  }
1434  else
1435  {
1436  *dataLen = buffer[IND_LENEXTH] * 256 + buffer[IND_LENEXTL];
1437  memcpy(data, &buffer[IND_DATAEXT0], *dataLen);
1438  }
1439  }
1440  else if (dataLen != nullptr)
1441  {
1442  dataLen = nullptr;
1443  }
1444 
1445  m_clkEnd = clkOld;
1446  return (m_retVal = MTRV_OK);
1447  }
1448  }
1449  else if (m_retVal == MTRV_ENDOFFILE)
1450  {
1451  m_clkEnd = clkOld;
1452  return (m_retVal = MTRV_ENDOFFILE);
1453  }
1454  }
1455 
1456  m_clkEnd = clkOld;
1457  return (m_retVal = MTRV_TIMEOUT);
1458  }
1459 
1460  ////////////////////////////////////////////////////////////////////
1461  // reqSetting (integer & no param variant)
1462  //
1463  // Request a integer setting from the device. This setting
1464  // can be an unsigned 1,2 or 4 bytes setting. Only valid
1465  // for serial port connections
1466  //
1467  // Input
1468  // mid : Message ID of message to send
1469  // bid : Bus ID of message to send (def 0xFF)
1470  //
1471  // Output
1472  // = MTRV_OK if an Ack message is received
1473  // = MTRV_RECVERRORMSG if an error message is received
1474  // = MTRV_TIMEOUT if timeout occurred
1475  //
1476  // value contains the integer value of the data field of the ack message
1477  //
1478  short CXsensMTiModule::reqSetting(const unsigned char mid, unsigned long& value, const unsigned char bid)
1479  {
1480  unsigned char buffer[MAXMSGLEN ];
1481  short msgLen;
1482 
1483  if (m_fileOpen)
1484  {
1486  }
1487 
1488  if (!m_portOpen)
1489  {
1490  return (m_retVal = MTRV_NOINPUTINITIALIZED);
1491  }
1492 
1493  buffer[IND_PREAMBLE] = PREAMBLE;
1494  buffer[IND_BID] = bid;
1495  buffer[IND_MID] = mid;
1496  buffer[IND_LEN] = 0;
1497  calcChecksum(buffer, LEN_MSGHEADER + buffer[IND_LEN]);
1498 
1499  // Send message
1500  writeData(buffer, LEN_MSGHEADERCS + buffer[IND_LEN]);
1501 
1502  // Read next message or else timeout
1503  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
1504  {
1505  // Message received
1506  if (buffer[IND_MID] == (mid + 1))
1507  {
1508  // Acknowledge received
1509  value = 0;
1510  swapEndian(&buffer[IND_DATA0], (unsigned char*) &value, buffer[IND_LEN]);
1511  return (m_retVal = MTRV_OK);
1512  }
1513  else if (buffer[IND_MID] == MID_ERROR)
1514  {
1515  m_deviceError = buffer[IND_DATA0];
1516  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
1517  }
1518  else
1519  {
1520  return (m_retVal = MTRV_UNEXPECTEDMSG); // Unexpected message
1521  }
1522  }
1523 
1524  return m_retVal;
1525  }
1526 
1527  ////////////////////////////////////////////////////////////////////
1528  // reqSetting (integer & param variant)
1529  //
1530  // Request a integer setting from the device. This setting
1531  // can be an unsigned 1,2 or 4 bytes setting. Only valid
1532  // for serial port connections.
1533  //
1534  // Input
1535  // mid : Message ID of message to send
1536  // param : For messages that need a parameter
1537  // bid : Bus ID of message to send (def 0xFF)
1538  //
1539  // Output
1540  // = MTRV_OK if an Ack message is received
1541  // = MTRV_RECVERRORMSG if an error message is received
1542  // = MTRV_TIMEOUT if timeout occurred
1543  //
1544  // value contains the integer value of the data field of the ack message
1545  //
1546  short CXsensMTiModule::reqSetting(const unsigned char mid, const unsigned char param, unsigned long& value, const unsigned char bid)
1547  {
1548  unsigned char buffer[MAXMSGLEN ];
1549  short msgLen;
1550 
1551  if (m_fileOpen)
1552  {
1554  }
1555 
1556  if (!m_portOpen)
1557  {
1558  return (m_retVal = MTRV_NOINPUTINITIALIZED);
1559  }
1560 
1561  buffer[IND_PREAMBLE] = PREAMBLE;
1562  buffer[IND_BID] = bid;
1563  buffer[IND_MID] = mid;
1564 
1565  if (param != 0xFF)
1566  {
1567  buffer[IND_LEN] = 1;
1568  buffer[IND_DATA0] = param;
1569  }
1570  else
1571  {
1572  buffer[IND_LEN] = 0;
1573  }
1574 
1575  calcChecksum(buffer, LEN_MSGHEADER + buffer[IND_LEN]);
1576 
1577  // Send message
1578  writeData(buffer, LEN_MSGHEADERCS + buffer[IND_LEN]);
1579 
1580  // Read next message or else timeout
1581  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
1582  {
1583  // Message received
1584  if (buffer[IND_MID] == (mid + 1))
1585  {
1586  // Acknowledge received
1587  value = 0;
1588 
1589  if (param == 0xFF)
1590  {
1591  swapEndian(&buffer[IND_DATA0], (unsigned char*) &value, buffer[IND_LEN]);
1592  }
1593  else
1594  {
1595  swapEndian(&buffer[IND_DATA0] + 1, (unsigned char*) &value, buffer[IND_LEN] - 1);
1596  }
1597 
1598  return (m_retVal = MTRV_OK);
1599  }
1600  else if (buffer[IND_MID] == MID_ERROR)
1601  {
1602  m_deviceError = buffer[IND_DATA0];
1603  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
1604  }
1605  else
1606  {
1607  return (m_retVal = MTRV_UNEXPECTEDMSG); // Unexpected message
1608  }
1609  }
1610 
1611  return m_retVal;
1612  }
1613 
1614  ////////////////////////////////////////////////////////////////////
1615  // reqSetting (float & no param variant)
1616  //
1617  // Request a float setting from the device. Only valid
1618  // for serial port connections.
1619  //
1620  // Input
1621  // mid : Message ID of message to send
1622  // bid : Bus ID of message to send (def 0xFF)
1623  //
1624  // Output
1625  // = MTRV_OK if an Ack message is received
1626  // = MTRV_RECVERRORMSG if an error message is received
1627  // = MTRV_TIMEOUT if timeout occurred
1628  //
1629  // value contains the float value of the acknowledge data field
1630  //
1631  short CXsensMTiModule::reqSetting(const unsigned char mid, float& value, const unsigned char bid)
1632  {
1633  unsigned char buffer[MAXMSGLEN ];
1634  short msgLen;
1635 
1636  if (m_fileOpen)
1637  {
1639  }
1640 
1641  if (!m_portOpen)
1642  {
1643  return (m_retVal = MTRV_NOINPUTINITIALIZED);
1644  }
1645 
1646  buffer[IND_PREAMBLE] = PREAMBLE;
1647  buffer[IND_BID] = bid;
1648  buffer[IND_MID] = mid;
1649  buffer[IND_LEN] = 0;
1650  calcChecksum(buffer, LEN_MSGHEADER + buffer[IND_LEN]);
1651 
1652  // Send message
1653  writeData(buffer, LEN_MSGHEADERCS + buffer[IND_LEN]);
1654 
1655  // Read next message or else timeout
1656  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
1657  {
1658  // Message received
1659  if (buffer[IND_MID] == (mid + 1))
1660  {
1661  // Acknowledge received
1662  value = 0;
1663  swapEndian(&buffer[IND_DATA0], (unsigned char*) &value, buffer[IND_LEN]);
1664  return (m_retVal = MTRV_OK);
1665  }
1666  else if (buffer[IND_MID] == MID_ERROR)
1667  {
1668  m_deviceError = buffer[IND_DATA0];
1669  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
1670  }
1671  else
1672  {
1673  return (m_retVal = MTRV_UNEXPECTEDMSG); // Unexpected message
1674  }
1675  }
1676 
1677  return m_retVal;
1678  }
1679 
1680  ////////////////////////////////////////////////////////////////////
1681  // reqSetting (float & param variant)
1682  //
1683  // Request a float setting from the device. Only valid
1684  // for serial port connections.
1685  //
1686  // Input
1687  // mid : Message ID of message to send
1688  // param : For messages that need a parameter (optional)
1689  // bid : Bus ID of message to send (def 0xFF)
1690  //
1691  // Output
1692  // = MTRV_OK if an Ack message is received
1693  // = MTRV_RECVERRORMSG if an error message is received
1694  // = MTRV_TIMEOUT if timeout occurred
1695  //
1696  // value contains the float value of the acknowledge data field
1697  //
1698  short CXsensMTiModule::reqSetting(const unsigned char mid, const unsigned char param, float& value, const unsigned char bid)
1699  {
1700  unsigned char buffer[MAXMSGLEN ];
1701  short msgLen;
1702 
1703  if (m_fileOpen)
1704  {
1706  }
1707 
1708  if (!m_portOpen)
1709  {
1710  return (m_retVal = MTRV_NOINPUTINITIALIZED);
1711  }
1712 
1713  buffer[IND_PREAMBLE] = PREAMBLE;
1714  buffer[IND_BID] = bid;
1715  buffer[IND_MID] = mid;
1716 
1717  if (param != 0xFF)
1718  {
1719  buffer[IND_LEN] = 1;
1720  buffer[IND_DATA0] = param;
1721  }
1722  else
1723  {
1724  buffer[IND_LEN] = 0;
1725  }
1726 
1727  calcChecksum(buffer, LEN_MSGHEADER + buffer[IND_LEN]);
1728 
1729  // Send message
1730  writeData(buffer, LEN_MSGHEADERCS + buffer[IND_LEN]);
1731 
1732  // Read next message or else timeout
1733  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
1734  {
1735  // Message received
1736  if (buffer[IND_MID] == (mid + 1))
1737  {
1738  // Acknowledge received
1739  value = 0;
1740 
1741  if (param == 0xFF)
1742  {
1743  swapEndian(&buffer[IND_DATA0], (unsigned char*) &value, buffer[IND_LEN]);
1744  }
1745  else
1746  {
1747  swapEndian(&buffer[IND_DATA0] + 1, (unsigned char*) &value, buffer[IND_LEN] - 1);
1748  }
1749 
1750  return (m_retVal = MTRV_OK);
1751  }
1752  else if (buffer[IND_MID] == MID_ERROR)
1753  {
1754  m_deviceError = buffer[IND_DATA0];
1755  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
1756  }
1757  else
1758  {
1759  return (m_retVal = MTRV_UNEXPECTEDMSG); // Unexpected message
1760  }
1761  }
1762 
1763  return m_retVal;
1764  }
1765 
1766  ////////////////////////////////////////////////////////////////////
1767  // reqSetting (byte array & no param variant)
1768  //
1769  // Send a message to the device and the data of acknowledge message
1770  // will be returned. Only valid for serial port connections
1771  //
1772  // Input
1773  // mid : Message ID of message to send
1774  // bid : Bus ID of message to send (def 0xFF)
1775  //
1776  // Output
1777  // = MTRV_OK if an Ack message is received
1778  // = MTRV_RECVERRORMSG if an error message is received
1779  // = MTRV_TIMEOUT if timeout occurred
1780  //
1781  // data[] contains the data of the acknowledge message
1782  // dataLen contains the number bytes returned
1783  //
1784  short CXsensMTiModule::reqSetting(const unsigned char mid, unsigned char data[], short& dataLen, const unsigned char bid)
1785  {
1786  unsigned char buffer[MAXMSGLEN ];
1787  short msgLen;
1788 
1789  if (m_fileOpen)
1790  {
1792  }
1793 
1794  if (!m_portOpen)
1795  {
1796  return (m_retVal = MTRV_NOINPUTINITIALIZED);
1797  }
1798 
1799  buffer[IND_PREAMBLE] = PREAMBLE;
1800  buffer[IND_BID] = bid;
1801  buffer[IND_MID] = mid;
1802  buffer[IND_LEN] = 0;
1803  calcChecksum(buffer, LEN_MSGHEADER + buffer[IND_LEN]);
1804 
1805  // Send message
1806  writeData(buffer, LEN_MSGHEADERCS + buffer[IND_LEN]);
1807 
1808  dataLen = 0;
1809 
1810  // Read next message or else timeout
1811  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
1812  {
1813  // Message received
1814  if (buffer[IND_MID] == (mid + 1))
1815  {
1816  // Acknowledge received
1817  if (buffer[IND_LEN] != EXTLENCODE)
1818  {
1819  dataLen = buffer[IND_LEN];
1820  memcpy(data, &buffer[IND_DATA0], dataLen);
1821  }
1822  else
1823  {
1824  dataLen = buffer[IND_LENEXTH] * 256 + buffer[IND_LENEXTL];
1825  memcpy(data, &buffer[IND_DATAEXT0], dataLen);
1826  }
1827 
1828  return (m_retVal = MTRV_OK);
1829  }
1830  else if (buffer[IND_MID] == MID_ERROR)
1831  {
1832  m_deviceError = buffer[IND_DATA0];
1833  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
1834  }
1835  else
1836  {
1837  return (m_retVal = MTRV_UNEXPECTEDMSG); // Unexpected message
1838  }
1839  }
1840 
1841  return m_retVal;
1842  }
1843 
1844  ////////////////////////////////////////////////////////////////////
1845  // reqSetting (byte array in + out & no param variant)
1846  //
1847  // Send a message to the device and the data of acknowledge message
1848  // will be returned. Only valid for serial port connections
1849  //
1850  // Input
1851  // mid : Message ID of message to send
1852  // bid : Bus ID of message to send (def 0xFF)
1853  // dataIn : Data to be included in request
1854  // dataInLen : Number of bytes in dataIn
1855  //
1856  // Output
1857  // = MTRV_OK if an Ack message is received
1858  // = MTRV_RECVERRORMSG if an error message is received
1859  // = MTRV_TIMEOUT if timeout occurred
1860  //
1861  // dataOut[] contains the data of the acknowledge message
1862  // dataOutLen contains the number bytes returned
1863  //
1864  short CXsensMTiModule::reqSetting(const unsigned char mid, unsigned char dataIn[], short dataInLen, unsigned char dataOut[], short& dataOutLen, const unsigned char bid)
1865  {
1866  unsigned char buffer[MAXMSGLEN ];
1867  short headerLength;
1868  short msgLen;
1869 
1870  if (m_fileOpen)
1871  {
1873  }
1874 
1875  if (!m_portOpen)
1876  {
1877  return (m_retVal = MTRV_NOINPUTINITIALIZED);
1878  }
1879 
1880  buffer[IND_PREAMBLE] = PREAMBLE;
1881  buffer[IND_BID] = bid;
1882  buffer[IND_MID] = mid;
1883 
1884  if (dataInLen < EXTLENCODE)
1885  {
1886  buffer[IND_LEN] = (unsigned char) dataInLen;
1887  headerLength = LEN_MSGHEADER;
1888  }
1889  else
1890  {
1891  buffer[IND_LEN] = EXTLENCODE;
1892  buffer[IND_LENEXTH] = (unsigned char)(dataInLen >> 8);
1893  buffer[IND_LENEXTL] = (unsigned char)(dataInLen & 0x00FF);
1894  headerLength = LEN_MSGEXTHEADER;
1895  }
1896 
1897  memcpy(&buffer[headerLength], dataIn, dataInLen);
1898  calcChecksum(buffer, headerLength + dataInLen);
1899 
1900  // Send message
1901  writeData(buffer, headerLength + dataInLen + LEN_CHECKSUM);
1902 
1903  dataOutLen = 0;
1904 
1905  // Read next message or else timeout
1906  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
1907  {
1908  // Message received
1909  if (buffer[IND_MID] == (mid + 1))
1910  {
1911  // Acknowledge received
1912  if (buffer[IND_LEN] != EXTLENCODE)
1913  {
1914  dataOutLen = buffer[IND_LEN];
1915  memcpy(dataOut, &buffer[IND_DATA0], dataOutLen);
1916  }
1917  else
1918  {
1919  dataOutLen = buffer[IND_LENEXTH] * 256 + buffer[IND_LENEXTL];
1920  memcpy(dataOut, &buffer[IND_DATAEXT0], dataOutLen);
1921  }
1922 
1923  return (m_retVal = MTRV_OK);
1924  }
1925  else if (buffer[IND_MID] == MID_ERROR)
1926  {
1927  m_deviceError = buffer[IND_DATA0];
1928  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
1929  }
1930  else
1931  {
1932  return (m_retVal = MTRV_UNEXPECTEDMSG); // Unexpected message
1933  }
1934  }
1935 
1936  return m_retVal;
1937  }
1938 
1939  ////////////////////////////////////////////////////////////////////
1940  // reqSetting (byte array & param variant)
1941  //
1942  // Send a message to the device and the data of acknowledge message
1943  // will be returned. Only valid for serial port connections
1944  //
1945  // Input
1946  // mid : Message ID of message to send
1947  // param : For messages that need a parameter (optional)
1948  // bid : Bus ID of message to send (def 0xFF)
1949  //
1950  // Output
1951  // = MTRV_OK if an Ack message is received
1952  // = MTRV_RECVERRORMSG if an error message is received
1953  // = MTRV_TIMEOUT if timeout occurred
1954  //
1955  // data[] contains the data of the acknowledge message (including param!!)
1956  // dataLen contains the number bytes returned
1957  //
1958  short CXsensMTiModule::reqSetting(const unsigned char mid, const unsigned char param, unsigned char data[], short& dataLen, const unsigned char bid)
1959  {
1960  unsigned char buffer[MAXMSGLEN ];
1961  short msgLen;
1962 
1963  if (m_fileOpen)
1964  {
1966  }
1967 
1968  if (!m_portOpen)
1969  {
1970  return (m_retVal = MTRV_NOINPUTINITIALIZED);
1971  }
1972 
1973  buffer[IND_PREAMBLE] = PREAMBLE;
1974  buffer[IND_BID] = bid;
1975  buffer[IND_MID] = mid;
1976 
1977  if (param != 0xFF)
1978  {
1979  buffer[IND_LEN] = 1;
1980  buffer[IND_DATA0] = param;
1981  }
1982  else
1983  {
1984  buffer[IND_LEN] = 0;
1985  }
1986 
1987  calcChecksum(buffer, LEN_MSGHEADER + buffer[IND_LEN]);
1988 
1989  // Send message
1990  writeData(buffer, LEN_MSGHEADERCS + buffer[IND_LEN]);
1991 
1992  dataLen = 0;
1993 
1994  // Read next message or else timeout
1995  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
1996  {
1997  // Message received
1998  if (buffer[IND_MID] == (mid + 1))
1999  {
2000  // Acknowledge received
2001  if (buffer[IND_LEN] != EXTLENCODE)
2002  {
2003  dataLen = buffer[IND_LEN];
2004  memcpy(data, &buffer[IND_DATA0], dataLen);
2005  }
2006  else
2007  {
2008  dataLen = buffer[IND_LENEXTH] * 256 + buffer[IND_LENEXTL];
2009  memcpy(data, &buffer[IND_DATAEXT0], dataLen);
2010  }
2011 
2012  return (m_retVal = MTRV_OK);
2013  }
2014  else if (buffer[IND_MID] == MID_ERROR)
2015  {
2016  m_deviceError = buffer[IND_DATA0];
2017  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
2018  }
2019  else
2020  {
2021  return (m_retVal = MTRV_UNEXPECTEDMSG); // Unexpected message
2022  }
2023  }
2024 
2025  return m_retVal;
2026  }
2027 
2028  ////////////////////////////////////////////////////////////////////
2029  // setSetting (integer & no param variant)
2030  //
2031  // Sets a integer setting of the device. This setting
2032  // can be an unsigned 1,2 or 4 bytes setting. Only valid
2033  // for serial port connections.
2034  //
2035  // Input
2036  // mid : Message ID of message to send
2037  // bid : Bus ID of message to send (def 0xFF)
2038  // value : Contains the integer value to be used
2039  // valuelen : Length in bytes of the value
2040  //
2041  // Output
2042  // = MTRV_OK if an Ack message is received
2043  // = MTRV_RECVERRORMSG if an error message is received
2044  // = MTRV_TIMEOUT if timeout occurred
2045  //
2046  //
2047  short CXsensMTiModule::setSetting(const unsigned char mid, const unsigned long value, const unsigned short valuelen, const unsigned char bid)
2048  {
2049  unsigned char buffer[MAXMSGLEN ];
2050  short msgLen;
2051 
2052  if (m_fileOpen)
2053  {
2055  }
2056 
2057  if (!m_portOpen)
2058  {
2059  return (m_retVal = MTRV_NOINPUTINITIALIZED);
2060  }
2061 
2062  msgLen = LEN_MSGHEADER;
2063  buffer[IND_PREAMBLE] = PREAMBLE;
2064  buffer[IND_BID] = bid;
2065  buffer[IND_MID] = mid;
2066  buffer[IND_LEN] = (unsigned char) valuelen;
2067  swapEndian((unsigned char*) &value, &buffer[msgLen], valuelen);
2068  calcChecksum(buffer, LEN_MSGHEADER + buffer[IND_LEN]);
2069 
2070  // Send message
2071  writeData(buffer, LEN_MSGHEADERCS + buffer[IND_LEN]);
2072 
2073  // Read next received message
2074  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
2075  {
2076  // Message received
2077  if (buffer[IND_MID] == (mid + 1))
2078  {
2079  return (m_retVal = MTRV_OK); // Acknowledge received
2080  }
2081  else if (buffer[IND_MID] == MID_ERROR)
2082  {
2083  m_deviceError = buffer[IND_DATA0];
2084  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
2085  }
2086  }
2087 
2088  return m_retVal;
2089  }
2090 
2091  ////////////////////////////////////////////////////////////////////
2092  // setSetting (integer & param variant)
2093  //
2094  // Sets a integer setting of the device. This setting
2095  // can be an unsigned 1,2 or 4 bytes setting. Only valid
2096  // for serial port connections.
2097  //
2098  // Input
2099  // mid : Message ID of message to send
2100  // param : For messages that need a parameter (optional)
2101  // bid : Bus ID of message to send (def 0xFF)
2102  // value : Contains the integer value to be used
2103  // valuelen : Length in bytes of the value
2104  //
2105  // Output
2106  // = MTRV_OK if an Ack message is received
2107  // = MTRV_RECVERRORMSG if an error message is received
2108  // = MTRV_TIMEOUT if timeout occurred
2109  //
2110  //
2111  short CXsensMTiModule::setSetting(const unsigned char mid, const unsigned char param, const unsigned long value, const unsigned short valuelen, const unsigned char bid)
2112  {
2113  unsigned char buffer[MAXMSGLEN ];
2114  short msgLen;
2115 
2116  if (m_fileOpen)
2117  {
2119  }
2120 
2121  if (!m_portOpen)
2122  {
2123  return (m_retVal = MTRV_NOINPUTINITIALIZED);
2124  }
2125 
2126  msgLen = LEN_MSGHEADER;
2127  buffer[IND_PREAMBLE] = PREAMBLE;
2128  buffer[IND_BID] = bid;
2129  buffer[IND_MID] = mid;
2130 
2131  if (param != 0xFF)
2132  {
2133  msgLen++;
2134  buffer[IND_LEN] = valuelen + 1;
2135  buffer[IND_DATA0] = param;
2136  }
2137  else
2138  {
2139  buffer[IND_LEN] = (unsigned char) valuelen;
2140  }
2141 
2142  swapEndian((unsigned char*) &value, &buffer[msgLen], valuelen);
2143  calcChecksum(buffer, LEN_MSGHEADER + buffer[IND_LEN]);
2144 
2145  // Send message
2146  writeData(buffer, LEN_MSGHEADERCS + buffer[IND_LEN]);
2147 
2148  // Read next received message
2149  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
2150  {
2151  // Message received
2152  if (buffer[IND_MID] == (mid + 1))
2153  {
2154  return (m_retVal = MTRV_OK); // Acknowledge received
2155  }
2156  else if (buffer[IND_MID] == MID_ERROR)
2157  {
2158  m_deviceError = buffer[IND_DATA0];
2159  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
2160  }
2161  }
2162 
2163  return m_retVal;
2164  }
2165 
2166  ////////////////////////////////////////////////////////////////////
2167  // setSetting (float & no param variant)
2168  //
2169  // Sets a float setting of the device. Only valid
2170  // for serial port connections.
2171  //
2172  // Input
2173  // mid : Message ID of message to send
2174  // bid : Bus ID of message to send (def 0xFF)
2175  // value : Contains the float value to be used
2176  //
2177  // Output
2178  // = MTRV_OK if an Ack message is received
2179  // = MTRV_RECVERRORMSG if an error message is received
2180  // = MTRV_TIMEOUT if timeout occurred
2181  //
2182  short CXsensMTiModule::setSetting(const unsigned char mid, const float value, const unsigned char bid)
2183  {
2184  unsigned char buffer[MAXMSGLEN ];
2185  short msgLen;
2186 
2187  if (m_fileOpen)
2188  {
2190  }
2191 
2192  if (!m_portOpen)
2193  {
2194  return (m_retVal = MTRV_NOINPUTINITIALIZED);
2195  }
2196 
2197  msgLen = LEN_MSGHEADER;
2198  buffer[IND_PREAMBLE] = PREAMBLE;
2199  buffer[IND_BID] = bid;
2200  buffer[IND_MID] = mid;
2201  buffer[IND_LEN] = LEN_FLOAT;
2202  swapEndian((unsigned char*) &value, &buffer[msgLen], LEN_FLOAT);
2204 
2205  // Send message
2206  writeData(buffer, LEN_MSGHEADERCS + LEN_FLOAT);
2207 
2208  // Read next received message
2209  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
2210  {
2211  // Message received
2212  if (buffer[IND_MID] == (mid + 1))
2213  {
2214  return (m_retVal = MTRV_OK); // Acknowledge received
2215  }
2216  else if (buffer[IND_MID] == MID_ERROR)
2217  {
2218  m_deviceError = buffer[IND_DATA0];
2219  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
2220  }
2221  }
2222 
2223  return m_retVal;
2224  }
2225 
2226  ////////////////////////////////////////////////////////////////////
2227  // setSetting (float & param variant)
2228  //
2229  // Sets a float setting of the device. Only valid
2230  // for serial port connections.
2231  //
2232  // Input
2233  // mid : Message ID of message to send
2234  // param : For messages that need a parameter (optional)
2235  // bid : Bus ID of message to send (def 0xFF)
2236  // value : Contains the float value to be used
2237  //
2238  // Output
2239  // = MTRV_OK if an Ack message is received
2240  // = MTRV_RECVERRORMSG if an error message is received
2241  // = MTRV_TIMEOUT if timeout occurred
2242  //
2243  //
2244  short CXsensMTiModule::setSetting(const unsigned char mid, const unsigned char param, const float value, const unsigned char bid)
2245  {
2246  unsigned char buffer[MAXMSGLEN ];
2247  short msgLen;
2248 
2249  if (m_fileOpen)
2250  {
2252  }
2253 
2254  if (!m_portOpen)
2255  {
2256  return (m_retVal = MTRV_NOINPUTINITIALIZED);
2257  }
2258 
2259  msgLen = LEN_MSGHEADER;
2260  buffer[IND_PREAMBLE] = PREAMBLE;
2261  buffer[IND_BID] = bid;
2262  buffer[IND_MID] = mid;
2263 
2264  if (param != 0xFF)
2265  {
2266  msgLen++;
2267  buffer[IND_LEN] = LEN_FLOAT + 1;
2268  buffer[IND_DATA0] = param;
2269  }
2270  else
2271  {
2272  buffer[IND_LEN] = LEN_FLOAT;
2273  }
2274 
2275  swapEndian((unsigned char*) &value, &buffer[msgLen], LEN_FLOAT);
2276  calcChecksum(buffer, LEN_MSGHEADER + buffer[IND_LEN]);
2277 
2278  // Send message
2279  writeData(buffer, LEN_MSGHEADERCS + buffer[IND_LEN]);
2280 
2281  // Read next received message
2282  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
2283  {
2284  // Message received
2285  if (buffer[IND_MID] == (mid + 1))
2286  {
2287  return (m_retVal = MTRV_OK); // Acknowledge received
2288  }
2289  else if (buffer[IND_MID] == MID_ERROR)
2290  {
2291  m_deviceError = buffer[IND_DATA0];
2292  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
2293  }
2294  }
2295 
2296  return m_retVal;
2297  }
2298 
2299  ////////////////////////////////////////////////////////////////////
2300  // setSetting (float & param & store variant)
2301  //
2302  // Sets a float setting of the device and with the Store field.
2303  // Only valid for serial port connections
2304  //
2305  // Input
2306  // mid : Message ID of message to send
2307  // param : For messages that need a parameter (optional)
2308  // value : Contains the float value to be used
2309  // store ; Store in non-volatile memory (1) or not (0)
2310  // bid : Bus ID of message to send (def 0xFF)
2311  //
2312  // Output
2313  // = MTRV_OK if an Ack message is received
2314  // = MTRV_RECVERRORMSG if an error message is received
2315  // = MTRV_TIMEOUT if timeout occurred
2316  //
2317  //
2318  short CXsensMTiModule::setSetting(const unsigned char mid, const unsigned char param, const float value, const bool store, const unsigned char bid)
2319  {
2320  unsigned char buffer[MAXMSGLEN ];
2321  short msgLen;
2322 
2323  if (m_fileOpen)
2324  {
2326  }
2327 
2328  if (!m_portOpen)
2329  {
2330  return (m_retVal = MTRV_NOINPUTINITIALIZED);
2331  }
2332 
2333  msgLen = LEN_MSGHEADER;
2334  buffer[IND_PREAMBLE] = PREAMBLE;
2335  buffer[IND_BID] = bid;
2336  buffer[IND_MID] = mid;
2337 
2338  if (param != 0xFF)
2339  {
2340  msgLen++;
2341  buffer[IND_LEN] = LEN_FLOAT + 2;
2342  buffer[IND_DATA0] = param;
2343  }
2344  else
2345  {
2346  buffer[IND_LEN] = LEN_FLOAT + 1;
2347  }
2348 
2349  swapEndian((unsigned char*) &value, &buffer[msgLen], LEN_FLOAT);
2350  buffer[msgLen + LEN_FLOAT ] = store;
2351  calcChecksum(buffer, LEN_MSGHEADER + buffer[IND_LEN]);
2352 
2353  // Send message
2354  writeData(buffer, LEN_MSGHEADERCS + buffer[IND_LEN]);
2355 
2356  // Read next received message
2357  if (readMessageRaw(buffer, &msgLen) == MTRV_OK)
2358  {
2359  // Message received
2360  if (buffer[IND_MID] == (mid + 1))
2361  {
2362  return (m_retVal = MTRV_OK); // Acknowledge received
2363  }
2364  else if (buffer[IND_MID] == MID_ERROR)
2365  {
2366  m_deviceError = buffer[IND_DATA0];
2367  return (m_retVal = MTRV_RECVERRORMSG); // Error message received
2368  }
2369  }
2370 
2371  return m_retVal;
2372  }
2373 
2374  ////////////////////////////////////////////////////////////////////
2375  // getDeviceMode
2376  //
2377  // Requests the current output mode/setting of input (file or serialport)
2378  // the Outputmode, Outputsettings, DataLength & number of devices
2379  // are stored in member variables of the MTComm class. These values
2380  // are needed for the GetValue functions.
2381  // The function optionally returns the number of devices
2382  //
2383  // File: expects the Configuration message at the start of the file
2384  // which holds the OutputMode & OutputSettings. File position
2385  // is after the first message
2386  //
2387  // Input
2388  // Output
2389  // numDevices : [optional] number of devices connected to port or
2390  // found in configuration file
2391  //
2392  // returns MTRV_OK if the mode & settings are read
2393  //
2394  short CXsensMTiModule::getDeviceMode(unsigned short* numDevices)
2395  {
2396  unsigned char mid = 0, data[MAXMSGLEN ];
2397  short datalen;
2398 
2399  if (numDevices != nullptr)
2400  {
2401  *numDevices = 0;
2402  }
2403 
2404  // In case serial port is used (live device / XM or MT)
2405  if (m_portOpen)
2406  {
2407  if (reqSetting(MID_INITBUS, data, datalen) != MTRV_OK)
2408  {
2409  return m_retVal;
2410  }
2411 
2412  // Retrieve outputmode + outputsettings
2413  for (int i = 0 ; i < datalen / LEN_DEVICEID ; i++)
2414  {
2416  {
2417  return m_retVal;
2418  }
2419 
2421  {
2422  return m_retVal;
2423  }
2424 
2426  {
2427  return m_retVal;
2428  }
2429  }
2430 
2431  if (numDevices != nullptr)
2432  {
2433  *numDevices = datalen / LEN_DEVICEID;
2434  }
2435 
2436  unsigned char masterDID[4];
2437  short DIDlen;
2438 
2439  if (reqSetting(MID_REQDID, masterDID, DIDlen) != MTRV_OK)
2440  {
2441  return m_retVal;
2442  }
2443 
2444  if (memcmp(masterDID, data, LEN_DEVICEID) != 0)
2445  {
2446  // Using an XbusMaster
2450  }
2451  else
2452  {
2456  }
2457 
2458  return (m_retVal = MTRV_OK);
2459  }
2460  else if (m_fileOpen)
2461  {
2462  // Configuration message should be the first message in the file
2463  setFilePos(0);
2464 
2465  if (readMessage(mid, data, datalen) == MTRV_OK)
2466  {
2467  if (mid == MID_CONFIGURATION)
2468  {
2469  unsigned short _numDevices = 0;
2470  swapEndian(data + CONF_NUMDEVICES, (unsigned char*) &_numDevices, CONF_NUMDEVICESLEN);
2471 
2472  for (unsigned int i = 0 ; i < _numDevices ; i++)
2473  {
2474  m_storedOutputMode[BID_MT + i] = 0;
2475  swapEndian(data + CONF_OUTPUTMODE + i * CONF_BLOCKLEN, (unsigned char*)(m_storedOutputMode + BID_MT + i),
2477  m_storedOutputSettings[BID_MT + i] = 0;
2480  m_storedDataLength[BID_MT + i] = 0;
2481  swapEndian(data + CONF_DATALENGTH + i * CONF_BLOCKLEN, (unsigned char*)(m_storedDataLength + BID_MT + i),
2483  }
2484 
2485  if (numDevices != nullptr)
2486  {
2487  *numDevices = _numDevices;
2488  }
2489 
2490  if (memcmp(data + CONF_MASTERDID, data + CONF_DID, LEN_DEVICEID) != 0)
2491  {
2492  // Using an XbusMaster
2496  }
2497  else
2498  {
2502  }
2503 
2504  return (m_retVal = MTRV_OK);
2505  }
2506  }
2507 
2508  return (m_retVal = MTRV_NOTSUCCESSFUL);
2509  }
2510 
2511  return (m_retVal = MTRV_NOINPUTINITIALIZED);
2512  }
2513 
2514  ////////////////////////////////////////////////////////////////////
2515  // setDeviceMode
2516  //
2517  // Sets the current output mode/setting of input (not for file-based
2518  // inputs)
2519  //
2520  // Input
2521  // OutputMode : OutputMode to be set in device & stored in MTComm
2522  // class member variable
2523  // OutputSettings : OutputSettings to be set in device & stored in
2524  // MTComm class member variable
2525  // Output
2526  //
2527  // returns MTRV_OK if the mode & settings are read
2528  //
2529  short CXsensMTiModule::setDeviceMode(unsigned long OutputMode, unsigned long OutputSettings, const unsigned char bid)
2530  {
2531  // In case serial port is used (live XM / MT)
2532  if (m_portOpen)
2533  {
2534  // Set OutputMode
2535  if (setSetting(MID_SETOUTPUTMODE, OutputMode, LEN_OUTPUTMODE, bid) != MTRV_OK)
2536  {
2537  return m_retVal;
2538  }
2539 
2540  if (bid == BID_MASTER || (bid == BID_MT && m_storedOutputMode[0] != OUTPUTMODE_XM))
2541  {
2542  m_storedOutputMode[0] = m_storedOutputMode[BID_MT ] = OutputMode;
2543  }
2544  else
2545  {
2546  m_storedOutputMode[bid] = OutputMode;
2547  }
2548 
2549  // Set OutputSettings
2550  if (setSetting(MID_SETOUTPUTSETTINGS, OutputSettings, LEN_OUTPUTSETTINGS, bid) != MTRV_OK)
2551  {
2552  return m_retVal;
2553  }
2554 
2555  if (bid == BID_MASTER || (bid == BID_MT && m_storedOutputMode[0] != OUTPUTMODE_XM))
2556  {
2557  m_storedOutputSettings[0] = m_storedOutputSettings[BID_MT ] = OutputSettings;
2558  }
2559  else
2560  {
2561  m_storedOutputSettings[bid] = OutputSettings;
2562  }
2563 
2564  // Get DataLength from device
2565  if (OutputMode != OUTPUTMODE_XM)
2566  {
2567  unsigned long value;
2568 
2569  if (reqSetting(MID_REQDATALENGTH, value, bid) == MTRV_OK)
2570  {
2571  if ((bid == BID_MASTER) || ((bid == BID_MT) && (m_storedOutputMode[0] != OUTPUTMODE_XM)))
2572  {
2574  }
2575  else
2576  {
2577  m_storedDataLength[bid] = value;
2578  }
2579  }
2580  }
2581  else
2582  {
2584  }
2585 
2586  return (m_retVal = MTRV_OK);
2587  }
2588 
2590  }
2591 
2592  ////////////////////////////////////////////////////////////////////
2593  // getMode
2594  //
2595  // Gets the output mode/setting used in MTComm class and the corresponding
2596  // datalength. These variables are set by the functions GetDeviceMode,
2597  // SetDeviceMode or SetMode
2598  //
2599  // Input
2600  // Output
2601  // OutputMode : OutputMode stored in MTComm class member variable
2602  // OutputSettings : OutputSettings stored in MTComm class member variable
2603  //
2604  // returns always MTRV_OK
2605  //
2606  short CXsensMTiModule::getMode(unsigned long& OutputMode, unsigned long& OutputSettings, unsigned short& dataLength, const unsigned char bid)
2607  {
2608  unsigned char nbid = (bid == BID_MASTER) ? 0 : bid;
2609  OutputMode = m_storedOutputMode[nbid];
2610  OutputSettings = m_storedOutputSettings[nbid];
2611  dataLength = (unsigned short) m_storedDataLength[nbid];
2612  return (m_retVal = MTRV_OK);
2613  }
2614 
2615  ////////////////////////////////////////////////////////////////////
2616  // setMode
2617  //
2618  // Sets the output mode/setting used in MTComm class. Use the function
2619  // GetDeviceMode to retrieve the current values of file/device.
2620  // This function will also calculate the data length field
2621  //
2622  // Input
2623  // OutputMode : OutputMode to be stored in MTComm class member variable
2624  // OutputSettings : OutputSettings to be stored in MTComm class member variable
2625  // Output
2626  //
2627  // returns always MTRV_OK
2628  //
2629  short CXsensMTiModule::setMode(unsigned long OutputMode, unsigned long OutputSettings, const unsigned char bid)
2630  {
2631  unsigned char nbid = bid;
2632 
2633  if (nbid == BID_MASTER)
2634  {
2635  nbid = 0;
2636  }
2637 
2638  m_storedOutputMode[nbid] = OutputMode;
2639  m_storedOutputSettings[nbid] = OutputSettings;
2640 
2641  if (OutputMode == INVALIDSETTINGVALUE || OutputSettings == INVALIDSETTINGVALUE)
2642  {
2643  m_storedDataLength[nbid] = 0;
2644  }
2645  else
2646  {
2647  unsigned short dataLength = 0;
2648 
2649  if (OutputMode & OUTPUTMODE_MT9)
2650  {
2652  }
2653  else if (OutputMode == OUTPUTMODE_XM)
2654  {
2655  // XbusMaster concatenates sample counter
2656  dataLength = LEN_SAMPLECNT;
2657  }
2658  else
2659  {
2660  if (OutputMode & OUTPUTMODE_RAW)
2661  {
2662  dataLength = LEN_RAWDATA;
2663  }
2664  else
2665  {
2666  if (OutputMode & OUTPUTMODE_CALIB)
2667  {
2668  dataLength = LEN_CALIBDATA;
2669  }
2670 
2671  if (OutputMode & OUTPUTMODE_ORIENT)
2672  {
2673  switch (OutputSettings & OUTPUTSETTINGS_ORIENTMODE_MASK)
2674  {
2676  dataLength += LEN_ORIENT_QUATDATA;
2677  break;
2678 
2680  dataLength += LEN_ORIENT_EULERDATA;
2681  break;
2682 
2684  dataLength += LEN_ORIENT_MATRIXDATA;
2685  break;
2686 
2687  default:
2688  break;
2689  }
2690  }
2691  }
2692 
2693  switch (OutputSettings & OUTPUTSETTINGS_TIMESTAMP_MASK)
2694  {
2696  dataLength += LEN_SAMPLECNT;
2697  break;
2698 
2699  default:
2700  break;
2701  }
2702  }
2703 
2704  m_storedDataLength[nbid] = dataLength;
2705  }
2706 
2707  // If not XbusMaster store also in BID_MT
2708  if (bid == BID_MASTER && OutputMode != OUTPUTMODE_XM)
2709  {
2713  }
2714 
2715  return (m_retVal = MTRV_OK);
2716  }
2717 
2718  ////////////////////////////////////////////////////////////////////
2719  // getValue (unsigned short variant)
2720  //
2721  // Retrieves a unsigned short value from the data input parameter
2722  // This function is valid for the following value specifiers:
2723  // VALUE_RAW_TEMP
2724  // VALUE_SAMPLECNT
2725  //
2726  // Use getDeviceMode or setMode to initialize the Outputmode
2727  // and Outputsettings member variables used to retrieve the correct
2728  // value
2729  //
2730  // Input
2731  // valueSpec : Specifier of the value to be retrieved
2732  // data[] : Data field of a MTData / BusData message
2733  // bid : bus identifier of the device of which the
2734  // value should be returned (default = BID_MT)
2735  // Output
2736  // value : reference to unsigned short in which the retrieved
2737  // value will be returned
2738  //
2739  // Return value
2740  // MTRV_OK : value is successfully retrieved
2741  // != MTRV_OK : not successful
2742  //
2743  short CXsensMTiModule::getValue(const unsigned long valueSpec, unsigned short& value, const unsigned char data[], const unsigned char bid)
2744  {
2745  short offset = 0;
2746  unsigned char nbid = bid;
2747 
2748  if (nbid == BID_MASTER)
2749  {
2750  nbid = 0;
2751  }
2752 
2753  // Check for invalid mode/settings
2755  {
2757  }
2758 
2759  // Calculate offset for XM input
2761  {
2762  int i = 0;
2763 
2764  while (i < nbid)
2765  {
2766  offset += (short) m_storedDataLength[i++];
2767  }
2768  }
2769 
2770  // Check if data is unsigned short & available in data
2772 
2773  if (valueSpec == VALUE_RAW_TEMP)
2774  {
2776  {
2778  swapEndian(data + offset + valueSpec * LEN_UNSIGSHORT * 3, (unsigned char*) &value, LEN_RAW_TEMP);
2779  m_retVal = MTRV_OK;
2780  }
2781  }
2782  else if (valueSpec == VALUE_SAMPLECNT)
2783  {
2785  {
2786  if (!(m_storedOutputMode[nbid] == OUTPUTMODE_MT9))
2787  {
2788  offset += (short) m_storedDataLength[nbid] - LEN_SAMPLECNT;
2789  }
2790 
2791  swapEndian(data + offset, (unsigned char*) &value, LEN_SAMPLECNT);
2792  m_retVal = MTRV_OK;
2793  }
2794  }
2795 
2796  return m_retVal;
2797  }
2798 
2799  ////////////////////////////////////////////////////////////////////
2800  // getValue (array of unsigned short variant)
2801  //
2802  // Retrieves an array of unsigned short values from the data input
2803  // parameter. This function is valid for the following value specifiers:
2804  // VALUE_RAW_ACC
2805  // VALUE_RAW_GYR
2806  // VALUE_RAW_MAG
2807  //
2808  // Use getDeviceMode or setMode to initialize the Outputmode
2809  // and Outputsettings member variables used to retrieve the correct
2810  // value
2811  //
2812  // Input
2813  // valueSpec : Specifier of the value to be retrieved
2814  // data[] : Data field of a MTData / BusData message
2815  // bid : bus identifier of the device of which the
2816  // value should be returned (default = BID_MT)
2817  // Output
2818  // value[] : pointer to array of unsigned shorts in which the
2819  // retrieved values will be returned
2820  //
2821  // Return value
2822  // MTRV_OK : value is successfully retrieved
2823  // != MTRV_OK : not successful
2824  //
2825  short CXsensMTiModule::getValue(const unsigned long valueSpec, unsigned short value[], const unsigned char data[], const unsigned char bid)
2826  {
2827  short offset = 0;
2828  unsigned char nbid = bid;
2829 
2830  if (nbid == BID_MASTER)
2831  {
2832  nbid = 0;
2833  }
2834 
2835  // Check for invalid mode/settings
2837  {
2839  }
2840 
2841  // Calculate offset for XM input
2843  {
2844  int i = 0;
2845 
2846  while (i < nbid)
2847  {
2848  offset += (short) m_storedDataLength[i++];
2849  }
2850  }
2851 
2852  // Check if data is unsigned short, available in data & retrieve data
2854 
2855  //if (valueSpec >= VALUE_RAW_ACC && valueSpec <= VALUE_RAW_MAG)
2856  if (valueSpec <= VALUE_RAW_MAG)
2857  {
2859  {
2860  offset += (short)(valueSpec * LEN_UNSIGSHORT * 3);
2862 
2863  for (int i = 0 ; i < 3 ; i++)
2864  {
2865  swapEndian(data + offset + i * LEN_UNSIGSHORT, (unsigned char*) value + i * LEN_UNSIGSHORT, LEN_UNSIGSHORT);
2866  }
2867 
2868  m_retVal = MTRV_OK;
2869  }
2870  }
2871 
2872  return m_retVal;
2873  }
2874 
2875  ////////////////////////////////////////////////////////////////////
2876  // getValue (array of floats variant)
2877  //
2878  // Retrieves an array of float values from the data input parameter.
2879  // This function is valid for the following value specifiers:
2880  // VALUE_TEMP
2881  // VALUE_CALIB_ACC
2882  // VALUE_CALIB_GYR
2883  // VALUE_CALIB_MAG
2884  // VALUE_ORIENT_QUAT
2885  // VALUE_ORIENT_EULER
2886  // VALUE_ORIENT_MATRIX
2887  //
2888  // Use getDeviceMode or setMode to initialize the Outputmode
2889  // and Outputsettings member variables used to retrieve the correct
2890  // value
2891  //
2892  // Input
2893  // valueSpec : Specifier of the value to be retrieved
2894  // data[] : Data field of a MTData / BusData message
2895  // bid : bus identifier of the device of which the
2896  // value should be returned (default = BID_MT)
2897  // Output
2898  // value[] : pointer to array of floats in which the
2899  // retrieved values will be returned
2900  //
2901  // Return value
2902  // MTRV_OK : value is successfully retrieved
2903  // != MTRV_OK : not successful
2904  //
2905  short CXsensMTiModule::getValue(const unsigned long valueSpec, float value[], const unsigned char data[], const unsigned char bid)
2906  {
2907  short offset = 0;
2908  int nElements = 0;
2909  unsigned char nbid = bid;
2910 
2911  if (nbid == BID_MASTER)
2912  {
2913  nbid = 0;
2914  }
2915 
2916  // Check for invalid mode/settings
2918  {
2920  }
2921 
2922  // Calculate offset for XM input
2924  {
2925  int i = 0;
2926 
2927  while (i < nbid)
2928  {
2929  offset += (short) m_storedDataLength[i++];
2930  }
2931  }
2932 
2933  // Check if data is float & available in data
2935 
2936  if (valueSpec == VALUE_TEMP)
2937  {
2938  if (m_storedOutputMode[nbid] & OUTPUTMODE_TEMP)
2939  {
2940  nElements = LEN_TEMPDATA / LEN_FLOAT;
2941  m_retVal = MTRV_OK;
2942  }
2943  }
2944  else if (valueSpec == VALUE_CALIB_ACC)
2945  {
2946  offset += ((m_storedOutputMode[nbid] & OUTPUTMODE_TEMP) != 0) ? LEN_TEMPDATA : 0;
2947 
2949  {
2950  nElements = LEN_CALIB_ACCDATA / LEN_FLOAT;
2951  m_retVal = MTRV_OK;
2952  }
2953  }
2954  else if (valueSpec == VALUE_CALIB_GYR)
2955  {
2956  offset += ((m_storedOutputMode[nbid] & OUTPUTMODE_TEMP) != 0) ? LEN_TEMPDATA : 0;
2957 
2959  {
2960  offset += ((m_storedOutputSettings[nbid] & OUTPUTSETTINGS_CALIBMODE_ACC_MASK) == 0) ? LEN_CALIB_ACCX * 3 : 0;
2961  nElements = LEN_CALIB_GYRDATA / LEN_FLOAT;
2962  m_retVal = MTRV_OK;
2963  }
2964  }
2965  else if (valueSpec == VALUE_CALIB_MAG)
2966  {
2967  offset += ((m_storedOutputMode[nbid] & OUTPUTMODE_TEMP) != 0) ? LEN_TEMPDATA : 0;
2968 
2970  {
2971  offset += ((m_storedOutputSettings[nbid] & OUTPUTSETTINGS_CALIBMODE_ACC_MASK) == 0) ? LEN_CALIB_ACCX * 3 : 0;
2972  offset += ((m_storedOutputSettings[nbid] & OUTPUTSETTINGS_CALIBMODE_GYR_MASK) == 0) ? LEN_CALIB_GYRX * 3 : 0;
2973  nElements = LEN_CALIB_MAGDATA / LEN_FLOAT;
2974  m_retVal = MTRV_OK;
2975  }
2976  }
2977  else if (valueSpec >= VALUE_ORIENT_QUAT && valueSpec <= VALUE_ORIENT_MATRIX)
2978  {
2979  offset += ((m_storedOutputMode[nbid] & OUTPUTMODE_TEMP) != 0) ? LEN_TEMPDATA : 0;
2980 
2981  if ((m_storedOutputMode[nbid] & OUTPUTMODE_CALIB))
2982  {
2983  offset += ((m_storedOutputSettings[nbid] & OUTPUTSETTINGS_CALIBMODE_ACC_MASK) == 0) ? LEN_CALIB_ACCX * 3 : 0;
2984  offset += ((m_storedOutputSettings[nbid] & OUTPUTSETTINGS_CALIBMODE_GYR_MASK) == 0) ? LEN_CALIB_GYRX * 3 : 0;
2985  offset += ((m_storedOutputSettings[nbid] & OUTPUTSETTINGS_CALIBMODE_MAG_MASK) == 0) ? LEN_CALIB_MAGX * 3 : 0;
2986  }
2987 
2989  {
2990  unsigned long orientmode = m_storedOutputSettings[nbid] & OUTPUTSETTINGS_ORIENTMODE_MASK;
2991 
2992  switch (valueSpec)
2993  {
2994  case VALUE_ORIENT_QUAT:
2995  if (orientmode == OUTPUTSETTINGS_ORIENTMODE_QUATERNION)
2996  {
2997  nElements = LEN_ORIENT_QUATDATA / LEN_FLOAT;
2998  m_retVal = MTRV_OK;
2999  }
3000 
3001  break;
3002 
3003  case VALUE_ORIENT_EULER:
3004  if (orientmode == OUTPUTSETTINGS_ORIENTMODE_EULER)
3005  {
3006  nElements = LEN_ORIENT_EULERDATA / LEN_FLOAT;
3007  m_retVal = MTRV_OK;
3008  }
3009 
3010  break;
3011 
3012  case VALUE_ORIENT_MATRIX:
3013  if (orientmode == OUTPUTSETTINGS_ORIENTMODE_MATRIX)
3014  {
3015  nElements = LEN_ORIENT_MATRIXDATA / LEN_FLOAT;
3016  m_retVal = MTRV_OK;
3017  }
3018 
3019  break;
3020 
3021  default:
3022  break;
3023  }
3024  }
3025  }
3026 
3027  if (m_retVal == MTRV_OK)
3028  {
3030  {
3031  for (int i = 0 ; i < nElements ; i++)
3032  {
3033  swapEndian(data + offset + i * LEN_FLOAT, (unsigned char*) value + i * LEN_FLOAT, LEN_FLOAT);
3034  }
3035  }
3036  else
3037  {
3038  int temp;
3039 
3040  for (int i = 0 ; i < nElements ; i++)
3041  {
3042  swapEndian(data + offset + i * LEN_FLOAT, (unsigned char*) &temp, 4);
3043  value[i] = (float) temp / 1048576;
3044  }
3045  }
3046  }
3047 
3048  return m_retVal;
3049  }
3050 
3051  //////////////////////////////////////////////////////////////////////
3052  // getLastDeviceError
3053  //
3054  // Returns the last reported device error of the latest received Error
3055  // message
3056  //
3057  // Output
3058  // Error code
3060  {
3061  return m_deviceError;
3062  }
3063 
3064  //////////////////////////////////////////////////////////////////////
3065  // getLastRetVal
3066  //
3067  // Returns the returned value of the last called function
3068  //
3069  // Output
3070  // Return value
3072  {
3073  return m_retVal;
3074  }
3075 
3076  //////////////////////////////////////////////////////////////////////
3077  // setTimeOut
3078  //
3079  // Sets the time out value in milliseconds used by the functions
3080  // Use 0 for infinite timeout
3081  //
3082  // Output
3083  // MTRV_OK is set, MTRV_INVALIDTIMEOUT if time value < 0
3084  short CXsensMTiModule::setTimeOut(short timeOutMs)
3085  {
3086  if (timeOutMs >= 0)
3087  {
3088  m_timeOut = timeOutMs;
3089  return (m_retVal = MTRV_OK);
3090  }
3091  else
3092  {
3093  return (m_retVal = MTRV_INVALIDTIMEOUT);
3094  }
3095  }
3096 
3097  //////////////////////////////////////////////////////////////////////
3098  // swapEndian
3099  //
3100  // Convert 2 or 4 bytes data from little to big endian or back
3101  //
3102  // Input
3103  // input : Pointer to data to be converted
3104  // output : Pointer where converted data is stored
3105  // length : Length of setting (0,2 & 4)
3106  //
3107  // Remarks:
3108  // Allocate enough bytes for output buffer
3109 
3110  void CXsensMTiModule::swapEndian(const unsigned char input[], unsigned char output[], const int length)
3111  {
3112  switch (length)
3113  {
3114  case 4:
3115  output[0] = input[3];
3116  output[1] = input[2];
3117  output[2] = input[1];
3118  output[3] = input[0];
3119  break;
3120 
3121  case 2:
3122  output[0] = input[1];
3123  output[1] = input[0];
3124  break;
3125 
3126  case 1:
3127  output[0] = input[0];
3128  break;
3129 
3130  default:
3131  for (int i = 0, j = length - 1 ; i < length ; i++, j--)
3132  {
3133  output[j] = input[i];
3134  }
3135 
3136  break;
3137  }
3138  }
3139 
3140  //////////////////////////////////////////////////////////////////////
3141  // calcChecksum
3142  //
3143  // Calculate and append checksum to msgBuffer
3144  //
3145  void CXsensMTiModule::calcChecksum(unsigned char* msgBuffer, const int msgBufferLength)
3146  {
3147  unsigned char checkSum = 0;
3148  int i;
3149 
3150  for (i = 1; i < msgBufferLength ; i++)
3151  {
3152  checkSum += msgBuffer[i];
3153  }
3154 
3155  msgBuffer[msgBufferLength] = -checkSum; // Store chksum
3156  }
3157 
3158  //////////////////////////////////////////////////////////////////////
3159  // checkChecksum
3160  //
3161  // Checks if message checksum is valid
3162  //
3163  // Output
3164  // returns true checksum is OK
3165  bool CXsensMTiModule::checkChecksum(const unsigned char* msgBuffer, const int msgBufferLength)
3166  {
3167  unsigned char checkSum = 0;
3168  int i;
3169 
3170  for (i = 1; i < msgBufferLength ; i++)
3171  {
3172  checkSum += msgBuffer[i];
3173  }
3174 
3175  if (checkSum == 0)
3176  {
3177  return true;
3178  }
3179  else
3180  {
3181  return false;
3182  }
3183  }
3184 }
3185 
3186 #endif
MTRV_NOTSUCCESSFUL
#define MTRV_NOTSUCCESSFUL
Definition: XsensMTiModule.h:906
CONF_NUMDEVICESLEN
#define CONF_NUMDEVICESLEN
Definition: XsensMTiModule.h:709
IND_LENEXTH
#define IND_LENEXTH
Definition: XsensMTiModule.h:144
IMU::Xsens::CXsensMTiModule::m_clkEnd
clock_t m_clkEnd
Definition: XsensMTiModule.h:998
IND_PREAMBLE
#define IND_PREAMBLE
Definition: XsensMTiModule.h:139
VALUE_RAW_MAG
#define VALUE_RAW_MAG
Definition: XsensMTiModule.h:495
IMU::Xsens::CXsensMTiModule::readData
int readData(unsigned char *msgBuffer, const int nBytesToRead)
Definition: XsensMTiModule.cpp:568
MTRV_INVALIDFORFILEINPUT
#define MTRV_INVALIDFORFILEINPUT
Definition: XsensMTiModule.h:923
IMU::Xsens::CXsensMTiModule::m_portOpen
bool m_portOpen
Definition: XsensMTiModule.h:993
LEN_RAWDATA
#define LEN_RAWDATA
Definition: XsensMTiModule.h:346
OUTPUTMODE_MT9
#define OUTPUTMODE_MT9
Definition: XsensMTiModule.h:795
IMU::Xsens::CXsensMTiModule::checkChecksum
bool checkChecksum(const unsigned char *msgBuffer, const int msgBufferLength)
Definition: XsensMTiModule.cpp:3165
LEN_CALIB_MAGDATA
#define LEN_CALIB_MAGDATA
Definition: XsensMTiModule.h:350
LEN_CALIB_MAGX
#define LEN_CALIB_MAGX
Definition: XsensMTiModule.h:469
LEN_CALIB_ACCDATA
#define LEN_CALIB_ACCDATA
Definition: XsensMTiModule.h:348
BID_MT
#define BID_MT
Definition: XsensMTiModule.h:153
MID_SETOUTPUTMODE
#define MID_SETOUTPUTMODE
Definition: XsensMTiModule.h:243
LEN_CALIB_GYRDATA
#define LEN_CALIB_GYRDATA
Definition: XsensMTiModule.h:349
IMU::Xsens::CXsensMTiModule::readMessageRaw
short readMessageRaw(unsigned char *msgBuffer, short *msgBufferLength)
Definition: XsensMTiModule.cpp:970
PREAMBLE
#define PREAMBLE
Definition: XsensMTiModule.h:151
LEN_CALIB_ACCX
#define LEN_CALIB_ACCX
Definition: XsensMTiModule.h:463
OUTPUTSETTINGS_TIMESTAMP_SAMPLECNT
#define OUTPUTSETTINGS_TIMESTAMP_SAMPLECNT
Definition: XsensMTiModule.h:805
OUTPUTSETTINGS_ORIENTMODE_EULER
#define OUTPUTSETTINGS_ORIENTMODE_EULER
Definition: XsensMTiModule.h:807
IMU::Xsens::CXsensMTiModule::openPort
short openPort(const int portNumber, const unsigned long baudrate=PBR_115K2, const unsigned long inqueueSize=4096, const unsigned long outqueueSize=1024)
Definition: XsensMTiModule.cpp:197
MTRV_TIMEOUT
#define MTRV_TIMEOUT
Definition: XsensMTiModule.h:907
MTRV_NOINPUTINITIALIZED
#define MTRV_NOINPUTINITIALIZED
Definition: XsensMTiModule.h:919
IMU::Xsens::CXsensMTiModule::reqSetting
short reqSetting(const unsigned char mid, unsigned long &value, const unsigned char bid=BID_MASTER)
Definition: XsensMTiModule.cpp:1478
VALUE_ORIENT_EULER
#define VALUE_ORIENT_EULER
Definition: XsensMTiModule.h:501
XsensMTiModule.h
CONF_NUMDEVICES
#define CONF_NUMDEVICES
Definition: XsensMTiModule.h:690
IMU::Xsens::CXsensMTiModule::isFileOpen
bool isFileOpen()
Definition: XsensMTiModule.cpp:551
IND_LEN
#define IND_LEN
Definition: XsensMTiModule.h:142
OUTPUTMODE_RAW
#define OUTPUTMODE_RAW
Definition: XsensMTiModule.h:797
LEN_CALIB_GYRX
#define LEN_CALIB_GYRX
Definition: XsensMTiModule.h:466
OUTPUTSETTINGS_CALIBMODE_ACC_MASK
#define OUTPUTSETTINGS_CALIBMODE_ACC_MASK
Definition: XsensMTiModule.h:820
LEN_FLOAT
#define LEN_FLOAT
Definition: XsensMTiModule.h:163
IMU::Xsens::CXsensMTiModule::getMode
short getMode(unsigned long &OutputMode, unsigned long &OutputSettings, unsigned short &dataLength, const unsigned char bid=BID_MASTER)
Definition: XsensMTiModule.cpp:2606
OUTPUTSETTINGS_XM
#define OUTPUTSETTINGS_XM
Definition: XsensMTiModule.h:803
OUTPUTSETTINGS_ORIENTMODE_QUATERNION
#define OUTPUTSETTINGS_ORIENTMODE_QUATERNION
Definition: XsensMTiModule.h:806
MTRV_ENDOFFILE
#define MTRV_ENDOFFILE
Definition: XsensMTiModule.h:918
MTRV_TIMEOUTNODATA
#define MTRV_TIMEOUTNODATA
Definition: XsensMTiModule.h:908
MTRV_NOVALIDMODESPECIFIED
#define MTRV_NOVALIDMODESPECIFIED
Definition: XsensMTiModule.h:920
VALUE_ORIENT_QUAT
#define VALUE_ORIENT_QUAT
Definition: XsensMTiModule.h:500
IMU::Xsens::CXsensMTiModule::setFilePos
short setFilePos(long relPos, unsigned long moveMethod=FILEPOS_BEGIN)
Definition: XsensMTiModule.cpp:746
LEN_MSGEXTHEADER
#define LEN_MSGEXTHEADER
Definition: XsensMTiModule.h:157
OUTPUTSETTINGS_ORIENTMODE_MASK
#define OUTPUTSETTINGS_ORIENTMODE_MASK
Definition: XsensMTiModule.h:819
MTRV_INVALIDVALUESPEC
#define MTRV_INVALIDVALUESPEC
Definition: XsensMTiModule.h:922
IMU::Xsens::CXsensMTiModule::CXsensMTiModule
CXsensMTiModule()
Definition: XsensMTiModule.cpp:130
IMU::Xsens::CXsensMTiModule::setPortQueueSize
void setPortQueueSize(const unsigned long inqueueSize=4096, const unsigned long outqueueSize=1024)
Definition: XsensMTiModule.cpp:719
IMU::Xsens::CXsensMTiModule::m_fileOpen
bool m_fileOpen
Definition: XsensMTiModule.h:994
OUTPUTSETTINGS_CALIBMODE_GYR_MASK
#define OUTPUTSETTINGS_CALIBMODE_GYR_MASK
Definition: XsensMTiModule.h:821
IMU::Xsens::CXsensMTiModule::isPortOpen
bool isPortOpen()
Definition: XsensMTiModule.cpp:541
IMU::Xsens::CXsensMTiModule::m_storedDataLength
unsigned long m_storedDataLength[MAXDEVICES+1]
Definition: XsensMTiModule.h:1003
MID_MTDATA
#define MID_MTDATA
Definition: XsensMTiModule.h:337
CONF_OUTPUTMODE
#define CONF_OUTPUTMODE
Definition: XsensMTiModule.h:694
IMU::Xsens
Definition: Xsens.h:17
LEN_MSGHEADER
#define LEN_MSGHEADER
Definition: XsensMTiModule.h:156
IMU::Xsens::CXsensMTiModule::m_retVal
short m_retVal
Definition: XsensMTiModule.h:996
MTRV_INVALIDTIMEOUT
#define MTRV_INVALIDTIMEOUT
Definition: XsensMTiModule.h:914
IMU::Xsens::CXsensMTiModule::flush
void flush()
Definition: XsensMTiModule.cpp:682
LEN_OUTPUTMODE
#define LEN_OUTPUTMODE
Definition: XsensMTiModule.h:242
IMU::Xsens::CXsensMTiModule::getLastDeviceError
short getLastDeviceError()
Definition: XsensMTiModule.cpp:3059
OUTPUTSETTINGS_DATAFORMAT_F1220
#define OUTPUTSETTINGS_DATAFORMAT_F1220
Definition: XsensMTiModule.h:817
CONF_DATALENGTHLEN
#define CONF_DATALENGTHLEN
Definition: XsensMTiModule.h:712
MTRV_RECVERRORMSG
#define MTRV_RECVERRORMSG
Definition: XsensMTiModule.h:911
LEN_ORIENT_QUATDATA
#define LEN_ORIENT_QUATDATA
Definition: XsensMTiModule.h:351
MTRV_INPUTCANNOTBEOPENED
#define MTRV_INPUTCANNOTBEOPENED
Definition: XsensMTiModule.h:916
LEN_CALIBDATA
#define LEN_CALIBDATA
Definition: XsensMTiModule.h:347
armarx::armem::server::ltm::mongodb::util::store
void store(const mongocxx::database &db, const armem::wm::Memory &m)
Definition: operations.cpp:237
VALUE_TEMP
#define VALUE_TEMP
Definition: XsensMTiModule.h:504
IMU::Xsens::CXsensMTiModule::~CXsensMTiModule
virtual ~CXsensMTiModule()
Definition: XsensMTiModule.cpp:149
OUTPUTSETTINGS_CALIBMODE_MAG_MASK
#define OUTPUTSETTINGS_CALIBMODE_MAG_MASK
Definition: XsensMTiModule.h:822
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
IMU::Xsens::CXsensMTiModule::m_timeOut
short m_timeOut
Definition: XsensMTiModule.h:997
IND_LENEXTL
#define IND_LENEXTL
Definition: XsensMTiModule.h:145
MID_ERROR
#define MID_ERROR
Definition: XsensMTiModule.h:511
LEN_TEMPDATA
#define LEN_TEMPDATA
Definition: XsensMTiModule.h:355
OUTPUTMODE_TEMP
#define OUTPUTMODE_TEMP
Definition: XsensMTiModule.h:798
VALUE_ORIENT_MATRIX
#define VALUE_ORIENT_MATRIX
Definition: XsensMTiModule.h:502
MTRV_ANINPUTALREADYOPEN
#define MTRV_ANINPUTALREADYOPEN
Definition: XsensMTiModule.h:917
MAXDEVICES
#define MAXDEVICES
Definition: XsensMTiModule.h:149
MTRV_OK
#define MTRV_OK
Definition: XsensMTiModule.h:905
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
IMU::Xsens::CXsensMTiModule::m_storedOutputSettings
unsigned long m_storedOutputSettings[MAXDEVICES+1]
Definition: XsensMTiModule.h:1002
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
IND_DATA0
#define IND_DATA0
Definition: XsensMTiModule.h:143
IMU::Xsens::CXsensMTiModule::readDataMessage
short readDataMessage(unsigned char data[], short &dataLen)
Definition: XsensMTiModule.cpp:918
INVALID_SET_FILE_POINTER
#define INVALID_SET_FILE_POINTER
Definition: XsensMTiModule.h:135
IMU::Xsens::CXsensMTiModule::setDeviceMode
short setDeviceMode(unsigned long OutputMode, unsigned long OutputSettings, const unsigned char bid=BID_MASTER)
Definition: XsensMTiModule.cpp:2529
armarx::read
void read(auto &eigen, auto *table)
Definition: FTSensorCalibrationGuiWidgetController.cpp:462
VALUE_SAMPLECNT
#define VALUE_SAMPLECNT
Definition: XsensMTiModule.h:503
IMU::Xsens::CXsensMTiModule::setMode
short setMode(unsigned long OutputMode, unsigned long OutputSettings, const unsigned char bid=BID_MASTER)
Definition: XsensMTiModule.cpp:2629
MID_CONFIGURATION
#define MID_CONFIGURATION
Definition: XsensMTiModule.h:206
LEN_ORIENT_EULERDATA
#define LEN_ORIENT_EULERDATA
Definition: XsensMTiModule.h:352
BID_MASTER
#define BID_MASTER
Definition: XsensMTiModule.h:152
ECHO
#define ECHO
Definition: Scanner.cpp:633
MID_REQDATALENGTH
#define MID_REQDATALENGTH
Definition: XsensMTiModule.h:202
IMU::Xsens::CXsensMTiModule::setTimeOut
short setTimeOut(short timeOutMs)
Definition: XsensMTiModule.cpp:3084
OUTPUTMODE_CALIB
#define OUTPUTMODE_CALIB
Definition: XsensMTiModule.h:799
IMU::Xsens::CXsensMTiModule::getValue
short getValue(const unsigned long valueSpec, unsigned short &value, const unsigned char data[], const unsigned char bid=BID_MT)
Definition: XsensMTiModule.cpp:2743
IMU::Xsens::CXsensMTiModule::m_handle
int m_handle
Definition: XsensMTiModule.h:991
CONF_OUTPUTSETTINGSLEN
#define CONF_OUTPUTSETTINGSLEN
Definition: XsensMTiModule.h:714
LEN_MSGEXTHEADERCS
#define LEN_MSGEXTHEADERCS
Definition: XsensMTiModule.h:159
LEN_MSGHEADERCS
#define LEN_MSGHEADERCS
Definition: XsensMTiModule.h:158
INVALIDSETTINGVALUE
#define INVALIDSETTINGVALUE
Definition: XsensMTiModule.h:506
CONF_MASTERDID
#define CONF_MASTERDID
Definition: XsensMTiModule.h:682
LEN_SAMPLECNT
#define LEN_SAMPLECNT
Definition: XsensMTiModule.h:354
TO_DEFAULT
#define TO_DEFAULT
Definition: XsensMTiModule.h:862
IND_BID
#define IND_BID
Definition: XsensMTiModule.h:140
IMU::Xsens::CXsensMTiModule::clockms
clock_t clockms()
Definition: XsensMTiModule.cpp:165
IMU::Xsens::CXsensMTiModule::swapEndian
static void swapEndian(const unsigned char input[], unsigned char output[], const int length)
Definition: XsensMTiModule.cpp:3110
OUTPUTSETTINGS_ORIENTMODE_MATRIX
#define OUTPUTSETTINGS_ORIENTMODE_MATRIX
Definition: XsensMTiModule.h:808
IMU::Xsens::CXsensMTiModule::getLastRetVal
short getLastRetVal()
Definition: XsensMTiModule.cpp:3071
IMU::Xsens::CXsensMTiModule::readMessage
short readMessage(unsigned char &mid, unsigned char data[], short &dataLen, unsigned char *bid=NULL)
Definition: XsensMTiModule.cpp:869
IMU::Xsens::CXsensMTiModule::setSetting
short setSetting(const unsigned char mid, const unsigned long value, const unsigned short valuelen, const unsigned char bid=BID_MASTER)
Definition: XsensMTiModule.cpp:2047
VALUE_RAW_TEMP
#define VALUE_RAW_TEMP
Definition: XsensMTiModule.h:496
EXTLENCODE
#define EXTLENCODE
Definition: XsensMTiModule.h:154
VALUE_CALIB_MAG
#define VALUE_CALIB_MAG
Definition: XsensMTiModule.h:499
float
#define float
Definition: 16_Level.h:22
LEN_OUTPUTSETTINGS
#define LEN_OUTPUTSETTINGS
Definition: XsensMTiModule.h:248
IMU::Xsens::CXsensMTiModule::m_nTempBufferLen
int m_nTempBufferLen
Definition: XsensMTiModule.h:1007
VALUE_CALIB_GYR
#define VALUE_CALIB_GYR
Definition: XsensMTiModule.h:498
IMU::Xsens::CXsensMTiModule::close
short close()
Definition: XsensMTiModule.cpp:817
CONF_OUTPUTSETTINGS
#define CONF_OUTPUTSETTINGS
Definition: XsensMTiModule.h:695
IMU::Xsens::CXsensMTiModule::m_deviceError
short m_deviceError
Definition: XsensMTiModule.h:995
IMU::Xsens::CXsensMTiModule::m_storedOutputMode
unsigned long m_storedOutputMode[MAXDEVICES+1]
Definition: XsensMTiModule.h:1001
IMU::Xsens::CXsensMTiModule::escape
void escape(unsigned long function)
Definition: XsensMTiModule.cpp:706
IMU::Xsens::CXsensMTiModule::openFile
short openFile(const char *fileName, bool createAlways=false)
Definition: XsensMTiModule.cpp:490
LEN_CHECKSUM
#define LEN_CHECKSUM
Definition: XsensMTiModule.h:160
OUTPUTMODE_XM
#define OUTPUTMODE_XM
Definition: XsensMTiModule.h:796
IMU::Xsens::CXsensMTiModule::m_tempBuffer
unsigned char m_tempBuffer[MAXMSGLEN]
Definition: XsensMTiModule.h:1006
armarx::aron::write
requires data::isWriter< WriterT > void write(WriterT &aron_w, const Eigen::Matrix< EigenT, rows, cols, options > &input, typename WriterT::ReturnType &ret, const armarx::aron::Path &aron_p=armarx::aron::Path())
Definition: eigen.h:134
LEN_DEVICEID
#define LEN_DEVICEID
Definition: XsensMTiModule.h:185
OUTPUTMODE_ORIENT
#define OUTPUTMODE_ORIENT
Definition: XsensMTiModule.h:800
OUTPUTSETTINGS_TIMESTAMP_MASK
#define OUTPUTSETTINGS_TIMESTAMP_MASK
Definition: XsensMTiModule.h:818
LEN_RAW_TEMP
#define LEN_RAW_TEMP
Definition: XsensMTiModule.h:461
CONF_DID
#define CONF_DID
Definition: XsensMTiModule.h:692
IMU::Xsens::CXsensMTiModule::getDeviceMode
short getDeviceMode(unsigned short *numDevices=NULL)
Definition: XsensMTiModule.cpp:2394
MID_REQOUTPUTMODE
#define MID_REQOUTPUTMODE
Definition: XsensMTiModule.h:240
MID_REQOUTPUTSETTINGS
#define MID_REQOUTPUTSETTINGS
Definition: XsensMTiModule.h:246
IMU::Xsens::CXsensMTiModule::waitForMessage
short waitForMessage(const unsigned char mid, unsigned char data[]=NULL, short *dataLen=NULL, unsigned char *bid=NULL)
Definition: XsensMTiModule.cpp:1396
CONF_DATALENGTH
#define CONF_DATALENGTH
Definition: XsensMTiModule.h:693
CONF_OUTPUTMODELEN
#define CONF_OUTPUTMODELEN
Definition: XsensMTiModule.h:713
MAXMSGLEN
#define MAXMSGLEN
Definition: XsensMTiModule.h:168
IMU::Xsens::CXsensMTiModule::writeData
int writeData(const unsigned char *msgBuffer, const int nBytesToWrite)
Definition: XsensMTiModule.cpp:658
MID_SETOUTPUTSETTINGS
#define MID_SETOUTPUTSETTINGS
Definition: XsensMTiModule.h:249
IMU::Xsens::CXsensMTiModule::writeMessage
short writeMessage(const unsigned char mid, const unsigned long dataValue=0, const unsigned char dataValueLen=0, const unsigned char bid=BID_MASTER)
Definition: XsensMTiModule.cpp:1195
LEN_ORIENT_MATRIXDATA
#define LEN_ORIENT_MATRIXDATA
Definition: XsensMTiModule.h:353
VALUE_CALIB_ACC
#define VALUE_CALIB_ACC
Definition: XsensMTiModule.h:497
MTRV_UNEXPECTEDMSG
#define MTRV_UNEXPECTEDMSG
Definition: XsensMTiModule.h:915
IMU::Xsens::CXsensMTiModule::getFileSize
short getFileSize(unsigned long &fileSize)
Definition: XsensMTiModule.cpp:783
CONF_BLOCKLEN
#define CONF_BLOCKLEN
Definition: XsensMTiModule.h:696
LEN_UNSIGSHORT
#define LEN_UNSIGSHORT
Definition: XsensMTiModule.h:161
MID_INITBUS
#define MID_INITBUS
Definition: XsensMTiModule.h:186
IND_DATAEXT0
#define IND_DATAEXT0
Definition: XsensMTiModule.h:146
MID_REQDID
#define MID_REQDID
Definition: XsensMTiModule.h:183
IMU::Xsens::CXsensMTiModule::calcChecksum
void calcChecksum(unsigned char *msgBuffer, const int msgBufferLength)
Definition: XsensMTiModule.cpp:3145
IND_MID
#define IND_MID
Definition: XsensMTiModule.h:141