1863b9246SPatrick Venture #pragma once 2863b9246SPatrick Venture 3863b9246SPatrick Venture #include "interfaces.hpp" 4863b9246SPatrick Venture 5da4a5dd1SPatrick Venture #include <string> 6863b9246SPatrick Venture 7*a076487aSPatrick Venture namespace pid_control 8*a076487aSPatrick Venture { 9*a076487aSPatrick Venture 10863b9246SPatrick Venture /** 11863b9246SPatrick Venture * Abstract base class for all sensors. 12863b9246SPatrick Venture */ 13863b9246SPatrick Venture class Sensor 14863b9246SPatrick Venture { 15863b9246SPatrick Venture public: 16a510ea2bSPatrick Venture /** 17a510ea2bSPatrick Venture * Given a sensor's type, return the default timeout value. 18a510ea2bSPatrick Venture * A timeout of 0 means there isn't a timeout for this sensor. 19a510ea2bSPatrick Venture * By default a fan sensor isn't checked for a timeout, whereas 20a510ea2bSPatrick Venture * any of sensor is meant to be sampled once per second. By default. 21a510ea2bSPatrick Venture * 22a510ea2bSPatrick Venture * @param[in] type - the sensor type (e.g. fan) 23a510ea2bSPatrick Venture * @return the default timeout for that type (in seconds). 24a510ea2bSPatrick Venture */ 25a510ea2bSPatrick Venture static int64_t getDefaultTimeout(const std::string& type) 26a510ea2bSPatrick Venture { 27a510ea2bSPatrick Venture return (type == "fan") ? 0 : 2; 28a510ea2bSPatrick Venture } 29a510ea2bSPatrick Venture 30df766f25SPatrick Venture Sensor(const std::string& name, int64_t timeout) : 31df766f25SPatrick Venture _name(name), _timeout(timeout) 32a83a3eccSPatrick Venture {} 33863b9246SPatrick Venture 34da4a5dd1SPatrick Venture virtual ~Sensor() 35a83a3eccSPatrick 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*a076487aSPatrick Venture 62*a076487aSPatrick Venture } // namespace pid_control 63