blob: 6df5aa2974526136255630d4c4e5ce6da9d70c2a [file] [log] [blame]
Patrick Venture863b9242018-03-08 08:29:23 -08001#pragma once
2
Patrick Venture863b9242018-03-08 08:29:23 -08003#include "interfaces.hpp"
4
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07005#include <chrono>
6#include <string>
Patrick Venture863b9242018-03-08 08:29:23 -08007
8/**
9 * Abstract base class for all sensors.
10 */
11class Sensor
12{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070013 public:
Patrick Venturedf766f22018-10-13 09:30:58 -070014 Sensor(const std::string& name, int64_t timeout) :
15 _name(name), _timeout(timeout)
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070016 {
17 }
Patrick Venture863b9242018-03-08 08:29:23 -080018
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070019 virtual ~Sensor()
20 {
21 }
Patrick Venture863b9242018-03-08 08:29:23 -080022
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070023 virtual ReadReturn read(void) = 0;
24 virtual void write(double value) = 0;
James Feist36b7d8e2018-10-05 15:39:01 -070025 virtual bool getFailed(void)
26 {
27 return false;
28 };
Patrick Venture863b9242018-03-08 08:29:23 -080029
Patrick Venture563a3562018-10-30 09:31:26 -070030 std::string getName(void) const
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070031 {
32 return _name;
33 }
Patrick Venture863b9242018-03-08 08:29:23 -080034
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070035 /* Returns the configurable timeout period
36 * for this sensor in seconds (undecorated).
37 */
Patrick Venture563a3562018-10-30 09:31:26 -070038 int64_t getTimeout(void) const
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070039 {
40 return _timeout;
41 }
Patrick Venture863b9242018-03-08 08:29:23 -080042
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070043 private:
44 std::string _name;
45 int64_t _timeout;
Patrick Venture863b9242018-03-08 08:29:23 -080046};