xref: /openbmc/phosphor-modbus/rtu/device/base_device.hpp (revision e92aba4516471f5a01d4ab1f93eb9919ec05c21f)
1 #pragma once
2 
3 #include "base_config.hpp"
4 #include "modbus/modbus.hpp"
5 #include "port/base_port.hpp"
6 
7 #include <sdbusplus/async.hpp>
8 #include <xyz/openbmc_project/Sensor/Value/aserver.hpp>
9 
10 namespace phosphor::modbus::rtu::device
11 {
12 
13 class Device;
14 
15 using SensorValueIntf =
16     sdbusplus::aserver::xyz::openbmc_project::sensor::Value<Device>;
17 using PortIntf = phosphor::modbus::rtu::port::BasePort;
18 
19 class BaseDevice
20 {
21   public:
22     BaseDevice() = delete;
23 
24     explicit BaseDevice(sdbusplus::async::context& ctx,
25                         const config::Config& config, PortIntf& serialPort);
26 
27     auto readSensorRegisters() -> sdbusplus::async::task<void>;
28 
29   private:
30     auto createSensors() -> void;
31 
32     using sensors_map_t =
33         std::unordered_map<std::string, std::unique_ptr<SensorValueIntf>>;
34     sdbusplus::async::context& ctx;
35     const config::Config config;
36     PortIntf& serialPort;
37     sensors_map_t sensors;
38 };
39 
40 } // namespace phosphor::modbus::rtu::device
41