blob: 3a2f0a87e1dc200b43810a9d2dd9dae997058f76 [file] [log] [blame]
Jagpal Singh Gille92aba42025-10-16 00:00:13 -07001#pragma once
2
3#include "base_config.hpp"
Jagpal Singh Gill71848052025-10-16 00:28:58 -07004#include "common/events.hpp"
Jagpal Singh Gille92aba42025-10-16 00:00:13 -07005#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
11namespace phosphor::modbus::rtu::device
12{
13
14class Device;
15
16using SensorValueIntf =
17 sdbusplus::aserver::xyz::openbmc_project::sensor::Value<Device>;
18using PortIntf = phosphor::modbus::rtu::port::BasePort;
Jagpal Singh Gill71848052025-10-16 00:28:58 -070019namespace EventIntf = phosphor::modbus::events;
Jagpal Singh Gille92aba42025-10-16 00:00:13 -070020
21class BaseDevice
22{
23 public:
24 BaseDevice() = delete;
25
26 explicit BaseDevice(sdbusplus::async::context& ctx,
Jagpal Singh Gill71848052025-10-16 00:28:58 -070027 const config::Config& config, PortIntf& serialPort,
28 EventIntf::Events& events);
Jagpal Singh Gille92aba42025-10-16 00:00:13 -070029
30 auto readSensorRegisters() -> sdbusplus::async::task<void>;
31
32 private:
33 auto createSensors() -> void;
34
Jagpal Singh Gill71848052025-10-16 00:28:58 -070035 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 Gille92aba42025-10-16 00:00:13 -070042 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 Gill71848052025-10-16 00:28:58 -070047 EventIntf::Events& events;
Jagpal Singh Gille92aba42025-10-16 00:00:13 -070048 sensors_map_t sensors;
49};
50
51} // namespace phosphor::modbus::rtu::device