blob: 829024a6fb5ac87f66046b81793514e203844dd7 [file] [log] [blame]
Jagpal Singh Gillcad9ecf2025-10-22 19:53:16 -07001#pragma once
2
3#include "modbus/modbus.hpp"
4#include "port/base_port.hpp"
5
6#include <sdbusplus/async.hpp>
7#include <xyz/openbmc_project/Inventory/Source/Modbus/FRU/aserver.hpp>
8
9#include <cstdint>
10#include <map>
11#include <string>
12#include <tuple>
13#include <vector>
14
15namespace phosphor::modbus::rtu::inventory
16{
17
18class Device;
19
20namespace ModbusIntf = phosphor::modbus::rtu;
21using SerialPortIntf = phosphor::modbus::rtu::port::BasePort;
22using InventorySourceIntf =
23 sdbusplus::aserver::xyz::openbmc_project::inventory::source::modbus::FRU<
24 Device>;
25
26namespace config
27{
28
29struct Register
30{
31 std::string name = "unknown";
32 uint16_t offset = 0;
33 uint8_t size = 0;
34};
35
36struct AddressRange
37{
38 uint8_t start;
39 uint8_t end;
40};
41
42struct Config
43{
44 using address_range_arr_t = std::vector<AddressRange>;
45 using port_address_map_t =
46 std::map<std::string,
47 address_range_arr_t>; // <port name, device address range list>
48
49 std::string name = "unknown";
50 port_address_map_t addressMap = {};
51 std::vector<Register> registers = {};
52 ModbusIntf::Parity parity = ModbusIntf::Parity::unknown;
53 uint32_t baudRate = 0;
54};
55
56auto getConfig(sdbusplus::async::context& ctx,
57 sdbusplus::message::object_path objectPath)
58 -> sdbusplus::async::task<std::optional<Config>>;
59
60} // namespace config
61
62class Device
63{
64 public:
65 Device() = delete;
66 using serial_port_map_t =
67 std::unordered_map<std::string, std::unique_ptr<SerialPortIntf>>;
68
69 explicit Device(sdbusplus::async::context& ctx,
70 const config::Config& config,
71 serial_port_map_t& serialPorts);
72
73 auto probePorts() -> sdbusplus::async::task<void>;
74
75 auto probePort(std::string portName) -> sdbusplus::async::task<void>;
76
77 auto probeDevice(uint8_t address, const std::string& portName,
78 SerialPortIntf& port) -> sdbusplus::async::task<void>;
79
80 auto addInventorySource(uint8_t address, const std::string& portName,
81 SerialPortIntf& port)
82 -> sdbusplus::async::task<void>;
83
Jagpal Singh Gille92aba42025-10-16 00:00:13 -070084 const config::Config config;
85
Jagpal Singh Gillcad9ecf2025-10-22 19:53:16 -070086 private:
87 sdbusplus::async::context& ctx;
Jagpal Singh Gillcad9ecf2025-10-22 19:53:16 -070088 serial_port_map_t& serialPorts;
89 std::map<std::string, std::unique_ptr<InventorySourceIntf>>
90 inventorySources;
91};
92
93} // namespace phosphor::modbus::rtu::inventory