1 #pragma once 2 3 #include "base_config.hpp" 4 #include "common/events.hpp" 5 #include "firmware/device_firmware.hpp" 6 #include "port/base_port.hpp" 7 8 #include <sdbusplus/async.hpp> 9 #include <sdbusplus/async/server.hpp> 10 #include <xyz/openbmc_project/Association/Definitions/aserver.hpp> 11 #include <xyz/openbmc_project/Sensor/Threshold/Critical/aserver.hpp> 12 #include <xyz/openbmc_project/Sensor/Threshold/Warning/aserver.hpp> 13 #include <xyz/openbmc_project/Sensor/Value/aserver.hpp> 14 #include <xyz/openbmc_project/State/Decorator/Availability/aserver.hpp> 15 #include <xyz/openbmc_project/State/Decorator/OperationalStatus/aserver.hpp> 16 17 namespace phosphor::modbus::rtu::device 18 { 19 20 class BaseDevice; 21 22 using SensorIntf = sdbusplus::async::server_t< 23 BaseDevice, sdbusplus::aserver::xyz::openbmc_project::sensor::Value, 24 sdbusplus::aserver::xyz::openbmc_project::state::decorator::Availability, 25 sdbusplus::aserver::xyz::openbmc_project::state::decorator:: 26 OperationalStatus, 27 sdbusplus::aserver::xyz::openbmc_project::sensor::threshold::Warning, 28 sdbusplus::aserver::xyz::openbmc_project::sensor::threshold::Critical, 29 sdbusplus::aserver::xyz::openbmc_project::association::Definitions>; 30 31 using PortIntf = phosphor::modbus::rtu::port::BasePort; 32 namespace EventIntf = phosphor::modbus::events; 33 34 class BaseDevice 35 { 36 public: 37 BaseDevice() = delete; 38 39 explicit BaseDevice(sdbusplus::async::context& ctx, 40 const config::Config& config, PortIntf& serialPort, 41 EventIntf::Events& events); 42 43 auto readSensorRegisters() -> sdbusplus::async::task<void>; 44 45 private: 46 auto createSensors() -> void; 47 48 auto readStatusRegisters() -> sdbusplus::async::task<void>; 49 50 auto generateEvent(const config::StatusBit& statusBit, 51 const sdbusplus::message::object_path& objectPath, 52 double sensorValue, SensorIntf::Unit sensorUnit, 53 bool statusAsserted) -> sdbusplus::async::task<void>; 54 55 using sensors_map_t = 56 std::unordered_map<std::string, std::unique_ptr<SensorIntf>>; 57 sdbusplus::async::context& ctx; 58 const config::Config config; 59 PortIntf& serialPort; 60 EventIntf::Events& events; 61 std::unique_ptr<DeviceFirmware> currentFirmware; 62 sensors_map_t sensors; 63 }; 64 65 } // namespace phosphor::modbus::rtu::device 66