Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 3 | #include "interfaces.hpp" |
| 4 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 5 | #include <string> |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 6 | |
| 7 | /** |
| 8 | * Abstract base class for all sensors. |
| 9 | */ |
| 10 | class Sensor |
| 11 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 12 | public: |
Patrick Venture | a510ea2 | 2019-02-08 09:30:49 -0800 | [diff] [blame] | 13 | /** |
| 14 | * Given a sensor's type, return the default timeout value. |
| 15 | * A timeout of 0 means there isn't a timeout for this sensor. |
| 16 | * By default a fan sensor isn't checked for a timeout, whereas |
| 17 | * any of sensor is meant to be sampled once per second. By default. |
| 18 | * |
| 19 | * @param[in] type - the sensor type (e.g. fan) |
| 20 | * @return the default timeout for that type (in seconds). |
| 21 | */ |
| 22 | static int64_t getDefaultTimeout(const std::string& type) |
| 23 | { |
| 24 | return (type == "fan") ? 0 : 2; |
| 25 | } |
| 26 | |
Patrick Venture | df766f2 | 2018-10-13 09:30:58 -0700 | [diff] [blame] | 27 | Sensor(const std::string& name, int64_t timeout) : |
| 28 | _name(name), _timeout(timeout) |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 29 | {} |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 30 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 31 | virtual ~Sensor() |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 32 | {} |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 33 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 34 | virtual ReadReturn read(void) = 0; |
| 35 | virtual void write(double value) = 0; |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 36 | virtual bool getFailed(void) |
| 37 | { |
| 38 | return false; |
| 39 | }; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 40 | |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 41 | std::string getName(void) const |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 42 | { |
| 43 | return _name; |
| 44 | } |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 45 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 46 | /* Returns the configurable timeout period |
| 47 | * for this sensor in seconds (undecorated). |
| 48 | */ |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 49 | int64_t getTimeout(void) const |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 50 | { |
| 51 | return _timeout; |
| 52 | } |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 53 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 54 | private: |
| 55 | std::string _name; |
| 56 | int64_t _timeout; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 57 | }; |