blob: ccfa204da2fdbefbccdb4caae5a31b6bec920065 [file] [log] [blame]
Jagpal Singh Gilla32d2412025-10-01 14:55:05 -07001#pragma once
2
3#include "modbus/modbus_message.hpp"
4
5#include <sdbusplus/async.hpp>
6
7using MessageBase = phosphor::modbus::rtu::Message;
8
9namespace phosphor::modbus::test
10{
11
12class MessageIntf : public MessageBase
13{
14 friend class ServerTester;
15};
16
Jagpal Singh Gillcad9ecf2025-10-22 19:53:16 -070017// Read Holding Registers Testing Constants
Jagpal Singh Gilla32d2412025-10-01 14:55:05 -070018static constexpr uint8_t testDeviceAddress = 0xa;
19constexpr uint16_t testSuccessReadHoldingRegisterOffset = 0x0102;
20constexpr uint16_t testSuccessReadHoldingRegisterCount = 0x2;
21constexpr uint16_t testSuccessReadHoldingRegisterSegmentedOffset = 0x0103;
Jagpal Singh Gille92aba42025-10-16 00:00:13 -070022const std::vector<uint16_t> testSuccessReadHoldingRegisterResponse = {
23 0x1234, 0x5678};
Jagpal Singh Gilla32d2412025-10-01 14:55:05 -070024constexpr uint16_t testFailureReadHoldingRegister = 0x0105;
25
Jagpal Singh Gillcad9ecf2025-10-22 19:53:16 -070026// Device Inventory Testing Constants
27constexpr uint16_t testReadHoldingRegisterModelOffset = 0x0112;
28constexpr uint16_t testReadHoldingRegisterModelCount = 0x8;
Jagpal Singh Gille92aba42025-10-16 00:00:13 -070029const std::vector<uint16_t> testReadHoldingRegisterModel = {
30 0x5244, 0x4630, 0x3430, 0x4453, 0x5335, 0x3139, 0x0000, 0x3000};
Jagpal Singh Gillcad9ecf2025-10-22 19:53:16 -070031constexpr std::string testReadHoldingRegisterModelStr = "RDF040DSS519";
32
Jagpal Singh Gille92aba42025-10-16 00:00:13 -070033// Device Sensors Testing Constants
34constexpr uint16_t testReadHoldingRegisterTempCount = 0x1;
35constexpr uint16_t testReadHoldingRegisterTempUnsignedOffset = 0x0113;
36const std::vector<uint16_t> testReadHoldingRegisterTempUnsigned = {
37 0x0050}; // 80.0
38constexpr uint16_t testReadHoldingRegisterTempSignedOffset = 0x0114;
39const std::vector<uint16_t> testReadHoldingRegisterTempSigned = {
40 0xFFB0}; // -80.0
41
42static const std::map<uint16_t, std::tuple<uint16_t, std::vector<uint16_t>>>
43 testReadHoldingRegisterMap = {
44 {testSuccessReadHoldingRegisterOffset,
45 {testSuccessReadHoldingRegisterCount,
46 testSuccessReadHoldingRegisterResponse}},
47 {testSuccessReadHoldingRegisterSegmentedOffset,
48 {testSuccessReadHoldingRegisterCount,
49 testSuccessReadHoldingRegisterResponse}},
50 {testReadHoldingRegisterModelOffset,
51 {testReadHoldingRegisterModelCount, testReadHoldingRegisterModel}},
52 {testReadHoldingRegisterTempUnsignedOffset,
53 {testReadHoldingRegisterTempCount,
54 testReadHoldingRegisterTempUnsigned}},
55 {testReadHoldingRegisterTempSignedOffset,
56 {testReadHoldingRegisterTempCount, testReadHoldingRegisterTempSigned}},
57};
58
Jagpal Singh Gilla32d2412025-10-01 14:55:05 -070059class ServerTester
60{
61 public:
62 explicit ServerTester(sdbusplus::async::context& ctx, int fd);
63
64 auto processRequests() -> sdbusplus::async::task<void>;
65
66 private:
67 void processMessage(MessageIntf& request, size_t requestSize,
68 MessageIntf& response, bool& segmentedResponse);
69
70 void processReadHoldingRegisters(MessageIntf& request, size_t requestSize,
71 MessageIntf& response,
72 bool& segmentedResponse);
73
74 int fd;
75 sdbusplus::async::fdio fdioInstance;
Jagpal Singh Gillcad9ecf2025-10-22 19:53:16 -070076 sdbusplus::async::mutex mutex;
Jagpal Singh Gilla32d2412025-10-01 14:55:05 -070077};
78} // namespace phosphor::modbus::test