00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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