xref: /openbmc/phosphor-modbus/rtu/device/base_device.hpp (revision cf77ef540b925e10e3078bbdfbd795a0c1d9ff1f)
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 <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;
19 namespace EventIntf = phosphor::modbus::events;
20 
21 class BaseDevice
22 {
23   public:
24     BaseDevice() = delete;
25 
26     explicit BaseDevice(sdbusplus::async::context& ctx,
27                         const config::Config& config, PortIntf& serialPort,
28                         EventIntf::Events& events);
29 
30     auto readSensorRegisters() -> sdbusplus::async::task<void>;
31 
32   private:
33     auto createSensors() -> void;
34 
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 
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;
47     EventIntf::Events& events;
48     std::unique_ptr<DeviceFirmware> currentFirmware;
49     sensors_map_t sensors;
50 };
51 
52 } // namespace phosphor::modbus::rtu::device
53