MTComm.h

00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2006 Radu Bogdan Rusu (rusu@cs.tum.edu)
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  */
00020 /*
00021  Desc: Driver for XSens MTx/MTi IMU. CMTComm class borrowed from XSens under GPL.
00022  Author: Radu Bogdan Rusu
00023  Date: 1 Aug 2006
00024 */
00025 // MTComm.h: interface for the CMTComm class.
00026 //
00027 // Version 1.2.0
00028 // Public release
00029 //
00030 // v1.2.0
00031 // 27-02-2006 - Renamed Xbus class to Motion Tracker C++ Communication class, short MTComm
00032 //                        - Defines XBRV_* accordingly renamed to MTRV_*
00033 //                        - Fixed device length not correct for bid 0 when using Xbus Master and setDeviceMode function
00034 //
00035 // v1.1.7
00036 // 15-02-2006 - Added fixed point signed 12.20 dataformat support
00037 //                              Added selective calibrated data output per sensor type support
00038 //                              Added outputmode temperature support
00039 //                              Fixed warning C4244: '=' : conversion from '' to '', possible loss of data
00040 // v1.1.6
00041 // 25-01-2006 - Added escape function for CLRDTR, CLRRTS, SETDTR, SETRTS, SETXOFF, SETXON, SETBREAK, CLRBREAK
00042 //
00043 // v1.1.5
00044 // 14-11-2005 - Made swapEndian a static member function, Job Mulder
00045 //
00046 // v1.1.4
00047 // 08-11-2005 - Changed practically all uses of m_timeOut into uses of the new m_clkEnd
00048 //                        - Changed COM timeout in win32 to return immediately if data is available,
00049 //                              but wait 1ms otherwise
00050 //
00051 // v1.1.3
00052 // 18-10-2005 - Added MID_REQPRODUCTCODE, MID_REQ/SETTRANSMITDELAY
00053 //                        - Added XBRV_TIMEOUTNODATA indicating timeout occurred due to no data read
00054 //
00055 // v1.1.2
00056 // 16-09-2005 - Added eMTS version 0.1->1.0 changes (EMTS_FACTORYMODE)
00057 //                        - Added factory output mode defines
00058 //
00059 // v1.1.1
00060 // 01-09-2005 - Added defines for Extended output mode
00061 //                        - Added reqSetting (byte array in + out & no param variant)
00062 //
00063 // v1.1
00064 // 08-08-2005 - Added file read and write support
00065 //                        - Added functions for data retrieval (getValue etc)
00066 //                                for easy data retrieval of acc, gyr, mag etc
00067 //                        - ReadMessageRaw:
00068 //                              - added a temporary buffer for unprocessed bytes
00069 //                              - check for invalid length messages
00070 //                        - Changed BID_MT into 1 and added BID_MASTER (=0xFF)
00071 //                        - Changed various ....SerialPort functions to .....Port
00072 //                        - Changed mtSendMessage functions to mtWriteMessage
00073 //                        - Added numerous defines
00074 //                        - Deleted obsolete functions
00075 //                        - Changed function getLastErrorCode into getLastDeviceError
00076 //                        - Changed OpenPort function for compatiblity with Bluetooth ports
00077 //                        - Added workaround for lockup of USB driver (close function) 
00078 //                        - Added workaround for clock() problem with read function of USB driver
00079 //
00080 // v1.0.2
00081 // 29-06-2005 - Inserted initSerialPort with devicename input
00082 //                        - Changed return value defines names from X_ to XBRV_
00083 //                        - Removed unneeded includes for linux
00084 //
00085 // v1.0.1
00086 // 22-06-2005 - Fixed ReqSetting functions (byte array & param variant)
00087 //                              mtSendRawString had wrong length input
00088 //
00089 // v1.0.0
00090 // 20-06-2005 - Initial release
00091 //
00092 // ----------------------------------------------------------------------------
00093 //  This file is an Xsens Code Example.
00094 //
00095 //  Copyright (C) Xsens Technologies B.V., 2005.
00096 //
00097 //  This source code is intended only as a example of the implementation
00098 //      of the Xsens MT Communication protocol.
00099 //      It was written for cross platform capabilities.
00100 //
00101 //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
00102 //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
00103 //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00104 //  PARTICULAR PURPOSE.
00106 
00107 #if !defined(AFX_XBUS_H__F4580A3F_2CF2_4ED2_A747_B4B015A0328E__INCLUDED_)
00108 #define AFX_XBUS_H__F4580A3F_2CF2_4ED2_A747_B4B015A0328E__INCLUDED_
00109 
00110 #if _MSC_VER > 1000
00111 #pragma once
00112 #endif // _MSC_VER > 1000
00113 
00114 #include <string.h>
00115 #include <stdio.h>
00116 #ifdef WIN32
00117 #include <windows.h>
00118 #include <conio.h>
00119 #include <time.h>
00120 #else
00121 #include <fcntl.h>      /* POSIX Standard: 6.5 File Control Operations     */
00122 #include <termios.h>    /* terminal i/o system, talks to /dev/tty* ports  */
00123 #include <unistd.h>             /* Read function */
00124 #include <sys/time.h>   /* gettimeofday function */
00125 #include <sys/stat.h>   /* stat calls and structures*/
00126 #endif
00127 
00128 #ifndef INVALID_SET_FILE_POINTER
00129 #define INVALID_SET_FILE_POINTER        ((DWORD)(-1))
00130 #endif
00131 
00132 // Field message indexes
00133 #define IND_PREAMBLE                            0
00134 #define IND_BID                                         1
00135 #define IND_MID                                         2
00136 #define IND_LEN                                         3
00137 #define IND_DATA0                                       4
00138 #define IND_LENEXTH                                     4
00139 #define IND_LENEXTL                                     5
00140 #define IND_DATAEXT0                            6
00141 
00142 // Maximum number of sensors supported
00143 #define MAXDEVICES                                      20
00144 
00145 #define PREAMBLE                                        (const unsigned char)0xFA
00146 #define BID_MASTER                                      (const unsigned char)0xFF
00147 #define BID_MT                                          (const unsigned char)0x01
00148 #define EXTLENCODE                                      0xFF
00149 
00150 #define LEN_MSGHEADER                           (const unsigned short)4
00151 #define LEN_MSGEXTHEADER                        (const unsigned short)6
00152 #define LEN_MSGHEADERCS                         (const unsigned short)5
00153 #define LEN_MSGEXTHEADERCS                      (const unsigned short)7
00154 #define LEN_CHECKSUM                            (const unsigned short)1
00155 #define LEN_UNSIGSHORT                          (const unsigned short)2
00156 #define LEN_UNSIGINT                            (const unsigned short)4
00157 #define LEN_FLOAT                                       (const unsigned short)4
00158 
00159 // Maximum message/data length
00160 #define MAXDATALEN                                      (const unsigned short)2048
00161 #define MAXSHORTDATALEN                         (const unsigned short)254
00162 #define MAXMSGLEN                                       (const unsigned short)(MAXDATALEN+7)
00163 #define MAXSHORTMSGLEN                          (const unsigned short)(MAXSHORTDATALEN+5)
00164 
00165 
00166 // DID Type (high nibble)
00167 #define DID_TYPEH_MASK                          (const unsigned long)0x00F00000
00168 #define DID_TYPEH_MT                            (const unsigned long)0x00000000
00169 #define DID_TYPEH_XM                            (const unsigned long)0x00100000
00170 #define DID_TYPEH_MTI_MTX                       (const unsigned long)0x00300000
00171 
00172 // All Message identifiers
00173 // WakeUp state messages
00174 #define MID_WAKEUP                                      (const unsigned char)0x3E
00175 #define MID_WAKEUPACK                           (const unsigned char)0x3F
00176 
00177 // Config state messages
00178 #define MID_REQDID                                      (const unsigned char)0x00
00179 #define MID_DEVICEID                            (const unsigned char)0x01
00180 #define LEN_DEVICEID                            (const unsigned short)4
00181 #define MID_INITBUS                                     (const unsigned char)0x02
00182 #define MID_INITBUSRESULTS                      (const unsigned char)0x03
00183 #define LEN_INITBUSRESULTS                      (const unsigned short)4
00184 #define MID_REQPERIOD                           (const unsigned char)0x04
00185 #define MID_REQPERIODACK                        (const unsigned char)0x05
00186 #define LEN_PERIOD                                      (const unsigned short)2
00187 #define MID_SETPERIOD                           (const unsigned char)0x04
00188 #define MID_SETPERIODACK                        (const unsigned char)0x05
00189 // XbusMaster
00190 #define MID_SETBID                                      (const unsigned char)0x06
00191 #define MID_SETBIDACK                           (const unsigned char)0x07
00192 #define MID_AUTOSTART                           (const unsigned char)0x06
00193 #define MID_AUTOSTARTACK                        (const unsigned char)0x07
00194 #define MID_BUSPWROFF                           (const unsigned char)0x08
00195 #define MID_BUSPWROFFACK                        (const unsigned char)0x09
00196 // End XbusMaster
00197 #define MID_REQDATALENGTH                       (const unsigned char)0x0A
00198 #define MID_DATALENGTH                          (const unsigned char)0x0B
00199 #define LEN_DATALENGTH                          (const unsigned short)2
00200 #define MID_REQCONFIGURATION            (const unsigned char)0x0C
00201 #define MID_CONFIGURATION                       (const unsigned char)0x0D
00202 #define LEN_CONFIGURATION                       (const unsigned short)118
00203 #define MID_RESTOREFACTORYDEF           (const unsigned char)0x0E
00204 #define MID_RESTOREFACTORYDEFACK        (const unsigned char)0x0F
00205 
00206 #define MID_GOTOMEASUREMENT                     (const unsigned char)0x10
00207 #define MID_GOTOMEASUREMENTACK          (const unsigned char)0x11
00208 #define MID_REQFWREV                            (const unsigned char)0x12
00209 #define MID_FIRMWAREREV                         (const unsigned char)0x13
00210 #define LEN_FIRMWAREREV                         (const unsigned short)3
00211 // XbusMaster
00212 #define MID_REQBTDISABLE                        (const unsigned char)0x14
00213 #define MID_REQBTDISABLEACK                     (const unsigned char)0x15
00214 #define MID_DISABLEBT                           (const unsigned char)0x14
00215 #define MID_DISABLEBTACK                        (const unsigned char)0x15
00216 #define MID_REQOPMODE                           (const unsigned char)0x16
00217 #define MID_REQOPMODEACK                        (const unsigned char)0x17
00218 #define MID_SETOPMODE                           (const unsigned char)0x16
00219 #define MID_SETOPMODEACK                        (const unsigned char)0x17
00220 // End XbusMaster
00221 #define MID_REQBAUDRATE                         (const unsigned char)0x18
00222 #define MID_REQBAUDRATEACK                      (const unsigned char)0x19
00223 #define LEN_BAUDRATE                            (const unsigned short)1
00224 #define MID_SETBAUDRATE                         (const unsigned char)0x18
00225 #define MID_SETBAUDRATEACK                      (const unsigned char)0x19
00226 // XbusMaster
00227 #define MID_REQSYNCMODE                         (const unsigned char)0x1A
00228 #define MID_REQSYNCMODEACK                      (const unsigned char)0x1B
00229 #define MID_SETSYNCMODE                         (const unsigned char)0x1A
00230 #define MID_SETSYNCMODEACK                      (const unsigned char)0x1B
00231 // End XbusMaster
00232 #define MID_REQPRODUCTCODE                      (const unsigned char)0x1C
00233 #define MID_PRODUCTCODE                         (const unsigned char)0x1D
00234 
00235 #define MID_REQOUTPUTMODE                       (const unsigned char)0xD0
00236 #define MID_REQOUTPUTMODEACK            (const unsigned char)0xD1
00237 #define LEN_OUTPUTMODE                          (const unsigned short)2
00238 #define MID_SETOUTPUTMODE                       (const unsigned char)0xD0
00239 #define MID_SETOUTPUTMODEACK            (const unsigned char)0xD1
00240 
00241 #define MID_REQOUTPUTSETTINGS           (const unsigned char)0xD2
00242 #define MID_REQOUTPUTSETTINGSACK        (const unsigned char)0xD3
00243 #define LEN_OUTPUTSETTINGS                      (const unsigned short)4
00244 #define MID_SETOUTPUTSETTINGS           (const unsigned char)0xD2
00245 #define MID_SETOUTPUTSETTINGSACK        (const unsigned char)0xD3
00246 
00247 #define MID_REQOUTPUTSKIPFACTOR         (const unsigned char)0xD4
00248 #define MID_REQOUTPUTSKIPFACTORACK      (const unsigned char)0xD5
00249 #define LEN_OUTPUTSKIPFACTOR            (const unsigned short)2
00250 #define MID_SETOUTPUTSKIPFACTOR         (const unsigned char)0xD4
00251 #define MID_SETOUTPUTSKIPFACTORACK      (const unsigned char)0xD5
00252 
00253 #define MID_REQSYNCINSETTINGS           (const unsigned char)0xD6
00254 #define MID_REQSYNCINSETTINGSACK        (const unsigned char)0xD7
00255 #define LEN_SYNCINMODE                          (const unsigned short)2
00256 #define LEN_SYNCINSKIPFACTOR            (const unsigned short)2
00257 #define LEN_SYNCINOFFSET                        (const unsigned short)4
00258 #define MID_SETSYNCINSETTINGS           (const unsigned char)0xD6
00259 #define MID_SETSYNCINSETTINGSACK        (const unsigned char)0xD7
00260 
00261 #define MID_REQSYNCOUTSETTINGS          (const unsigned char)0xD8
00262 #define MID_REQSYNCOUTSETTINGSACK       (const unsigned char)0xD9
00263 #define LEN_SYNCOUTMODE                         (const unsigned short)2
00264 #define LEN_SYNCOUTSKIPFACTOR           (const unsigned short)2
00265 #define LEN_SYNCOUTOFFSET                       (const unsigned short)4
00266 #define LEN_SYNCOUTPULSEWIDTH           (const unsigned short)4
00267 #define MID_SETSYNCOUTSETTINGS          (const unsigned char)0xD8
00268 #define MID_SETSYNCOUTSETTINGSACK       (const unsigned char)0xD9
00269 
00270 #define MID_REQERRORMODE                        (const unsigned char)0xDA
00271 #define MID_REQERRORMODEACK                     (const unsigned char)0xDB
00272 #define LEN_ERRORMODE                           (const unsigned short)2
00273 #define MID_SETERRORMODE                        (const unsigned char)0xDA
00274 #define MID_SETERRORMODEACK                     (const unsigned char)0xDB
00275 
00276 #define MID_REQTRANSMITDELAY            (const unsigned char)0xDC
00277 #define MID_REQTRANSMITDELAYACK         (const unsigned char)0xDD
00278 #define LEN_TRANSMITDELAY                       (const unsigned short)2
00279 #define MID_SETTRANSMITDELAY            (const unsigned char)0xDC
00280 #define MID_SETTRANSMITDELAYACK         (const unsigned char)0xDD               
00281 
00282 // Xbus Master
00283 #define MID_REQXMERRORMODE                      (const unsigned char)0x82
00284 #define MID_REQXMERRORMODEACK           (const unsigned char)0x83
00285 #define LEN_XMERRORMODE                         (const unsigned short)2
00286 #define MID_SETXMERRORMODE                      (const unsigned char)0x82
00287 #define MID_SETXMERRORMODEACK           (const unsigned char)0x83
00288 
00289 #define MID_REQBUFFERSIZE                       (const unsigned char)0x84
00290 #define MID_REQBUFFERSIZEACK            (const unsigned char)0x85
00291 #define LEN_BUFFERSIZE                          (const unsigned short)2
00292 #define MID_SETBUFFERSIZE                       (const unsigned char)0x84
00293 #define MID_SETBUFFERSIZEACK            (const unsigned char)0x85                       
00294 // End Xbus Master
00295 
00296 #define MID_REQHEADING                          (const unsigned char)0x82
00297 #define MID_REQHEADINGACK                       (const unsigned char)0x83
00298 #define LEN_HEADING                                     (const unsigned short)4
00299 #define MID_SETHEADING                          (const unsigned char)0x82
00300 #define MID_SETHEADINGACK                       (const unsigned char)0x83
00301 
00302 #define MID_REQLOCATIONID                       (const unsigned char)0x84
00303 #define MID_REQLOCATIONIDACK            (const unsigned char)0x85
00304 #define LEN_LOCATIONID                          (const unsigned short)2
00305 #define MID_SETLOCATIONID                       (const unsigned char)0x84
00306 #define MID_SETLOCATIONIDACK            (const unsigned char)0x85
00307 
00308 #define MID_REQEXTOUTPUTMODE            (const unsigned char)0x86
00309 #define MID_REQEXTOUTPUTMODEACK         (const unsigned char)0x87
00310 #define LEN_EXTOUTPUTMODE                       (const unsigned short)2
00311 #define MID_SETEXTOUTPUTMODE            (const unsigned char)0x86
00312 #define MID_SETEXTOUTPUTMODEACK         (const unsigned char)0x87
00313 
00314 // XbusMaster
00315 #define MID_REQBATLEVEL                         (const unsigned char)0x88
00316 #define MID_BATLEVEL                            (const unsigned char)0x89
00317 // End XbusMaster
00318 
00319 #define MID_REQINITTRACKMODE            (const unsigned char)0x88
00320 #define MID_REQINITTRACKMODEACK         (const unsigned char)0x89
00321 #define LEN_INITTRACKMODE                       (const unsigned short)2
00322 #define MID_SETINITTRACKMODE            (const unsigned char)0x88
00323 #define MID_SETINITTRACKMODEACK         (const unsigned char)0x89
00324 
00325 #define MID_STOREFILTERSTATE            (const unsigned char)0x8A
00326 #define MID_STOREFILTERSTATEACK         (const unsigned char)0x8B
00327 
00328 // Measurement state
00329 #define MID_GOTOCONFIG                          (const unsigned char)0x30
00330 #define MID_GOTOCONFIGACK                       (const unsigned char)0x31
00331 #define MID_BUSDATA                                     (const unsigned char)0x32
00332 #define MID_MTDATA                                      (const unsigned char)0x32
00333 
00334 // Manual
00335 #define MID_PREPAREDATA                         (const unsigned char)0x32
00336 #define MID_REQDATA                                     (const unsigned char)0x34
00337 #define MID_REQDATAACK                          (const unsigned char)0x35
00338 
00339 // MTData defines 
00340 // Length of data blocks in bytes
00341 #define LEN_RAWDATA                                     (const unsigned short)20
00342 #define LEN_CALIBDATA                           (const unsigned short)36
00343 #define LEN_CALIB_ACCDATA                       (const unsigned short)12
00344 #define LEN_CALIB_GYRDATA                       (const unsigned short)12
00345 #define LEN_CALIB_MAGDATA                       (const unsigned short)12
00346 #define LEN_ORIENT_QUATDATA                     (const unsigned short)16
00347 #define LEN_ORIENT_EULERDATA            (const unsigned short)12
00348 #define LEN_ORIENT_MATRIXDATA           (const unsigned short)36
00349 #define LEN_SAMPLECNT                           (const unsigned short)2
00350 #define LEN_TEMPDATA                            (const unsigned short)4
00351 
00352 // Length of data blocks in floats
00353 #define LEN_CALIBDATA_FLT                       (const unsigned short)9
00354 #define LEN_ORIENT_QUATDATA_FLT         (const unsigned short)4
00355 #define LEN_ORIENT_EULERDATA_FLT        (const unsigned short)3
00356 #define LEN_ORIENT_MATRIXDATA_FLT       (const unsigned short)9
00357 
00358 // Indices of fields in DATA field of MTData message in bytes
00359 // use in combination with LEN_CALIB etc
00360 // Un-calibrated raw data
00361 #define IND_RAW_ACCX                            0
00362 #define IND_RAW_ACCY                            2
00363 #define IND_RAW_ACCZ                            4
00364 #define IND_RAW_GYRX                            6
00365 #define IND_RAW_GYRY                            8
00366 #define IND_RAW_GYRZ                            10
00367 #define IND_RAW_MAGX                            12
00368 #define IND_RAW_MAGY                            14
00369 #define IND_RAW_MAGZ                            16
00370 #define IND_RAW_TEMP                            18
00371 // Calibrated data
00372 #define IND_CALIB_ACCX                          0
00373 #define IND_CALIB_ACCY                          4
00374 #define IND_CALIB_ACCZ                          8
00375 #define IND_CALIB_GYRX                          12
00376 #define IND_CALIB_GYRY                          16
00377 #define IND_CALIB_GYRZ                          20
00378 #define IND_CALIB_MAGX                          24
00379 #define IND_CALIB_MAGY                          28
00380 #define IND_CALIB_MAGZ                          32
00381 // Orientation data - quat
00382 #define IND_ORIENT_Q0                           0
00383 #define IND_ORIENT_Q1                           4
00384 #define IND_ORIENT_Q2                           8
00385 #define IND_ORIENT_Q3                           12
00386 // Orientation data - euler
00387 #define IND_ORIENT_ROLL                         0
00388 #define IND_ORIENT_PITCH                        4
00389 #define IND_ORIENT_YAW                          8
00390 // Orientation data - matrix
00391 #define IND_ORIENT_A                            0
00392 #define IND_ORIENT_B                            4
00393 #define IND_ORIENT_C                            8
00394 #define IND_ORIENT_D                            12
00395 #define IND_ORIENT_E                            16
00396 #define IND_ORIENT_F                            20
00397 #define IND_ORIENT_G                            24
00398 #define IND_ORIENT_H                            28
00399 #define IND_ORIENT_I                            32
00400 // Orientation data - euler
00401 #define IND_SAMPLECNTH                          0
00402 #define IND_SAMPLECNTL                          1
00403 
00404 // Indices of fields in DATA field of MTData message
00405 // Un-calibrated raw data
00406 #define FLDNUM_RAW_ACCX                         0
00407 #define FLDNUM_RAW_ACCY                         1
00408 #define FLDNUM_RAW_ACCZ                         2
00409 #define FLDNUM_RAW_GYRX                         3
00410 #define FLDNUM_RAW_GYRY                         4
00411 #define FLDNUM_RAW_GYRZ                         5
00412 #define FLDNUM_RAW_MAGX                         6
00413 #define FLDNUM_RAW_MAGY                         7
00414 #define FLDNUM_RAW_MAGZ                         8
00415 #define FLDNUM_RAW_TEMP                         9
00416 // Calibrated data
00417 #define FLDNUM_CALIB_ACCX                       0
00418 #define FLDNUM_CALIB_ACCY                       1
00419 #define FLDNUM_CALIB_ACCZ                       2
00420 #define FLDNUM_CALIB_GYRX                       3
00421 #define FLDNUM_CALIB_GYRY                       4
00422 #define FLDNUM_CALIB_GYRZ                       5
00423 #define FLDNUM_CALIB_MAGX                       6
00424 #define FLDNUM_CALIB_MAGY                       7
00425 #define FLDNUM_CALIB_MAGZ                       8
00426 // Orientation data - quat
00427 #define FLDNUM_ORIENT_Q0                        0
00428 #define FLDNUM_ORIENT_Q1                        1
00429 #define FLDNUM_ORIENT_Q2                        2
00430 #define FLDNUM_ORIENT_Q3                        3
00431 // Orientation data - euler
00432 #define FLDNUM_ORIENT_ROLL                      0
00433 #define FLDNUM_ORIENT_PITCH                     1
00434 #define FLDNUM_ORIENT_YAW                       2
00435 // Orientation data - matrix
00436 #define FLDNUM_ORIENT_A                         0
00437 #define FLDNUM_ORIENT_B                         1
00438 #define FLDNUM_ORIENT_C                         2
00439 #define FLDNUM_ORIENT_D                         3
00440 #define FLDNUM_ORIENT_E                         4
00441 #define FLDNUM_ORIENT_F                         5
00442 #define FLDNUM_ORIENT_G                         6
00443 #define FLDNUM_ORIENT_H                         7
00444 #define FLDNUM_ORIENT_I                         8
00445 // Length
00446 // Uncalibrated raw data
00447 #define LEN_RAW_ACCX                            2
00448 #define LEN_RAW_ACCY                            2
00449 #define LEN_RAW_ACCZ                            2
00450 #define LEN_RAW_GYRX                            2
00451 #define LEN_RAW_GYRY                            2
00452 #define LEN_RAW_GYRZ                            2
00453 #define LEN_RAW_MAGX                            2
00454 #define LEN_RAW_MAGY                            2
00455 #define LEN_RAW_MAGZ                            2
00456 #define LEN_RAW_TEMP                            2
00457 // Calibrated data
00458 #define LEN_CALIB_ACCX                          4
00459 #define LEN_CALIB_ACCY                          4
00460 #define LEN_CALIB_ACCZ                          4
00461 #define LEN_CALIB_GYRX                          4
00462 #define LEN_CALIB_GYRY                          4
00463 #define LEN_CALIB_GYRZ                          4
00464 #define LEN_CALIB_MAGX                          4
00465 #define LEN_CALIB_MAGY                          4
00466 #define LEN_CALIB_MAGZ                          4
00467 // Orientation data - quat
00468 #define LEN_ORIENT_Q0                           4
00469 #define LEN_ORIENT_Q1                           4
00470 #define LEN_ORIENT_Q2                           4
00471 #define LEN_ORIENT_Q3                           4
00472 // Orientation data - euler
00473 #define LEN_ORIENT_ROLL                         4
00474 #define LEN_ORIENT_PITCH                        4
00475 #define LEN_ORIENT_YAW                          4
00476 // Orientation data - matrix
00477 #define LEN_ORIENT_A                            4
00478 #define LEN_ORIENT_B                            4
00479 #define LEN_ORIENT_C                            4
00480 #define LEN_ORIENT_D                            4
00481 #define LEN_ORIENT_E                            4
00482 #define LEN_ORIENT_F                            4
00483 #define LEN_ORIENT_G                            4
00484 #define LEN_ORIENT_H                            4
00485 #define LEN_ORIENT_I                            4
00486 
00487 // Defines for getDataValue
00488 #define VALUE_RAW_ACC                           0
00489 #define VALUE_RAW_GYR                           1
00490 #define VALUE_RAW_MAG                           2
00491 #define VALUE_RAW_TEMP                          3
00492 #define VALUE_CALIB_ACC                         4
00493 #define VALUE_CALIB_GYR                         5
00494 #define VALUE_CALIB_MAG                         6
00495 #define VALUE_ORIENT_QUAT                       7
00496 #define VALUE_ORIENT_EULER                      8
00497 #define VALUE_ORIENT_MATRIX                     9
00498 #define VALUE_SAMPLECNT                         10
00499 #define VALUE_TEMP                                      11
00500 
00501 #define INVALIDSETTINGVALUE                     0xFFFFFFFF
00502 
00503 
00504 // Valid in all states
00505 #define MID_RESET                                       (const unsigned char)0x40
00506 #define MID_RESETACK                            (const unsigned char)0x41
00507 #define MID_ERROR                                       (const unsigned char)0x42
00508 #define LEN_ERROR                                       (const unsigned short)1
00509 // XbusMaster
00510 #define MID_XMPWROFF                            (const unsigned char)0x44
00511 // End XbusMaster
00512 
00513 #define MID_REQFILTERSETTINGS           (const unsigned char)0xA0
00514 #define MID_REQFILTERSETTINGSACK        (const unsigned char)0xA1
00515 #define LEN_FILTERSETTINGS                      (const unsigned short)4
00516 #define MID_SETFILTERSETTINGS           (const unsigned char)0xA0
00517 #define MID_SETFILTERSETTINGSACK        (const unsigned char)0xA1
00518 #define MID_REQAMD                                      (const unsigned char)0xA2
00519 #define MID_REQAMDACK                           (const unsigned char)0xA3
00520 #define LEN_AMD                                         (const unsigned short)2
00521 #define MID_SETAMD                                      (const unsigned char)0xA2
00522 #define MID_SETAMDACK                           (const unsigned char)0xA3
00523 #define MID_RESETORIENTATION            (const unsigned char)0xA4
00524 #define MID_RESETORIENTATIONACK         (const unsigned char)0xA5
00525 #define LEN_RESETORIENTATION            (const unsigned short)2
00526 
00527 // All Messages
00528 // WakeUp state messages
00529 #define MSG_WAKEUPLEN                           5
00530 #define MSG_WAKEUPACK                           (const unsigned char *)"\xFA\xFF\x3F\x00"
00531 #define MSG_WAKEUPACKLEN                        4
00532 // Config state messages
00533 #define MSG_REQDID                                      (const unsigned char *)"\xFA\xFF\x00\x00"
00534 #define MSG_REQDIDLEN                           4
00535 #define MSG_DEVICEIDLEN                         9
00536 #define MSG_INITBUS                                     (const unsigned char *)"\xFA\xFF\x02\x00"
00537 #define MSG_INITBUSLEN                          4
00538 #define MSG_INITBUSRESMAXLEN            (5 + 4 * MAXSENSORS)
00539 #define MSG_REQPERIOD                           (const unsigned char *)"\xFA\xFF\x04\x00"
00540 #define MSG_REQPERIODLEN                        4
00541 #define MSG_REQPERIODACKLEN                     7
00542 #define MSG_SETPERIOD                           (const unsigned char *)"\xFA\xFF\x04\x02"
00543 #define MSG_SETPERIODLEN                        6
00544 #define MSG_SETPERIODACKLEN                     5
00545 #define MSG_SETBID                                      (const unsigned char *)"\xFA\xFF\x06\x05"
00546 #define MSG_SETBIDLEN                           9
00547 #define MSG_SETBIDACKLEN                        5
00548 #define MSG_AUTOSTART                           (const unsigned char *)"\xFA\xFF\x06\x00"
00549 #define MSG_AUTOSTARTLEN                        4
00550 #define MSG_AUTOSTARTACKLEN                     5
00551 #define MSG_BUSPWROFF                           (const unsigned char *)"\xFA\xFF\x08\x00"
00552 #define MSG_BUSPWROFFLEN                        4
00553 #define MSG_BUSPWROFFACKLEN                     5
00554 #define MSG_RESTOREFACTORYDEF           (const unsigned char *)"\xFA\xFF\x0E\x00"
00555 #define MSG_RESTOREFACTORYDEFLEN        4
00556 #define MSG_RESTOREFACTORYDEFACKLEN     5
00557 #define MSG_REQDATALENGTH                       (const unsigned char *)"\xFA\xFF\x0A\x00"
00558 #define MSG_REQDATALENGTHLEN            4
00559 #define MSG_DATALENGTHLEN                       7
00560 #define MSG_REQCONFIGURATION            (const unsigned char *)"\xFA\xFF\x0C\x00"
00561 #define MSG_REQCONFIGURATIONLEN         4
00562 #define MSG_GOTOMEASUREMENT                     (const unsigned char *)"\xFA\xFF\x10\x00"
00563 #define MSG_GOTOMEASUREMENTLEN          4
00564 #define MSG_GOTOMEASMAN                         (const unsigned char *)"\xFA\x01\x10\x00"
00565 #define MSG_GOTOMEASMANLEN                      4
00566 #define MSG_GOTOMEASACKLEN                      5
00567 #define MSG_REQFWREV                            (const unsigned char *)"\xFA\xFF\x12\x00"
00568 #define MSG_REQFWREVLEN                         4
00569 #define MSG_FIRMWAREREVLEN                      8
00570 #define MSG_REQBTDISABLED                       (const unsigned char *)"\xFA\xFF\x14\x00"
00571 #define MSG_REQBTDISABLEDLEN            4
00572 #define MSG_REQBTDISABLEDACKLEN         6
00573 #define MSG_DISABLEBT                           (const unsigned char *)"\xFA\xFF\x14\x01"
00574 #define MSG_DISABLEBTLEN                        5
00575 #define MSG_DISABLEBTACKLEN                     5
00576 #define MSG_REQOPMODE                           (const unsigned char *)"\xFA\xFF\x16\x00"
00577 #define MSG_REQOPMODELEN                        4
00578 #define MSG_REQOPMODEACKLEN                     6
00579 #define MSG_SETOPMODE                           (const unsigned char *)"\xFA\xFF\x16\x01"
00580 #define MSG_SETOPMODELEN                        5
00581 #define MSG_SETOPMODEACKLEN                     5
00582 #define MSG_REQBAUDRATE                         (const unsigned char *)"\xFA\xFF\x18\x00"
00583 #define MSG_REQBAUDRATELEN                      4
00584 #define MSG_REQBAUDRATEACKLEN           6       
00585 #define MSG_SETBAUDRATE                         (const unsigned char *)"\xFA\xFF\x18\x01"
00586 #define MSG_SETBAUDRATELEN                      5
00587 #define MSG_SETBAUDRATEACKLEN           5
00588 #define MSG_REQSYNCMODE                         (const unsigned char *)"\xFA\xFF\x1A\x00"
00589 #define MSG_REQSYNCMODELEN                      4
00590 #define MSG_REQSYNCMODEACKLEN           6
00591 #define MSG_SETSYNCMODE                         (const unsigned char *)"\xFA\xFF\x1A\x01"
00592 #define MSG_SETSYNCMODELEN                      5
00593 #define MSG_SETSYNCMODEACKLEN           6
00594 #define MSG_REQMTS                                      (const unsigned char *)"\xFA\xFF\x90\x01"
00595 #define MSG_REQMTSLEN                           5
00596 #define MSG_MTSDATA                                     61
00597 #define MSG_STORECUSMTS                         (const unsigned char *)"\xFA\xFF\x92\x58"
00598 #define MSG_STORECUSMTSLEN                      92
00599 #define MSG_STORECUSMTSACKLEN           5
00600 #define MSG_REVTOORGMTS                         (const unsigned char *)"\xFA\xFF\x94\x00"
00601 #define MSG_REVTOORGMTSLEN                      4
00602 #define MSG_REVTOORGMTSACKLEN           5
00603 #define MSG_STOREMTS                            (const unsigned char *)"\xFA\xFF\x96\x41"
00604 #define MSG_STOREMTSLEN                         69
00605 #define MSG_STOREMTSACKLEN                      5
00606 #define MSG_REQSYNCOUTMODE                      (const unsigned char *)"\xFA\xFF\xD8\x01\x00"
00607 #define MSG_REQSYNCOUTMODELEN           5
00608 #define MSG_REQSYNCOUTSKIPFACTOR        (const unsigned char *)"\xFA\xFF\xD8\x01\x01"
00609 #define MSG_REQSYNCOUTSKIPFACTORLEN     5
00610 #define MSG_REQSYNCOUTOFFSET            (const unsigned char *)"\xFA\xFF\xD8\x01\x02"
00611 #define MSG_REQSYNCOUTOFFSETLEN         5
00612 #define MSG_REQSYNCOUTPULSEWIDTH        (const unsigned char *)"\xFA\xFF\xD8\x01\x03"
00613 #define MSG_REQSYNCOUTPULSEWIDTHLEN     5
00614 #define MSG_REQERRORMODE                        (const unsigned char *)"\xFA\xFF\xDA\x00"
00615 #define MSG_REQERRORMODELEN                     4
00616 #define MSG_REQERRORMODEACKLEN          7
00617 // Measurement state - auto messages
00618 #define MSG_GOTOCONFIG                          (const unsigned char *)"\xFA\xFF\x30\x00"
00619 #define MSG_GOTOCONFIGLEN                       4
00620 #define MSG_GOTOCONFIGACKLEN            5
00621 // Measurement state - manual messages (Use DID = 0x01)
00622 #define MSG_GOTOCONFIGM                         (const unsigned char *)"\xFA\x01\x30\x00"
00623 #define MSG_GOTOCONFIGMLEN                      4
00624 #define MSG_GOTOCONFIGMACKLEN           5
00625 #define MSG_PREPAREDATA                         (const unsigned char *)"\xFA\x01\x32\x00"
00626 #define MSG_PREPAREDATALEN                      4
00627 #define MSG_REQDATA                                     (const unsigned char *)"\xFA\x01\x34\x00"
00628 #define MSG_REQDATALEN                          4
00629 // Valid in all states
00630 #define MSG_RESET                                       (const unsigned char *)"\xFA\xFF\x40\x00"
00631 #define MSG_RESETLEN                            4
00632 #define MSG_RESETACKLEN                         5
00633 #define MSG_XMPWROFF                            (const unsigned char *)"\xFA\xFF\x44\x00"
00634 #define MSG_XMPWROFFLEN                         4
00635 #define MSG_XMPWROFFACKLEN                      5
00636 
00637 // Baudrate defines for SetBaudrate message
00638 #define BAUDRATE_9K6                            0x09
00639 #define BAUDRATE_14K4                           0x08
00640 #define BAUDRATE_19K2                           0x07
00641 #define BAUDRATE_28K8                           0x06
00642 #define BAUDRATE_38K4                           0x05
00643 #define BAUDRATE_57K6                           0x04
00644 #define BAUDRATE_76K8                           0x03
00645 #define BAUDRATE_115K2                          0x02
00646 #define BAUDRATE_230K4                          0x01
00647 #define BAUDRATE_460K8                          0x00
00648 #define BAUDRATE_921K6                          0x80
00649 
00650 // Xbus protocol error codes (Error)
00651 #define ERROR_NOBUSCOMM                         0x01
00652 #define ERROR_BUSNOTREADY                       0x02
00653 #define ERROR_PERIODINVALID                     0x03
00654 #define ERROR_MESSAGEINVALID            0x04
00655 #define ERROR_INITOFBUSFAILED1          0x10
00656 #define ERROR_INITOFBUSFAILED2          0x11
00657 #define ERROR_INITOFBUSFAILED3          0x12
00658 #define ERROR_SETBIDPROCFAILED1         0x14
00659 #define ERROR_SETBIDPROCFAILED2         0x15
00660 #define ERROR_MEASUREMENTFAILED1        0x18
00661 #define ERROR_MEASUREMENTFAILED2        0x19
00662 #define ERROR_MEASUREMENTFAILED3        0x1A
00663 #define ERROR_MEASUREMENTFAILED4        0x1B
00664 #define ERROR_MEASUREMENTFAILED5        0x1C
00665 #define ERROR_MEASUREMENTFAILED6        0x1D
00666 #define ERROR_TIMEROVERFLOW                     0x1E
00667 #define ERROR_BAUDRATEINVALID           0x20
00668 #define ERROR_PARAMETERINVALID          0x21
00669 #define ERROR_MEASUREMENTFAILED7        0x23
00670 
00671 // Error modes (SetErrorMode)
00672 #define ERRORMODE_IGNORE                                        0x0000
00673 #define ERRORMODE_INCSAMPLECNT                          0x0001
00674 #define ERRORMODE_INCSAMPLECNT_SENDERROR        0x0002
00675 #define ERRORMODE_SENDERROR_GOTOCONFIG          0x0003
00676 
00677 // Configuration message defines
00678 #define CONF_MASTERDID                          0
00679 #define CONF_PERIOD                                     4
00680 #define CONF_OUTPUTSKIPFACTOR           6
00681 #define CONF_SYNCIN_MODE                        8
00682 #define CONF_SYNCIN_SKIPFACTOR          10
00683 #define CONF_SYNCIN_OFFSET                      12
00684 #define CONF_DATE                                       16
00685 #define CONF_TIME                                       24
00686 #define CONF_NUMDEVICES                         96
00687 // Configuration sensor block properties
00688 #define CONF_DID                                        98
00689 #define CONF_DATALENGTH                         102
00690 #define CONF_OUTPUTMODE                         104
00691 #define CONF_OUTPUTSETTINGS                     106
00692 #define CONF_BLOCKLEN                           20
00693 // To calculate the offset in data field for output mode of sensor #2 use
00694 //              CONF_OUTPUTMODE + 1*CONF_BLOCKLEN
00695 #define CONF_MASTERDIDLEN                       4
00696 #define CONF_PERIODLEN                          2
00697 #define CONF_OUTPUTSKIPFACTORLEN        2
00698 #define CONF_SYNCIN_MODELEN                     2
00699 #define CONF_SYNCIN_SKIPFACTORLEN       2
00700 #define CONF_SYNCIN_OFFSETLEN           4
00701 #define CONF_DATELEN                            8
00702 #define CONF_TIMELEN                            8
00703 #define CONF_RESERVED_CLIENTLEN         32
00704 #define CONF_RESERVED_HOSTLEN           32
00705 #define CONF_NUMDEVICESLEN                      2
00706 // Configuration sensor block properties
00707 #define CONF_DIDLEN                                     4
00708 #define CONF_DATALENGTHLEN                      2
00709 #define CONF_OUTPUTMODELEN                      2
00710 #define CONF_OUTPUTSETTINGSLEN          4
00711 
00712 // Clock frequency for offset & pulse width
00713 #define SYNC_CLOCKFREQ                          29.4912e6
00714 
00715 // SyncIn params
00716 #define PARAM_SYNCIN_MODE                       (const unsigned char)0x00
00717 #define PARAM_SYNCIN_SKIPFACTOR         (const unsigned char)0x01
00718 #define PARAM_SYNCIN_OFFSET                     (const unsigned char)0x02
00719 
00720 // SyncIn mode
00721 #define SYNCIN_DISABLED                         0x0000
00722 #define SYNCIN_EDGE_RISING                      0x0001
00723 #define SYNCIN_EDGE_FALLING                     0x0002
00724 #define SYNCIN_EDGE_BOTH                        0x0003
00725 #define SYNCIN_TYPE_SENDLASTDATA        0x0004
00726 #define SYNCIN_TYPE_DOSAMPLING          0x0000
00727 #define SYNCIN_EDGE_MASK                        0x0003
00728 #define SYNCIN_TYPE_MASK                        0x000C
00729 
00730 // SyncOut params
00731 #define PARAM_SYNCOUT_MODE                      (const unsigned char)0x00
00732 #define PARAM_SYNCOUT_SKIPFACTOR        (const unsigned char)0x01
00733 #define PARAM_SYNCOUT_OFFSET            (const unsigned char)0x02
00734 #define PARAM_SYNCOUT_PULSEWIDTH        (const unsigned char)0x03
00735 
00736 // SyncOut mode
00737 #define SYNCOUT_DISABLED                0x0000
00738 #define SYNCOUT_TYPE_TOGGLE             0x0001
00739 #define SYNCOUT_TYPE_PULSE              0x0002
00740 #define SYNCOUT_POL_NEG                 0x0000
00741 #define SYNCOUT_POL_POS                 0x0010
00742 #define SYNCOUT_TYPE_MASK               0x000F
00743 #define SYNCOUT_POL_MASK                0x0010
00744 
00745 // Sample frequencies (SetPeriod)
00746 #define PERIOD_10HZ                             0x2D00
00747 #define PERIOD_12HZ                             0x2580
00748 #define PERIOD_15HZ                             0x1E00
00749 #define PERIOD_16HZ                             0x1C20
00750 #define PERIOD_18HZ                             0x1900
00751 #define PERIOD_20HZ                             0x1680
00752 #define PERIOD_24HZ                             0x12C0
00753 #define PERIOD_25HZ                             0x1200
00754 #define PERIOD_30HZ                             0x0F00
00755 #define PERIOD_32HZ                             0x0E10
00756 #define PERIOD_36HZ                             0x0C80
00757 #define PERIOD_40HZ                             0x0B40
00758 #define PERIOD_45HZ                             0x0A00
00759 #define PERIOD_48HZ                             0x0960
00760 #define PERIOD_50HZ                             0x0900
00761 #define PERIOD_60HZ                             0x0780
00762 #define PERIOD_64HZ                             0x0708
00763 #define PERIOD_72HZ                             0x0640
00764 #define PERIOD_75HZ                             0x0600
00765 #define PERIOD_80HZ                             0x05A0
00766 #define PERIOD_90HZ                             0x0500
00767 #define PERIOD_96HZ                             0x04B0
00768 #define PERIOD_100HZ                    0x0480
00769 #define PERIOD_120HZ                    0x03C0
00770 #define PERIOD_128HZ                    0x0384
00771 #define PERIOD_144HZ                    0x0320
00772 #define PERIOD_150HZ                    0x0300
00773 #define PERIOD_160HZ                    0x02D0
00774 #define PERIOD_180HZ                    0x0280
00775 #define PERIOD_192HZ                    0x0258
00776 #define PERIOD_200HZ                    0x0240
00777 #define PERIOD_225HZ                    0x0200
00778 #define PERIOD_240HZ                    0x01E0
00779 #define PERIOD_256HZ                    0x01C2
00780 #define PERIOD_288HZ                    0x0190
00781 #define PERIOD_300HZ                    0x0180
00782 #define PERIOD_320HZ                    0x0168
00783 #define PERIOD_360HZ                    0x0140
00784 #define PERIOD_384HZ                    0x012C
00785 #define PERIOD_400HZ                    0x0120
00786 #define PERIOD_450HZ                    0x0100
00787 #define PERIOD_480HZ                    0x00F0
00788 #define PERIOD_512HZ                    0x00E1
00789 
00790 // OutputModes
00791 #define OUTPUTMODE_MT9                          0x8000
00792 #define OUTPUTMODE_XM                           0x0000
00793 #define OUTPUTMODE_RAW                          0x4000
00794 #define OUTPUTMODE_TEMP                         0x0001
00795 #define OUTPUTMODE_CALIB                        0x0002
00796 #define OUTPUTMODE_ORIENT                       0x0004
00797 
00798 // OutputSettings
00799 #define OUTPUTSETTINGS_XM                                               0x00000001
00800 #define OUTPUTSETTINGS_TIMESTAMP_NONE                   0x00000000
00801 #define OUTPUTSETTINGS_TIMESTAMP_SAMPLECNT              0x00000001
00802 #define OUTPUTSETTINGS_ORIENTMODE_QUATERNION    0x00000000
00803 #define OUTPUTSETTINGS_ORIENTMODE_EULER                 0x00000004
00804 #define OUTPUTSETTINGS_ORIENTMODE_MATRIX                0x00000008
00805 #define OUTPUTSETTINGS_CALIBMODE_ACCGYRMAG              0x00000000
00806 #define OUTPUTSETTINGS_CALIBMODE_ACC                    0x00000060
00807 #define OUTPUTSETTINGS_CALIBMODE_ACCGYR                 0x00000040
00808 #define OUTPUTSETTINGS_CALIBMODE_ACCMAG                 0x00000020
00809 #define OUTPUTSETTINGS_CALIBMODE_GYR                    0x00000050
00810 #define OUTPUTSETTINGS_CALIBMODE_GYRMAG                 0x00000010
00811 #define OUTPUTSETTINGS_CALIBMODE_MAG                    0x00000030
00812 #define OUTPUTSETTINGS_DATAFORMAT_FLOAT                 0x00000000
00813 #define OUTPUTSETTINGS_DATAFORMAT_F1220                 0x00000100
00814 #define OUTPUTSETTINGS_TIMESTAMP_MASK                   0x00000003
00815 #define OUTPUTSETTINGS_ORIENTMODE_MASK                  0x0000000C
00816 #define OUTPUTSETTINGS_CALIBMODE_ACC_MASK               0x00000010
00817 #define OUTPUTSETTINGS_CALIBMODE_GYR_MASK               0x00000020
00818 #define OUTPUTSETTINGS_CALIBMODE_MAG_MASK               0x00000040
00819 #define OUTPUTSETTINGS_CALIBMODE_MASK                   0x00000070
00820 #define OUTPUTSETTINGS_DATAFORMAT_MASK                  0x00000300
00821 
00822 // Extended Output Modes
00823 #define EXTOUTPUTMODE_DISABLED                  0x0000
00824 #define EXTOUTPUTMODE_EULER                             0x0001
00825 
00826 // Factory Output Mode
00827 #define FACTORYOUTPUTMODE_DISABLE               0x0000
00828 #define FACTORYOUTPUTMODE_DEFAULT               0x0001
00829 #define FACTORYOUTPUTMODE_CUSTOM                0x0002
00830 
00831 // Initial tracking mode (SetInitTrackMode)
00832 #define INITTRACKMODE_DISABLED          0x0000
00833 #define INITTRACKMODE_ENABLED           0x0001
00834 
00835 // Filter settings params
00836 #define PARAM_FILTER_GAIN                       (const unsigned char)0x00
00837 #define PARAM_FILTER_RHO                        (const unsigned char)0x01
00838 #define DONOTSTORE                                      0x00
00839 #define STORE                                           0x01
00840 
00841 // AMDSetting (SetAMD)
00842 #define AMDSETTING_DISABLED                     0x0000
00843 #define AMDSETTING_ENABLED                      0x0001
00844 
00845 // Reset orientation message type
00846 #define RESETORIENTATION_STORE          0
00847 #define RESETORIENTATION_HEADING        1
00848 #define RESETORIENTATION_GLOBAL         2
00849 #define RESETORIENTATION_OBJECT         3
00850 #define RESETORIENTATION_ALIGN          4
00851 
00852 // Send raw string mode
00853 #define SENDRAWSTRING_INIT                      0
00854 #define SENDRAWSTRING_DEFAULT           1
00855 #define SENDRAWSTRING_SEND                      2
00856 
00857 // Timeouts     
00858 #define TO_DEFAULT                                      500
00859 #define TO_INIT                                         250
00860 #define TO_RETRY                                        50
00861 
00862 // openPort baudrates
00863 #ifdef WIN32
00864 #define PBR_9600                                        CBR_9600
00865 #define PBR_14K4                                        CBR_14400
00866 #define PBR_19K2                                        CBR_19200
00867 #define PBR_28K8                                        28800
00868 #define PBR_38K4                                        CBR_38400
00869 #define PBR_57K6                                        CBR_57600
00870 #define PBR_76K8                                        76800
00871 #define PBR_115K2                                       CBR_115200
00872 #define PBR_230K4                                       230400
00873 #define PBR_460K8                                       460800
00874 #define PBR_921K6                                       921600
00875 #else
00876 #define PBR_9600                                        B9600
00877 #define PBR_14K4                                        B14400
00878 #define PBR_19K2                                        B19200
00879 #define PBR_28K8                                        B28800
00880 #define PBR_38K4                                        B38400
00881 #define PBR_57K6                                        B57600
00882 #define PBR_76K8                                        B76800
00883 #define PBR_115K2                                       B115200
00884 #define PBR_230K4                                       B230400
00885 #define PBR_460K8                                       B460800
00886 #define PBR_921K6                                       B921600
00887 #endif
00888 
00889 // setFilePos defines
00890 #ifdef WIN32
00891 #define FILEPOS_BEGIN                           FILE_BEGIN
00892 #define FILEPOS_CURRENT                         FILE_CURRENT
00893 #define FILEPOS_END                                     FILE_END
00894 #else
00895 #define FILEPOS_BEGIN                           SEEK_SET
00896 #define FILEPOS_CURRENT                         SEEK_CUR
00897 #define FILEPOS_END                                     SEEK_END
00898 #endif
00899 
00900 // Return values
00901 #define MTRV_OK                                         0       // Operation successful
00902 #define MTRV_NOTSUCCESSFUL                      1       // General no success return value
00903 #define MTRV_TIMEOUT                            2       // Operation aborted because of a timeout
00904 #define MTRV_TIMEOUTNODATA                      3       // Operation aborted because of no data read
00905 #define MTRV_CHECKSUMFAULT                      4       // Checksum fault occured
00906 #define MTRV_NODATA                                     5       // No data is received
00907 #define MTRV_RECVERRORMSG                       6       // A error message is received
00908 #define MTRV_OUTOFMEMORY                        7       // No internal memory available
00909 #define MTRV_UNKNOWDATA                         8       // An invalid message is read
00910 #define MTRV_INVALIDTIMEOUT                     9       // An invalid value is used to set the timeout
00911 #define MTRV_UNEXPECTEDMSG                      10      // Unexpected message received (e.g. no acknowledge message received)
00912 #define MTRV_INPUTCANNOTBEOPENED        11      // The specified file / serial port can not be opened
00913 #define MTRV_ANINPUTALREADYOPEN         12      // File and serial port can not be opened at same time
00914 #define MTRV_ENDOFFILE                          13      // End of file is reached
00915 #define MTRV_NOINPUTINITIALIZED         14      // No file or serial port opened for reading/writing
00916 #define MTRV_NOVALIDMODESPECIFIED       15      // No valid outputmode or outputsettings are specified (use 
00917                                                                                 // mtGetDeviceMode or mtSetMode)
00918 #define MTRV_INVALIDVALUESPEC           16      // Value specifier does not match value type or not available in data
00919 #define MTRV_INVALIDFORFILEINPUT        17      // Function is not valid for file based interfaces
00920 
00921 class CMTComm  
00922 {
00923 public:
00924         CMTComm();
00925         virtual ~CMTComm();
00926 
00927         // Low level general functions
00928         clock_t clockms();
00929 
00930         // Low level COM port / file functions
00931         short   openPort(const int portNumber, const unsigned long baudrate = PBR_115K2, const unsigned long inqueueSize = 4096, const unsigned long outqueueSize = 1024);
00932         short   openPort(const char *portName, const unsigned long baudrate = PBR_115K2, const unsigned long inqueueSize = 4096, const unsigned long outqueueSize = 1024);
00933         short   openFile(const char *fileName, bool createAlways = false);
00934         bool    isPortOpen();
00935         bool    isFileOpen();
00936         int     readData(unsigned char* msgBuffer, const int nBytesToRead);
00937         int             writeData(const unsigned char* msgBuffer, const int nBytesToWrite);
00938         void    flush();
00939         void    escape(unsigned long function);
00940         void    setPortQueueSize(const unsigned long inqueueSize = 4096, const unsigned long outqueueSize = 1024);
00941         short   setFilePos(long relPos, unsigned long moveMethod = FILEPOS_BEGIN);
00942         short   getFileSize(unsigned long &fileSize);
00943         short   close();
00944 
00945         // Read & write message functions
00946         short   readMessage(unsigned char &mid, unsigned char data[], short &dataLen, unsigned char *bid = NULL);
00947         short   readDataMessage(unsigned char data[], short &dataLen);
00948         short   readMessageRaw(unsigned char *msgBuffer, short *msgBufferLength);
00949         short   writeMessage(const unsigned char mid, const unsigned long dataValue = 0, 
00950                                                   const unsigned char dataValueLen = 0, const unsigned char bid = BID_MASTER);
00951         short   writeMessage(const unsigned char mid, const unsigned char data[], 
00952                                                            const unsigned short &dataLen, const unsigned char bid = BID_MASTER);
00953         short   waitForMessage(const unsigned char mid, unsigned char data[] = NULL, short *dataLen = NULL, unsigned char *bid = NULL);
00954 
00955         // Request & set setting functions
00956         short   reqSetting(const unsigned char mid, unsigned long &value, const unsigned char bid = BID_MASTER);
00957         short   reqSetting(const unsigned char mid, const unsigned char param, unsigned long &value,  
00958                                                           const unsigned char bid = BID_MASTER);
00959         short   reqSetting(const unsigned char mid, float &value, const unsigned char bid = BID_MASTER);
00960         short   reqSetting(const unsigned char mid, const unsigned char param, float &value,
00961                                                           const unsigned char bid = BID_MASTER);
00962         short   reqSetting(const unsigned char mid, 
00963                                                           unsigned char data[], short &dataLen, const unsigned char bid = BID_MASTER);
00964         short   reqSetting(const unsigned char mid,
00965                                                           unsigned char dataIn[], short dataInLen,
00966                                                           unsigned char dataOut[], short &dataOutLen, 
00967                                                           const unsigned char bid = BID_MASTER);
00968         short   reqSetting(const unsigned char mid, const unsigned char param, 
00969                                                           unsigned char data[], short &dataLen, const unsigned char bid = BID_MASTER);
00970         short   setSetting(const unsigned char mid,
00971                                                           const unsigned long value, const unsigned short valuelen,
00972                                                           const unsigned char bid = BID_MASTER);
00973         short   setSetting(const unsigned char mid, const unsigned char param,
00974                                                           const unsigned long value, const unsigned short valuelen,
00975                                                           const unsigned char bid = BID_MASTER);
00976         short   setSetting(const unsigned char mid, const float value, const unsigned char bid = BID_MASTER);
00977         short   setSetting(const unsigned char mid, const unsigned char param,
00978                                                           const float value, const unsigned char bid = BID_MASTER);
00979         short   setSetting(const unsigned char mid, const unsigned char param,
00980                                                           const float value, const bool store, const unsigned char bid = BID_MASTER);
00981         // Data-related functions
00982         short   getDeviceMode(unsigned short *numDevices = NULL);
00983         short   setDeviceMode(unsigned long OutputMode, unsigned long OutputSettings, const unsigned char bid = BID_MASTER);
00984         short   getMode(unsigned long &OutputMode, unsigned long &OutputSettings, unsigned short &dataLength, 
00985                                           const unsigned char bid = BID_MASTER);
00986         short   setMode(unsigned long OutputMode, unsigned long OutputSettings, const unsigned char bid = BID_MASTER);
00987         short   getValue(const unsigned long valueSpec, unsigned short &value, const unsigned char data[], 
00988                                            const unsigned char bid = BID_MT);
00989         short   getValue(const unsigned long valueSpec, unsigned short value[], const unsigned char data[], 
00990                                            const unsigned char bid = BID_MT);
00991         short   getValue(const unsigned long valueSpec, float value[], const unsigned char data[], 
00992                                            const unsigned char bid = BID_MT);
00993 
00994         // Generic MTComm functions
00995         short   getLastDeviceError();
00996         short   getLastRetVal();
00997         short   setTimeOut(short timeOutMs);
00998         static void     swapEndian(const unsigned char input[], unsigned char output[], const short length);
00999         void    calcChecksum(unsigned char *msgBuffer, const int msgBufferLength);
01000         bool    checkChecksum(const unsigned char *msgBuffer, const int msgBufferLength);       
01001 protected:
01002         // member variables
01003 #ifdef WIN32
01004         HANDLE  m_handle;
01005 #else
01006         int             m_handle;
01007 #endif
01008         bool    m_portOpen;
01009         bool    m_fileOpen;
01010         short   m_deviceError;
01011         short   m_retVal;
01012         short   m_timeOut;
01013         clock_t m_clkEnd;
01014 
01015         // OutputMode, OutputSettings & DataLength for connected devices + 1 for master
01016         unsigned long   m_storedOutputMode[MAXDEVICES+1];
01017         unsigned long   m_storedOutputSettings[MAXDEVICES+1];
01018         unsigned long   m_storedDataLength[MAXDEVICES+1];
01019 
01020         // Temporary buffer for excess bytes read in ReadMessageRaw
01021         unsigned char   m_tempBuffer[MAXMSGLEN];
01022         int                             m_nTempBufferLen;
01023 
01024 private:
01025 };
01026 
01027 #endif // !defined(AFX_XBUS_H__F4580A3F_2CF2_4ED2_A747_B4B015A0328E__INCLUDED_)

Last updated 12 September 2005 21:38:45