1 #pragma once 2 3 #include <chrono> 4 5 namespace pid_control 6 { 7 8 struct ReadReturn 9 { 10 double value = std::numeric_limits<double>::quiet_NaN(); 11 std::chrono::high_resolution_clock::time_point updated; 12 double unscaled = value; 13 14 bool operator==(const ReadReturn& rhs) const 15 { 16 return ((this->value == rhs.value) && (this->updated == rhs.updated) && 17 (this->unscaled == rhs.unscaled)); 18 } 19 }; 20 21 struct ValueCacheEntry 22 { 23 // This is normalized to (0.0, 1.0) range, using configured min and max 24 double scaled; 25 26 // This is the raw value, as received from the input/output sensors 27 double unscaled; 28 }; 29 30 /* 31 * A ReadInterface is a plug-in for the PluggableSensor and anyone implementing 32 * this basically is providing a way to read a sensor. 33 */ 34 class ReadInterface 35 { 36 public: 37 ReadInterface() = default; 38 39 virtual ~ReadInterface() = default; 40 41 virtual ReadReturn read(void) = 0; 42 43 virtual bool getFailed(void) const 44 { 45 return false; 46 } 47 48 virtual std::string getFailReason(void) const 49 { 50 return "Unimplemented"; 51 } 52 }; 53 54 /* 55 * A WriteInterface is a plug-in for the PluggableSensor and anyone implementing 56 * this basically is providing a way to write a sensor. 57 */ 58 class WriteInterface 59 { 60 public: 61 WriteInterface(int64_t min, int64_t max) : _min(min), _max(max) {} 62 63 virtual ~WriteInterface() = default; 64 65 virtual void write(double value) = 0; 66 67 /* 68 * A wrapper around write(), with additional parameters. 69 * force = true to perform redundant write, even if raw value unchanged. 70 * written = non-null to be filled in with the actual raw value written. 71 */ 72 virtual void write(double value, bool force, int64_t* written) 73 { 74 (void)force; 75 (void)written; 76 return write(value); 77 } 78 79 /* 80 * All WriteInterfaces have min/max available in case they want to error 81 * check. 82 */ 83 int64_t getMin(void) 84 { 85 return _min; 86 } 87 int64_t getMax(void) 88 { 89 return _max; 90 } 91 92 private: 93 int64_t _min; 94 int64_t _max; 95 }; 96 97 } // namespace pid_control 98