| Jagpal Singh Gill | cad9ecf | 2025-10-22 19:53:16 -0700 | [diff] [blame] | 1 | #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 | |
| 15 | namespace phosphor::modbus::rtu::inventory |
| 16 | { |
| 17 | |
| 18 | class Device; |
| 19 | |
| 20 | namespace ModbusIntf = phosphor::modbus::rtu; |
| 21 | using SerialPortIntf = phosphor::modbus::rtu::port::BasePort; |
| 22 | using InventorySourceIntf = |
| 23 | sdbusplus::aserver::xyz::openbmc_project::inventory::source::modbus::FRU< |
| 24 | Device>; |
| 25 | |
| 26 | namespace config |
| 27 | { |
| 28 | |
| 29 | struct Register |
| 30 | { |
| 31 | std::string name = "unknown"; |
| 32 | uint16_t offset = 0; |
| 33 | uint8_t size = 0; |
| 34 | }; |
| 35 | |
| 36 | struct AddressRange |
| 37 | { |
| 38 | uint8_t start; |
| 39 | uint8_t end; |
| 40 | }; |
| 41 | |
| 42 | struct 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 | |
| 56 | auto getConfig(sdbusplus::async::context& ctx, |
| 57 | sdbusplus::message::object_path objectPath) |
| 58 | -> sdbusplus::async::task<std::optional<Config>>; |
| 59 | |
| 60 | } // namespace config |
| 61 | |
| 62 | class 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 Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 84 | const config::Config config; |
| 85 | |
| Jagpal Singh Gill | cad9ecf | 2025-10-22 19:53:16 -0700 | [diff] [blame] | 86 | private: |
| 87 | sdbusplus::async::context& ctx; |
| Jagpal Singh Gill | cad9ecf | 2025-10-22 19:53:16 -0700 | [diff] [blame] | 88 | serial_port_map_t& serialPorts; |
| 89 | std::map<std::string, std::unique_ptr<InventorySourceIntf>> |
| 90 | inventorySources; |
| 91 | }; |
| 92 | |
| 93 | } // namespace phosphor::modbus::rtu::inventory |