| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "base_config.hpp" |
| Jagpal Singh Gill | 7184805 | 2025-10-16 00:28:58 -0700 | [diff] [blame^] | 4 | #include "common/events.hpp" |
| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 5 | #include "modbus/modbus.hpp" |
| 6 | #include "port/base_port.hpp" |
| 7 | |
| 8 | #include <sdbusplus/async.hpp> |
| 9 | #include <xyz/openbmc_project/Sensor/Value/aserver.hpp> |
| 10 | |
| 11 | namespace phosphor::modbus::rtu::device |
| 12 | { |
| 13 | |
| 14 | class Device; |
| 15 | |
| 16 | using SensorValueIntf = |
| 17 | sdbusplus::aserver::xyz::openbmc_project::sensor::Value<Device>; |
| 18 | using PortIntf = phosphor::modbus::rtu::port::BasePort; |
| Jagpal Singh Gill | 7184805 | 2025-10-16 00:28:58 -0700 | [diff] [blame^] | 19 | namespace EventIntf = phosphor::modbus::events; |
| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 20 | |
| 21 | class BaseDevice |
| 22 | { |
| 23 | public: |
| 24 | BaseDevice() = delete; |
| 25 | |
| 26 | explicit BaseDevice(sdbusplus::async::context& ctx, |
| Jagpal Singh Gill | 7184805 | 2025-10-16 00:28:58 -0700 | [diff] [blame^] | 27 | const config::Config& config, PortIntf& serialPort, |
| 28 | EventIntf::Events& events); |
| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 29 | |
| 30 | auto readSensorRegisters() -> sdbusplus::async::task<void>; |
| 31 | |
| 32 | private: |
| 33 | auto createSensors() -> void; |
| 34 | |
| Jagpal Singh Gill | 7184805 | 2025-10-16 00:28:58 -0700 | [diff] [blame^] | 35 | auto readStatusRegisters() -> sdbusplus::async::task<void>; |
| 36 | |
| 37 | auto generateEvent(const config::StatusBit& statusBit, |
| 38 | const sdbusplus::message::object_path& objectPath, |
| 39 | double sensorValue, SensorValueIntf::Unit sensorUnit, |
| 40 | bool statusAsserted) -> sdbusplus::async::task<void>; |
| 41 | |
| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 42 | using sensors_map_t = |
| 43 | std::unordered_map<std::string, std::unique_ptr<SensorValueIntf>>; |
| 44 | sdbusplus::async::context& ctx; |
| 45 | const config::Config config; |
| 46 | PortIntf& serialPort; |
| Jagpal Singh Gill | 7184805 | 2025-10-16 00:28:58 -0700 | [diff] [blame^] | 47 | EventIntf::Events& events; |
| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 48 | sensors_map_t sensors; |
| 49 | }; |
| 50 | |
| 51 | } // namespace phosphor::modbus::rtu::device |