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/tests/modbus_server_tester.hpp b/tests/modbus_server_tester.hpp
index c9b4416..ccfa204 100644
--- a/tests/modbus_server_tester.hpp
+++ b/tests/modbus_server_tester.hpp
@@ -19,18 +19,43 @@
constexpr uint16_t testSuccessReadHoldingRegisterOffset = 0x0102;
constexpr uint16_t testSuccessReadHoldingRegisterCount = 0x2;
constexpr uint16_t testSuccessReadHoldingRegisterSegmentedOffset = 0x0103;
-constexpr std::array<uint16_t, testSuccessReadHoldingRegisterCount>
- testSuccessReadHoldingRegisterResponse = {0x1234, 0x5678};
+const std::vector<uint16_t> testSuccessReadHoldingRegisterResponse = {
+ 0x1234, 0x5678};
constexpr uint16_t testFailureReadHoldingRegister = 0x0105;
// Device Inventory Testing Constants
constexpr uint16_t testReadHoldingRegisterModelOffset = 0x0112;
constexpr uint16_t testReadHoldingRegisterModelCount = 0x8;
-constexpr std::array<uint16_t, testReadHoldingRegisterModelCount>
- testReadHoldingRegisterModel = {0x5244, 0x4630, 0x3430, 0x4453,
- 0x5335, 0x3139, 0x0000, 0x3000};
+const std::vector<uint16_t> testReadHoldingRegisterModel = {
+ 0x5244, 0x4630, 0x3430, 0x4453, 0x5335, 0x3139, 0x0000, 0x3000};
constexpr std::string testReadHoldingRegisterModelStr = "RDF040DSS519";
+// Device Sensors Testing Constants
+constexpr uint16_t testReadHoldingRegisterTempCount = 0x1;
+constexpr uint16_t testReadHoldingRegisterTempUnsignedOffset = 0x0113;
+const std::vector<uint16_t> testReadHoldingRegisterTempUnsigned = {
+ 0x0050}; // 80.0
+constexpr uint16_t testReadHoldingRegisterTempSignedOffset = 0x0114;
+const std::vector<uint16_t> testReadHoldingRegisterTempSigned = {
+ 0xFFB0}; // -80.0
+
+static const std::map<uint16_t, std::tuple<uint16_t, std::vector<uint16_t>>>
+ testReadHoldingRegisterMap = {
+ {testSuccessReadHoldingRegisterOffset,
+ {testSuccessReadHoldingRegisterCount,
+ testSuccessReadHoldingRegisterResponse}},
+ {testSuccessReadHoldingRegisterSegmentedOffset,
+ {testSuccessReadHoldingRegisterCount,
+ testSuccessReadHoldingRegisterResponse}},
+ {testReadHoldingRegisterModelOffset,
+ {testReadHoldingRegisterModelCount, testReadHoldingRegisterModel}},
+ {testReadHoldingRegisterTempUnsignedOffset,
+ {testReadHoldingRegisterTempCount,
+ testReadHoldingRegisterTempUnsigned}},
+ {testReadHoldingRegisterTempSignedOffset,
+ {testReadHoldingRegisterTempCount, testReadHoldingRegisterTempSigned}},
+};
+
class ServerTester
{
public: