This file is indexed.

/usr/include/IGSTK/igstkSerialCommunication.h is in libigstk4-dev 4.4.0-6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/*=========================================================================

  Program:   Image Guided Surgery Software Toolkit
  Module:    $RCSfile: igstkSerialCommunication.h,v $
  Language:  C++
  Date:      $Date: 2008-02-11 01:41:51 $
  Version:   $Revision: 1.16 $

  Copyright (c) ISC  Insight Software Consortium.  All rights reserved.
  See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#ifndef __igstkSerialCommunication_h
#define __igstkSerialCommunication_h

// Disabling warning C4355: 'this' : used in base member initializer list
#if defined(_MSC_VER)
#pragma warning ( disable : 4355 )
#endif

#include "itkObject.h"
#include "itkEventObject.h"
#include "igstkLogger.h"
#include "itkStdStreamLogOutput.h"

#include "igstkMacros.h"
#include "igstkEvents.h"
#include "igstkCommunication.h"
#include "igstkStateMachine.h"


namespace igstk
{

/** \class SerialCommunication
 * 
 * \brief This class implements communication over a serial port
 *        via RS-232.
 *
 * This class provides a common interface for the interactions with a serial
 * port independently of the platform. The actual interactions are implemented
 * on derived classes that are platform specific. This class is not intended
 * for being instantiated directly, instead, the derived classes should be
 * used.
 * 
 * \image html  igstkSerialCommunication.png 
 *               "Serial Communication State Machine Diagram"
 *
 * \image latex igstkSerialCommunication.eps 
 *               "Serial Communication State Machine Diagram"
 * 
 *
 *
 *
 * \ingroup Communication
 */

class SerialCommunication : public Communication
{
public:

  /** Available port numbers. */
  enum PortNumberType { PortNumber0 = 0,
                        PortNumber1 = 1,
                        PortNumber2 = 2,
                        PortNumber3 = 3,
                        PortNumber4 = 4,
                        PortNumber5 = 5,
                        PortNumber6 = 6,
                        PortNumber7 = 7 };

  /** Available baud rates. */
  enum BaudRateType { BaudRate9600 = 9600,
                      BaudRate19200 = 19200,
                      BaudRate38400 = 38400,
                      BaudRate57600 = 57600,
                      BaudRate115200 = 115200 };

  /** Available data bits settings. */
  enum DataBitsType { DataBits7 = 7,
                      DataBits8 = 8 };

  /** Available parity settings. */
  enum ParityType { NoParity = 'N',
                    OddParity = 'O',
                    EvenParity = 'E' };

  /** Available stop bits settings. */
  enum StopBitsType { StopBits1 = 1,
                      StopBits2 = 2 };

  /** Available hardware handshaking settings. */
  enum HandshakeType { HandshakeOff = 0,
                       HandshakeOn = 1 };

  typedef Communication::ResultType      ResultType;

  /** Standard traits of a basic class */
  igstkStandardClassBasicTraitsMacro( SerialCommunication, Communication );

  /** Customized New method that will return the implementation of
   * SerialCommunication that is appropriate for this platform.  
   * \sa SerialCommunicationForWindows 
   * \sa SerialCommunicationForPosix
   */
  static Pointer New(void);


  /** Specify which serial port to use.  If communication is open,
   *  this has no effect until communication is closed and reopened. */
  igstkSetMacro( PortNumber, PortNumberType );
  /** Get the serial port, where the ports are numbered 0 through 3. */
  igstkGetMacro( PortNumber, PortNumberType );

  /** Set the baud rate to use.  Baud rates of 57600 or higher should
   *  not be used unless some sort of error checking is in place. */
  igstkSetMacro( BaudRate, BaudRateType );
  /** Get the baud rate. */
  igstkGetMacro( BaudRate, BaudRateType );

  /** Set the number of bits per character.  This should usually be
   *  set to 8, since 7 bits is only valid for pure ASCII data. */
  igstkSetMacro( DataBits, DataBitsType );
  /** Get the number of bits per character. */
  igstkGetMacro( DataBits, DataBitsType );

  /** Set the parity.  The default is no parity. */
  igstkSetMacro( Parity, ParityType );
  /** Get the parity. */
  igstkGetMacro( Parity, ParityType );

  /** Set the number of stop bits.  The default is one stop bit. */
  igstkSetMacro( StopBits, StopBitsType );
  /** Get the number of stop bits. */
  igstkGetMacro( StopBits, StopBitsType );

  /** Set whether to use hardware handshaking. */
  igstkSetMacro( HardwareHandshake, HandshakeType );
  /** Get whether hardware handshaking is enabled. */
  igstkGetMacro( HardwareHandshake, HandshakeType );

  /** Set the name of the file into which the data stream is recorded. */
  void SetCaptureFileName(const char* filename);
  /** Get the filename into which the data stream is recorded. */
  const char* GetCaptureFileName() const;

  /** Set whether to record the data. */
  igstkSetMacro( Capture, bool );
  /** Get whether the data is being recorded. */
  igstkGetMacro( Capture, bool );

  /** Update the communication parameters, in case you need to change
   *  the baud rate, handshaking, timeout, etc. after opening the port */
  ResultType UpdateParameters( void );

  /** The method OpenCommunication sets up communication as per the data
   *  provided. */
  ResultType OpenCommunication( void );

  /** The method CloseCommunication closes the communication. */
  ResultType CloseCommunication( void );

  /** Set the RTS value 
   *  0 : Clear the RTS (request-to-send) signal 
   *  1 : Sends the RTS signal */
  ResultType SetRTS( unsigned int signal );

  /** Write method sends the string via the communication link. */
  ResultType Write( const char *message, unsigned int numberOfBytes );

  /** Read method receives the string via the communication link. The
   *  data will always be null-terminated, so ensure that 'data' is at
   *  least numberOfBytes+1 in size. */
  ResultType Read( char *data, unsigned int numberOfBytes,
                   unsigned int &bytesRead );

  /** Send a break in the serial communication, which by definition is
   *  a series of zeroes that lasts for a 0.3 second duration.  Some
   *  devices interpret this as a "reset" signal because the device is
   *  guaranteed to see it even if the baud rate, parity, or data bits
   *  are not matched between the host and the device. */
  ResultType SendBreak( void );

  /** Purge the contents of the buffers.  This is used if the device 
   *  connected to the serial port has just been reset after an error,
   *  and the contents of the serial port buffers has to be thrown out
   *  before communication can continue. */
  ResultType PurgeBuffers( void );

  /** Sleep for the specified number of milliseconds. This is useful
   *  after a reset of a device on the other end of the serial port,
   *  if the device is known to take a certain amount of time to
   *  initialize. */
  void Sleep( unsigned int milliseconds );

  /** Declarations related to the State Machine. */
  igstkStateMachineMacro();

  /** Declarations related to the Logger. */
  igstkLoggerMacro();

protected:

  SerialCommunication();

  ~SerialCommunication();

  // These methods are the interface to the derived classes.

  /** Opens serial port for communication; */
  virtual ResultType InternalOpenPort( void ) { return SUCCESS; }

  /** Set communication parameters on the open port. */
  virtual ResultType InternalUpdateParameters( void ) { return SUCCESS; }

  /** Closes serial port. */
  virtual ResultType InternalClosePort( void ) { return SUCCESS; }

  /** Closes serial port. */
  virtual ResultType InternalSetRTS( unsigned int ) { return SUCCESS; }

  /** write the data to the serial port. */
  virtual ResultType InternalWrite( const char *, unsigned int ) {
    return TIMEOUT; }

  /** read the data from the serial port. */
  virtual ResultType InternalRead( char *, unsigned int, unsigned int &) {
    return TIMEOUT; }

  /** Send a break to the across the serial port. */
  virtual ResultType InternalSendBreak( void ) { return SUCCESS; }

  /** Purge the buffers. */
  virtual ResultType InternalPurgeBuffers( void ) { return SUCCESS; }

  /** Sleep for the period of time specified, in milliseconds. */
  virtual void InternalSleep( unsigned int ) {};

  /** Print object information. */
  virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const; 

private:

  // Communication Parameters

  /**  Port Number */
  PortNumberType  m_PortNumber;   

  /** Baud rate of communication */
  BaudRateType    m_BaudRate;  

  /** Number of bits/byte */
  DataBitsType    m_DataBits;

  /** Parity */
  ParityType      m_Parity;

  /** Stop bits */
  StopBitsType    m_StopBits;

  /** Hardware handshaking */
  HandshakeType  m_HardwareHandshake;

  /** Time to sleep for, in milliseconds. */
  unsigned int m_SleepPeriod;

  /** Input data */
  char *m_InputData;

  /** Output data */
  const char *m_OutputData;

  /** The number of bytes to write. */
  unsigned int m_BytesToWrite;

  /** Number of bytes to try to read. */
  unsigned int m_BytesToRead;

  /** Actual number of bytes read. */
  unsigned int m_BytesRead;

  /** Type used to map between integer values and inputs */
  typedef std::map<int, InputType>     IntegerInputMapType;
  
  /** Record file name */
  std::string              m_CaptureFileName;

  /** File output stream for recording stream into a file */
  std::ofstream            m_CaptureFileStream;

  /** Current message number */
  unsigned int             m_CaptureMessageNumber;

  /** Recording flag */
  bool                     m_Capture;
  
  /** Logger for recording */
  igstk::Object::LoggerType::Pointer     m_Recorder;
  
  /** RTS Signal type */
  unsigned int             m_RTSSignal;

  /** LogOutput for File output stream */
  itk::StdStreamLogOutput::Pointer  m_CaptureFileOutput;
  
  /** For storing return values */
  ResultType                m_ReturnValue;
  
  /** For mapping return values to state machine inputs */
  IntegerInputMapType       m_ResultInputMap;
  
  // List of States 
  igstkDeclareStateMacro( Idle );
  igstkDeclareStateMacro( AttemptingToOpenPort );
  igstkDeclareStateMacro( PortOpen );
  igstkDeclareStateMacro( AttemptingToUpdateParameters );
  igstkDeclareStateMacro( ReadyForCommunication );
  igstkDeclareStateMacro( AttemptingToClosePort );
  igstkDeclareStateMacro( AttemptingToRead );
  igstkDeclareStateMacro( AttemptingToWrite );
  igstkDeclareStateMacro( AttemptingToSendBreak );
  igstkDeclareStateMacro( AttemptingToPurgeBuffers );
  igstkDeclareStateMacro( AttemptingToSetRTS );
  igstkDeclareStateMacro( Sleep );

  // List of Inputs
  igstkDeclareInputMacro( Success );
  igstkDeclareInputMacro( Failure );
  igstkDeclareInputMacro( Timeout );
  igstkDeclareInputMacro( OpenPort );
  igstkDeclareInputMacro( ClosePort );
  igstkDeclareInputMacro( UpdateParameters );
  igstkDeclareInputMacro( Read );
  igstkDeclareInputMacro( Write );
  igstkDeclareInputMacro( SendBreak );
  igstkDeclareInputMacro( PurgeBuffers );
  igstkDeclareInputMacro( Sleep );
  igstkDeclareInputMacro( SetRTS );

  /** called by state machine serial port is successfully opened */
  void OpenPortSuccessProcessing( void );

  /** called by state machine when serial port fails to open */
  void OpenPortFailureProcessing( void );

  /** called by state machine serial port is successfully closed */
  void ClosePortSuccessProcessing( void );

  /** called by state machine when serial port fails to close */
  void ClosePortFailureProcessing( void );
  
  /** called by state machine when writing succeeded */
  void SuccessProcessing( void );
  
  /** called by state machine when writing failed */
  void FailureProcessing( void );
  
  /** called by state machine when writing was timed out */
  void TimeoutProcessing( void );
  
  /** Null operation for a state machine transition */
  void NoProcessing();

  /** Called by the state machine when communication is to be opened */
  void AttemptToOpenPortProcessing( void );

  /** Called by the state machine when transfer parameters are to be set */
  void AttemptToUpdateParametersProcessing( void );

  /** Called by the state machine when communication is to be closed */
  void AttemptToClosePortProcessing( void );
    
  /** Called by the state machine when communication is to be closed */
  void AttemptToSetRTSProcessing( void );

  /** Called by the state machine when writing is to be done */
  void AttemptToWriteProcessing( void );
  
  /** Called by the state machine when reading is to be done */
  void AttemptToReadProcessing( void );

  /** Called by the state machine to send a break */
  void AttemptToSendBreakProcessing( void );

  /** Called by the state machine to purge the buffers */
  void AttemptToPurgeBuffersProcessing( void );

  /** Called by the state machine to purge the buffers */
  void SleepProcessing( void );

  /** Helper function to map a return value to an input */
  const InputType &MapResultToInput( int condition );
};

} // end namespace igstk

#endif // __igstkSerialCommunication_h