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