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