dmmclass.h

Go to the documentation of this file.
00001 //======================================================================
00002 // File:        dmmclass.h
00003 // Author:      Matthias Toussaint
00004 // Created:     Sat Nov 25 18:12:23 CET 2006
00005 // Project:     QtDMM
00006 // Description: Encapsulates a DMM class (protokoll)
00007 //----------------------------------------------------------------------
00008 // This file  may  be used under  the terms of  the GNU  General Public
00009 // License  version 2.0 as published   by the Free Software  Foundation
00010 // and appearing  in the file LICENSE.GPL included  in the packaging of
00011 // this file.
00012 // 
00013 // This file is provided AS IS with  NO WARRANTY OF ANY KIND, INCLUDING 
00014 // THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00015 // PURPOSE.
00016 //----------------------------------------------------------------------
00017 // Copyright 2006 Matthias Toussaint
00018 //======================================================================
00019 
00020 #ifndef DMMCLASS_HH
00021 #define DMMCLASS_HH
00022 
00023 #include <thread.h>
00024 #include <mutex.h>
00025 #include <port.h>
00026 #include <string>
00027 #include <time.h>
00028 #include <util.h>
00029 
00030 //class DMMClass;
00031 
00056 class DMMClass : public Thread
00057 {
00058 public:
00059   DMMClass();
00060   virtual ~DMMClass();
00061       
00067   Port::Error open( const std::string & config );
00070   virtual Port::Error close()=0;
00071   
00078   void setNumValues( int num ) { m_numValues = num; }
00085   int numValues() { return m_numValues; }
00086   
00104   std::string mode( int i=0 );
00110   std::string unit( int i=0 );
00115   double value( int i=0 );
00116   
00121   bool hasValue() { MutexLocker lovk( &m_mutex ); return m_hasValue; }
00127   bool overflow() { MutexLocker lock( &m_mutex ); return m_overflow; }
00133   bool lowBat() { MutexLocker lock( &m_mutex ); return m_lowBat; }
00134   
00135   void setConsoleLogging( bool on ) { m_consoleLogging = on; }
00140   bool timeout() const;
00141   
00144   class Protocol
00145   {
00146   public:
00147     Protocol( DMMClass *(*_fkt)(void), 
00148               const std::string & _name, 
00149               const std::string & _menuText ) :
00150       createFunction( _fkt ),
00151       name( _name ),
00152       menuText( _menuText )
00153     {
00154     }
00156     DMMClass *(*createFunction)(void);
00158     std::string name;
00160     std::string menuText;
00161   };
00162 
00165   class Device
00166   {
00167   public:
00168     Device();
00169     Device( const std::string & _brand, 
00170             const std::string & _name,
00171             const std::string & _protocol, 
00172             const std::string & _port, int _numValues ) :
00173       brand( _brand ),
00174       name( _name ),
00175       protocol( _protocol ),
00176       port( _port ),
00177       numValues( _numValues )
00178     {
00179     }
00181     std::string brand;
00183     std::string name;
00185     std::string protocol; 
00187     std::string port;
00189     int numValues;
00190   };
00191 
00211   static DMMClass *create_protocol( std::string protocolName );
00214   static int num_protocols();
00221   static Protocol protocol( int i ) { return s_protocol[i]; }
00224   static std::string print_protocols();
00227   static std::string print_devices();
00233   static bool has_device( const std::string & deviceName );
00238   static Device get_device( const std::string & deviceName );
00241   static std::string html_device_table();
00244   static std::string device_table();
00245   
00246 protected:
00248   time_t      m_openTime;
00250   bool        m_hasValue;
00252   int         m_numValues;
00254   bool        m_overflow;
00256   bool        m_lowBat;
00258   Mutex       m_mutex;
00260   std::string m_mode[8];
00262   std::string m_unit[8];
00264   double      m_value[8];
00265   bool        m_consoleLogging;
00266   
00267   static Protocol s_protocol[];
00268   static Device s_device[];
00269       
00304   virtual void run()=0;
00305   
00319   int readData( Port *port, unsigned char *buffer, int syncByte, 
00320                 int minLen, int maxLen ) const;
00321   
00322   void addValue( double value, int index );
00323   
00329   virtual Port::Error open_impl( const std::string & config ) = 0;
00330   
00331 private:
00332   static int count_protocols();
00333 
00334 };
00335 
00336 #endif // DMMCLASS_HH

Generated on Mon Jan 22 23:24:18 2007 for cdmm by  doxygen 1.4.6