1863b9246SPatrick Venture #pragma once 2863b9246SPatrick Venture 3863b9246SPatrick Venture #include "interfaces.hpp" 4863b9246SPatrick Venture 5da4a5dd1SPatrick Venture #include <string> 6863b9246SPatrick Venture 7a076487aSPatrick Venture namespace pid_control 8a076487aSPatrick Venture { 9a076487aSPatrick 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 */ getDefaultTimeout(const std::string & type)25a510ea2bSPatrick Venture static int64_t getDefaultTimeout(const std::string& type) 26a510ea2bSPatrick Venture { 27a510ea2bSPatrick Venture return (type == "fan") ? 0 : 2; 28a510ea2bSPatrick Venture } 29a510ea2bSPatrick Venture Sensor(const std::string & name,int64_t timeout)30df766f25SPatrick Venture Sensor(const std::string& name, int64_t timeout) : 31df766f25SPatrick Venture _name(name), _timeout(timeout) 32a83a3eccSPatrick Venture {} 33863b9246SPatrick Venture ~Sensor()34*8c051121SPatrick Williams virtual ~Sensor() {} 35863b9246SPatrick Venture 36863b9246SPatrick Venture virtual ReadReturn read(void) = 0; 37863b9246SPatrick Venture virtual void write(double value) = 0; 382400ce43SJosh Lehan write(double value,bool force,int64_t * written)392400ce43SJosh Lehan virtual void write(double value, bool force, int64_t* written) 402400ce43SJosh Lehan { 412400ce43SJosh Lehan (void)force; 422400ce43SJosh Lehan (void)written; 432400ce43SJosh Lehan return write(value); 442400ce43SJosh Lehan } 452400ce43SJosh Lehan getFailed(void)4636b7d8ebSJames Feist virtual bool getFailed(void) 4736b7d8ebSJames Feist { 4836b7d8ebSJames Feist return false; 4936b7d8ebSJames Feist }; 50863b9246SPatrick Venture getName(void) const51563a356fSPatrick Venture std::string getName(void) const 52863b9246SPatrick Venture { 53863b9246SPatrick Venture return _name; 54863b9246SPatrick Venture } 55863b9246SPatrick Venture 56863b9246SPatrick Venture /* Returns the configurable timeout period 57863b9246SPatrick Venture * for this sensor in seconds (undecorated). 58863b9246SPatrick Venture */ getTimeout(void) const59563a356fSPatrick Venture int64_t getTimeout(void) const 60863b9246SPatrick Venture { 61863b9246SPatrick Venture return _timeout; 62863b9246SPatrick Venture } 63863b9246SPatrick Venture 64863b9246SPatrick Venture private: 65863b9246SPatrick Venture std::string _name; 66863b9246SPatrick Venture int64_t _timeout; 67863b9246SPatrick Venture }; 68a076487aSPatrick Venture 69a076487aSPatrick Venture } // namespace pid_control 70