1863b9246SPatrick Venture #pragma once 2863b9246SPatrick Venture 3863b9246SPatrick Venture #include "interfaces.hpp" 4863b9246SPatrick Venture 5da4a5dd1SPatrick Venture #include <chrono> 6da4a5dd1SPatrick Venture #include <string> 7863b9246SPatrick Venture 8863b9246SPatrick Venture /** 9863b9246SPatrick Venture * Abstract base class for all sensors. 10863b9246SPatrick Venture */ 11863b9246SPatrick Venture class Sensor 12863b9246SPatrick Venture { 13863b9246SPatrick Venture public: 14*a510ea2bSPatrick Venture /** 15*a510ea2bSPatrick Venture * Given a sensor's type, return the default timeout value. 16*a510ea2bSPatrick Venture * A timeout of 0 means there isn't a timeout for this sensor. 17*a510ea2bSPatrick Venture * By default a fan sensor isn't checked for a timeout, whereas 18*a510ea2bSPatrick Venture * any of sensor is meant to be sampled once per second. By default. 19*a510ea2bSPatrick Venture * 20*a510ea2bSPatrick Venture * @param[in] type - the sensor type (e.g. fan) 21*a510ea2bSPatrick Venture * @return the default timeout for that type (in seconds). 22*a510ea2bSPatrick Venture */ 23*a510ea2bSPatrick Venture static int64_t getDefaultTimeout(const std::string& type) 24*a510ea2bSPatrick Venture { 25*a510ea2bSPatrick Venture return (type == "fan") ? 0 : 2; 26*a510ea2bSPatrick Venture } 27*a510ea2bSPatrick Venture 28df766f25SPatrick Venture Sensor(const std::string& name, int64_t timeout) : 29df766f25SPatrick Venture _name(name), _timeout(timeout) 30da4a5dd1SPatrick Venture { 31da4a5dd1SPatrick Venture } 32863b9246SPatrick Venture 33da4a5dd1SPatrick Venture virtual ~Sensor() 34da4a5dd1SPatrick Venture { 35da4a5dd1SPatrick Venture } 36863b9246SPatrick Venture 37863b9246SPatrick Venture virtual ReadReturn read(void) = 0; 38863b9246SPatrick Venture virtual void write(double value) = 0; 3936b7d8ebSJames Feist virtual bool getFailed(void) 4036b7d8ebSJames Feist { 4136b7d8ebSJames Feist return false; 4236b7d8ebSJames Feist }; 43863b9246SPatrick Venture 44563a356fSPatrick Venture std::string getName(void) const 45863b9246SPatrick Venture { 46863b9246SPatrick Venture return _name; 47863b9246SPatrick Venture } 48863b9246SPatrick Venture 49863b9246SPatrick Venture /* Returns the configurable timeout period 50863b9246SPatrick Venture * for this sensor in seconds (undecorated). 51863b9246SPatrick Venture */ 52563a356fSPatrick Venture int64_t getTimeout(void) const 53863b9246SPatrick Venture { 54863b9246SPatrick Venture return _timeout; 55863b9246SPatrick Venture } 56863b9246SPatrick Venture 57863b9246SPatrick Venture private: 58863b9246SPatrick Venture std::string _name; 59863b9246SPatrick Venture int64_t _timeout; 60863b9246SPatrick Venture }; 61