IGSTK
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"
55 
56 #include <string>
57 
58 namespace igstk
59 {
60 
70 {
71  FB_POINT = 'B',
72  FB_STREAM = '@',
77 
79  FB_C_ANGLES = 'W',
80  FB_C_MATRIX = 'X',
85 
88 
93 
94  FB_FBB_RESET = '/',
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',
106 
109 };
110 
119 {
120  FB_POSITION = 'V',
121  FB_ANGLES = 'W',
122  FB_MATRIX = 'X',
127 };
128 
136 {
140  FB_STATUS_XOFF = 0x0040,
147  FB_STATUS_ERROR = 0x2000,
150 };
151 
161 {
170 };
171 
177 {
188 };
189 
198 {
202 };
203 
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 
229 {
232 };
233 
242 {
243  FB_STATUS = 0,
245  FB_SPEED = 2,
248  FB_FILTER = 4,
251  FB_RATE = 7,
258  FB_VM = 12,
284 };
285 
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,
299 };
300 
302 {
303 public:
304 
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 
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 
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 
474 
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 */