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