XsensMTiModule.h
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.h: interface for 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 XBRV_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 XBRV_
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 Example.
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 #if !defined(AFX_XBUS_H__F4580A3F_2CF2_4ED2_A747_B4B015A0328E__INCLUDED_)
107 #define AFX_XBUS_H__F4580A3F_2CF2_4ED2_A747_B4B015A0328E__INCLUDED_
108 
109 #if _MSC_VER > 1000
110 #pragma once
111 #endif // _MSC_VER > 1000
112 
113 #include <string.h>
114 #include <stdio.h>
115 #ifdef WIN32
116 #include <windows.h>
117 #include <conio.h>
118 #include <time.h>
119 #else
120 #include <fcntl.h> /* POSIX Standard: 6.5 File Control Operations */
121 #include <termios.h> /* terminal i/o system, talks to /dev/tty* ports */
122 #include <unistd.h> /* Read function */
123 #include <sys/time.h> /* gettimeofday function */
124 #include <sys/stat.h> /* stat calls and structures*/
125 #endif
126 
127 #include "../Includes.h"
128 
129 #ifdef _IMU_USE_XSENS_DEVICE_
130 
131 namespace IMU::Xsens
132 {
133 
134 #ifndef INVALID_SET_FILE_POINTER
135 #define INVALID_SET_FILE_POINTER ((DWORD)(-1))
136 #endif
137 
138  // Field message indexes
139 #define IND_PREAMBLE 0
140 #define IND_BID 1
141 #define IND_MID 2
142 #define IND_LEN 3
143 #define IND_DATA0 4
144 #define IND_LENEXTH 4
145 #define IND_LENEXTL 5
146 #define IND_DATAEXT0 6
147 
148  // Maximum number of sensors supported
149 #define MAXDEVICES 20
150 
151 #define PREAMBLE (unsigned char)0xFA
152 #define BID_MASTER (unsigned char)0xFF
153 #define BID_MT (unsigned char)0x01
154 #define EXTLENCODE 0xFF
155 
156 #define LEN_MSGHEADER (unsigned short)4
157 #define LEN_MSGEXTHEADER (unsigned short)6
158 #define LEN_MSGHEADERCS (unsigned short)5
159 #define LEN_MSGEXTHEADERCS (unsigned short)7
160 #define LEN_CHECKSUM (unsigned short)1
161 #define LEN_UNSIGSHORT (unsigned short)2
162 #define LEN_UNSIGINT (unsigned short)4
163 #define LEN_FLOAT (unsigned short)4
164 
165  // Maximum message/data length
166 #define MAXDATALEN (unsigned short)2048
167 #define MAXSHORTDATALEN (unsigned short)254
168 #define MAXMSGLEN (unsigned short)(MAXDATALEN+7)
169 #define MAXSHORTMSGLEN (unsigned short)(MAXSHORTDATALEN+5)
170 
171  // DID Type (high nibble)
172 #define DID_TYPEH_MASK (unsigned long)0x00F00000
173 #define DID_TYPEH_MT (unsigned long)0x00000000
174 #define DID_TYPEH_XM (unsigned long)0x00100000
175 #define DID_TYPEH_MTI_MTX (unsigned long)0x00300000
176 
177  // All Message identifiers
178  // WakeUp state messages
179 #define MID_WAKEUP (unsigned char)0x3E
180 #define MID_WAKEUPACK (unsigned char)0x3F
181 
182  // Config state messages
183 #define MID_REQDID (unsigned char)0x00
184 #define MID_DEVICEID (unsigned char)0x01
185 #define LEN_DEVICEID (unsigned short)4
186 #define MID_INITBUS (unsigned char)0x02
187 #define MID_INITBUSRESULTS (unsigned char)0x03
188 #define LEN_INITBUSRESULTS (unsigned short)4
189 #define MID_REQPERIOD (unsigned char)0x04
190 #define MID_REQPERIODACK (unsigned char)0x05
191 #define LEN_PERIOD (unsigned short)2
192 #define MID_SETPERIOD (unsigned char)0x04
193 #define MID_SETPERIODACK (unsigned char)0x05
194  // XbusMaster
195 #define MID_SETBID (unsigned char)0x06
196 #define MID_SETBIDACK (unsigned char)0x07
197 #define MID_AUTOSTART (unsigned char)0x06
198 #define MID_AUTOSTARTACK (unsigned char)0x07
199 #define MID_BUSPWROFF (unsigned char)0x08
200 #define MID_BUSPWROFFACK (unsigned char)0x09
201  // End XbusMaster
202 #define MID_REQDATALENGTH (unsigned char)0x0A
203 #define MID_DATALENGTH (unsigned char)0x0B
204 #define LEN_DATALENGTH (unsigned short)2
205 #define MID_REQCONFIGURATION (unsigned char)0x0C
206 #define MID_CONFIGURATION (unsigned char)0x0D
207 #define LEN_CONFIGURATION (unsigned short)118
208 #define MID_RESTOREFACTORYDEF (unsigned char)0x0E
209 #define MID_RESTOREFACTORYDEFACK (unsigned char)0x0F
210 
211 #define MID_GOTOMEASUREMENT (unsigned char)0x10
212 #define MID_GOTOMEASUREMENTACK (unsigned char)0x11
213 #define MID_REQFWREV (unsigned char)0x12
214 #define MID_FIRMWAREREV (unsigned char)0x13
215 #define LEN_FIRMWAREREV (unsigned short)3
216  // XbusMaster
217 #define MID_REQBTDISABLE (unsigned char)0x14
218 #define MID_REQBTDISABLEACK (unsigned char)0x15
219 #define MID_DISABLEBT (unsigned char)0x14
220 #define MID_DISABLEBTACK (unsigned char)0x15
221 #define MID_REQOPMODE (unsigned char)0x16
222 #define MID_REQOPMODEACK (unsigned char)0x17
223 #define MID_SETOPMODE (unsigned char)0x16
224 #define MID_SETOPMODEACK (unsigned char)0x17
225  // End XbusMaster
226 #define MID_REQBAUDRATE (unsigned char)0x18
227 #define MID_REQBAUDRATEACK (unsigned char)0x19
228 #define LEN_BAUDRATE (unsigned short)1
229 #define MID_SETBAUDRATE (unsigned char)0x18
230 #define MID_SETBAUDRATEACK (unsigned char)0x19
231  // XbusMaster
232 #define MID_REQSYNCMODE (unsigned char)0x1A
233 #define MID_REQSYNCMODEACK (unsigned char)0x1B
234 #define MID_SETSYNCMODE (unsigned char)0x1A
235 #define MID_SETSYNCMODEACK (unsigned char)0x1B
236  // End XbusMaster
237 #define MID_REQPRODUCTCODE (unsigned char)0x1C
238 #define MID_PRODUCTCODE (unsigned char)0x1D
239 
240 #define MID_REQOUTPUTMODE (unsigned char)0xD0
241 #define MID_REQOUTPUTMODEACK (unsigned char)0xD1
242 #define LEN_OUTPUTMODE (unsigned short)2
243 #define MID_SETOUTPUTMODE (unsigned char)0xD0
244 #define MID_SETOUTPUTMODEACK (unsigned char)0xD1
245 
246 #define MID_REQOUTPUTSETTINGS (unsigned char)0xD2
247 #define MID_REQOUTPUTSETTINGSACK (unsigned char)0xD3
248 #define LEN_OUTPUTSETTINGS (unsigned short)4
249 #define MID_SETOUTPUTSETTINGS (unsigned char)0xD2
250 #define MID_SETOUTPUTSETTINGSACK (unsigned char)0xD3
251 
252 #define MID_REQOUTPUTSKIPFACTOR (unsigned char)0xD4
253 #define MID_REQOUTPUTSKIPFACTORACK (unsigned char)0xD5
254 #define LEN_OUTPUTSKIPFACTOR (unsigned short)2
255 #define MID_SETOUTPUTSKIPFACTOR (unsigned char)0xD4
256 #define MID_SETOUTPUTSKIPFACTORACK (unsigned char)0xD5
257 
258 #define MID_REQSYNCINSETTINGS (unsigned char)0xD6
259 #define MID_REQSYNCINSETTINGSACK (unsigned char)0xD7
260 #define LEN_SYNCINMODE (unsigned short)2
261 #define LEN_SYNCINSKIPFACTOR (unsigned short)2
262 #define LEN_SYNCINOFFSET (unsigned short)4
263 #define MID_SETSYNCINSETTINGS (unsigned char)0xD6
264 #define MID_SETSYNCINSETTINGSACK (unsigned char)0xD7
265 
266 #define MID_REQSYNCOUTSETTINGS (unsigned char)0xD8
267 #define MID_REQSYNCOUTSETTINGSACK (unsigned char)0xD9
268 #define LEN_SYNCOUTMODE (unsigned short)2
269 #define LEN_SYNCOUTSKIPFACTOR (unsigned short)2
270 #define LEN_SYNCOUTOFFSET (unsigned short)4
271 #define LEN_SYNCOUTPULSEWIDTH (unsigned short)4
272 #define MID_SETSYNCOUTSETTINGS (unsigned char)0xD8
273 #define MID_SETSYNCOUTSETTINGSACK (unsigned char)0xD9
274 
275 #define MID_REQERRORMODE (unsigned char)0xDA
276 #define MID_REQERRORMODEACK (unsigned char)0xDB
277 #define LEN_ERRORMODE (unsigned short)2
278 #define MID_SETERRORMODE (unsigned char)0xDA
279 #define MID_SETERRORMODEACK (unsigned char)0xDB
280 
281 #define MID_REQTRANSMITDELAY (unsigned char)0xDC
282 #define MID_REQTRANSMITDELAYACK (unsigned char)0xDD
283 #define LEN_TRANSMITDELAY (unsigned short)2
284 #define MID_SETTRANSMITDELAY (unsigned char)0xDC
285 #define MID_SETTRANSMITDELAYACK (unsigned char)0xDD
286 
287  // Xbus Master
288 #define MID_REQXMERRORMODE (unsigned char)0x82
289 #define MID_REQXMERRORMODEACK (unsigned char)0x83
290 #define LEN_XMERRORMODE (unsigned short)2
291 #define MID_SETXMERRORMODE (unsigned char)0x82
292 #define MID_SETXMERRORMODEACK (unsigned char)0x83
293 
294 #define MID_REQBUFFERSIZE (unsigned char)0x84
295 #define MID_REQBUFFERSIZEACK (unsigned char)0x85
296 #define LEN_BUFFERSIZE (unsigned short)2
297 #define MID_SETBUFFERSIZE (unsigned char)0x84
298 #define MID_SETBUFFERSIZEACK (unsigned char)0x85
299  // End Xbus Master
300 
301 #define MID_REQHEADING (unsigned char)0x82
302 #define MID_REQHEADINGACK (unsigned char)0x83
303 #define LEN_HEADING (unsigned short)4
304 #define MID_SETHEADING (unsigned char)0x82
305 #define MID_SETHEADINGACK (unsigned char)0x83
306 
307 #define MID_REQLOCATIONID (unsigned char)0x84
308 #define MID_REQLOCATIONIDACK (unsigned char)0x85
309 #define LEN_LOCATIONID (unsigned short)2
310 #define MID_SETLOCATIONID (unsigned char)0x84
311 #define MID_SETLOCATIONIDACK (unsigned char)0x85
312 
313 #define MID_REQEXTOUTPUTMODE (unsigned char)0x86
314 #define MID_REQEXTOUTPUTMODEACK (unsigned char)0x87
315 #define LEN_EXTOUTPUTMODE (unsigned short)2
316 #define MID_SETEXTOUTPUTMODE (unsigned char)0x86
317 #define MID_SETEXTOUTPUTMODEACK (unsigned char)0x87
318 
319  // XbusMaster
320 #define MID_REQBATLEVEL (unsigned char)0x88
321 #define MID_BATLEVEL (unsigned char)0x89
322  // End XbusMaster
323 
324 #define MID_REQINITTRACKMODE (unsigned char)0x88
325 #define MID_REQINITTRACKMODEACK (unsigned char)0x89
326 #define LEN_INITTRACKMODE (unsigned short)2
327 #define MID_SETINITTRACKMODE (unsigned char)0x88
328 #define MID_SETINITTRACKMODEACK (unsigned char)0x89
329 
330 #define MID_STOREFILTERSTATE (unsigned char)0x8A
331 #define MID_STOREFILTERSTATEACK (unsigned char)0x8B
332 
333  // Measurement state
334 #define MID_GOTOCONFIG (unsigned char)0x30
335 #define MID_GOTOCONFIGACK (unsigned char)0x31
336 #define MID_BUSDATA (unsigned char)0x32
337 #define MID_MTDATA (unsigned char)0x32
338 
339  // Manual
340 #define MID_PREPAREDATA (unsigned char)0x32
341 #define MID_REQDATA (unsigned char)0x34
342 #define MID_REQDATAACK (unsigned char)0x35
343 
344  // MTData defines
345  // Length of data blocks in bytes
346 #define LEN_RAWDATA (unsigned short)20
347 #define LEN_CALIBDATA (unsigned short)36
348 #define LEN_CALIB_ACCDATA (unsigned short)12
349 #define LEN_CALIB_GYRDATA (unsigned short)12
350 #define LEN_CALIB_MAGDATA (unsigned short)12
351 #define LEN_ORIENT_QUATDATA (unsigned short)16
352 #define LEN_ORIENT_EULERDATA (unsigned short)12
353 #define LEN_ORIENT_MATRIXDATA (unsigned short)36
354 #define LEN_SAMPLECNT (unsigned short)2
355 #define LEN_TEMPDATA (unsigned short)4
356 
357  // Length of data blocks in floats
358 #define LEN_CALIBDATA_FLT (unsigned short)9
359 #define LEN_ORIENT_QUATDATA_FLT (unsigned short)4
360 #define LEN_ORIENT_EULERDATA_FLT (unsigned short)3
361 #define LEN_ORIENT_MATRIXDATA_FLT (unsigned short)9
362 
363  // Indices of fields in DATA field of MTData message in bytes
364  // use in combination with LEN_CALIB etc
365  // Un-calibrated raw data
366 #define IND_RAW_ACCX 0
367 #define IND_RAW_ACCY 2
368 #define IND_RAW_ACCZ 4
369 #define IND_RAW_GYRX 6
370 #define IND_RAW_GYRY 8
371 #define IND_RAW_GYRZ 10
372 #define IND_RAW_MAGX 12
373 #define IND_RAW_MAGY 14
374 #define IND_RAW_MAGZ 16
375 #define IND_RAW_TEMP 18
376  // Calibrated data
377 #define IND_CALIB_ACCX 0
378 #define IND_CALIB_ACCY 4
379 #define IND_CALIB_ACCZ 8
380 #define IND_CALIB_GYRX 12
381 #define IND_CALIB_GYRY 16
382 #define IND_CALIB_GYRZ 20
383 #define IND_CALIB_MAGX 24
384 #define IND_CALIB_MAGY 28
385 #define IND_CALIB_MAGZ 32
386  // Orientation data - quat
387 #define IND_ORIENT_Q0 0
388 #define IND_ORIENT_Q1 4
389 #define IND_ORIENT_Q2 8
390 #define IND_ORIENT_Q3 12
391  // Orientation data - euler
392 #define IND_ORIENT_ROLL 0
393 #define IND_ORIENT_PITCH 4
394 #define IND_ORIENT_YAW 8
395  // Orientation data - matrix
396 #define IND_ORIENT_A 0
397 #define IND_ORIENT_B 4
398 #define IND_ORIENT_C 8
399 #define IND_ORIENT_D 12
400 #define IND_ORIENT_E 16
401 #define IND_ORIENT_F 20
402 #define IND_ORIENT_G 24
403 #define IND_ORIENT_H 28
404 #define IND_ORIENT_I 32
405  // Orientation data - euler
406 #define IND_SAMPLECNTH 0
407 #define IND_SAMPLECNTL 1
408 
409  // Indices of fields in DATA field of MTData message
410  // Un-calibrated raw data
411 #define FLDNUM_RAW_ACCX 0
412 #define FLDNUM_RAW_ACCY 1
413 #define FLDNUM_RAW_ACCZ 2
414 #define FLDNUM_RAW_GYRX 3
415 #define FLDNUM_RAW_GYRY 4
416 #define FLDNUM_RAW_GYRZ 5
417 #define FLDNUM_RAW_MAGX 6
418 #define FLDNUM_RAW_MAGY 7
419 #define FLDNUM_RAW_MAGZ 8
420 #define FLDNUM_RAW_TEMP 9
421  // Calibrated data
422 #define FLDNUM_CALIB_ACCX 0
423 #define FLDNUM_CALIB_ACCY 1
424 #define FLDNUM_CALIB_ACCZ 2
425 #define FLDNUM_CALIB_GYRX 3
426 #define FLDNUM_CALIB_GYRY 4
427 #define FLDNUM_CALIB_GYRZ 5
428 #define FLDNUM_CALIB_MAGX 6
429 #define FLDNUM_CALIB_MAGY 7
430 #define FLDNUM_CALIB_MAGZ 8
431  // Orientation data - quat
432 #define FLDNUM_ORIENT_Q0 0
433 #define FLDNUM_ORIENT_Q1 1
434 #define FLDNUM_ORIENT_Q2 2
435 #define FLDNUM_ORIENT_Q3 3
436  // Orientation data - euler
437 #define FLDNUM_ORIENT_ROLL 0
438 #define FLDNUM_ORIENT_PITCH 1
439 #define FLDNUM_ORIENT_YAW 2
440  // Orientation data - matrix
441 #define FLDNUM_ORIENT_A 0
442 #define FLDNUM_ORIENT_B 1
443 #define FLDNUM_ORIENT_C 2
444 #define FLDNUM_ORIENT_D 3
445 #define FLDNUM_ORIENT_E 4
446 #define FLDNUM_ORIENT_F 5
447 #define FLDNUM_ORIENT_G 6
448 #define FLDNUM_ORIENT_H 7
449 #define FLDNUM_ORIENT_I 8
450  // Length
451  // Uncalibrated raw data
452 #define LEN_RAW_ACCX 2
453 #define LEN_RAW_ACCY 2
454 #define LEN_RAW_ACCZ 2
455 #define LEN_RAW_GYRX 2
456 #define LEN_RAW_GYRY 2
457 #define LEN_RAW_GYRZ 2
458 #define LEN_RAW_MAGX 2
459 #define LEN_RAW_MAGY 2
460 #define LEN_RAW_MAGZ 2
461 #define LEN_RAW_TEMP 2
462  // Calibrated data
463 #define LEN_CALIB_ACCX 4
464 #define LEN_CALIB_ACCY 4
465 #define LEN_CALIB_ACCZ 4
466 #define LEN_CALIB_GYRX 4
467 #define LEN_CALIB_GYRY 4
468 #define LEN_CALIB_GYRZ 4
469 #define LEN_CALIB_MAGX 4
470 #define LEN_CALIB_MAGY 4
471 #define LEN_CALIB_MAGZ 4
472  // Orientation data - quat
473 #define LEN_ORIENT_Q0 4
474 #define LEN_ORIENT_Q1 4
475 #define LEN_ORIENT_Q2 4
476 #define LEN_ORIENT_Q3 4
477  // Orientation data - euler
478 #define LEN_ORIENT_ROLL 4
479 #define LEN_ORIENT_PITCH 4
480 #define LEN_ORIENT_YAW 4
481  // Orientation data - matrix
482 #define LEN_ORIENT_A 4
483 #define LEN_ORIENT_B 4
484 #define LEN_ORIENT_C 4
485 #define LEN_ORIENT_D 4
486 #define LEN_ORIENT_E 4
487 #define LEN_ORIENT_F 4
488 #define LEN_ORIENT_G 4
489 #define LEN_ORIENT_H 4
490 #define LEN_ORIENT_I 4
491 
492  // Defines for getDataValue
493 #define VALUE_RAW_ACC 0
494 #define VALUE_RAW_GYR 1
495 #define VALUE_RAW_MAG 2
496 #define VALUE_RAW_TEMP 3
497 #define VALUE_CALIB_ACC 4
498 #define VALUE_CALIB_GYR 5
499 #define VALUE_CALIB_MAG 6
500 #define VALUE_ORIENT_QUAT 7
501 #define VALUE_ORIENT_EULER 8
502 #define VALUE_ORIENT_MATRIX 9
503 #define VALUE_SAMPLECNT 10
504 #define VALUE_TEMP 11
505 
506 #define INVALIDSETTINGVALUE 0xFFFFFFFF
507 
508  // Valid in all states
509 #define MID_RESET (unsigned char)0x40
510 #define MID_RESETACK (unsigned char)0x41
511 #define MID_ERROR (unsigned char)0x42
512 #define LEN_ERROR (unsigned short)1
513  // XbusMaster
514 #define MID_XMPWROFF (unsigned char)0x44
515  // End XbusMaster
516 
517 #define MID_REQFILTERSETTINGS (unsigned char)0xA0
518 #define MID_REQFILTERSETTINGSACK (unsigned char)0xA1
519 #define LEN_FILTERSETTINGS (unsigned short)4
520 #define MID_SETFILTERSETTINGS (unsigned char)0xA0
521 #define MID_SETFILTERSETTINGSACK (unsigned char)0xA1
522 #define MID_REQAMD (unsigned char)0xA2
523 #define MID_REQAMDACK (unsigned char)0xA3
524 #define LEN_AMD (unsigned short)2
525 #define MID_SETAMD (unsigned char)0xA2
526 #define MID_SETAMDACK (unsigned char)0xA3
527 #define MID_RESETORIENTATION (unsigned char)0xA4
528 #define MID_RESETORIENTATIONACK (unsigned char)0xA5
529 #define LEN_RESETORIENTATION (unsigned short)2
530 
531  // All Messages
532  // WakeUp state messages
533 #define MSG_WAKEUPLEN 5
534 #define MSG_WAKEUPACK (const unsigned char *)"\xFA\xFF\x3F\x00"
535 #define MSG_WAKEUPACKLEN 4
536  // Config state messages
537 #define MSG_REQDID (const unsigned char *)"\xFA\xFF\x00\x00"
538 #define MSG_REQDIDLEN 4
539 #define MSG_DEVICEIDLEN 9
540 #define MSG_INITBUS (const unsigned char *)"\xFA\xFF\x02\x00"
541 #define MSG_INITBUSLEN 4
542 #define MSG_INITBUSRESMAXLEN (5 + 4 * MAXSENSORS)
543 #define MSG_REQPERIOD (const unsigned char *)"\xFA\xFF\x04\x00"
544 #define MSG_REQPERIODLEN 4
545 #define MSG_REQPERIODACKLEN 7
546 #define MSG_SETPERIOD (const unsigned char *)"\xFA\xFF\x04\x02"
547 #define MSG_SETPERIODLEN 6
548 #define MSG_SETPERIODACKLEN 5
549 #define MSG_SETBID (const unsigned char *)"\xFA\xFF\x06\x05"
550 #define MSG_SETBIDLEN 9
551 #define MSG_SETBIDACKLEN 5
552 #define MSG_AUTOSTART (const unsigned char *)"\xFA\xFF\x06\x00"
553 #define MSG_AUTOSTARTLEN 4
554 #define MSG_AUTOSTARTACKLEN 5
555 #define MSG_BUSPWROFF (const unsigned char *)"\xFA\xFF\x08\x00"
556 #define MSG_BUSPWROFFLEN 4
557 #define MSG_BUSPWROFFACKLEN 5
558 #define MSG_RESTOREFACTORYDEF (const unsigned char *)"\xFA\xFF\x0E\x00"
559 #define MSG_RESTOREFACTORYDEFLEN 4
560 #define MSG_RESTOREFACTORYDEFACKLEN 5
561 #define MSG_REQDATALENGTH (const unsigned char *)"\xFA\xFF\x0A\x00"
562 #define MSG_REQDATALENGTHLEN 4
563 #define MSG_DATALENGTHLEN 7
564 #define MSG_REQCONFIGURATION (const unsigned char *)"\xFA\xFF\x0C\x00"
565 #define MSG_REQCONFIGURATIONLEN 4
566 #define MSG_GOTOMEASUREMENT (const unsigned char *)"\xFA\xFF\x10\x00"
567 #define MSG_GOTOMEASUREMENTLEN 4
568 #define MSG_GOTOMEASMAN (const unsigned char *)"\xFA\x01\x10\x00"
569 #define MSG_GOTOMEASMANLEN 4
570 #define MSG_GOTOMEASACKLEN 5
571 #define MSG_REQFWREV (const unsigned char *)"\xFA\xFF\x12\x00"
572 #define MSG_REQFWREVLEN 4
573 #define MSG_FIRMWAREREVLEN 8
574 #define MSG_REQBTDISABLED (const unsigned char *)"\xFA\xFF\x14\x00"
575 #define MSG_REQBTDISABLEDLEN 4
576 #define MSG_REQBTDISABLEDACKLEN 6
577 #define MSG_DISABLEBT (const unsigned char *)"\xFA\xFF\x14\x01"
578 #define MSG_DISABLEBTLEN 5
579 #define MSG_DISABLEBTACKLEN 5
580 #define MSG_REQOPMODE (const unsigned char *)"\xFA\xFF\x16\x00"
581 #define MSG_REQOPMODELEN 4
582 #define MSG_REQOPMODEACKLEN 6
583 #define MSG_SETOPMODE (const unsigned char *)"\xFA\xFF\x16\x01"
584 #define MSG_SETOPMODELEN 5
585 #define MSG_SETOPMODEACKLEN 5
586 #define MSG_REQBAUDRATE (const unsigned char *)"\xFA\xFF\x18\x00"
587 #define MSG_REQBAUDRATELEN 4
588 #define MSG_REQBAUDRATEACKLEN 6
589 #define MSG_SETBAUDRATE (const unsigned char *)"\xFA\xFF\x18\x01"
590 #define MSG_SETBAUDRATELEN 5
591 #define MSG_SETBAUDRATEACKLEN 5
592 #define MSG_REQSYNCMODE (const unsigned char *)"\xFA\xFF\x1A\x00"
593 #define MSG_REQSYNCMODELEN 4
594 #define MSG_REQSYNCMODEACKLEN 6
595 #define MSG_SETSYNCMODE (const unsigned char *)"\xFA\xFF\x1A\x01"
596 #define MSG_SETSYNCMODELEN 5
597 #define MSG_SETSYNCMODEACKLEN 6
598 #define MSG_REQMTS (const unsigned char *)"\xFA\xFF\x90\x01"
599 #define MSG_REQMTSLEN 5
600 #define MSG_MTSDATA 61
601 #define MSG_STORECUSMTS (const unsigned char *)"\xFA\xFF\x92\x58"
602 #define MSG_STORECUSMTSLEN 92
603 #define MSG_STORECUSMTSACKLEN 5
604 #define MSG_REVTOORGMTS (const unsigned char *)"\xFA\xFF\x94\x00"
605 #define MSG_REVTOORGMTSLEN 4
606 #define MSG_REVTOORGMTSACKLEN 5
607 #define MSG_STOREMTS (const unsigned char *)"\xFA\xFF\x96\x41"
608 #define MSG_STOREMTSLEN 69
609 #define MSG_STOREMTSACKLEN 5
610 #define MSG_REQSYNCOUTMODE (const unsigned char *)"\xFA\xFF\xD8\x01\x00"
611 #define MSG_REQSYNCOUTMODELEN 5
612 #define MSG_REQSYNCOUTSKIPFACTOR (const unsigned char *)"\xFA\xFF\xD8\x01\x01"
613 #define MSG_REQSYNCOUTSKIPFACTORLEN 5
614 #define MSG_REQSYNCOUTOFFSET (const unsigned char *)"\xFA\xFF\xD8\x01\x02"
615 #define MSG_REQSYNCOUTOFFSETLEN 5
616 #define MSG_REQSYNCOUTPULSEWIDTH (const unsigned char *)"\xFA\xFF\xD8\x01\x03"
617 #define MSG_REQSYNCOUTPULSEWIDTHLEN 5
618 #define MSG_REQERRORMODE (const unsigned char *)"\xFA\xFF\xDA\x00"
619 #define MSG_REQERRORMODELEN 4
620 #define MSG_REQERRORMODEACKLEN 7
621  // Measurement state - auto messages
622 #define MSG_GOTOCONFIG (const unsigned char *)"\xFA\xFF\x30\x00"
623 #define MSG_GOTOCONFIGLEN 4
624 #define MSG_GOTOCONFIGACKLEN 5
625  // Measurement state - manual messages (Use DID = 0x01)
626 #define MSG_GOTOCONFIGM (const unsigned char *)"\xFA\x01\x30\x00"
627 #define MSG_GOTOCONFIGMLEN 4
628 #define MSG_GOTOCONFIGMACKLEN 5
629 #define MSG_PREPAREDATA (const unsigned char *)"\xFA\x01\x32\x00"
630 #define MSG_PREPAREDATALEN 4
631 #define MSG_REQDATA (const unsigned char *)"\xFA\x01\x34\x00"
632 #define MSG_REQDATALEN 4
633  // Valid in all states
634 #define MSG_RESET (const unsigned char *)"\xFA\xFF\x40\x00"
635 #define MSG_RESETLEN 4
636 #define MSG_RESETACKLEN 5
637 #define MSG_XMPWROFF (const unsigned char *)"\xFA\xFF\x44\x00"
638 #define MSG_XMPWROFFLEN 4
639 #define MSG_XMPWROFFACKLEN 5
640 
641  // Baudrate defines for SetBaudrate message
642 #define BAUDRATE_9K6 0x09
643 #define BAUDRATE_14K4 0x08
644 #define BAUDRATE_19K2 0x07
645 #define BAUDRATE_28K8 0x06
646 #define BAUDRATE_38K4 0x05
647 #define BAUDRATE_57K6 0x04
648 #define BAUDRATE_76K8 0x03
649 #define BAUDRATE_115K2 0x02
650 #define BAUDRATE_230K4 0x01
651 #define BAUDRATE_460K8 0x00
652 #define BAUDRATE_921K6 0x80
653 
654  // Xbus protocol error codes (Error)
655 #define ERROR_NOBUSCOMM 0x01
656 #define ERROR_BUSNOTREADY 0x02
657 #define ERROR_PERIODINVALID 0x03
658 #define ERROR_MESSAGEINVALID 0x04
659 #define ERROR_INITOFBUSFAILED1 0x10
660 #define ERROR_INITOFBUSFAILED2 0x11
661 #define ERROR_INITOFBUSFAILED3 0x12
662 #define ERROR_SETBIDPROCFAILED1 0x14
663 #define ERROR_SETBIDPROCFAILED2 0x15
664 #define ERROR_MEASUREMENTFAILED1 0x18
665 #define ERROR_MEASUREMENTFAILED2 0x19
666 #define ERROR_MEASUREMENTFAILED3 0x1A
667 #define ERROR_MEASUREMENTFAILED4 0x1B
668 #define ERROR_MEASUREMENTFAILED5 0x1C
669 #define ERROR_MEASUREMENTFAILED6 0x1D
670 #define ERROR_TIMEROVERFLOW 0x1E
671 #define ERROR_BAUDRATEINVALID 0x20
672 #define ERROR_PARAMETERINVALID 0x21
673 #define ERROR_MEASUREMENTFAILED7 0x23
674 
675  // Error modes (SetErrorMode)
676 #define ERRORMODE_IGNORE 0x0000
677 #define ERRORMODE_INCSAMPLECNT 0x0001
678 #define ERRORMODE_INCSAMPLECNT_SENDERROR 0x0002
679 #define ERRORMODE_SENDERROR_GOTOCONFIG 0x0003
680 
681  // Configuration message defines
682 #define CONF_MASTERDID 0
683 #define CONF_PERIOD 4
684 #define CONF_OUTPUTSKIPFACTOR 6
685 #define CONF_SYNCIN_MODE 8
686 #define CONF_SYNCIN_SKIPFACTOR 10
687 #define CONF_SYNCIN_OFFSET 12
688 #define CONF_DATE 16
689 #define CONF_TIME 24
690 #define CONF_NUMDEVICES 96
691  // Configuration sensor block properties
692 #define CONF_DID 98
693 #define CONF_DATALENGTH 102
694 #define CONF_OUTPUTMODE 104
695 #define CONF_OUTPUTSETTINGS 106
696 #define CONF_BLOCKLEN 20
697  // To calculate the offset in data field for output mode of sensor #2 use
698  // CONF_OUTPUTMODE + 1*CONF_BLOCKLEN
699 #define CONF_MASTERDIDLEN 4
700 #define CONF_PERIODLEN 2
701 #define CONF_OUTPUTSKIPFACTORLEN 2
702 #define CONF_SYNCIN_MODELEN 2
703 #define CONF_SYNCIN_SKIPFACTORLEN 2
704 #define CONF_SYNCIN_OFFSETLEN 4
705 #define CONF_DATELEN 8
706 #define CONF_TIMELEN 8
707 #define CONF_RESERVED_CLIENTLEN 32
708 #define CONF_RESERVED_HOSTLEN 32
709 #define CONF_NUMDEVICESLEN 2
710  // Configuration sensor block properties
711 #define CONF_DIDLEN 4
712 #define CONF_DATALENGTHLEN 2
713 #define CONF_OUTPUTMODELEN 2
714 #define CONF_OUTPUTSETTINGSLEN 4
715 
716  // Clock frequency for offset & pulse width
717 #define SYNC_CLOCKFREQ 29.4912e6
718 
719  // SyncIn params
720 #define PARAM_SYNCIN_MODE (const unsigned char)0x00
721 #define PARAM_SYNCIN_SKIPFACTOR (const unsigned char)0x01
722 #define PARAM_SYNCIN_OFFSET (const unsigned char)0x02
723 
724  // SyncIn mode
725 #define SYNCIN_DISABLED 0x0000
726 #define SYNCIN_EDGE_RISING 0x0001
727 #define SYNCIN_EDGE_FALLING 0x0002
728 #define SYNCIN_EDGE_BOTH 0x0003
729 #define SYNCIN_TYPE_SENDLASTDATA 0x0004
730 #define SYNCIN_TYPE_DOSAMPLING 0x0000
731 #define SYNCIN_EDGE_MASK 0x0003
732 #define SYNCIN_TYPE_MASK 0x000C
733 
734  // SyncOut params
735 #define PARAM_SYNCOUT_MODE (const unsigned char)0x00
736 #define PARAM_SYNCOUT_SKIPFACTOR (const unsigned char)0x01
737 #define PARAM_SYNCOUT_OFFSET (const unsigned char)0x02
738 #define PARAM_SYNCOUT_PULSEWIDTH (const unsigned char)0x03
739 
740  // SyncOut mode
741 #define SYNCOUT_DISABLED 0x0000
742 #define SYNCOUT_TYPE_TOGGLE 0x0001
743 #define SYNCOUT_TYPE_PULSE 0x0002
744 #define SYNCOUT_POL_NEG 0x0000
745 #define SYNCOUT_POL_POS 0x0010
746 #define SYNCOUT_TYPE_MASK 0x000F
747 #define SYNCOUT_POL_MASK 0x0010
748 
749  // Sample frequencies (SetPeriod)
750 #define PERIOD_10HZ 0x2D00
751 #define PERIOD_12HZ 0x2580
752 #define PERIOD_15HZ 0x1E00
753 #define PERIOD_16HZ 0x1C20
754 #define PERIOD_18HZ 0x1900
755 #define PERIOD_20HZ 0x1680
756 #define PERIOD_24HZ 0x12C0
757 #define PERIOD_25HZ 0x1200
758 #define PERIOD_30HZ 0x0F00
759 #define PERIOD_32HZ 0x0E10
760 #define PERIOD_36HZ 0x0C80
761 #define PERIOD_40HZ 0x0B40
762 #define PERIOD_45HZ 0x0A00
763 #define PERIOD_48HZ 0x0960
764 #define PERIOD_50HZ 0x0900
765 #define PERIOD_60HZ 0x0780
766 #define PERIOD_64HZ 0x0708
767 #define PERIOD_72HZ 0x0640
768 #define PERIOD_75HZ 0x0600
769 #define PERIOD_80HZ 0x05A0
770 #define PERIOD_90HZ 0x0500
771 #define PERIOD_96HZ 0x04B0
772 #define PERIOD_100HZ 0x0480
773 #define PERIOD_120HZ 0x03C0
774 #define PERIOD_128HZ 0x0384
775 #define PERIOD_144HZ 0x0320
776 #define PERIOD_150HZ 0x0300
777 #define PERIOD_160HZ 0x02D0
778 #define PERIOD_180HZ 0x0280
779 #define PERIOD_192HZ 0x0258
780 #define PERIOD_200HZ 0x0240
781 #define PERIOD_225HZ 0x0200
782 #define PERIOD_240HZ 0x01E0
783 #define PERIOD_256HZ 0x01C2
784 #define PERIOD_288HZ 0x0190
785 #define PERIOD_300HZ 0x0180
786 #define PERIOD_320HZ 0x0168
787 #define PERIOD_360HZ 0x0140
788 #define PERIOD_384HZ 0x012C
789 #define PERIOD_400HZ 0x0120
790 #define PERIOD_450HZ 0x0100
791 #define PERIOD_480HZ 0x00F0
792 #define PERIOD_512HZ 0x00E1
793 
794  // OutputModes
795 #define OUTPUTMODE_MT9 0x8000
796 #define OUTPUTMODE_XM 0x0000
797 #define OUTPUTMODE_RAW 0x4000
798 #define OUTPUTMODE_TEMP 0x0001
799 #define OUTPUTMODE_CALIB 0x0002
800 #define OUTPUTMODE_ORIENT 0x0004
801 
802  // OutputSettings
803 #define OUTPUTSETTINGS_XM 0x00000001
804 #define OUTPUTSETTINGS_TIMESTAMP_NONE 0x00000000
805 #define OUTPUTSETTINGS_TIMESTAMP_SAMPLECNT 0x00000001
806 #define OUTPUTSETTINGS_ORIENTMODE_QUATERNION 0x00000000
807 #define OUTPUTSETTINGS_ORIENTMODE_EULER 0x00000004
808 #define OUTPUTSETTINGS_ORIENTMODE_MATRIX 0x00000008
809 #define OUTPUTSETTINGS_CALIBMODE_ACCGYRMAG 0x00000000
810 #define OUTPUTSETTINGS_CALIBMODE_ACC 0x00000060
811 #define OUTPUTSETTINGS_CALIBMODE_ACCGYR 0x00000040
812 #define OUTPUTSETTINGS_CALIBMODE_ACCMAG 0x00000020
813 #define OUTPUTSETTINGS_CALIBMODE_GYR 0x00000050
814 #define OUTPUTSETTINGS_CALIBMODE_GYRMAG 0x00000010
815 #define OUTPUTSETTINGS_CALIBMODE_MAG 0x00000030
816 #define OUTPUTSETTINGS_DATAFORMAT_FLOAT 0x00000000
817 #define OUTPUTSETTINGS_DATAFORMAT_F1220 0x00000100
818 #define OUTPUTSETTINGS_TIMESTAMP_MASK 0x00000003
819 #define OUTPUTSETTINGS_ORIENTMODE_MASK 0x0000000C
820 #define OUTPUTSETTINGS_CALIBMODE_ACC_MASK 0x00000010
821 #define OUTPUTSETTINGS_CALIBMODE_GYR_MASK 0x00000020
822 #define OUTPUTSETTINGS_CALIBMODE_MAG_MASK 0x00000040
823 #define OUTPUTSETTINGS_CALIBMODE_MASK 0x00000070
824 #define OUTPUTSETTINGS_DATAFORMAT_MASK 0x00000300
825 
826  // Extended Output Modes
827 #define EXTOUTPUTMODE_DISABLED 0x0000
828 #define EXTOUTPUTMODE_EULER 0x0001
829 
830  // Factory Output Mode
831 #define FACTORYOUTPUTMODE_DISABLE 0x0000
832 #define FACTORYOUTPUTMODE_DEFAULT 0x0001
833 #define FACTORYOUTPUTMODE_CUSTOM 0x0002
834 
835  // Initial tracking mode (SetInitTrackMode)
836 #define INITTRACKMODE_DISABLED 0x0000
837 #define INITTRACKMODE_ENABLED 0x0001
838 
839  // Filter settings params
840 #define PARAM_FILTER_GAIN (const unsigned char)0x00
841 #define PARAM_FILTER_RHO (const unsigned char)0x01
842 #define DONOTSTORE 0x00
843 #define STORE 0x01
844 
845  // AMDSetting (SetAMD)
846 #define AMDSETTING_DISABLED 0x0000
847 #define AMDSETTING_ENABLED 0x0001
848 
849  // Reset orientation message type
850 #define RESETORIENTATION_STORE 0
851 #define RESETORIENTATION_HEADING 1
852 #define RESETORIENTATION_GLOBAL 2
853 #define RESETORIENTATION_OBJECT 3
854 #define RESETORIENTATION_ALIGN 4
855 
856  // Send raw string mode
857 #define SENDRAWSTRING_INIT 0
858 #define SENDRAWSTRING_DEFAULT 1
859 #define SENDRAWSTRING_SEND 2
860 
861  // Timeouts
862 #define TO_DEFAULT 500
863 #define TO_INIT 250
864 #define TO_RETRY 50
865 
866  // openPort baudrates
867 #ifdef WIN32
868 #define PBR_9600 CBR_9600
869 #define PBR_14K4 CBR_14400
870 #define PBR_19K2 CBR_19200
871 #define PBR_28K8 28800
872 #define PBR_38K4 CBR_38400
873 #define PBR_57K6 CBR_57600
874 #define PBR_76K8 76800
875 #define PBR_115K2 CBR_115200
876 #define PBR_230K4 230400
877 #define PBR_460K8 460800
878 #define PBR_921K6 921600
879 #else
880 #define PBR_9600 B9600
881 #define PBR_14K4 B14400
882 #define PBR_19K2 B19200
883 #define PBR_28K8 B28800
884 #define PBR_38K4 B38400
885 #define PBR_57K6 B57600
886 #define PBR_76K8 B76800
887 #define PBR_115K2 B115200
888 #define PBR_230K4 B230400
889 #define PBR_460K8 B460800
890 #define PBR_921K6 B921600
891 #endif
892 
893  // setFilePos defines
894 #ifdef WIN32
895 #define FILEPOS_BEGIN FILE_BEGIN
896 #define FILEPOS_CURRENT FILE_CURRENT
897 #define FILEPOS_END FILE_END
898 #else
899 #define FILEPOS_BEGIN SEEK_SET
900 #define FILEPOS_CURRENT SEEK_CUR
901 #define FILEPOS_END SEEK_END
902 #endif
903 
904  // Return values
905 #define MTRV_OK 0 // Operation successful
906 #define MTRV_NOTSUCCESSFUL 1 // General no success return value
907 #define MTRV_TIMEOUT 2 // Operation aborted because of a timeout
908 #define MTRV_TIMEOUTNODATA 3 // Operation aborted because of no data read
909 #define MTRV_CHECKSUMFAULT 4 // Checksum fault occured
910 #define MTRV_NODATA 5 // No data is received
911 #define MTRV_RECVERRORMSG 6 // A error message is received
912 #define MTRV_OUTOFMEMORY 7 // No internal memory available
913 #define MTRV_UNKNOWDATA 8 // An invalid message is read
914 #define MTRV_INVALIDTIMEOUT 9 // An invalid value is used to set the timeout
915 #define MTRV_UNEXPECTEDMSG 10 // Unexpected message received (e.g. no acknowledge message received)
916 #define MTRV_INPUTCANNOTBEOPENED 11 // The specified file / serial port can not be opened
917 #define MTRV_ANINPUTALREADYOPEN 12 // File and serial port can not be opened at same time
918 #define MTRV_ENDOFFILE 13 // End of file is reached
919 #define MTRV_NOINPUTINITIALIZED 14 // No file or serial port opened for reading/writing
920 #define MTRV_NOVALIDMODESPECIFIED 15 // No valid outputmode or outputsettings are specified (use
921  // mtGetDeviceMode or mtSetMode)
922 #define MTRV_INVALIDVALUESPEC 16 // Value specifier does not match value type or not available in data
923 #define MTRV_INVALIDFORFILEINPUT 17 // Function is not valid for file based interfaces
924 
926  {
927  public:
928  CXsensMTiModule();
929  virtual ~CXsensMTiModule();
930 
931  // Low level general functions
932  clock_t clockms();
933 
934  // Low level COM port / file functions
935  short openPort(const int portNumber, const unsigned long baudrate = PBR_115K2, const unsigned long inqueueSize = 4096, const unsigned long outqueueSize = 1024);
936  short openPort(const char* portName, const unsigned long baudrate = PBR_115K2, const unsigned long inqueueSize = 4096, const unsigned long outqueueSize = 1024);
937  short openFile(const char* fileName, bool createAlways = false);
938  bool isPortOpen();
939  bool isFileOpen();
940  int readData(unsigned char* msgBuffer, const int nBytesToRead);
941  int writeData(const unsigned char* msgBuffer, const int nBytesToWrite);
942  void flush();
943  void escape(unsigned long function);
944  void setPortQueueSize(const unsigned long inqueueSize = 4096, const unsigned long outqueueSize = 1024);
945  short setFilePos(long relPos, unsigned long moveMethod = FILEPOS_BEGIN);
946  short getFileSize(unsigned long& fileSize);
947  short close();
948 
949  // Read & write message functions
950  short readMessage(unsigned char& mid, unsigned char data[], short& dataLen, unsigned char* bid = NULL);
951  short readDataMessage(unsigned char data[], short& dataLen);
952  short readMessageRaw(unsigned char* msgBuffer, short* msgBufferLength);
953  short writeMessage(const unsigned char mid, const unsigned long dataValue = 0, const unsigned char dataValueLen = 0, const unsigned char bid = BID_MASTER);
954  short writeMessage(const unsigned char mid, const unsigned char data[], const unsigned short& dataLen, const unsigned char bid = BID_MASTER);
955  short waitForMessage(const unsigned char mid, unsigned char data[] = NULL, short* dataLen = NULL, unsigned char* bid = NULL);
956 
957  // Request & set setting functions
958  short reqSetting(const unsigned char mid, unsigned long& value, const unsigned char bid = BID_MASTER);
959  short reqSetting(const unsigned char mid, const unsigned char param, unsigned long& value, const unsigned char bid = BID_MASTER);
960  short reqSetting(const unsigned char mid, float& value, const unsigned char bid = BID_MASTER);
961  short reqSetting(const unsigned char mid, const unsigned char param, float& value, const unsigned char bid = BID_MASTER);
962  short reqSetting(const unsigned char mid, unsigned char data[], short& dataLen, const unsigned char bid = BID_MASTER);
963  short reqSetting(const unsigned char mid, unsigned char dataIn[], short dataInLen, unsigned char dataOut[], short& dataOutLen, const unsigned char bid = BID_MASTER);
964  short reqSetting(const unsigned char mid, const unsigned char param, unsigned char data[], short& dataLen, const unsigned char bid = BID_MASTER);
965  short setSetting(const unsigned char mid, const unsigned long value, const unsigned short valuelen, const unsigned char bid = BID_MASTER);
966  short setSetting(const unsigned char mid, const unsigned char param, const unsigned long value, const unsigned short valuelen, const unsigned char bid = BID_MASTER);
967  short setSetting(const unsigned char mid, const float value, const unsigned char bid = BID_MASTER);
968  short setSetting(const unsigned char mid, const unsigned char param, const float value, const unsigned char bid = BID_MASTER);
969  short setSetting(const unsigned char mid, const unsigned char param, const float value, const bool store, const unsigned char bid = BID_MASTER);
970  // Data-related functions
971  short getDeviceMode(unsigned short* numDevices = NULL);
972  short setDeviceMode(unsigned long OutputMode, unsigned long OutputSettings, const unsigned char bid = BID_MASTER);
973  short getMode(unsigned long& OutputMode, unsigned long& OutputSettings, unsigned short& dataLength, const unsigned char bid = BID_MASTER);
974  short setMode(unsigned long OutputMode, unsigned long OutputSettings, const unsigned char bid = BID_MASTER);
975  short getValue(const unsigned long valueSpec, unsigned short& value, const unsigned char data[], const unsigned char bid = BID_MT);
976  short getValue(const unsigned long valueSpec, unsigned short value[], const unsigned char data[], const unsigned char bid = BID_MT);
977  short getValue(const unsigned long valueSpec, float value[], const unsigned char data[], const unsigned char bid = BID_MT);
978 
979  // Generic MTComm functions
980  short getLastDeviceError();
981  short getLastRetVal();
982  short setTimeOut(short timeOutMs);
983  static void swapEndian(const unsigned char input[], unsigned char output[], const int length);
984  void calcChecksum(unsigned char* msgBuffer, const int msgBufferLength);
985  bool checkChecksum(const unsigned char* msgBuffer, const int msgBufferLength);
986  protected:
987  // member variables
988 #ifdef WIN32
989  HANDLE m_handle;
990 #else
991  int m_handle;
992 #endif
996  short m_retVal;
997  short m_timeOut;
998  clock_t m_clkEnd;
999 
1000  // OutputMode, OutputSettings & DataLength for connected devices + 1 for master
1001  unsigned long m_storedOutputMode[MAXDEVICES + 1];
1003  unsigned long m_storedDataLength[MAXDEVICES + 1];
1004 
1005  // Temporary buffer for excess bytes read in ReadMessageRaw
1006  unsigned char m_tempBuffer[MAXMSGLEN ];
1008 
1009  private:
1010  };
1011 }
1012 
1013 #endif
1014 
1015 #endif // !defined(AFX_XBUS_H__F4580A3F_2CF2_4ED2_A747_B4B015A0328E__INCLUDED_)
IMU::Xsens::CXsensMTiModule::m_clkEnd
clock_t m_clkEnd
Definition: XsensMTiModule.h:998
IMU::Xsens::CXsensMTiModule::readData
int readData(unsigned char *msgBuffer, const int nBytesToRead)
Definition: XsensMTiModule.cpp:568
IMU::Xsens::CXsensMTiModule::m_portOpen
bool m_portOpen
Definition: XsensMTiModule.h:993
IMU::Xsens::CXsensMTiModule::checkChecksum
bool checkChecksum(const unsigned char *msgBuffer, const int msgBufferLength)
Definition: XsensMTiModule.cpp:3165
BID_MT
#define BID_MT
Definition: XsensMTiModule.h:153
IMU::Xsens::CXsensMTiModule
Definition: XsensMTiModule.h:925
IMU::Xsens::CXsensMTiModule::readMessageRaw
short readMessageRaw(unsigned char *msgBuffer, short *msgBufferLength)
Definition: XsensMTiModule.cpp:970
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
string.h
IMU::Xsens::CXsensMTiModule::reqSetting
short reqSetting(const unsigned char mid, unsigned long &value, const unsigned char bid=BID_MASTER)
Definition: XsensMTiModule.cpp:1478
IMU::Xsens::CXsensMTiModule::isFileOpen
bool isFileOpen()
Definition: XsensMTiModule.cpp:551
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
IMU::Xsens::CXsensMTiModule::setFilePos
short setFilePos(long relPos, unsigned long moveMethod=FILEPOS_BEGIN)
Definition: XsensMTiModule.cpp:746
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
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
FILEPOS_BEGIN
#define FILEPOS_BEGIN
Definition: XsensMTiModule.h:899
IMU::Xsens
Definition: Xsens.h:17
IMU::Xsens::CXsensMTiModule::m_retVal
short m_retVal
Definition: XsensMTiModule.h:996
IMU::Xsens::CXsensMTiModule::flush
void flush()
Definition: XsensMTiModule.cpp:682
IMU::Xsens::CXsensMTiModule::getLastDeviceError
short getLastDeviceError()
Definition: XsensMTiModule.cpp:3059
armarx::armem::server::ltm::mongodb::util::store
void store(const mongocxx::database &db, const armem::wm::Memory &m)
Definition: operations.cpp:237
IMU::Xsens::CXsensMTiModule::~CXsensMTiModule
virtual ~CXsensMTiModule()
Definition: XsensMTiModule.cpp:149
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
IMU::Xsens::CXsensMTiModule::m_timeOut
short m_timeOut
Definition: XsensMTiModule.h:997
PBR_115K2
#define PBR_115K2
Definition: XsensMTiModule.h:887
MAXDEVICES
#define MAXDEVICES
Definition: XsensMTiModule.h:149
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
IMU::Xsens::CXsensMTiModule::readDataMessage
short readDataMessage(unsigned char data[], short &dataLen)
Definition: XsensMTiModule.cpp:918
IMU::Xsens::CXsensMTiModule::setDeviceMode
short setDeviceMode(unsigned long OutputMode, unsigned long OutputSettings, const unsigned char bid=BID_MASTER)
Definition: XsensMTiModule.cpp:2529
IMU::Xsens::CXsensMTiModule::setMode
short setMode(unsigned long OutputMode, unsigned long OutputSettings, const unsigned char bid=BID_MASTER)
Definition: XsensMTiModule.cpp:2629
BID_MASTER
#define BID_MASTER
Definition: XsensMTiModule.h:152
IMU::Xsens::CXsensMTiModule::setTimeOut
short setTimeOut(short timeOutMs)
Definition: XsensMTiModule.cpp:3084
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
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
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
IMU::Xsens::CXsensMTiModule::m_nTempBufferLen
int m_nTempBufferLen
Definition: XsensMTiModule.h:1007
IMU::Xsens::CXsensMTiModule::close
short close()
Definition: XsensMTiModule.cpp:817
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
IMU::Xsens::CXsensMTiModule::m_tempBuffer
unsigned char m_tempBuffer[MAXMSGLEN]
Definition: XsensMTiModule.h:1006
IMU::Xsens::CXsensMTiModule::getDeviceMode
short getDeviceMode(unsigned short *numDevices=NULL)
Definition: XsensMTiModule.cpp:2394
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
MAXMSGLEN
#define MAXMSGLEN
Definition: XsensMTiModule.h:168
IMU::Xsens::CXsensMTiModule::writeData
int writeData(const unsigned char *msgBuffer, const int nBytesToWrite)
Definition: XsensMTiModule.cpp:658
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
IMU::Xsens::CXsensMTiModule::getFileSize
short getFileSize(unsigned long &fileSize)
Definition: XsensMTiModule.cpp:783
IMU::Xsens::CXsensMTiModule::calcChecksum
void calcChecksum(unsigned char *msgBuffer, const int msgBufferLength)
Definition: XsensMTiModule.cpp:3145