00001 /*========================================================================= 00002 00003 Program: Image Guided Surgery Software Toolkit 00004 Module: $RCSfile: igstkSerialCommunicationSimulator.h,v $ 00005 Language: C++ 00006 Date: $Date: 2008-02-11 01:41:51 $ 00007 Version: $Revision: 1.11 $ 00008 00009 Copyright (c) ISC Insight Software Consortium. All rights reserved. 00010 See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #ifndef __igstkSerialCommunicationSimulator_h 00019 #define __igstkSerialCommunicationSimulator_h 00020 00021 #include <fstream> 00022 #include <iomanip> 00023 #include <map> 00024 #include <vector> 00025 00026 #include "igstkBinaryData.h" 00027 #include "igstkSerialCommunication.h" 00028 00029 namespace igstk 00030 { 00031 00039 class SerialCommunicationSimulator : public SerialCommunication 00040 { 00041 public: 00042 00044 igstkStandardClassTraitsMacro( SerialCommunicationSimulator, 00045 SerialCommunication ) 00046 00047 public: 00048 00050 typedef std::ifstream FileType; 00051 00053 void SetFileName(const char* filename); 00054 00056 const char *GetFileName() const; 00057 00058 protected: 00059 00060 typedef SerialCommunication::ResultType ResultType; 00061 00063 SerialCommunicationSimulator(); 00064 00066 ~SerialCommunicationSimulator(); 00067 00069 virtual ResultType InternalOpenPort( void ); 00070 00073 virtual ResultType InternalUpdateParameters( void ); 00074 00076 virtual ResultType InternalClosePort( void ); 00077 00079 virtual ResultType InternalSendBreak( void ); 00080 00082 virtual void InternalSleep( unsigned int milliseconds ); 00083 00085 virtual ResultType InternalPurgeBuffers( void ); 00086 00088 virtual ResultType InternalWrite( const char *message, 00089 unsigned int numberOfBytes ); 00090 00092 virtual ResultType InternalRead( char *data, unsigned int numberOfBytes, 00093 unsigned int &bytesRead ); 00094 00096 virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const; 00097 00098 private: 00099 00101 typedef std::map<BinaryData, std::vector<BinaryData> > ResponseTableType; 00102 00104 typedef std::map<BinaryData, std::vector<double> > ResponseTimeType; 00105 00108 typedef std::map<BinaryData, unsigned> ResponseCounterType; 00109 00111 FileType m_File; 00112 00114 std::string m_FileName; 00115 00117 ResponseTableType m_ResponseTable; 00118 00120 ResponseTimeType m_TimeTable; 00121 00123 ResponseCounterType m_CounterTable; 00124 00126 BinaryData m_Command; 00127 00128 }; 00129 00130 } // end namespace igstk 00131 00132 #endif // __igstkSerialCommunicationSimulator_h