1e92aba45SJagpal Singh Gill #include "reservoir_pump_unit.hpp"
2e92aba45SJagpal Singh Gill
3e92aba45SJagpal Singh Gill #include "device_factory.hpp"
4e92aba45SJagpal Singh Gill
5e92aba45SJagpal Singh Gill #include <phosphor-logging/lg2.hpp>
6e92aba45SJagpal Singh Gill
7e92aba45SJagpal Singh Gill namespace phosphor::modbus::rtu::device
8e92aba45SJagpal Singh Gill {
9e92aba45SJagpal Singh Gill
10e92aba45SJagpal Singh Gill PHOSPHOR_LOG2_USING;
11e92aba45SJagpal Singh Gill
12e92aba45SJagpal Singh Gill static constexpr auto ModbusRDF040DSS5193E0ReservoirPumpUnitInterface =
13e92aba45SJagpal Singh Gill "xyz.openbmc_project.Configuration.ModbusRDF040DSS5193E0ReservoirPumpUnit";
14e92aba45SJagpal Singh Gill
15e92aba45SJagpal Singh Gill static const std::unordered_map<std::string_view, config::DeviceModel>
16e92aba45SJagpal Singh Gill validDevices = {{ModbusRDF040DSS5193E0ReservoirPumpUnitInterface,
17e92aba45SJagpal Singh Gill config::DeviceModel::RDF040DSS5193E0}};
18e92aba45SJagpal Singh Gill
ReservoirPumpUnit(sdbusplus::async::context & ctx,const config::Config & config,PortIntf & serialPort,EventIntf::Events & events)19*7184805aSJagpal Singh Gill ReservoirPumpUnit::ReservoirPumpUnit(
20*7184805aSJagpal Singh Gill sdbusplus::async::context& ctx, const config::Config& config,
21*7184805aSJagpal Singh Gill PortIntf& serialPort, EventIntf::Events& events) :
22*7184805aSJagpal Singh Gill BaseDevice(ctx, config, serialPort, events)
23e92aba45SJagpal Singh Gill {
24e92aba45SJagpal Singh Gill info("Reservoir pump unit {NAME} created successfully", "NAME",
25e92aba45SJagpal Singh Gill config.name);
26e92aba45SJagpal Singh Gill }
27e92aba45SJagpal Singh Gill
getInterfaces()28e92aba45SJagpal Singh Gill auto ReservoirPumpUnit::getInterfaces() -> std::unordered_set<std::string>
29e92aba45SJagpal Singh Gill {
30e92aba45SJagpal Singh Gill return {ModbusRDF040DSS5193E0ReservoirPumpUnitInterface};
31e92aba45SJagpal Singh Gill }
32e92aba45SJagpal Singh Gill
getConfig(sdbusplus::async::context & ctx,const sdbusplus::message::object_path & objectPath,const std::string & interfaceName)33e92aba45SJagpal Singh Gill auto ReservoirPumpUnit::getConfig(
34e92aba45SJagpal Singh Gill sdbusplus::async::context& ctx,
35e92aba45SJagpal Singh Gill const sdbusplus::message::object_path& objectPath,
36e92aba45SJagpal Singh Gill const std::string& interfaceName)
37e92aba45SJagpal Singh Gill -> sdbusplus::async::task<std::optional<config::DeviceFactoryConfig>>
38e92aba45SJagpal Singh Gill {
39e92aba45SJagpal Singh Gill config::DeviceFactoryConfig config{};
40e92aba45SJagpal Singh Gill
41e92aba45SJagpal Singh Gill auto res = co_await config::updateBaseConfig(ctx, objectPath, interfaceName,
42e92aba45SJagpal Singh Gill config);
43e92aba45SJagpal Singh Gill if (!res)
44e92aba45SJagpal Singh Gill {
45e92aba45SJagpal Singh Gill co_return std::nullopt;
46e92aba45SJagpal Singh Gill }
47e92aba45SJagpal Singh Gill
48e92aba45SJagpal Singh Gill for (const auto& [deviceInterface, deviceModel] : validDevices)
49e92aba45SJagpal Singh Gill {
50e92aba45SJagpal Singh Gill if (interfaceName == deviceInterface)
51e92aba45SJagpal Singh Gill {
52e92aba45SJagpal Singh Gill config.deviceModel = deviceModel;
53e92aba45SJagpal Singh Gill }
54e92aba45SJagpal Singh Gill }
55e92aba45SJagpal Singh Gill
56e92aba45SJagpal Singh Gill if (config.deviceModel == config::DeviceModel::unknown)
57e92aba45SJagpal Singh Gill {
58e92aba45SJagpal Singh Gill error("Invalid device model {MODEL} for {NAME}", "MODEL", interfaceName,
59e92aba45SJagpal Singh Gill "NAME", config.name);
60e92aba45SJagpal Singh Gill co_return std::nullopt;
61e92aba45SJagpal Singh Gill }
62e92aba45SJagpal Singh Gill
63e92aba45SJagpal Singh Gill config.deviceType = config::DeviceType::reservoirPumpUnit;
64e92aba45SJagpal Singh Gill
65e92aba45SJagpal Singh Gill co_return config;
66e92aba45SJagpal Singh Gill }
67e92aba45SJagpal Singh Gill
68e92aba45SJagpal Singh Gill } // namespace phosphor::modbus::rtu::device
69