rtu: implement modbus sensor read
Read the modbus device config from the Entity Manager configuration and
create the sensor interfaces for related sensor register config.
Tested:
Added new Unit test named test_sensors -
```
> meson test -t 10 -C builddir/ --print-errorlogs --wrapper="valgrind --error-exitcode=1" test_sensors
ninja: Entering directory `/host/repos/Modbus/phosphor-modbus/builddir'
[2/2] Linking target tests/test_sensors
1/1 test_sensors OK 13.98s
Ok: 1
Fail: 0
```
Tested on Qemu using Mock Modbus Device -
```
root@ventura:~# busctl tree xyz.openbmc_project.ModbusRTU
└─ /xyz
└─ /xyz/openbmc_project
├─ /xyz/openbmc_project/inventory_source
│ ├─ /xyz/openbmc_project/inventory_source/Heat_Exchanger_12_DevTTYUSB0
│ ├─ /xyz/openbmc_project/inventory_source/Heat_Exchanger_12_DevTTYUSB1
│ ├─ /xyz/openbmc_project/inventory_source/Reservoir_Pumping_Unit_12_DevTTYUSB0
│ └─ /xyz/openbmc_project/inventory_source/Reservoir_Pumping_Unit_12_DevTTYUSB1
└─ /xyz/openbmc_project/sensors
└─ /xyz/openbmc_project/sensors/temperature
├─ /xyz/openbmc_project/sensors/temperature/Reservoir_Pumping_Unit_12_DevTTYUSB0_RPU_Coolant_Inlet_Temp_C
├─ /xyz/openbmc_project/sensors/temperature/Reservoir_Pumping_Unit_12_DevTTYUSB0_RPU_Coolant_Outlet_Temp_C
├─ /xyz/openbmc_project/sensors/temperature/Reservoir_Pumping_Unit_12_DevTTYUSB1_RPU_Coolant_Inlet_Temp_C
└─ /xyz/openbmc_project/sensors/temperature/Reservoir_Pumping_Unit_12_DevTTYUSB1_RPU_Coolant_Outlet_Temp_C
busctl introspect xyz.openbmc_project.ModbusRTU /xyz/openbmc_project/sensors/temperature/Reservoir_Pumping_Unit_12_DevTTYUSB1_RPU_Coolant_Outlet_Temp_C
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
org.freedesktop.DBus.Introspectable interface - - -
.Introspect method - s -
org.freedesktop.DBus.Peer interface - - -
.GetMachineId method - s -
.Ping method - - -
org.freedesktop.DBus.Properties interface - - -
.Get method ss v -
.GetAll method s a{sv} -
.Set method ssv - -
.PropertiesChanged signal sa{sv}as - -
xyz.openbmc_project.Sensor.Value interface - - -
.MaxValue property d nan emits-change writable
.MinValue property d nan emits-change writable
.Unit property s "xyz.openbmc_project.Sensor.Value.Unit.… emits-change writable
.Value property d 1670.6 emits-change writable
```
Change-Id: I1368e8df5999b5cee9ac19d185ee110a9ecc3021
Signed-off-by: Jagpal Singh Gill <paligill@gmail.com>
diff --git a/rtu/device/reservoir_pump_unit.cpp b/rtu/device/reservoir_pump_unit.cpp
new file mode 100644
index 0000000..58debee
--- /dev/null
+++ b/rtu/device/reservoir_pump_unit.cpp
@@ -0,0 +1,68 @@
+#include "reservoir_pump_unit.hpp"
+
+#include "device_factory.hpp"
+
+#include <phosphor-logging/lg2.hpp>
+
+namespace phosphor::modbus::rtu::device
+{
+
+PHOSPHOR_LOG2_USING;
+
+static constexpr auto ModbusRDF040DSS5193E0ReservoirPumpUnitInterface =
+ "xyz.openbmc_project.Configuration.ModbusRDF040DSS5193E0ReservoirPumpUnit";
+
+static const std::unordered_map<std::string_view, config::DeviceModel>
+ validDevices = {{ModbusRDF040DSS5193E0ReservoirPumpUnitInterface,
+ config::DeviceModel::RDF040DSS5193E0}};
+
+ReservoirPumpUnit::ReservoirPumpUnit(sdbusplus::async::context& ctx,
+ const config::Config& config,
+ PortIntf& serialPort) :
+ BaseDevice(ctx, config, serialPort)
+{
+ info("Reservoir pump unit {NAME} created successfully", "NAME",
+ config.name);
+}
+
+auto ReservoirPumpUnit::getInterfaces() -> std::unordered_set<std::string>
+{
+ return {ModbusRDF040DSS5193E0ReservoirPumpUnitInterface};
+}
+
+auto ReservoirPumpUnit::getConfig(
+ sdbusplus::async::context& ctx,
+ const sdbusplus::message::object_path& objectPath,
+ const std::string& interfaceName)
+ -> sdbusplus::async::task<std::optional<config::DeviceFactoryConfig>>
+{
+ config::DeviceFactoryConfig config{};
+
+ auto res = co_await config::updateBaseConfig(ctx, objectPath, interfaceName,
+ config);
+ if (!res)
+ {
+ co_return std::nullopt;
+ }
+
+ for (const auto& [deviceInterface, deviceModel] : validDevices)
+ {
+ if (interfaceName == deviceInterface)
+ {
+ config.deviceModel = deviceModel;
+ }
+ }
+
+ if (config.deviceModel == config::DeviceModel::unknown)
+ {
+ error("Invalid device model {MODEL} for {NAME}", "MODEL", interfaceName,
+ "NAME", config.name);
+ co_return std::nullopt;
+ }
+
+ config.deviceType = config::DeviceType::reservoirPumpUnit;
+
+ co_return config;
+}
+
+} // namespace phosphor::modbus::rtu::device