Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

comms_device.h

00001 
00002 
00003 
00010 
00011 
00012 
00013 #ifndef COMMSDEVICE_H
00014 #define COMMSDEVICE_H
00015 
00016 #include <cstring>
00017 #include <time.h>
00018 
00019 
00020 class CommsDevice
00021 {
00022     public:
00023 
00025         enum State { IDLE, OFFLINE, ONLINE };
00026 
00028 
00031         CommsDevice(const char* id) : id(id), state(IDLE), 
00032                                       timeoutCount(0) {  };
00033 
00035 
00041         virtual int init(int addr)                   { return -1; };
00042 
00044         /*
00045         * Writes data or sets an instrument parameter.
00046         * @param addr   The address to write to.
00047         * @param val    The value to write.
00048         * @return   Zero for success, negative for error, positive for a warning.
00049         * @note     Method is a no-op in this class.
00050         **/        
00051         virtual int cmd(int addr, int val)           { return -1; };
00052 
00054 
00061         virtual int mon(int addr, int* val)          { return -1; };
00062 
00064 
00072         virtual int mon(int addr, int* val, int timeOut) { return -1; };
00073 
00075 
00082         virtual int mon(int addr, float* volts)      { return -1; };
00083 
00085 
00088         virtual void clear()                         { return;    };
00089 
00091         State getState()                             { return state; };
00092 
00094         const char* getID()                          { return id;    };
00095 
00097 
00100         static const char* getUT();
00101 
00103 
00108         virtual const char* getErrMsg(int code) = 0;
00109        
00110 
00111     protected:
00112 
00113         const char* id;     
00114         State state;        
00115 
00117         void flagTimeoutErr() 
00118         { 
00119             if (++timeoutCount >= 5) 
00120             { state = OFFLINE; 
00121               timeoutCount = 5;  
00122             }
00123         };
00124         void clearTimeoutErr() { timeoutCount = 0;} ;
00125 
00126     private:
00127 
00128         int timeoutCount;   
00129 
00130         // Disallow copy and assignment
00131         CommsDevice(const CommsDevice&);
00132         CommsDevice& operator=(CommsDevice&);
00133 
00134 };
00135 
00136 inline const char* CommsDevice::getUT()
00137 {
00138     static char timestamp[15];
00139     time_t t;
00140 
00141     t = time(NULL);
00142     strftime(timestamp, 14, "%H:%M:%S", gmtime(&t));
00143 
00144     return timestamp;
00145 }
00146 
00147 #endif

Generated on Mon Apr 30 13:32:34 2007 for Parkes M & C - PKMC C++ library API by  doxygen 1.4.4