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