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