| #pragma once |
| |
| #include "Thresholds.hpp" |
| #include "sensor.hpp" |
| |
| #include <sdbusplus/asio/object_server.hpp> |
| |
| #include <chrono> |
| #include <string> |
| #include <vector> |
| |
| class ExternalSensor : |
| public Sensor, |
| public std::enable_shared_from_this<ExternalSensor> |
| { |
| public: |
| ExternalSensor( |
| const std::string& objectType, |
| sdbusplus::asio::object_server& objectServer, |
| std::shared_ptr<sdbusplus::asio::connection>& conn, |
| const std::string& sensorName, const std::string& sensorUnits, |
| std::vector<thresholds::Threshold>&& thresholdsIn, |
| const std::string& sensorConfiguration, double maxReading, |
| double minReading, double timeoutSecs, const PowerState& powerState); |
| ~ExternalSensor() override; |
| |
| // Call this immediately after calling the constructor |
| void initWriteHook( |
| std::function<void(std::chrono::steady_clock::time_point now)>&& |
| writeHookIn); |
| |
| // Returns true if sensor has external Value that is subject to timeout |
| bool isAliveAndPerishable() const; |
| |
| // Returns true if AliveAndPerishable and timeout has not yet happened |
| bool |
| isAliveAndFresh(const std::chrono::steady_clock::time_point& now) const; |
| |
| // Marks the time when Value successfully received from external source |
| void writeBegin(const std::chrono::steady_clock::time_point& now); |
| |
| // Marks sensor as timed out, replacing Value with floating-point "NaN" |
| void writeInvalidate(); |
| |
| // Returns amount of time elapsed since last writeBegin() happened |
| std::chrono::steady_clock::duration |
| ageElapsed(const std::chrono::steady_clock::time_point& now) const; |
| |
| // Returns amount of time remaining until sensor timeout will happen |
| std::chrono::steady_clock::duration |
| ageRemaining(const std::chrono::steady_clock::time_point& now) const; |
| |
| private: |
| sdbusplus::asio::object_server& objServer; |
| |
| std::chrono::steady_clock::time_point writeLast; |
| std::chrono::steady_clock::duration writeTimeout; |
| bool writeAlive{false}; |
| bool writePerishable; |
| std::function<void(const std::chrono::steady_clock::time_point& now)> |
| writeHook; |
| |
| void checkThresholds() override; |
| void externalSetTrigger(); |
| }; |