IGSTK
Main Page
Namespaces
Classes
Files
File List
File Members
Source
igstkAscensionCommandInterpreter.h
Go to the documentation of this file.
1
/*=========================================================================
2
3
Program: Image Guided Surgery Software Toolkit
4
Module: $RCSfile: igstkAscensionCommandInterpreter.h,v $
5
Language: C++
6
Date: $Date: 2009-01-30 19:33:49 $
7
Version: $Revision: 1.1 $
8
9
Copyright (c) ISC Insight Software Consortium. All rights reserved.
10
See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
11
12
This software is distributed WITHOUT ANY WARRANTY; without even
13
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
PURPOSE. See the above copyright notices for more information.
15
16
=========================================================================
17
18
Copyright (c) 2000-2005 Atamai, Inc.
19
20
Use, modification and redistribution of the software, in source or
21
binary forms, are permitted provided that the following terms and
22
conditions are met:
23
24
1) Redistribution of the source code, in verbatim or modified
25
form, must retain the above copyright notice, this license,
26
the following disclaimer, and any notices that refer to this
27
license and/or the following disclaimer.
28
29
2) Redistribution in binary form must include the above copyright
30
notice, a copy of this license and the following disclaimer
31
in the documentation or with other materials provided with the
32
distribution.
33
34
3) Modified copies of the source code must be clearly marked as such,
35
and must not be misrepresented as verbatim copies of the source code.
36
37
THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS"
38
WITHOUT EXPRESSED OR IMPLIED WARRANTY INCLUDING, BUT NOT LIMITED TO,
39
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40
PURPOSE. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR OTHER PARTY WHO MAY
41
MODIFY AND/OR REDISTRIBUTE THE SOFTWARE UNDER THE TERMS OF THIS LICENSE
42
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES
43
(INCLUDING, BUT NOT LIMITED TO, LOSS OF DATA OR DATA BECOMING INACCURATE
44
OR LOSS OF PROFIT OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF
45
THE USE OR INABILITY TO USE THE SOFTWARE, EVEN IF ADVISED OF THE
46
POSSIBILITY OF SUCH DAMAGES.
47
48
=======================================================================*/
49
50
#ifndef __igstkAscensionCommandInterpreter_h
51
#define __igstkAscensionCommandInterpreter_h
52
53
#include "
igstkObject.h
"
54
#include "
igstkSerialCommunication.h
"
55
56
#include <string>
57
58
namespace
igstk
59
{
60
69
enum
AscensionCommand
70
{
71
FB_POINT
=
'B'
,
72
FB_STREAM
=
'@'
,
73
FB_REPORT_RATE_FULL
=
'Q'
,
74
FB_REPORT_RATE_DIV2
=
'R'
,
75
FB_REPORT_RATE_DIV8
=
'S'
,
76
FB_REPORT_RATE_DIV32
=
'T'
,
77
78
FB_C_POSITION
=
'V'
,
79
FB_C_ANGLES
=
'W'
,
80
FB_C_MATRIX
=
'X'
,
81
FB_C_POSITION_ANGLES
=
'Y'
,
82
FB_C_POSITION_MATRIX
=
'Z'
,
83
FB_C_QUATERNION
=
'\\'
,
84
FB_C_POSITION_QUATERNION
=
']'
,
85
86
FB_BUTTON_MODE
=
'M'
,
87
FB_BUTTON_READ
=
'N'
,
88
89
FB_ANGLE_ALIGN1
=
'J'
,
90
FB_REFERENCE_FRAME1
=
'H'
,
91
FB_ANGLE_ALIGN2
=
'q'
,
92
FB_REFERENCE_FRAME2
=
'r'
,
93
94
FB_FBB_RESET
=
'/'
,
95
FB_HEMISPHERE
=
'L'
,
96
FB_NEXT_TRANSMITTER
=
'0'
,
97
FB_RUN
=
'F'
,
98
FB_SLEEP
=
'G'
,
99
FB_SYNC
=
'A'
,
100
FB_XOFF
=
'\x13'
,
101
FB_XON
=
'\x11'
,
102
103
FB_RS232_TO_FBB
=
'\xF0'
,
104
FB_RS232_TO_FBB_E
=
'\xE0'
,
105
FB_RS232_TO_FBB_SE
=
'\xA0'
,
106
107
FB_EXAMINE_VALUE
=
'O'
,
108
FB_CHANGE_VALUE
=
'P'
,
109
};
110
118
enum
AscensionDataFormat
119
{
120
FB_POSITION
=
'V'
,
121
FB_ANGLES
=
'W'
,
122
FB_MATRIX
=
'X'
,
123
FB_POSITION_ANGLES
=
'Y'
,
124
FB_POSITION_MATRIX
=
'Z'
,
125
FB_QUATERNION
=
'\\'
,
126
FB_POSITION_QUATERNION
=
']'
,
127
};
128
135
enum
AscensionStatusBits
136
{
137
FB_STATUS_STREAMING
= 0x0001,
138
FB_STATUS_FORMAT
= 0x001E,
139
FB_STATUS_SLEEPING
= 0x0020,
140
FB_STATUS_XOFF
= 0x0040,
141
FB_STATUS_FACTORY
= 0x0080,
142
FB_STATUS_NO_SYNC
= 0x0100,
143
FB_STATUS_CRT_SYNC
= 0x0200,
144
FB_STATUS_EXPANDED
= 0x0400,
145
FB_STATUS_HOST_SYNC
= 0x0800,
146
FB_STATUS_RUNNING
= 0x1000,
147
FB_STATUS_ERROR
= 0x2000,
148
FB_STATUS_INITIALIZED
= 0x4000,
149
FB_STATUS_MASTER
= 0x8000,
150
};
151
160
enum
AscensionBusStatusBits
161
{
162
FB_FBB_STATUS_ERT0
= 0x01,
163
FB_FBB_STATUS_ERT1
= 0x02,
164
FB_FBB_STATUS_ERT2
= 0x04,
165
FB_FBB_STATUS_ERT3
= 0x08,
166
FB_FBB_STATUS_ERT
= 0x10,
167
FB_FBB_STATUS_SENSOR
= 0x20,
168
FB_FBB_STATUS_RUNNING
= 0x40,
169
FB_FBB_STATUS_ACCESSIBLE
= 0x80,
170
};
171
176
enum
AscensionErrorCode
177
{
178
FB_NO_ERROR
= 0,
179
FB_OPEN_ERROR
= 1,
180
FB_COM_ERROR
= 2,
181
FB_IO_ERROR
= 3,
182
FB_TIMEOUT_ERROR
= 4,
183
FB_PARM_ERROR
= 5,
184
FB_COMMAND_ERROR
= 6,
185
FB_ILLEGAL_ERROR
= 7,
186
FB_PHASE_ERROR
= 8,
187
FB_RESOURCE_ERROR
= 9,
188
};
189
197
enum
AscensionAddressMode
198
{
199
FB_NORMAL
= 0,
200
FB_EXPANDED
= 1,
201
FB_SUPER_EXPANDED
= 3,
202
};
203
210
enum
AscensionHemisphere
211
{
212
FB_FORWARD
= 0x0000,
213
FB_AFT
= 0x0100,
214
FB_UPPER
= 0x010C,
215
FB_LOWER
= 0x000C,
216
FB_LEFT
= 0x0106,
217
FB_RIGHT
= 0x0006,
218
};
219
228
enum
AscensionPositionScale
229
{
230
FB_STANDARD
= 0,
231
FB_EXTENDED
= 1,
232
};
233
241
enum
AscensionParameter
242
{
243
FB_STATUS
= 0,
244
FB_REVISION
= 1,
245
FB_SPEED
= 2,
246
FB_POSITION_SCALING
= 3,
248
FB_FILTER
= 4,
249
FB_ALPHA_MIN
= 5,
250
FB_RATE_COUNT
= 6,
251
FB_RATE
= 7,
253
FB_DATA_READY
= 8,
254
FB_DATA_READY_CHAR
= 9,
255
FB_ERROR_CODE
= 10,
256
FB_ERROR_BEHAVIOR
= 11,
258
FB_VM
= 12,
259
FB_ALPHA_MAX
= 13,
260
FB_ELIMINATION
= 14,
261
FB_IDENTIFICATION
= 15,
263
FB_ERROR_CODE_EXPANDED
= 16,
264
FB_REFERENCE_FRAME
= 17,
265
FB_TRANSMITTER_MODE
= 18,
266
FB_FBB_ADDRESS_MODE
= 19,
268
FB_LINE_FILTER
= 20,
269
FB_FBB_ADDRESS
= 21,
270
FB_P_HEMISPHERE
= 22,
271
FB_P_ANGLE_ALIGN2
= 23,
273
FB_P_REFERENCE_FRAME2
= 24,
274
FB_SERIAL_NUMBER
= 25,
275
FB_SENSOR_SERIAL_NUMBER
= 26,
276
FB_XMTR_SERIAL_NUMBER
= 27,
278
FB_FBB_DELAY
= 32,
279
FB_GROUP_MODE
= 35,
281
FB_FBB_STATUS
= 36,
283
FB_FBB_AUTOCONFIG
= 50,
284
};
285
290
enum
AscensionBaudRate
291
{
292
FB_2400
= 0,
293
FB_4800
= 1,
294
FB_9600
= 2,
295
FB_19200
= 3,
296
FB_38400
= 4,
297
FB_57600
= 5,
298
FB_115200
= 6,
299
};
300
301
class
AscensionCommandInterpreter
:
public
Object
302
{
303
public
:
304
306
igstkStandardClassTraitsMacro
(
AscensionCommandInterpreter
,
Object
)
307
308
public
:
309
311
typedef
SerialCommunication
CommunicationType;
312
314
void
SetCommunication(CommunicationType* communication);
315
317
CommunicationType*
GetCommunication
();
318
320
void
Open
();
321
323
void
Stop
();
324
void
Run
();
325
327
void
Close
();
328
330
void
Reset
();
331
333
void
SetHemisphere
(
AscensionHemisphere
hemisphere);
334
336
void
SetFormat
(
AscensionDataFormat
format);
337
339
void
SetButtonMode
(
bool
mode);
340
342
void
Point
();
343
345
void
Stream
();
346
348
void
EndStream
();
349
352
void
EndStreamIfStreaming
();
353
359
void
Update
();
360
366
unsigned
int
GetBird
();
367
373
void
GetPosition
(
float
xyz[3]);
374
379
void
GetAngles
(
float
zyx[3]);
380
387
void
GetMatrix
(
float
a[9]);
388
395
void
GetQuaternion
(
float
q[4]);
396
402
int
GetButton
();
403
405
void
MatrixFromAngles
(
float
a[9],
const
float
zyx[3]);
406
408
void
AnglesFromMatrix
(
float
zyx[3],
const
float
a[9]);
409
411
void
FBBReset
();
412
414
void
FBBAutoConfig
(
unsigned
int
num);
415
417
void
RS232ToFBB
(
unsigned
int
bird);
418
420
void
SendCommand
(
AscensionCommand
command);
421
423
void
SendCommandWords
(
AscensionCommand
command,
const
short
*data);
424
426
void
SendCommandBytes
(
AscensionCommand
command,
const
char
*data);
427
429
int
ExamineValue
(
AscensionParameter
parm);
430
432
int
ExamineValueWords
(
AscensionParameter
parm,
short
*data);
433
435
int
ExamineValueBytes
(
AscensionParameter
parm,
char
*data);
436
438
void
ChangeValue
(
AscensionParameter
parm,
int
data);
439
441
void
ChangeValueWords
(
AscensionParameter
parm,
const
short
*data);
442
444
void
ChangeValueBytes
(
AscensionParameter
parm,
const
char
*data);
445
452
AscensionErrorCode
GetError
();
453
455
const
char
*
GetErrorMessage
();
456
462
void
ButtonRead
(
int
*val);
463
465
int
GetShort
(
const
char
*cp);
466
468
void
PutShort
(
char
*cp,
int
val);
469
470
protected
:
471
473
AscensionCommandInterpreter
();
474
476
virtual
~AscensionCommandInterpreter
();
477
479
virtual
void
PrintSelf
( std::ostream& os, itk::Indent indent )
const
;
480
481
private
:
482
484
void
ReceiveRaw(
char
*reply,
unsigned
int
len);
485
487
void
SendRaw(
const
char
*text,
unsigned
int
len);
488
490
int
Unpack(
char
**cp);
491
493
void
SetErrorAndMessage(
AscensionErrorCode
errorcode,
const
char
*text);
494
495
/* stores last error */
496
AscensionErrorCode
m_Error;
497
498
/* stores text for last error */
499
std::string m_ErrorText;
500
501
/* revision number (quite important) */
502
int
m_Revision;
503
504
/* max examine/change parameter number for this rev */
505
AscensionParameter
m_MaxParameter;
506
507
/* FBB addressing mode */
508
AscensionAddressMode
m_AddressMode;
509
510
/* birds are in group mode */
511
bool
m_GroupMode;
512
513
/* number of running birds */
514
unsigned
int
m_NumberOfBirds;
515
516
/* true if currently stream */
517
bool
m_StreamData;
518
519
/* true if currently point */
520
bool
m_PointData;
521
522
/* stores bird address after RS232_TO_FBB */
523
unsigned
int
m_FBBAddress;
524
525
/* the bird which this data set is for */
526
unsigned
int
m_CurrentBird;
527
528
/* position scale mode for each bird */
529
AscensionPositionScale
m_PositionScale[128];
530
531
/* button mode for each bird */
532
bool
m_ButtonMode[128];
533
534
/* FB_POSITION, FB_ANGLES, etc for each bird */
535
AscensionDataFormat
m_DataFormat[128];
536
537
/* place where data is stored after being read */
538
char
m_DataBuffer[256];
539
540
/* leftover chars after a phase error */
541
unsigned
int
m_PhaseErrorLeftoverBytes;
542
544
CommunicationType::Pointer m_Communication;
545
};
546
547
}
/* end namespace igstk */
548
549
#endif
/* __igstkAscensionCommandInterpreter_h */
Generated on Thu Mar 20 2014 13:04:04 for IGSTK by
1.8.1.2